Thanks junpenglao! Its taken me a while but i have the grad() routine up and running now although i formulated my Theano Op slightly differently to @aseyboldt’s WIP notebook - i explicitly calculate the Jacobian matrix. When i run my PyMC3 model with this Op, however, i get the following error message:
Auto-assigning NUTS sampler…
Initializing NUTS using jitter+adapt_diag…
Initializing NUTS failed. Falling back to elementwise auto-assignment.
Sequential sampling (2 chains in 1 job)
The results produced by the model are good despite this error but i’m wondering if i can improve them. Once the sampling is complete (2 chains with 1000 samples each), i get the following messages:
The acceptance probability does not match the target. It is 0.7066969406166785, but should be close to 0.8. Try to increase the number of tuning steps.
The acceptance probability does not match the target. It is 0.7208052675795203, but should be close to 0.8. Try to increase the number of tuning steps.
The gelman-rubin statistic is larger than 1.4 for some parameters. The sampler did not converge.
The estimated number of effective samples is smaller than 200 for some parameters.
Do you know why the Initialising NUTS step fails and how i might be able to fix it? Below is the
grad functions from my Theano Op if it helps.
def perform(self, node, inputs, outputs):
pr_vec, = inputs
yr = self.getValuesAtSensors(self.ur_field)
outputs = yr # Models current estimate of the observed data
def grad(self, inputs, output_gradients):
jac = theano.shared(npy.transpose(self.jac()))
g, = output_gradients
return [tt.dot(jac, g)]
Additionally, below is my code for building and running the PyMC3 model:
with pm.Model() as GroundWaterModel:
pr_vec = pm.Normal(‘pr_vec’, mu=0, sd=1, shape=np, testval=npy.ones(np))
sigma = pm.HalfNormal(‘sigma’, sd=10)
yr = pm.Deterministic(‘yr’, reducedOp(pr_vec))
pm.Normal(‘y_rec’, mu=yr, sd=sigma, observed=yd) # recovered y values
trace = pm.sample()
Any assistance greatly appreciated.