Frage

I'm exploring PyMC3 through a regression example. I started with a line and then moved to a quadratic and that worked great. When I tried to move to a sine function with the random variable within it though things went sour.

Here's my PyMC3 code:

import pymc as pm
import numpy as np

trace = None
with pm.Model() as model:
    alpha = pm.Normal('alpha', mu=0, sd=20)
    beta = pm.Normal('beta', mu=0, sd=20)
    mewmew = pm.Normal('mewmew', mu=0, sd=20)
    sigma = pm.Uniform('sigma', lower=0, upper=20)

    y_est = alpha + beta * numpy.sin(mewmew * x)

    likelihood = pm.Normal('y', mu=y_est, sd=sigma, observed=y)

    start = pm.find_MAP()
    step = pm.NUTS(state=start)
    trace = pm.sample(2000, step, start=start, progressbar=False)

    pm.traceplot(trace);

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-139-60a584151c07> in <module>()
      9     sigma = pm.Uniform('sigma', lower=0, upper=20)
     10 
---> 11     y_est = alpha + beta * numpy.sin(mewmew * x)
     12 
     13     likelihood = pm.Normal('y', mu=y_est, sd=sigma, observed=y)

AttributeError: sin

Thanks in advance!

War es hilfreich?

Lösung

Turns out there is a sine function built into PyMC3. It's called "pymc.sin". I've blogged about this whole process here: http://www.databozo.com/2014/01/17/Exploring_PyMC3.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top