# SMC example with arbitrary function as model likelihood

**URL:** <https://discourse.pymc.io/t/smc-example-with-arbitrary-function-as-model-likelihood/3249>\
**Category:** Questions\
**Created:** [May 13, 2019, 1:19pm UTC](https://discourse.pymc.io/t/smc-example-with-arbitrary-function-as-model-likelihood/3249 "2019-05-13T13:19:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidbrochart](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/davidbrochart/32/61_2.png) [@davidbrochart](https://discourse.pymc.io/u/davidbrochart)\
**Post date:** [May 13, 2019, 1:19pm UTC](https://discourse.pymc.io/t/smc-example-with-arbitrary-function-as-model-likelihood/3249/1 "2019-05-13T13:19:20Z")

</div>

Hi,

In the SMC example Notebook: [https://docs.pymc.io/notebooks/SMC2\_gaussians.html](https://docs.pymc.io/notebooks/SMC2_gaussians.html)  
I would like to have a model likelihood that uses arbitrary functions. If I change `two_gaussians` to:

```python
@theano.as_op([tt.dvector], [tt.dscalar])
def two_gaussians(x):
    log_like1 = - 0.5 * n * np.log(2 * np.pi) \
                - 0.5 * np.log(dsigma) \
                - 0.5 * (x - mu1).T.dot(isigma).dot(x - mu1)
    log_like2 = - 0.5 * n * np.log(2 * np.pi) \
                - 0.5 * np.log(dsigma) \
                - 0.5 * (x - mu2).T.dot(isigma).dot(x - mu2)
    return np.log(w1 * np.exp(log_like1) + w2 * np.exp(log_like2))

```

I get the following error when sampling:

```auto
ValueError: expected an ndarray
Apply node that caused the error: MakeVector{dtype='float64'}(llk)
Toposort index: 3
Inputs types: [TensorType(float64, scalar)]
Inputs shapes: [()]
Inputs strides: [()]
Inputs values: [-166.83949357531378]
Outputs clients: [[Sum{acc_dtype=float64}(MakeVector{dtype='float64'}.0)]]

```

Is there something I am doing wrong?

---

<div class="post-metadata">

**Author:** ![aloctavodia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aloctavodia/32/8642_2.png) [@aloctavodia](https://discourse.pymc.io/u/aloctavodia)\
**Post date:** [May 15, 2019, 2:04pm UTC](https://discourse.pymc.io/t/smc-example-with-arbitrary-function-as-model-likelihood/3249/2 "2019-05-15T14:04:10Z")

</div>

Hi @davidbrochart you have to replace the last line with

return np.array(np.log(w1 \* np.exp(log\_like1) + w2 \* np.exp(log\_like2)))
