Skip to content

Simple example, mixture of gaussians #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timini opened this issue Jan 8, 2014 · 6 comments
Closed

Simple example, mixture of gaussians #452

timini opened this issue Jan 8, 2014 · 6 comments

Comments

@timini
Copy link

timini commented Jan 8, 2014

Sorry for bugging you with a question that is probably a fault of my modelling please feel free to delete this issue. I posted a question on cross validated about porting a simple model from pymc2 to pymc3:

http://stats.stackexchange.com/questions/81650/converting-a-mixture-of-gaussians-to-pymc3

@fonnesbeck
Copy link
Member

I will answer you question on CV.

@fonnesbeck
Copy link
Member

Actually, this may be a bug so I am reopening.

@fonnesbeck fonnesbeck reopened this Jan 8, 2014
@fonnesbeck
Copy link
Member

It turns out that your model is not working, so nodes like p have a trace populated with 10000 values of 0.5. So, when SciPy tries to calculate a KDE of the trace, it chokes. We probably need to add a more informative error message there.

@fonnesbeck
Copy link
Member

One of the issues is that ber is specified to be a scalar (the default). It looks like it needs to be the same length as the data, no?

@fonnesbeck
Copy link
Member

The other issue is that you are trying to use Metropolis to update a Bernoulli random variable. You should use BinaryMetropolis. I have taken the liberty of updating your model, including a few improvements on the specification. This one should work:

with pm.Model() as model:
    #priors
    p = pm.Uniform( "p", 0 , 1) #this is the fraction that come from mean1 vs mean2

    ber = pm.Bernoulli( "ber", p = p, shape=len(data)) # produces 1 with proportion p.

    sigma = pm.Uniform('sigma', 0, 100)
    precision = sigma**-2

    mean = pm.Normal( "mean", 0, 0.01, shape=2 )

    mu = pm.Deterministic('mu', mean[ber])

    process = pm.Normal('process', mu=mu, tau=precision, observed=data)

with model:
    step1 = pm.Metropolis([p, sigma, mean])
    step2 = pm.BinaryMetropolis([ber])
    trace = pm.sample(10000, [step1, step2])

@fonnesbeck
Copy link
Member

BTW, the best place to put usage questions regarding PyMC is on StackOverflow; CrossValidated tends not to like software questions. Be sure to add the pymc tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants