Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python 3.7 version of David Barber's MATLAB BRMLtoolbox

License

NotificationsYou must be signed in to change notification settings

MauroCE/PythonBRMLtoolbox

Repository files navigation

What is PythonBRMLtoolbox?

BRMLtoolboxin Python 3.7. My goal with this repository is to:

  1. Learn BRMLtoolbox with an insider perspective
  2. Provide a Python package for BRMLtoolbox which is availablein MATLAB, Python 2.7 and Julia.
  3. Improve my Python skills

Implementation details

Variables

When initializing a potential we can pass variables as argumentsin different ways:

  • We can pass a scalar value (int orfloat) when we onlyhave 1 variable. (We could also pass a list or a numpy arraywith only one value)
importnumpyasnpfrombrml.arrayimportArraypot=Array(variables=1)pot2=Array(variables=1.0)pot3=Array(variables=[1])pot4=Array(variables=np.array([1]))pot5=Array(variables=np.array([[1]]))
  • We can pass alist or anumpy.array when we have multiple variables.
importnumpyasnpfrombrml.arrayimportArraypot=Array(variables=[1,2])pot2=Array(variables=np.array([1,2]))pot3=Array(variables=np.array([[1,2]]))pot4=Array(variables=np.array([[1], [2]]))

All of these calls are equivalent among them because they are all converted toa 1Dnumpy.array (notice that in MATLAB, because 1D arrays don't exist, thisis different).It might be good to discuss whether it is better to convert all of these to 1Dnumpy.array or to a 2D array with shape(1, n) wheren is the number ofvariables.

It is worth mentioning that you don't need to pass variables on initialization.You can initialize an array without variables and without table, and add the later.For example:

importnumpyasnpfrombrml.arrayimportArraypot=Array()pot.set_variables(np.array([1,2]))

Notice, however, that you CANNOT initialize variables before initializing the table.That is, you cannot initialize an empty arraypot = Array() and then callpot.set_table(np.array([0.4, 0.6])) because this will throw an error. You mustfirst useset_variables method, and after use theset_table method. If, instead,you decide to pass variables and table on initialization, then everything will be fine.

Go tocheck/potential_variables.py and you'll find a test to checkthat the statements above are correct!

What is BRMLtoolbox?

The BRMLtoolbox is a MATLAB toolbox written by David Barber, Reader for the Computational Statistics and Machine Learning MSc at UCL. The BRML 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.

Software Requirements

  1. Python (3.6 onwards, although only type hints would need to be removed for Python 3.5)
  2. Numpy

Mathematical Requirements

The mathematical requirements for understanding classes within BRML toolbox are:

  1. Calculus & Linear Algebra
  2. Probability
  3. Algorithms
  4. Statistics (Bayesian mainly)I am currenlty trying to write an introduction to Probability here inmy Proofwiki account, although it is just a draft for now.

Contributions

Please feel free to contribute to this python version of the BRML toolbox! There are already a few incomplete implementations of the code, hopefully this version will be more up-to-date and efficient with your help!

Reference & Book

As I said earlier BRML toolbox comes withBayesian Reasoning and Machine Learning book.

@BOOK{barberBRML2012,author = {Barber, D.},title= {{Bayesian Reasoning and Machine Learning}},publisher = {{Cambridge University Press}},year = 2012}

[8]ページ先頭

©2009-2025 Movatter.jp