I have looked at a similar question here
pymc warning: value is neither numerical nor array with floating-point dtype
but there are no answers, can someone please tell me whether I should ignore this warning or what to do otherwise ?
The model has a stochastic variable (among others) tau
which is DiscreteUniform
Following is the relevant code for the model :
tau = pm.DiscreteUniform("tau", lower = 0, upper = n_count_data)
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)
print "Initial values: ", tau.value, lambda_1.value, lambda_2.value
@pm.deterministic
def lambda_(tau = tau, lambda_1 = lambda_1, lambda_2 = lambda_2):
out = np.zeros(n_count_data)
out[:tau] = lambda_1
out[tau:] = lambda_2
return out
observation = pm.Poisson("obs", lambda_, value = count_data, observed = True)
model = pm.Model([observation, lambda_1, lambda_2, tau]);
m = pm.MAP(model) # **This line caueses error**
print "Output after using MAP: ", tau.value, lambda_1.value, lambda_2.value
The pymc
documentation says "MAP
can only handle variables whose dtype is float
". Your tau
is from a discrete distribution so it should rather have a dtype like int
. If you call the fit
method to estimate maximum a posteriori values of your parameters tau
will be assumed to be a float. If this makes any sense and hence, whether you could ignore this warning depends on the problem at hand. If your likelihood is well-behaved you might end up with a float value of tau
that's close the integer value you'd actually like to estimate. But if you imagine a case where your likelihood will be 0 for all non-integer values a gradient method like fmin
will not work and your maximum a posteriori values don't make any sense. In this case you'd have to find a different way to calculate you maximum a posteriori values (again, depending on the problem at hand).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With