Questions about "observed=“

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.

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

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.

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

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’

From this thread, I found that

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

I follow the steps and encounter the error,
‘numpy.ndarray’ object has no attribute ‘type’
and I found this

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