# Get the distribution of a Determinitic variable

Hi,
I create a deterministic variable in my model, for which I want to display the distribution. Unfortunately, I don’t know how to access it. I tried this:

import numpy as np
import pymc3 as pm
import matplotlib.pyplot as plt
import theano.tensor as tt
import theano

with  pm.Model() as model:
log_y=pm.Normal('log_y',0,sigma=1,shape=(M,1))
y=pm.Deterministic('y',np.exp(log_y))

_, ax=plt.subplots(1,1,figsize=(5,5))
y=np.linspace(0,5,100)
prior_y=np.exp(model.named_vars['y'].distribution.logp(x).eval())
ax.plot(y,prior_y )
ay=ax.get_ylim()
ax.set_ylim([0,ay*1.05])
ax.set_xlabel('Y')
ax.set_title('Prior on Y')


I know that I could do that following the example in the api_quickstart notebook.
However, I would like to know if there is a way to do it using Determinitic?

The reason behind that is that in my project, I have two variables that are transformed using \log and logit function, and I have a multivariate Gaussian prior on those transformed parameter. I would like to display the prior corresonding to the untransformed parameters.

Thanks!

You can use a potential to place prior on a Deterministic, however, in this case I am not sure it really makes sense, since log transformed and logit tranformed variable are now bounded, which do not have the same support as multivariate Gaussian

I don’t know if I have been very clear.
Let’s say I have (x_1, x_2) that follow the constraints: x_1>0 and 0<x_2<1. I transform them as (tx_1,tx_2)= \left(\log(x_1), logit(x_2)\right).
I put a shrinkage prior on the transformed parameter using a multivariate Gaussian prior on (tx_1,tx_2), then I use Deterministic to go back to my original parameter.

I would like to know if it is possible to display the prior of x_1 and x_2?

You can do:

with pm.Model() as m:
# put prior on transformed variables t(x1) and t(x2)
txs = pm.MvNormal('txs', 0., np.diag(np.ones(2)), shape=2)
# transformations
x1 = pm.Deterministic('x1', pm.math.exp(txs))
x2 = pm.Deterministic('x2', pm.math.invlogit(txs))
trace = pm.sample()
pm.traceplot(trace);

1 Like