diff --git a/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb index 3be9978..3c3f7c4 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb @@ -81,14 +81,14 @@ " \n", " \n", "\n", - "where we have a binary $x$ and $y$ we have p=np.array([[0.2, 0.3],[0.1,0.4]]) where $p(x=0,y=0) = 0.2$, $p(x=0,y=1) = 0.3$, $p(x=1,y=0) = 0.1$, and $p(x=1,y=1) = 0.4$. If the variable $x$ can take more than two values for example, then we will have more than two rows in p (e.g. p = [0.15, 0.1; 0.1, 0.3; 0.15, 0.2]).\n", + "where we have a binary $x$ and $y$ we have p=np.array([[0.2, 0.3],[0.1,0.4]]) where $p(x=0,y=0) = 0.2$, $p(x=0,y=1) = 0.3$, $p(x=1,y=0) = 0.1$, and $p(x=1,y=1) = 0.4$. If the variable $x$ can take more than two values for example, then we will have more than two rows in p (e.g. p = np.array([[0.15, 0.1], [0.1, 0.3], [0.15, 0.2]])).\n", "\n", "1. To fill in the template, you will need to call your existing functions `jointentropy(p)` for $H(X,Y)$ and `entropy(p)` for $H(X)$ and $H(Y)$ to provide the calculations needed. Note that to compute $H(Y)$ you will need to extract $p(y)$ from the $p(x,y)$ matrix by summing over all $x$ rows (as per the activity for conditional entropy in the previous module), whilst for $H(X)$ you will need to extract $p(x)$ from the $p(x,y)$ matrix by summing over all $y$ columns." ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -150,7 +150,7 @@ "source": [ "2. Test that your code works, e.g. by running:\n", " 1. `mutualinformation(np.array([[0.2, 0.3],[ 0.1, 0.4]]))` and validating that you get the result 0.0349 bits. Recall that the conditional entropy computed for this $p(x,y)$ probability table in the previous module was 0.965 bits - is the result for MI sensible with respect to that result?
\n", - " Confirm that MI is symmetric with respect to the input variables by computing `mutualinformation([0.2, 0.1; 0.3, 0.4])`\n", + " Confirm that MI is symmetric with respect to the input variables by computing `mutualinformation(np.array([[0.2, 0.1], [0.3, 0.4]]))`\n", " 1. `mutualinformation(np.array([[0.5, 0],[ 0, 0.5]]))` and validating that you get the result 1 bit.\n", " 1. `mutualinformation(np.array([[0.25, 0.25],[ 0.25, 0.25]]))` and validating that you get the result 0 bits. Can you explain this and the previous result?" ] diff --git a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb index 8adba48..34f05ee 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb @@ -81,7 +81,7 @@ " \n", " \n", "\n", - "where we have a binary $x$ and $y$ we have p=np.array([[0.2, 0.3],[0.1,0.4]]) where $p(x=0,y=0) = 0.2$, $p(x=0,y=1) = 0.3$, $p(x=1,y=0) = 0.1$, and $p(x=1,y=1) = 0.4$. If the variable $x$ can take more than two values for example, then we will have more than two rows in p (e.g. p = [0.15, 0.1; 0.1, 0.3; 0.15, 0.2]).\n", + "where we have a binary $x$ and $y$ we have p=np.array([[0.2, 0.3],[0.1,0.4]]) where $p(x=0,y=0) = 0.2$, $p(x=0,y=1) = 0.3$, $p(x=1,y=0) = 0.1$, and $p(x=1,y=1) = 0.4$. If the variable $x$ can take more than two values for example, then we will have more than two rows in p (e.g. p = np.array([[0.15, 0.1], [0.1, 0.3], [0.15, 0.2]])).\n", "\n", "1. To fill in the template, you will need to call your existing functions `jointentropy(p)` for $H(X,Y)$ and `entropy(p)` for $H(X)$ and $H(Y)$ to provide the calculations needed. Note that to compute $H(Y)$ you will need to extract $p(y)$ from the $p(x,y)$ matrix by summing over all $x$ rows (as per the activity for conditional entropy in the previous module), whilst for $H(X)$ you will need to extract $p(x)$ from the $p(x,y)$ matrix by summing over all $y$ columns." ] @@ -150,7 +150,7 @@ "source": [ "2. Test that your code works, e.g. by running:\n", " 1. `mutualinformation(np.array([[0.2, 0.3],[ 0.1, 0.4]]))` and validating that you get the result 0.0349 bits. Recall that the conditional entropy computed for this $p(x,y)$ probability table in the previous module was 0.965 bits - is the result for MI sensible with respect to that result?
\n", - " Confirm that MI is symmetric with respect to the input variables by computing `mutualinformation([0.2, 0.1; 0.3, 0.4])`\n", + " Confirm that MI is symmetric with respect to the input variables by computing `mutualinformation(np.array([[0.2, 0.1], [0.3, 0.4]]))`\n", " 1. `mutualinformation(np.array([[0.5, 0],[ 0, 0.5]]))` and validating that you get the result 1 bit.\n", " 1. `mutualinformation(np.array([[0.25, 0.25],[ 0.25, 0.25]]))` and validating that you get the result 0 bits. Can you explain this and the previous result?" ]