def test_sample_ppc_w(self): data = np.random.normal(0, 1, size=200) with pm.Model() as model_0: mu = pm.Normal('mu', mu=0, sd=1) y = pm.Normal('y', mu=mu, sd=1, observed=data) trace_0 = pm.sample() with pm.Model() as model_1: mu = pm.Normal('mu', mu=0, sd=1, shape=len(data)) y = pm.Normal('y', mu=mu, sd=1, observed=data) trace_1 = pm.sample() traces = [trace_0, trace_0] models = [model_0, model_0] ppc = pm.sample_ppc_w(traces, 1000, models) assert ppc['y'].shape == (1000,) _, pval = stats.kstest(ppc['y'], stats.norm().cdf) assert pval > 0.001 traces = [trace_0, trace_1] models = [model_0, model_1] ppc = pm.sample_ppc_w(traces, 50, models) assert ppc['y'].shape == (50, 200)
def test_sample_ppc_w(self): data0 = np.random.normal(0, 1, size=500) with pm.Model() as model_0: mu = pm.Normal('mu', mu=0, sd=1) y = pm.Normal('y', mu=mu, sd=1, observed=data0, shape=500) trace_0 = pm.sample() with pm.Model() as model_1: mu = pm.Normal('mu', mu=0, sd=1, shape=len(data0)) y = pm.Normal('y', mu=mu, sd=1, observed=data0, shape=500) trace_1 = pm.sample() traces = [trace_0, trace_0] models = [model_0, model_0] ppc = pm.sample_ppc_w(traces, 100, models) assert ppc['y'].shape == (100, 500) traces = [trace_0, trace_1] models = [model_0, model_1] ppc = pm.sample_ppc_w(traces, 100, models) assert ppc['y'].shape == (100, 500)
np.exp(0.61) # %% logistic(4) # %% logistic(4 + 0.61) # %% d_pred = pd.DataFrame({"prosoc_left": [0, 1, 0, 1], "condition": [0, 0, 1, 1]}) traces = [trace_10_1, trace_10_2, trace_10_3] models = [model_10_1, model_10_2, model_10_3] chimp_ensemble = pm.sample_ppc_w( traces=traces, models=models, samples=1000, weights=comp_df.weight.sort_index(ascending=True), ) # %% rt = chimp_ensemble["pulled_left"] pred_mean = np.zeros((1000, 4)) cond = d.condition.unique() prosoc_l = d.prosoc_left.unique() for i in range(len(rt)): tmp = [] if rt[i].size < 2: continue for cp in cond: for pl in prosoc_l: