Giter Club home page Giter Club logo

Comments (5)

jluttine avatar jluttine commented on June 12, 2024

In Z, the number of states is implicitly given by alpha. That is, Z doesn't have K plates axis, instead it is an integer variable in range {0, ..., K-1}, and this range is determined by the dimensionality of alpha. That is, Z doesn't have K repeated variables but each single value is in range {0, ..., K-1}. Thus, you need to remove that plate axis, because that just adds an extra plate axis which has nothing to do with the mixture clusters. The parameter cluster_plate is related to the parameters of the Poisson distribution, that is, rate_parameter has the clusters on the second last plate axis, as you have correctly done. So, I think this should fix:

Z = Categorical(alpha, plates=(NSamples, D))

from bayespy.

jluttine avatar jluttine commented on June 12, 2024

You can also simplify the following line:

rate_parameter = Gamma(alpha, beta, plates=(K,D))

You don't need to do explicit broadcasting with np.ones(D) because broadcasting of plates is done automatically.

from bayespy.

jluttine avatar jluttine commented on June 12, 2024

Also, just noting that you are using separate cluster assignments for each of the D dimensions. If you don't want to do that, this should work:

Z = Categorical(alpha, plates=(NSamples, 1))

But in case you wanted separate cluster assignments for each dimension, then never mind. Just wanted to let you know if you hadn't noticed.

from bayespy.

ckemere avatar ckemere commented on June 12, 2024

Thanks - while I understand the plates in theory, I've been having trouble getting things to align properly once I get to the mixture model (being new to python and broadcasting doesn't help). Below is my updated/working code, where the order of the plate dimensions for the rate_parameter is different than you suggest above. Any advice on symmetry breaking in this model (I get rapid, but nonsensical convergence)?

rate_parameter = Gamma(alpha, beta, plates=(D,K))
a0 = Dirichlet(1e-3*np.ones(K))
Z = Categorical(a0, plates=(NSamples, 1))
Y = Mixture(Z, Poisson, rate_parameter)
Y.observe(y)

from bayespy.

jluttine avatar jluttine commented on June 12, 2024

That looks good! I suggest you initialize randomly with:

Z.initialize_from_random()

Then, make sure rate_parameter is learned before Z. Easiest way to do this, is by listing them in that order for VB:

Q = VB(Y, rate_parameter, Z, a0)

And yep, aligning plates and other axes can sometimes be a bit of a head ache. I've been thinking about some simpler and clearer syntax which would still utilize "array properties". Haven't come up with a good solution yet. Of course, if you have an idea what kind of syntax you would find intuitive, I'd be happy to hear and take that into account. :)

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.