def bad_y_exp_complex_sim(n=[12, 13, 9, 17, 11, 11, 13, 8, 15], n_mis=2):
    # generate full data
    d = data.complex_hierarchical_data(n)
    
    # make some data missing
    y_w_missing = [y_j.copy() for y_j in d['y']]
    for k in range(n_mis):
        j = random.choice(range(d['J']))
        i = random.choice(range(d['n'][j]))
        y_w_missing[j][i] = pl.nan

    # generate model
    m = models.complex_hierarchical_model(y_w_missing, d['X'], d['t'])

    # replace data prediction with wrong exponent
    m['y_exp'] = [mc.Lambda('y_exp_%d'%j, lambda mu=m['mu'], beta=m['beta'], gamma=m['gamma'], t=m['t'], j=j: mu[j] - pl.exp(beta[j])*t[j] - pl.exp(gamma[j])*t[j]**3) for j in range(m['J'])]
    @mc.potential
    def y_obs(y_exp=m['y_exp'], sigma=m['sigma'], y=m['y']):
        logp = 0.
        for j in range(m['J']):
            missing = pl.isnan(y[j])
            logp += mc.normal_like(y[j][~missing], y_exp[j][~missing], sigma[j]**-2)
        return logp
    m['y_obs'] = y_obs
    m['y_pred'] = [mc.Normal('y_pred_%d'%j, m['y_exp'][j], m['sigma'][j]**-2) for j in range(m['J'])]

    # fit model with Normal Approx
    na = mc.NormApprox(m)
    na.fit(method='fmin_powell', verbose=True)
    na.sample(5000)

    return d, m
def good_complex_sim(n=[12, 13, 9, 17, 11, 11, 13, 8, 15], n_mis=2):
    # generate full data
    d = data.complex_hierarchical_data(n)
    
    # make some data missing
    y_w_missing = [y_j.copy() for y_j in d['y']]
    for k in range(n_mis):
        j = random.choice(range(d['J']))
        i = random.choice(range(d['n'][j]))
        y_w_missing[j][i] = pl.nan

    # generate model
    m = models.complex_hierarchical_model(y_w_missing, d['X'], d['t'])

    # fit model with Normal Approx
    na = mc.NormApprox(m)
    na.fit(method='fmin_powell', verbose=True)
    na.sample(5000)

    return d, m
 def test_complex_model(self):
     d = data.complex_hierarchical_data([10,11,12])
     vars = models.complex_hierarchical_model(d['y'], d['X'], d['t'])
     assert 'mu' in vars
 def test_complex_model(self):
     d = data.complex_hierarchical_data([10, 11, 12])
     vars = models.complex_hierarchical_model(d['y'], d['X'], d['t'])
     assert 'mu' in vars