Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pymc MAP warning : Stochastic tau's value is neither numerical nor array with floating-point dtype. Recommend fitting method fmin (default)

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
like image 358
turing Avatar asked Nov 11 '22 05:11

turing


1 Answers

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).

like image 124
Fabian Rost Avatar answered Dec 22 '22 02:12

Fabian Rost