NumPy modelling of Belief Tables?
Magnus Lie Hetland
mlh at idi.ntnu.no
Thu Apr 6 12:39:33 EDT 2000
Hi!
I'm dabbling in Bayesian Networks at the moment, and have considered
implementing a system/framework in Python, using NymPy for the
Belief Table calculations... The calculations are quite simple, but I'm not
sure how I should do them all in Numeric Python...
In short, a Belief Table represents a discrete joint probability function
over
a set of variables, where each dimension of the table represents a variable,
and the indices of the dimension represent different values it may take.
When manipulating information in Bayesian Networks, you need to do some
operations on these tables. For instance, you may want to multiply them.
If the tables have the same dimensions (variables) then the standard NumPy
multiplication (i.e. *not* matrix multiplication) applies. Now that's
fine...
But if they *don't* have the same dimensions, then this won't work
directly...
If, for instance, the table t1 has the dimensions X and Y, while t2 has the
dimensions X and Z, then for each x, y, z in X, Y, X,
(t1 * t2)[x,y,z] = t1[x,y] * t2[x,z].
This may be simple to do in NumPy (it is certainly easy to do
algorithmically) - I just can't see how...
Division is about the same thing, except that 0/0 = 0... For tables with the
same dimensions, I guess one could use something like
t1 / where(equal(t2,0),1,t2)
where 1 is just an arbitrary value. (I'm not sure how this solution
generalizes when the dimensions differ...)
The other operation needed is marginalization of the tables. When a table
is marginalized over some of its dimensions, the elements having equal
coordinates in the remaining dimensions (i.e. the ones not being
marginalized
over) are added. For instance, if you have a two-dimensional table, t, over
the variables X and Y, and you want to marginalize out Y, then for each
x in X,
m[x] = sum with x in Y { t[x,y] },
where m is the marginalized table.
If anyone finds these problems interesting, I would appreciate any hints
or solutions.
--
Magnus
Lie
Hetland magnus @ hetland . org
More information about the Python-list
mailing list