How to specify this potential?

Hi everyone,

I’m having some trouble specifying this potential in PyMC3. Could one of you give me some advice on how to implement it?

To give a brief explanation:
alpha - is a constant that is specified by the user and does not need to be inferred by the model
T - the parameter that I’m interested in inferring based from this exponential potential
Nt - the length of the vector T

The caveat is that the parameter T needs to be positive and bound by some upper and lower limits (specified by user).

Currently, I’ve tried to implement this using DensityDist but I get a “nan energy” error.

Thanks for you help!

How is your current implementation looks like?
In general, the logp function (that you would wrap in a DensityDist) is alpha * fn_s(T), bounded by the constrain.

Hi @junpenglao! Thanks for answering.

See my code below:

var_alpha = theano.shared(value = 1., borrow = False)

phi_e = pm.Uniform(‘phi_e’, lower = lb_phi_e, upper = ub_phi_e, shape = (ub_phi_e.size))

S1_phi_e = (phi_e/phi_e.sum()*np.log(phi_e/phi_e.sum())).sum()

pm.DensityDist(‘phi_e_potential’, logp = -var_alpha*S1_phi_e)

The error I receive with this approach is “TypeError: ‘TensorVariable’ object is not callable”

To followup, I’ve had a bit of success when I implement the potential as follows:

pm.Potential(‘phi_e_potential’, np.exp(-var_alpha*S1_phi_e))

However, I get “ValueError: Bad initial energy: nan. The model might be misspecified.” when the initial value is not properly specified

If you are normalizing the uniform like this: phi_e/phi_e.sum(), you should use a Dirichlet distribution as prior instead.