# Posterior predictive sampling with shared matrix

**URL:** https://discourse.pymc.io/t/posterior-predictive-sampling-with-shared-matrix/1848
**Category:** Questions
**Created:** [August 31, 2018, 8:57am UTC](https://discourse.pymc.io/t/posterior-predictive-sampling-with-shared-matrix/1848 "2018-08-31T08:57:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dlepmet](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@dlepmet](https://discourse.pymc.io/u/dlepmet)
#### Post date: [August 31, 2018, 8:57am UTC](https://discourse.pymc.io/t/posterior-predictive-sampling-with-shared-matrix/1848/1 "2018-08-31T08:57:06Z")

</div>

Hello,  
I was trying to predict values for unseen data using a regression model, e.g. Y = \alpha + X \beta with Y, X and \beta being matrices of sizes (n,1), (n,m) and (m,1) respectively. I tried to use a shared variable for X. The model ran fine, however, changing X and using the sample\_ppc function to predict values always led to an error. I then tried to reproduce the error with simpler models. The following model which is based on an example from [https://docs.pymc.io/advanced\_theano.html](https://docs.pymc.io/advanced_theano.html) yields the same error.

```
x = np.random.randn(100)
y = x > 0

x_shared = theano.shared(x.reshape(-1,1))

with pm.Model() as model:
    coeff = pm.Normal('x', mu=0, sd=1)
    logistic = pm.math.sigmoid(coeff * x_shared)
    pm.Bernoulli('obs', p=logistic, observed=y.reshape(-1,1))

    # fit the model
    trace = pm.sample()

    # Switch out the observations and use `sample_posterior_predictive` to predict
    x_new = np.array([-1, 0, 1.]).reshape(-1,1)
    x_shared.set_value(x_new)
    post_pred = pm.sample_ppc(trace, samples=500)

```

The error from the sample\_ppc is

```
TypeError: Attempted to generate values with incompatible shapes:
            size: 1
            dist_shape: (3,)
            broadcast_shape: (3, 1)

```

If I turn both the shared variable and the observed data into vectors by removing the reshape(-1,1) everything works. Am I missing something or is this not possible due to limited support of changing shapes?

Thanks!

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [August 31, 2018, 9:26am UTC](https://discourse.pymc.io/t/posterior-predictive-sampling-with-shared-matrix/1848/2 "2018-08-31T09:26:49Z")

</div>

Seems to be a bug - could you open an issue on Github?

---

<div class="post-metadata">

### Author: ![dlepmet](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@dlepmet](https://discourse.pymc.io/u/dlepmet)
#### Post date: [August 31, 2018, 11:07am UTC](https://discourse.pymc.io/t/posterior-predictive-sampling-with-shared-matrix/1848/3 "2018-08-31T11:07:18Z")

</div>

Issue is now opened: [#3180](https://github.com/pymc-devs/pymc3/issues/3180)
