Hello,
I am following the example ODE Lotka-Volterra With Bayesian Inference in Multiple Ways and trying to apply it with my ODE model.
The problem I have is that my rhs (right hand side function defining the system of ODEs) requires an input of 17 species concentration, C and it outputs 17 ODEs (or my dC/dt). I only have observed data for 6 of the 17 species therefore I only need to take 6 concentration profiles or 6 ode solutions.
I tried doing the following:
@as_op(itypes=[pt.dvector], otypes=[pt.dmatrix])
def pytensor_forward_model_matrix(theta):
answer = solve_ivp(fun=rhs, t_span = [0, 1080], y0=y0_data[0], t_eval=time, args=(theta,), method='Radau')
return answer[:,[5, 9, 11, 6, 12, 13]]
where [5,9,11,6,12,13] are the column indices of the 6 species.
I got the following error:
Traceback (most recent call last):
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 970, in __call__
self.vm()
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/graph/op.py", line 543, in rval
r = p(n, [x[0] for x in i], o)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/compile/ops.py", line 259, in perform
outs = self.__fn(*inputs)
^^^^^^^^^^^^^^^^^^
File "/home/admin/pymc-projects/sunovion_sampler.py", line 291, in pytensor_forward_model_matrix
return answer[:,[5, 9, 11, 6, 12, 13]]
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'slice'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/admin/pymc-projects/sunovion_sampler.py", line 329, in <module>
trace_DEMZ = pm.sample(step=[pm.DEMetropolisZ(vars_list)], tune=tune, draws=draws, cores=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pymc/sampling/mcmc.py", line 608, in sample
model.check_start_vals(ip)
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pymc/model.py", line 1776, in check_start_vals
initial_eval = self.point_logps(point=elem)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pymc/model.py", line 1810, in point_logps
self.compile_fn(factor_logps_fn)(point),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pymc/pytensorf.py", line 764, in __call__
return self.f(**state)
^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 983, in __call__
raise_with_op(
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/link/utils.py", line 535, in raise_with_op
raise exc_value.with_traceback(exc_trace)
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 970, in __call__
self.vm()
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/graph/op.py", line 543, in rval
r = p(n, [x[0] for x in i], o)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/admin/anaconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/compile/ops.py", line 259, in perform
outs = self.__fn(*inputs)
^^^^^^^^^^^^^^^^^^
File "/home/admin/pymc-projects/sunovion_sampler.py", line 291, in pytensor_forward_model_matrix
return answer[:,[5, 9, 11, 6, 12, 13]]
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'slice'
Apply node that caused the error: FromFunctionOp{pytensor_forward_model_matrix}(MakeVector{dtype='float64'}.0)
Toposort index: 22
Inputs types: [TensorType(float64, (17,))]
Inputs shapes: [(17,)]
Inputs strides: [(8,)]
Inputs values: ['not shown']
Outputs clients: [[Elemwise{Composite}(Y_obs{[[4.200321..9168e-01]]}, FromFunctionOp{pytensor_forward_model_matrix}.0, InplaceDimShuffle{x,x}.0, TensorConstant{(1, 1) of -0.5}, TensorConstant{(1, 1) of ..5332046727}, Elemwise{log,no_inplace}.0, Elemwise{gt,no_inplace}.0, TensorConstant{(1, 1) of -inf})]]
Backtrace when the node is created (use PyTensor flag traceback__limit=N to make it longer):
File "/home/admin/pymc-projects/sunovion_sampler.py", line 316, in <module>
ode_solution = pytensor_forward_model_matrix(
HINT: Use the PyTensor flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
Any help would be greatly appreciated. Thanks.