Comments (4)
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.
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.
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.
Ok, thanks!
from bayespy.
Related Issues (20)
- ImageComparisonFailure error during tests HOT 1
- Creating Gaussian Node Raises Error HOT 4
- Extended Marble Example HOT 1
- Fast Variational Bayesian Linear State-Space Model HOT 2
- Performance Doubt HOT 3
- Implamenting
- How to approach bayesian?
- Online/Iterative Learning for Bayespy?
- Higher order Markov chains? HOT 3
- Anaconda install of bayespy causes a downgrade of ipython HOT 6
- Gate for Non Categorical Variable HOT 4
- How to extract posterior over latent states from CategoricalMarkovChain HOT 2
- Remove deprecated time.clock() call HOT 1
- Array of counts doesn't work in multinomial mixture HOT 2
- Using the posterior distribution? HOT 1
- Gaussian mixture HOT 2
- Increase the usage of augmented assignment statements
- Errors in the demos HOT 1
- More projects for "Similar projects"
- Equations not showing in docs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bayespy.