by

## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
cool, let me try it... :)
Jaakko Luttinen
@jluttine
and you can have plates in Z_new if you want it to contain more than one variable, for instance if you're learning sequentially using mini-batches
Yay!
It works!
bn4 = BayesianNetwork.objects.get(name="bn4")
Y = bn4.nodes.get(name="Y")
y = Y.get_data()
Y_eo = bn4.get_engine_object()["Y"]
alpha_eo = bn4.get_engine_object()["alpha"]
Z_eo = bn4.get_engine_object()["alpha"]
mu_eo = bn4.get_engine_object()["mu"]
Lambda_eo = bn4.get_engine_object()["Lambda"]
Q = bp.inference.VB(Y_eo, alpha_eo, Z_eo, mu_eo, Lambda_eo)
Y_eo.observe(y)
Q.update(repeat=1000)
##
Z_new = bp.nodes.Categorical(alpha_eo)
Z_new.initialize_from_random()
Y_new = bp.nodes.Mixture(Z_new, bp.nodes.Gaussian, mu_eo, Lambda_eo)
Y_new.observe([30.2, 29.8])
Q_0 = bp.inference.VB(Z_new, Y_new, Y_eo, alpha_eo, Z_eo, mu_eo, Lambda_eo)
Q_0.update(Z_new)
print(Z_new.get_moments())
(although I'm seeing now that Z_eo is pointing to alpha, but nevermind...)
Jaakko Luttinen
@jluttine
ok, nice!
Iteration 1: loglike=-1.098049e+03 (0.003 seconds)
[array([  0.00000000e+000,   5.14238102e-187,   0.00000000e+000,
0.00000000e+000,   0.00000000e+000,   1.53892421e-221,
0.00000000e+000,   8.68501324e-151,   0.00000000e+000,
1.00000000e+000])]
Now I have to see how to wrap it
Is there a way of sending the new nodes to the existing Q?
I mean, without redefining it?
Jaakko Luttinen
@jluttine
you don't even have to use VB object. it's just a convenience class. you can just use nodes directly, like Z.update(). you can create a new VB object from old one like: Q_new = VB(new_node1, new_node2, *Q.model)
you can also try adding a node to existing Q like: Q.model.append(new_node) but that's not recommended as you bypass some checkings so you may accidentally do something wrong. but in principle that works, perhaps
Oh, that's cool :)
thanks a lot for the help and your time
Jaakko Luttinen
@jluttine
no problem!
eykiriku
@eykiriku
Assume I have an observation node that instead of being Categorical like the activity node here (http://bayespy.org/examples/hmm.html), it represents the degree of activation of fuzzy rules: 80% walk and 20% shop are active. What node model should I use instead of Categorical to allow inference with observations that result from fuzzy sets?
Jaakko Luttinen
@jluttine
do you mean that you're knowledge about whether walk or shop is p(walk)=0.8 and p(shop)=0.2, or what is the meaning of those percentages?
eykiriku
@eykiriku
say this graph is yawning frequency per minute, my input is approx. 2.5 yawning per minute which will have a 80% activation of the high rule and 20% of the normal rule
in short, yes you were right
Jaakko Luttinen
@jluttine
if you observe probabilities, maybe one can use beta or dirichlet node. if you have noisy observations of a categorical variable, maybe you can add a noisy observed categorical variable that has the true (unknown) state as a parent.
s/probabilities/probabilities or some other variables that are positive and sum to one/
eykiriku
@eykiriku
true, thanks
eykiriku
@eykiriku
my problem was more related to bayespy, like assume i choose a dirichlet observation node Y. Y has 2 states, Normal and High. As above, any evidence will belong to the array [0, 5] and the fuzzy rules may lead to an output saying 80% activation of high and 20%.... My doubt is how to define the variable 'activity', the one to be observed for inference in Y.observe(activity), using this fuzzy ouput
@jluttine , Hi! Maybe you know why I can't fix the seed of the random number generator with np.random.seed()? Is it not the seed that must fix? I'm trying to obtain the same results in likelihood in different runs without success... :S
it seems silly, but I can't find a way in django tests to produce the same inference results, because neither np.random.seed or random.seed seems to work... :S
seems that PYTHONHASHSEED=number makes it work
Jaakko Luttinen
@jluttine
Marvie Demit
hi @jluttine I am starting to use bayespy and I want to make a wrapper function fitting gaussian mixture for model selection.
def fitted_gaussian(N, n_krnl, D, covariance = 'full'):
# Input:
# N = Number of data vectors
# D = Dimensionality
# n_krnl = Number of kernels
# Prior
P = nds.Dirichlet(1e-5*np.ones(n_krnl), name='P')
# N n_krnl-dimensional cluster (for the data)
I = nds.Categorical(P, plates=(N,), name='I')
# n_krnl D-dimensional components means
if covariance == 'full':
# n_krnl D-dim component covariance
mu = nds.Gaussian(np.zeros(D), 1e-5*np.identity(D), plates = (n_krnl,), name = 'mu')
Lambda = nds.Wishart(D, 1e-5*np.identity(D), plates = (n_krnl,), name = 'Lambda')
Y = nds.Mixture(I, nds.Gaussian, mu, Lambda, plates = (N,),  name = 'Y')
else:
print('diagonal')
# inverse variances
mu = nds.GaussianARD(np.zeros(D), 1e-5*np.identity(D), shape = (D,), plates = (n_krnl,), name = 'mu')
Lambda = nds.Gamma(1e-3, 1e-3, plates = (n_krnl, D), name = 'Lambda')
Y = nds.Mixture(I, nds.GaussianARD, mu, Lambda, plates = (N,),  name = 'Y')
I.initialize_from_random()
return VB(Y, mu, Lambda, I, P)
the problem is that I get this when I apply it with the diagonal; ValueError: The plates (2,) of the parents are not broadcastable to the given plates (10,).
How can I fix this?
Jaakko Luttinen
@jluttine
Jaakko Luttinen
@jluttine
Don_Chili_twitter: can't really test now but i guess the issue is that GaussianARD makes scalar gaussian variables by default. in principle, you should be able to fix it by giving ndim=1 to Mixture but i think it doesn't work atm. alternatively, you can create a diagonal matrix from Lambda by Lambda.as_diagonal_wishart() and using nds.Gaussian instead of nds.GaussianARD in
Mixture
that is: Y = nds.Mixture(I, nds.Gaussian, mu, Lambda.as_diagonal_wishart(), plates=(N,), name='Y')
couldn't test though
Marvie Demit
Hi @jluttine ! Thank you for your very fast response: n_krnl should be 10. I already tried your recommendation but there is something weird about the plates, although I already tried to make the parent plates the same dimension as the given plates but it never match......ValueError: The plates (2,) of the parents are not broadcastable to the given plates (10,).
Jaakko Luttinen
@jluttine
ok, i'll need to check that with actual python. maybe tomorrow
@jluttine are you there?
Jaakko Luttinen
@jluttine
yep
:)
Hi Jaako, can I ask you for a quick review on a text?
Jaakko Luttinen
@jluttine