Giter Club home page Giter Club logo

Comments (4)

jluttine avatar jluttine commented on June 12, 2024

Thanks for the report!

However, the example code doesn't run because z is not defined. Also, I can't see any use of Mixture node. Could you provide a simple example which gives a different output than you expected and tell what you would have expected to see?

I don't see why would you need to just copy the outcome of the parent deterministically to be the value of the child node. Probably there is a better way to achieve what you want, so you could elaborate a little bit on what it is that you are trying to do.

But as far as I understand, this probably answers your question: Note that if you use random() method for a node, it is not a true generative sampling process. It draws a sample from the current state of the VB factor for that node independently of its parents. So, as p has probabilities [0.5, 0.5], the child node has the same probabilities for each element because of the deterministic mapping. Thus, you'll end up sampling the elements of the child node from [0.5, 0.5]. Note, the key point is that the sampling is done independently of the parent because the distributions of the nodes are independent of other nodes. Thus, it is not a true generative sample.

And a rule of thumb: Don't use stochastic nodes like Mixture to create deterministic (or nearly deterministic) mappings: You'll end up having extremely strongly coupled variables in the posterior but they are approximated to be independent in the VB posterior, so the approximation is most likely extremely bad.

I hope this helps. Please don't hesitate to ask further questions!

from bayespy.

jluttine avatar jluttine commented on June 12, 2024

Was this problem solved (i.e., did my answer explain the weird things you saw) or could you provide a simple example to reproduce the bug at some point so I could take a look?

from bayespy.

viveksck avatar viveksck commented on June 12, 2024

Thanks! Yes I initially tried to use mixture to ensure that a set of categorical variables have the same value dependent on a parent. So if p = 0, I wanted a vector variable all to take [0,0]. If p = 1, I wanted that to take [1,1]. Your comment above indicates that this is not a right way to model and so yes you may close this issue.

Just for clarity, here is my code (apologies for the copy paste error) that I had initially tried:

from bayespy.nodes import Categorical, Mixture
from collections import Counter
import numpy as np
p = Categorical([0.5,0.5])
X = np.array([[[0.999,0.001],[0.999,0.001],[0.999,0.001]],[[0.001,0.999],[0.001,0.999], [0.001,0.999]]])
z = Mixture(p, Categorical, X, cluster_plate=-2)
z.random() #Output: array([1, 1, 0]) << We should never actually see (1,1,0) because when we select a component it should only either yield [0,0,0] or [1,1,1]

#Basically if p =0 , then the first component of the mixture is chosen and so when I draw a sample from it, I expect z to be [0,0,0]. Similarly if p happened to be 1, then I expect z to be [1,1,1]

q = Categorical(X[0], plates=(100,3))  # << This works only [0,0,0] should be returned
#Similarly X[1] Categorical(X[1], plates=(100,3)) only returns [1,1,1]

from bayespy.

jluttine avatar jluttine commented on June 12, 2024

Ok, thanks!

from bayespy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.