<jupyter_start><jupyter_text>https://github.com/pymc-devs/pymc3/issues/3012<jupyter_code>%pylab inline
import pymc3 as pm
import theano.tensor as tt
import theano
X = np.random.uniform(0., 10., size=100)
y = X*.5 + 1.5 + np.random.randn(100)*.8

with pm.Model() as m:
    X_ = pm.Uniform('x', 0., 10., observed=X)
    b = pm.Normal('b', 0., 5.)
    a = pm.Normal('a', 0., 5.)
    sd = pm.HalfNormal('sd', 1.)
    like = pm.Normal('obs', a+b*X_, sd, observed=y)
    trace = pm.sample()

pm.traceplot(trace);
with m:
    ppc = pm.sample_ppc(trace, 200)
ppc['x'].shape, ppc['obs'].shape
plt.plot(X, ppc['obs'].T, 'ko', alpha=.01);
plt.plot(X, y, 'o');
plt.plot(ppc['x'].T, ppc['obs'].T, 'ko', alpha=.01);
plt.plot(X, y, 'o');
with pm.Model() as m2:
    X_ = pm.Uniform('x', 0., 10., shape=X.shape)
    pm.Normal('obs1', X_, .01, observed=X)
    
    b = pm.Normal('b', 0., 5.)
    a = pm.Normal('a', 0., 5.)
    sd = pm.HalfNormal('sd', 1.)
    like = pm.Normal('obs2', a+b*X_, sd, observed=y)
    trace1 = pm.sample()
    ppc = pm.sample_ppc(trace1, 200)
ppc['obs1'].shape, ppc['obs2'].shape
ind = slice(0, 10)
plt.plot(ppc['obs1'][ind,:], ppc['obs2'][ind,:], 'ko', alpha=.1);
plt.plot(X, y, 'o');
with m:
    Xnew = pm.Uniform('xnew', 0., 10.)
    Ynew = pm.Normal('ynew', a+b*Xnew, sd)
    ppc = pm.sample_ppc(trace, 200, vars=[Xnew, Ynew])
ppc['xnew'].shape, ppc['ynew'].shape
plt.plot(ppc['xnew'], ppc['ynew'], 'ko', alpha=.1);
plt.plot(X, y, 'o');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.25135135135135134, 'fraction_numerical': 0.04527027027027027, 'mean_word_length': 3.657232704402516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '535864', 'license': 'MIT', 'n_tokens_mistral': 717, 'n_tokens_neox': 664, 'n_words': 139, 'path': 'PyMC3QnA/discourse_1334.ipynb', 'repo_name': 'junpenglao/Planet_Sakaar_Data_Science', 'size': '1480'}