In [1]:
%matplotlib inline
import sys
sys.path.append('/apps')
import django
django.setup()
from drivers.tree_builder import TreeNeo
from drivers.graph_models import TreeNode, Order, Family, graph,Kingdom,Occurrence
from drivers.graph_models import Cell,Mex4km, countObjectsOf
from drivers.graph_models import pickNode
import matplotlib.pyplot as plt
import pandas as pd
import itertools as it
import numpy as np
import pymc3 as pm
## Use the ggplot style
plt.style.use('ggplot')
In [2]:
import scipy
In [148]:
## true parameters
m = 2.5
b = 10
n = 500
tau2 = 1
alpha = 10
x = np.linspace(-10,10,n)
eps = scipy.random.normal(0,tau2,n)
per = np.sin(alpha * x)
y = m*x + b + per + eps
#y = per + eps
In [149]:
#plt.plot(y)
plt.scatter(x,y)
Out[149]:
In [152]:
## Ok let's do the model in Pymc3
with pm.Model() as model:
tau2 = pm.HalfCauchy('tau',beta=3,testval=1)
m = pm.Normal('slope', 0, sd=10)
#alpha = pm.HalfCauchy('alpha',beta=10)
#alpha = pm.Flat('alpha')
alpha = pm.Cauchy('alpha',0,100)
#b = pm.Normal('b',30,sd=1)
b = pm.Flat('b')
# Likelihood
likelihood = pm.Normal('y',mu=m*x + b + pm.math.sin(alpha*x) ,sd=tau2,observed=y)
In [153]:
with model:
trace = pm.sample(3000)
In [154]:
with model:
map_ = pm.find_MAP()
In [155]:
map_
Out[155]:
In [ ]: