From 1db1c3ac8c263c3aff10907c3e6b32b56da40bbf Mon Sep 17 00:00:00 2001 From: Joseph Lizier Date: Wed, 14 Aug 2024 09:25:36 +1000 Subject: [PATCH] Made comments in headers for Python simple functions more python like (referring to numpy arrays etc) --- .../Module_1_notebook.ipynb | 2 +- .../Module_2_notebook.ipynb | 32 +++++------ .../Module_3_notebook.ipynb | 11 ++-- .../Module_4_notebook.ipynb | 6 +-- .../Module_1_notebook_solutions.ipynb | 10 ++-- .../Module_2_notebook_solutions.ipynb | 50 ++++++++--------- .../Module_3_notebook_solutions.ipynb | 15 +++--- .../Module_4_notebook_solutions.ipynb | 14 ++--- .../completed/simpleinfotheory.py | 53 ++++++++++--------- 9 files changed, 100 insertions(+), 93 deletions(-) diff --git a/course/Module01-Entropy/PythonSimpleFunctions/Module_1_notebook.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/Module_1_notebook.ipynb index 9d723f8..1ee9a75 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/Module_1_notebook.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/Module_1_notebook.ipynb @@ -206,7 +206,7 @@ "Computes the Shannon entropy for a probability distribution p.\n", "\n", "Inputs:\n", - "- p - (array which much sum to 1) - a probability distribution to compute the Shannon info content for\n", + "- p - (numpy array or list which much sum to 1) - a probability distribution to compute the Shannon info content for\n", "\n", "Outputs:\n", "- result - Shannon entropy of the probability distribution p\n", diff --git a/course/Module01-Entropy/PythonSimpleFunctions/Module_2_notebook.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/Module_2_notebook.ipynb index 4b3742d..6f84152 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/Module_2_notebook.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/Module_2_notebook.ipynb @@ -74,13 +74,13 @@ "X from samples x_n.\n", "\n", "Inputs:\n", - "- xn - samples of outcomes x.\n", - " xn is a column vector, e.g. xn = [0;0;1;0;1;0;1;1;1;0] for a binary variable.\n", + "- xn - samples of outcomes x as a numpy array or a list,\n", + " e.g. xn = [0,0,1,0,1,0,1,1,1,0] for a binary variable.\n", "\n", "Outputs:\n", "- result - Shannon entropy over all outcomes\n", - "- symbols - list of unique samples\n", - "- probabilities - probabilities for each sample\n", + "- symbols - numpy array of unique samples\n", + "- probabilities - numpy array of probabilities for each sample\n", "\n", "Copyright (C) 2020-, Julio Correa, Joseph T. Lizier\n", "Distributed under GNU General Public License v3\n", @@ -199,10 +199,11 @@ "\n", "Inputs:\n", "- p - probability distribution function over all outcome vectors x.\n", - " p is a matrix over all combinations of the sub-variables of x,\n", - "where p(1,3) gives the probability of the first symbol of sub-variable\n", + " p is a numpy matrix (or list of lists) over all combinations of the sub-variables of x,\n", + "where p[0,2] gives the probability of the first symbol of sub-variable\n", "x1 co-occuring with the third symbol of sub-variable x2.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]])\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - joint Shannon entropy of the probability distribution p\n", @@ -275,7 +276,7 @@ "if they don't wish to join them outside of the call.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples\n", + "- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples\n", " (in which case yn is also supplied), or\n", " a 2D matrix, where each row is a vector sample for a multivariate X\n", " (in which case yn is not supplied).\n", @@ -284,8 +285,8 @@ "\n", "Outputs:\n", "- result - joint Shannon entropy over all samples\n", - "- symbols - list of unique joint vector samples\n", - "- probabilities - probabilities for each joint symbol\n", + "- symbols - numpy array of unique joint vector samples\n", + "- probabilities - numpy array of probabilities for each joint symbol\n", "\n", "Copyright (C) 2020-, Julio Correa, Joseph T. Lizier\n", "Distributed under GNU General Public License v3\n", @@ -377,10 +378,11 @@ "\n", "Inputs:\n", "- p - 2D probability distribution function over all outcomes (x,y).\n", - " p is a matrix over all combinations of x and y,\n", - "where p(1,3) gives the probability of the first symbol of variable\n", + " p is a numpy matrix over all combinations of x and y,\n", + "where p[0, 2] gives the probability of the first symbol of variable\n", "x co-occuring with the third symbol of variable y.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = nump.array([[0.2, 0.3], [0.1, 0.4]]).\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - conditional Shannon entropy of X given Y\n", @@ -476,9 +478,9 @@ "variable X, given samples yn of a random variable Y.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- yn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", "\n", diff --git a/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb index 4f62899..0dbda49 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/Module_3_notebook.ipynb @@ -100,10 +100,11 @@ "\n", "Inputs:\n", "- p - 2D probability distribution function over all outcomes (x,y).\n", - " p is a matrix over all combinations of x and y,\n", - "where p(1,3) gives the probability of the first symbol of variable\n", + " p is a numpy matrix (or list of lists) over all combinations of x and y,\n", + "where p[0,2] gives the probability of the first symbol of variable\n", "x co-occuring with the third symbol of variable y.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]]).\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - mutual information of X with Y\n", @@ -210,9 +211,9 @@ "variable X with samples yn of a random variable Y.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- yn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", "\n", diff --git a/course/Module01-Entropy/PythonSimpleFunctions/Module_4_notebook.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/Module_4_notebook.ipynb index b931bda..042c5f1 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/Module_4_notebook.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/Module_4_notebook.ipynb @@ -75,12 +75,12 @@ "samples zn of a random variable Z.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes y. May be a 1D vector of samples, or\n", + "- yn - numpy matrix of samples of outcomes y. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", - "- zn - matrix of samples of outcomes z. May be a 1D vector of samples, or\n", + "- zn - numpy matrix of samples of outcomes z. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Z\n", " which will be conditioned on.\n", " Must have the same number of rows as X.\n", diff --git a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_1_notebook_solutions.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_1_notebook_solutions.ipynb index 7734226..c6feaeb 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_1_notebook_solutions.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_1_notebook_solutions.ipynb @@ -247,7 +247,7 @@ "Computes the Shannon entropy for a probability distribution p.\n", "\n", "Inputs:\n", - "- p - (array which much sum to 1) - a probability distribution to compute the Shannon info content for\n", + "- p - (numpy array or list which much sum to 1) - a probability distribution to compute the Shannon info content for\n", "\n", "Outputs:\n", "- result - Shannon entropy of the probability distribution p\n", @@ -303,9 +303,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_617811/3406804068.py:20: RuntimeWarning: divide by zero encountered in log2\n", + "/tmp/ipykernel_1348680/3406804068.py:20: RuntimeWarning: divide by zero encountered in log2\n", " return -np.log2(p)\n", - "/tmp/ipykernel_617811/1887577405.py:28: RuntimeWarning: invalid value encountered in multiply\n", + "/tmp/ipykernel_1348680/253220426.py:28: RuntimeWarning: invalid value encountered in multiply\n", " weightedShannonInfos = p*(infocontent(p))\n" ] } @@ -349,9 +349,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_617811/3406804068.py:20: RuntimeWarning: divide by zero encountered in log2\n", + "/tmp/ipykernel_1348680/3406804068.py:20: RuntimeWarning: divide by zero encountered in log2\n", " return -np.log2(p)\n", - "/tmp/ipykernel_617811/1887577405.py:28: RuntimeWarning: invalid value encountered in multiply\n", + "/tmp/ipykernel_1348680/253220426.py:28: RuntimeWarning: invalid value encountered in multiply\n", " weightedShannonInfos = p*(infocontent(p))\n" ] }, diff --git a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_2_notebook_solutions.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_2_notebook_solutions.ipynb index c110f7c..1c6b07a 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_2_notebook_solutions.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_2_notebook_solutions.ipynb @@ -74,13 +74,13 @@ "X from samples x_n.\n", "\n", "Inputs:\n", - "- xn - samples of outcomes x.\n", - " xn is a column vector, e.g. xn = [0;0;1;0;1;0;1;1;1;0] for a binary variable.\n", + "- xn - samples of outcomes x as a numpy array or a list,\n", + " e.g. xn = [0,0,1,0,1,0,1,1,1,0] for a binary variable.\n", "\n", "Outputs:\n", "- result - Shannon entropy over all outcomes\n", - "- symbols - list of unique samples\n", - "- probabilities - probabilities for each sample\n", + "- symbols - numpy array of unique samples\n", + "- probabilities - numpy array of probabilities for each sample\n", "\n", "Copyright (C) 2020-, Julio Correa, Joseph T. Lizier\n", "Distributed under GNU General Public License v3\n", @@ -136,8 +136,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1.0\n", - "2.0\n" + "1.0\n" ] } ], @@ -146,8 +145,7 @@ "(result, symbols, probabilities) = entropyempirical([0,0,1,1])\n", "print( result )\n", "# Other cases:\n", - "(result, symbols, probabilities) = entropyempirical([0,0,1,1,2,2,3,3])\n", - "print( result )\n" + "(result, symbols, probabilities) = entropyempirical([0,0,1,1,2,2,3,3])\n" ] }, { @@ -192,9 +190,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "1.0\n", - "0.9987271686073539\n", - "1.9969914126082884\n" + "0.9709505944546686\n", + "0.9999884584088952\n", + "1.999117638235098\n" ] } ], @@ -244,10 +242,11 @@ "\n", "Inputs:\n", "- p - probability distribution function over all outcome vectors x.\n", - " p is a matrix over all combinations of the sub-variables of x,\n", - "where p(1,3) gives the probability of the first symbol of sub-variable\n", + " p is a numpy matrix (or list of lists) over all combinations of the sub-variables of x,\n", + "where p[0,2] gives the probability of the first symbol of sub-variable\n", "x1 co-occuring with the third symbol of sub-variable x2.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]])\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - joint Shannon entropy of the probability distribution p\n", @@ -294,9 +293,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/home/joseph/Dropbox/Work/Teaching/USyd/CSYS5030-InfoTheoryAndSelfOrg/Lectures/Module1-Entropy/PythonCode/completed/simpleinfotheory.py:23: RuntimeWarning: divide by zero encountered in log2\n", + "/home/joseph/JIDT/course/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py:23: RuntimeWarning: divide by zero encountered in log2\n", " return -np.log2(p)\n", - "/home/joseph/Dropbox/Work/Teaching/USyd/CSYS5030-InfoTheoryAndSelfOrg/Lectures/Module1-Entropy/PythonCode/completed/simpleinfotheory.py:48: RuntimeWarning: invalid value encountered in multiply\n", + "/home/joseph/JIDT/course/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py:52: RuntimeWarning: invalid value encountered in multiply\n", " weightedShannonInfos = p*(infocontent(p))\n" ] } @@ -342,7 +341,7 @@ "if they don't wish to join them outside of the call.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples\n", + "- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples\n", " (in which case yn is also supplied), or\n", " a 2D matrix, where each row is a vector sample for a multivariate X\n", " (in which case yn is not supplied).\n", @@ -351,8 +350,8 @@ "\n", "Outputs:\n", "- result - joint Shannon entropy over all samples\n", - "- symbols - list of unique joint vector samples\n", - "- probabilities - probabilities for each joint symbol\n", + "- symbols - numpy array of unique joint vector samples\n", + "- probabilities - numpy array of probabilities for each joint symbol\n", "\n", "Copyright (C) 2020-, Julio Correa, Joseph T. Lizier\n", "Distributed under GNU General Public License v3\n", @@ -407,7 +406,7 @@ "text": [ "2.0\n", "1.0\n", - "2.997035867545411\n" + "2.996212691342311\n" ] } ], @@ -459,10 +458,11 @@ "\n", "Inputs:\n", "- p - 2D probability distribution function over all outcomes (x,y).\n", - " p is a matrix over all combinations of x and y,\n", - "where p(1,3) gives the probability of the first symbol of variable\n", + " p is a numpy matrix over all combinations of x and y,\n", + "where p[0, 2] gives the probability of the first symbol of variable\n", "x co-occuring with the third symbol of variable y.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = nump.array([[0.2, 0.3], [0.1, 0.4]]).\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - conditional Shannon entropy of X given Y\n", @@ -582,9 +582,9 @@ "variable X, given samples yn of a random variable Y.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- yn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", "\n", 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 f9ddc75..a6cc00c 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_3_notebook_solutions.ipynb @@ -100,10 +100,11 @@ "\n", "Inputs:\n", "- p - 2D probability distribution function over all outcomes (x,y).\n", - " p is a matrix over all combinations of x and y,\n", - "where p(1,3) gives the probability of the first symbol of variable\n", + " p is a numpy matrix (or list of lists) over all combinations of x and y,\n", + "where p[0,2] gives the probability of the first symbol of variable\n", "x co-occuring with the third symbol of variable y.\n", - " E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1.\n", + " E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]]).\n", + " The sum over p must be 1.\n", "\n", "Outputs:\n", "- result - mutual information of X with Y\n", @@ -172,9 +173,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/home/joseph/Dropbox/Work/Teaching/USyd/CSYS5030-InfoTheoryAndSelfOrg/Lectures/Module1-Entropy/PythonCode/completed/simpleinfotheory.py:23: RuntimeWarning: divide by zero encountered in log2\n", + "/home/joseph/JIDT/course/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py:23: RuntimeWarning: divide by zero encountered in log2\n", " return -np.log2(p)\n", - "/home/joseph/Dropbox/Work/Teaching/USyd/CSYS5030-InfoTheoryAndSelfOrg/Lectures/Module1-Entropy/PythonCode/completed/simpleinfotheory.py:48: RuntimeWarning: invalid value encountered in multiply\n", + "/home/joseph/JIDT/course/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py:52: RuntimeWarning: invalid value encountered in multiply\n", " weightedShannonInfos = p*(infocontent(p))\n" ] } @@ -255,9 +256,9 @@ "variable X with samples yn of a random variable Y.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- yn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", "\n", diff --git a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_4_notebook_solutions.ipynb b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_4_notebook_solutions.ipynb index 2037c25..b440cdf 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_4_notebook_solutions.ipynb +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/Module_4_notebook_solutions.ipynb @@ -75,12 +75,12 @@ "samples zn of a random variable Z.\n", "\n", "Inputs:\n", - "- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or\n", + "- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate X.\n", - "- yn - matrix of samples of outcomes y. May be a 1D vector of samples, or\n", + "- yn - numpy matrix of samples of outcomes y. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Y.\n", " Must have the same number of rows as X.\n", - "- zn - matrix of samples of outcomes z. May be a 1D vector of samples, or\n", + "- zn - numpy matrix of samples of outcomes z. May be a 1D vector of samples, or\n", " a 2D matrix, where each row is a vector sample for a multivariate Z\n", " which will be conditioned on.\n", " Must have the same number of rows as X.\n", @@ -151,10 +151,10 @@ "0.0\n", "1.0\n", "1.0\n", - "I(X;Y) = 0.0004 bits\n", - "I(Z;Y) = 0.0004 bits\n", - "I(X;Y|Z) = 0.9995 bits\n", - "I(Z;Y|X) = 0.9995 bits\n" + "I(X;Y) = 0.0001 bits\n", + "I(Z;Y) = 0.0013 bits\n", + "I(X;Y|Z) = 0.9987 bits\n", + "I(Z;Y|X) = 0.9998 bits\n" ] } ], diff --git a/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py b/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py index 8b984ac..fc36ab7 100644 --- a/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py +++ b/course/Module01-Entropy/PythonSimpleFunctions/completed/simpleinfotheory.py @@ -26,7 +26,7 @@ def infocontent(p): Computes the Shannon entropy for a probability distribution p. Inputs: -- p - (array which much sum to 1) - a probability distribution to compute the Shannon info content for +- p - (numpy array or list which much sum to 1) - a probability distribution to compute the Shannon info content for Outputs: - result - Shannon entropy of the probability distribution p @@ -62,13 +62,13 @@ Computes the Shannon entropy over all outcomes x of a random variable X from samples x_n. Inputs: -- xn - samples of outcomes x. - xn is a column vector, e.g. xn = [0;0;1;0;1;0;1;1;1;0] for a binary variable. +- xn - samples of outcomes x as a numpy array or a list, + e.g. xn = [0,0,1,0,1,0,1,1,1,0] for a binary variable. Outputs: - result - Shannon entropy over all outcomes -- symbols - list of unique samples -- probabilities - probabilities for each sample +- symbols - numpy array of unique samples +- probabilities - numpy array of probabilities for each sample Copyright (C) 2020-, Julio Correa, Joseph T. Lizier Distributed under GNU General Public License v3 @@ -116,10 +116,11 @@ vector x. Inputs: - p - probability distribution function over all outcome vectors x. - p is a matrix over all combinations of the sub-variables of x, -where p(1,3) gives the probability of the first symbol of sub-variable + p is a numpy matrix (or list of lists) over all combinations of the sub-variables of x, +where p[0,2] gives the probability of the first symbol of sub-variable x1 co-occuring with the third symbol of sub-variable x2. - E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1. + E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]]) + The sum over p must be 1. Outputs: - result - joint Shannon entropy of the probability distribution p @@ -146,7 +147,7 @@ variable X from sample vectors x_n. User can call with two such arguments if they don't wish to join them outside of the call. Inputs: -- xn - matrix of samples of outcomes x. May be a 1D vector of samples +- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples (in which case yn is also supplied), or a 2D matrix, where each row is a vector sample for a multivariate X (in which case yn is not supplied). @@ -155,8 +156,8 @@ Inputs: Outputs: - result - joint Shannon entropy over all samples -- symbols - list of unique joint vector samples -- probabilities - probabilities for each joint symbol +- symbols - numpy array of unique joint vector samples +- probabilities - numpy array of probabilities for each joint symbol Copyright (C) 2020-, Julio Correa, Joseph T. Lizier Distributed under GNU General Public License v3 @@ -201,10 +202,11 @@ Probability matrix p(x,y) is given for each candidate outcome Inputs: - p - 2D probability distribution function over all outcomes (x,y). - p is a matrix over all combinations of x and y, -where p(1,3) gives the probability of the first symbol of variable + p is a numpy matrix over all combinations of x and y, +where p[0, 2] gives the probability of the first symbol of variable x co-occuring with the third symbol of variable y. - E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1. + E.g. p = nump.array([[0.2, 0.3], [0.1, 0.4]]). + The sum over p must be 1. Outputs: - result - conditional Shannon entropy of X given Y @@ -241,9 +243,9 @@ Computes the conditional Shannon entropy over all samples xn of a random variable X, given samples yn of a random variable Y. Inputs: -- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or +- xn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate X. -- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or +- yn - numpy matrix (or list of lists) of samples of outcomes x. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate Y. Must have the same number of rows as X. @@ -291,10 +293,11 @@ Probability matrix p(x,y) is given for each candidate outcome Inputs: - p - 2D probability distribution function over all outcomes (x,y). - p is a matrix over all combinations of x and y, -where p(1,3) gives the probability of the first symbol of variable + p is a numpy matrix (or list of lists) over all combinations of x and y, +where p[0,2] gives the probability of the first symbol of variable x co-occuring with the third symbol of variable y. - E.g. p = [0.2, 0.3; 0.1, 0.4]. The sum over p must be 1. + E.g. p = np.array([[0.2, 0.3], [0.1, 0.4]]). + The sum over p must be 1. Outputs: - result - mutual information of X with Y @@ -338,13 +341,13 @@ Computes the mutual information over all samples xn of a random variable X with samples yn of a random variable Y. Inputs: -- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or +- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate X. -- yn - matrix of samples of outcomes x. May be a 1D vector of samples, or +- yn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate Y. Must have the same number of rows as X. -Outputs: +Outputs: (There are additional outputs here in comparison to the solution notebook) - result - mutual information of X with Y - xySymbols - list of unique joint vector samples - xyProbs - probabilities for each joint symbol @@ -463,12 +466,12 @@ variable X with samples yn of a random variable Y, conditioning on samples zn of a random variable Z. Inputs: -- xn - matrix of samples of outcomes x. May be a 1D vector of samples, or +- xn - numpy matrix of samples of outcomes x. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate X. -- yn - matrix of samples of outcomes y. May be a 1D vector of samples, or +- yn - numpy matrix of samples of outcomes y. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate Y. Must have the same number of rows as X. -- zn - matrix of samples of outcomes z. May be a 1D vector of samples, or +- zn - numpy matrix of samples of outcomes z. May be a 1D vector of samples, or a 2D matrix, where each row is a vector sample for a multivariate Z which will be conditioned on. Must have the same number of rows as X.