Skip to content

Commit

Permalink
Update of model_1_missing with more compact 2.1 imputation syntax.
Browse files Browse the repository at this point in the history
git-svn-id: https://pymc.googlecode.com/svn/trunk@1154 15d7aa0b-6f1a-0410-991a-d59f85d14984
  • Loading branch information
fonnesbeck committed Jan 15, 2009
1 parent ebd1f53 commit 63d03ad
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pymc/examples/model_1_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
"""
__all__ = ['swichpoint','early_mean','late_mean','disasters']

from pymc import DiscreteUniform, Exponential, deterministic, Poisson, Uniform, Lambda, MCMC
from pymc.distributions import ImputeMissing
from pymc import DiscreteUniform, Exponential, deterministic, Poisson, Uniform, Lambda, MCMC, observed, poisson_like
from pymc.distributions import Impute
import numpy as np

# Missing values indicated by -999 placeholders
disasters_array = np.array([ 4, 5, 4, 0, 1, 4, 3, 4, 0, 6, 3, 3, 4, 0, 2, 6,
3, 3, 5, 4, 5, 3, 1, 4, 4, 1, 5, 5, 3, 4, 2, 5,
2, 2, 3, 4, 2, 1, 3, -999, 2, 1, 1, 1, 1, 3, 0, 0,
1, 0, 1, 1, 0, 0, 3, 1, 0, 3, 2, 2, 0, 1, 1, 1,
0, 1, 0, 1, 0, 0, 0, 2, 1, 0, 0, 0, 1, 1, 0, 2,
3, 3, 1, -999, 2, 1, 1, 1, 1, 2, 4, 2, 0, 0, 1, 4,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1])

# Mask for missing values
disasters_mask = disasters_array == -999


# Switchpoint
s = DiscreteUniform('s', lower=0, upper=110)
Expand All @@ -41,6 +40,5 @@ def r(s=s, e=e, l=l):
out[s:] = l
return out

# Where the mask is true, the value is taken as missing.
masked_data = np.ma.masked_array(disasters_array, disasters_mask)
D = ImputeMissing('D', Poisson, masked_data, mu=r)
# Where the value is -999, the datum is assumed to be missing.
D = Impute('D', Poisson, disasters_array, missing=-999, mu=r)

0 comments on commit 63d03ad

Please sign in to comment.