# Questions about "observed=“

**URL:** <https://discourse.pymc.io/t/questions-about-observed/2428>\
**Category:** Questions\
**Created:** [December 22, 2018, 6:24am UTC](https://discourse.pymc.io/t/questions-about-observed/2428 "2018-12-22T06:24:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Firgic](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@Firgic](https://discourse.pymc.io/u/Firgic)\
**Post date:** [December 22, 2018, 6:24am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/1 "2018-12-22T06:24:39Z")

</div>

Here is the thing, I want to write the logp myself,

> @as\_op(itypes=[tt.dvector, tt.dvector, tt.dvector,tt.dvector], otypes=[tt.dvector])  
> def logp(Liq, value, wF, wNF):  
> ……

> c = pm.DensityDist(  
> ‘c’, logp, observed={  
> ‘Liq’: Liq,  
> ‘value’: FS,  
> ‘wF’: wF,  
> ‘wNF’: wNF  
> })

and I meet the error:

> TypeError: make\_node() got an unexpected keyword argument ‘Liq’

Of course, I can delete the

> @as\_op(itypes=[tt.dvector, tt.dvector, tt.dvector,tt.dvector], otypes=[tt.dvector])

but I want to know the recommended way of coding the “observed=”。

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [December 23, 2018, 5:58am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/2 "2018-12-23T05:58:00Z")

</div>

I’m not 100% sure but I think that you can do this:

```python
def logp(value):
    Liq = value['Liq']
    wF = value['wF']
    wNF = value['wNF']
    value = value['value']
    ...

```

Then you just pass the observed as a dictionary, as you had done.

---

<div class="post-metadata">

**Author:** ![Firgic](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@Firgic](https://discourse.pymc.io/u/Firgic)\
**Post date:** [December 23, 2018, 7:26am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/3 "2018-12-23T07:26:46Z")

</div>

I think it’s a good idea, but some errors appear and kill the kernel.

> [I 15:22:28.201 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports  
> kernel b9d391bf-0a78-46f1-b157-d214d76bd9b7 restarted

---

<div class="post-metadata">

**Author:** ![Firgic](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@Firgic](https://discourse.pymc.io/u/Firgic)\
**Post date:** [December 23, 2018, 7:34am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/4 "2018-12-23T07:34:04Z")

</div>

Sorry, I just passed the observed as a DataFrame,  
when I do this,

> def logp(value):  
> Liq = value[‘Liq’]  
> wF = value[‘wF’]  
> wNF = value[‘wNF’]  
> value1 = value[‘value’]  
> …

> with pm.Model() as model\_h:  
> …  
> value={ ‘Liq’: Liq,  
> ‘value’: FS,  
> ‘wF’: wF,  
> ‘wNF’: wNF}  
> c = pm.DensityDist(  
> ‘c’, logp, observed=value)

The same error occurs,

> TypeError: make\_node() got an unexpected keyword argument ‘Liq’

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [December 23, 2018, 8:02am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/5 "2018-12-23T08:02:29Z")

</div>

From [this](https://discourse.pymc.io/t/how-to-deal-with-a-variable-size-of-the-observed-variable/377) thread, I found that

> [@How to deal with a variable size of the 'observed' variable](https://discourse.pymc.io/t/how-to-deal-with-a-variable-size-of-the-observed-variable/377/12):
>
> Functions decorated with `as_op` can’t take keyword arguments. You could wrap it in a simple python function

Maybe you could read through that to see if you can adapt what was said to your situation.

---

<div class="post-metadata">

**Author:** ![Firgic](https://avatars.discourse-cdn.com/v4/letter/f/13edae/32.png) [@Firgic](https://discourse.pymc.io/u/Firgic)\
**Post date:** [December 23, 2018, 10:12am UTC](https://discourse.pymc.io/t/questions-about-observed/2428/6 "2018-12-23T10:12:25Z")

</div>

I follow the steps and encounter the error,  
‘numpy.ndarray’ object has no attribute ‘type’  
and I found [this](https://discourse.pymc.io/t/scipy-stats-distributions-cdfs/1719/2)

like,

> @as\_op(itypes=[tt.dvector,tt.dvector,tt.dvector,tt.dvector], otypes=[tt.dvector])  
> def logplnln(Liq,value,wF,wNF):  
> …
> 
> with pm.Model() as model\_h:  
> def logp(value):  
> return logplnln(theano.shared(Liq.astype(‘float64’))  
> ,theano.shared(value.astype(‘float64’))  
> ,theano.shared(wF.astype(‘float64’))  
> ,theano.shared(wNF.astype(‘float64’)))  
> …  
> c = pm.DensityDist(  
> ‘c’, logp, observed=FS)

and with or without ‘.astype(‘float64’)’ encounter

> TypeError: Shared variable constructor needs numeric values and not symbolic variables.

I cannot figure out why, all the variables are np.array
