Hello everyone. I am running my Bayesian model using pymc4.But It
crushed . I wanna know where my problem was. Here is my code
import pymc as pm
import numpy as np
import aesara.tensor as at
from aesara.compile.ops import as_op
assert pm.__version__ == '4.0.0b6'
data = [0.05 + i for i in np.random.uniform(-0.05, 0.2, 1000)]
##https://www.pymc.io/projects/docs/en/latest/learn/core_notebooks/pymc_overview.html?highlight=switch#case-study-2-coal-mining-disasters
## example :Arbitary deterministics. I changed the function in the url above
@as_op(itypes=[at.dscalar, at.dscalar], otypes=[at.dscalar])
def piecewise_timespan_label(back, forward):
td = forward - back
if td >= 12:
return 1
elif td >= 8:
return 0.9
elif td >= 6:
return 0.8
elif td >= 4:
return 0.6
elif td >= 2:
return 0.4
elif td >= 1:
return 0.2
elif td >= 0.5:
return 0.1
elif td >= 0.05:
return 0.08
else:
return 0.05
with pm.Model() as model_deterministic:
back = pm.Exponential("back", 0.2)
forward = pm.Exponential("forward", 0.2)
ratio_est = piecewise_timespan_label(back, forward)
eps = pm.HalfCauchy("eps", 0.5)
y = pm.Normal("y", ratio_est, sigma=eps, observed=data)
with model_deterministic:
idata = pm.sample(1000)
print('here')
Here is my wronging message:
Canceled future for execute_request message before replies were done
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.
My system is window 10 21H2
I am running it on vscode jupyter:v2022.4.1021342353
aesara 2.5.1
pymc ‘4.0.0b6’
numpy 1.23.0rc1
I would first recommend trying to run your code in script rather than a notebook. It is often more difficult to diagnose what is happening because the notebook does not show all the output.
And I installed the mkl-services ,which version is 2.4.0. Then I tried the the python code python eda.py under my local path in my terminal.
Here is the output.
import right
data right
forward type <class 'aesara.tensor.var.TensorVariable'>
ratioest type <class 'aesara.tensor.var.TensorVariable'>
model right
td type <class 'numpy.float64'>
I add the xxx type in the print code for clarification.
import pymc as pm
import aesara.tensor as at
from aesara.compile.ops import as_op
@as_op(itypes=[at.lscalar], otypes=[at.lscalar])
def crazy_modulo3(value):
print('type of value is ' + str(type(value)))
if value > 0:
return value % 3
else:
return (-value + 1) % 3
with pm.Model() as model_deterministic:
a = pm.Poisson("a", 1)
b = crazy_modulo3(a)
pm.sample()
If that doesn’t sample for you, then it’s likely an installation issue.
Regardless, I can’t get your model to sample. Perhaps there’s an issue with the signature and/or return value of your op function? Any idea @ricardoV94 ?