Skip to content

Instantly share code, notes, and snippets.

@rcalsaverini
Created September 20, 2012 20:06
Show Gist options
  • Save rcalsaverini/3758033 to your computer and use it in GitHub Desktop.
Save rcalsaverini/3758033 to your computer and use it in GitHub Desktop.
Testing pymc
import pymc
import numpy
def model(disasters):
size = len(disasters)
low = pymc.Exponential('low', beta=1.)
high = pymc.Exponential('high', beta=2.)
@pymc.stochastic(dtype=int)
def switchpoint(value=5):
if value > 0 or value < size:
return -numpy.inf
else:
return -numpy.log(10)
@pymc.deterministic(plot=False)
def rate(s=switchpoint, low=low, high=high):
out = numpy.empty(size)
out[:s] = low
out[s:] = high
return out
disasters = pymc.Poisson('disasters', mu=rate, value=disasters, observed=True)
return locals()
disasters = [10, 10, 11, 12, 8, 11, 20, 30, 20, 25, 11, 10]
ourmodel = model(disasters)
print ourmodel
#mcmc.sample(100000, 50000, 2)
#print mcmc.stats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment