|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <!-- Global site tag (gtag.js) - Google Analytics --> |
| 5 | + <script async src="https://www.googletagmanager.com/gtag/js?id=UA-123451981-1"></script> |
| 6 | + <script> |
| 7 | + window.dataLayer = window.dataLayer || []; |
| 8 | + function gtag(){dataLayer.push(arguments);} |
| 9 | + gtag('js', new Date()); |
| 10 | + |
| 11 | + gtag('config', 'UA-123451981-1'); |
| 12 | + </script> |
| 13 | + <meta charset="utf-8"> |
| 14 | + <meta http-equiv="X-UA-Compatible" content="chrome=1"> |
| 15 | + <title>PythonBRMLtoolbox by MauroCE</title> |
| 16 | + |
| 17 | + <link rel="stylesheet" href="stylesheets/styles.css"> |
| 18 | + <link rel="stylesheet" href="stylesheets/github-dark.css"> |
| 19 | + <script src="javascripts/scale.fix.js"></script> |
| 20 | + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> |
| 21 | + |
| 22 | + <!--[if lt IE 9]> |
| 23 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 24 | + <![endif]--> |
| 25 | + </head> |
| 26 | + <body> |
| 27 | + <div class="wrapper"> |
| 28 | + <header> |
| 29 | + <h1>PythonBRMLtoolbox</h1> |
| 30 | + <p>Python Version of BRML toolbox for Bayesian Reasoning and Machine Learning</p> |
| 31 | + <p class="view"><a href="https://github.com/MauroCE/PythonBRMLtoolbox">View the Project on GitHub <small>MauroCE/PythonBRMLtoolbox</small></a></p> |
| 32 | + <ul> |
| 33 | + <li><a href="https://github.com/MauroCE/PythonBRMLtoolbox/zipball/master">Download <strong>ZIP File</strong></a></li> |
| 34 | + <li><a href="https://github.com/MauroCE/PythonBRMLtoolbox/tarball/master">Download <strong>TAR Ball</strong></a></li> |
| 35 | + <li><a href="https://github.com/MauroCE/PythonBRMLtoolbox">View On <strong>GitHub</strong></a></li> |
| 36 | + </ul> |
| 37 | + </header> |
| 38 | + <section> |
| 39 | + <h1> |
| 40 | +<a id="what" class="anchor" href="#what" aria-hidden="true"><span class="octicon octicon-link"></span></a>What is PythonBRMLtoolbox?</h1> |
| 41 | + |
| 42 | +<p> |
| 43 | +<a href="http://web4.cs.ucl.ac.uk/staff/D.Barber/pmwiki/pmwiki.php?n=Brml.Software">BRMLtoolbox</a> in Python 3.7. My goal with this repository is to: |
| 44 | + |
| 45 | +<ul> |
| 46 | +<li>Learn BRMLtoolbox with an insider perspective</li> |
| 47 | +<li>Provide a Python package for BRMLtoolbox which is available in MATLAB, Python 2.7 and Julia.</li> |
| 48 | +<li>Improve my Python skills</li> |
| 49 | +</ul> |
| 50 | +</p> |
| 51 | + |
| 52 | +<h2> |
| 53 | +<a id="implementation" class="anchor" href="#implementation" aria-hidden="true"><span class="octicon octicon-link"></span></a>Implementation details</h2> |
| 54 | + |
| 55 | +<p><strong>Variables</strong></p> |
| 56 | + |
| 57 | +<p> When initializing a potential we can pass variables as arguments |
| 58 | + in different ways: |
| 59 | + * We can pass a scalar value (int or float) when we only |
| 60 | + have 1 variable. (We could also pass a list or a numpy array |
| 61 | + with only one value) |
| 62 | + |
| 63 | +<pre class="brush: python"> |
| 64 | +<code> |
| 65 | +import numpy as np |
| 66 | +from brml.array import Array |
| 67 | +pot = Array(variables=1) |
| 68 | +pot2 = Array(variables=1.0) |
| 69 | +pot3 = Array(variables=[1]) |
| 70 | +pot4 = Array(variables=np.array([1])) |
| 71 | +pot5 = Array(variables=np.array([[1]])) |
| 72 | +</code> |
| 73 | +</pre> |
| 74 | + |
| 75 | + * We can pass a list or a numpy.array when we have multiple variables. |
| 76 | + |
| 77 | +<pre class="brush: python"> |
| 78 | +<code> |
| 79 | +import numpy as np |
| 80 | +from brml.array import Array |
| 81 | +pot = Array(variables=[1, 2]) |
| 82 | +pot2 = Array(variables=np.array([1, 2])) |
| 83 | +pot3 = Array(variables=np.array([[1, 2]])) |
| 84 | +pot4 = Array(variables=np.array([[1], [2]])) |
| 85 | +</code> |
| 86 | +</pre> |
| 87 | + |
| 88 | +All of these calls are equivalent among them because they are all converted to |
| 89 | +a 1D numpy.array (notice that in MATLAB, because 1D arrays don't exist, this |
| 90 | +is different). |
| 91 | +It might be good to discuss whether it is better to convert all of these to 1D |
| 92 | +numpy.array or to a 2D array with shape (1, n) where n is the number of |
| 93 | +variables. |
| 94 | + |
| 95 | +It is worth mentioning that you don't need to pass variables on initialization. |
| 96 | +You can initialize an array without variables and without table, and add the later. |
| 97 | +For example: |
| 98 | + |
| 99 | +<pre class="brush: python"> |
| 100 | +<code> |
| 101 | +import numpy as np |
| 102 | +from brml.array import Array |
| 103 | +pot = Array() |
| 104 | +pot.set_variables(np.array([1, 2])) |
| 105 | +</code> |
| 106 | +</pre> |
| 107 | + |
| 108 | +Notice, however, that you CANNOT initialize variables before initializing the table. |
| 109 | +That is, you cannot initialize an empty array pot = Array() and then call |
| 110 | +pot.set_table(np.array([0.4, 0.6])) because this will throw an error. You must |
| 111 | +first use set_variables method, and after use the set_table method. If, instead, |
| 112 | +you decide to pass variables and table on initialization, then everything will be fine. |
| 113 | + |
| 114 | +Go to check/potential_variables.py and you'll find a test to check |
| 115 | +that the statements above are correct!</p> |
| 116 | + |
| 117 | +<h2> |
| 118 | +<a id="what-BRML" class="anchor" href="#what-BRML" aria-hidden="true"><span class="octicon octicon-link"></span></a>What is BRMLtoolbox?</h2> |
| 119 | + |
| 120 | +<p> The BRMLtoolbox is a MATLAB toolbox written by David Barber, Reader for the Computational Statistics and Machine Learning MSc at UCL. The toolbox should be used together with the book Bayesian Reasoning and Machine Learning. It is a set of tools to help readers see how mathematical models translate into actual code. |
| 121 | + </p> |
| 122 | + |
| 123 | +<h2> |
| 124 | +<a id="software" class="anchor" href="#software" aria-hidden="true"><span class="octicon octicon-link"></span></a>Software Requirements</h2> |
| 125 | + |
| 126 | +<ul> |
| 127 | +<li>Python (3.6 onwards, although only type hints would need to be removed for Python 3.5)</li> |
| 128 | +<li> Numpy</li> |
| 129 | +</ul> |
| 130 | + |
| 131 | + |
| 132 | +<h2> |
| 133 | +<a id="math" class="anchor" href="#math" aria-hidden="true"><span class="octicon octicon-link"></span></a>Mathematical Requirements</h2> |
| 134 | + |
| 135 | +<ul> |
| 136 | +<li>Calculus & Linear Algebra</li> |
| 137 | +<li> Probability</li> |
| 138 | +<li> Algorithms</li> |
| 139 | +<li> Statistics (Bayesian Mainly)</li> |
| 140 | +</ul> |
| 141 | + |
| 142 | +<p>I am currenlty trying to write an introduction to Probability here in <a href="https://proofwiki.org/wiki/User:MauroCamaraEscudero">my Proofwiki account</a>, although it is just a draft for now.</p> |
| 143 | + |
| 144 | + |
| 145 | +<h2> |
| 146 | +<a id="contr" class="anchor" href="#contr" aria-hidden="true"><span class="octicon octicon-link"></span></a>Contributions</h2> |
| 147 | + |
| 148 | +<p>Please feel free to contribute to this project! There are already a few incomplete implementations of the code, hopefully this version will be more up-to-date and efficient with your help!</p> |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +<h2> |
| 153 | +<a id="ref" class="anchor" href="#ref" aria-hidden="true"><span class="octicon octicon-link"></span></a>References</h2> |
| 154 | + |
| 155 | +<p> As I said earlier BRMLtoolbox comes with <a href="http://web4.cs.ucl.ac.uk/staff/D.Barber/textbook/090310.pdf">Bayesian Reasoning and Machine Learning</a> book. |
| 156 | + </p> |
| 157 | + |
| 158 | +<pre><code> |
| 159 | +@BOOK{barberBRML2012, |
| 160 | +author = {Barber, D.}, |
| 161 | +title= {{Bayesian Reasoning and Machine Learning}}, |
| 162 | +publisher = {{Cambridge University Press}}, |
| 163 | +year = 2012} |
| 164 | +</code></pre> |
| 165 | + |
| 166 | + |
| 167 | + </section> |
| 168 | + </div> |
| 169 | + <footer> |
| 170 | + <p>Project maintained by <a href="https://github.com/MauroCE">MauroCE</a></p> |
| 171 | + <p>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></p> |
| 172 | + </footer> |
| 173 | + <!--[if !IE]><script>fixScale(document);</script><![endif]--> |
| 174 | + |
| 175 | + </body> |
| 176 | +</html> |
0 commit comments