RuntimeError: Chain 3 failed/ZeroDivisonError. Help!

Hello.

I’m new using this library.

I´m trying to run a code to calculate the stimated volatility from a stock. When the code reachs the line 53 it fails: RuntimeError Chain 3 failed.

This error comes after this:

**ZeroDivisionError: 0.0 cannot be raised to a negative power
Apply node that caused the error: Elemwise{Composite{(Switch(i0, (i1 * i2), i3) + i4 + (i5 * (((i6 * i7 * Composite{inv(Composite{(sqr(i0) * i0)}(i0))}(i8)) / i9) - (i10 * Composite{inv(Composite{(sqr(i0) * i0)}(i0))}(i8))) * (i11 ** i12) * inv(Composite{(sqr(i0) * i0)}(i2)) * i2))}}[(0, 7)](Elemwise{Composite{Cast{int8}(GE(i0, i1))}}.0, TensorConstant{-50.0}, sigma, TensorConstant{0}, TensorConstant{1.0}, TensorConstant{-2.0}, TensorConstant{0.5}, Sum{acc_dtype=float64}.0, Elemwise{Composite{inv(sqrt(i0))}}.0, Elemwise{Composite{inv(sqr(i0))}}.0, Sum{acc_dtype=float64}.0, Elemwise{Composite{inv(sqr(i0))}}.0, TensorConstant{-1.5})
Toposort index: 75
Inputs types: [TensorType(int8, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(int8, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float64, scalar), TensorType(float32, scalar)]
Inputs shapes: [(), (), (), (), (), (), (), (), (), (), (), (), ()]
Inputs strides: [(), (), (), (), (), (), (), (), (), (), (), (), ()]
Inputs values: [array(1, dtype=int8), array(-50.), array(inf), array(0, dtype=int8), array(1.), array(-2.), array(0.5), array(2263.), array(inf), array(0.), array(278.12717274), array(0.), array(-1.5, dtype=float32)]
Outputs clients: [[Reshape{1}((d__logp/dsigma_log__), MakeVector{dtype='int64'}.0)]]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node. **

I don´t know what`s going on. I give it a round number and the pymc3 divides internally by 0. How could I fix this error?

samples = 1500

image

What could i do to solve this.

The packages and versions installed in this env are this:

packages and versions

Name Version Build Channel

alabaster 0.7.12 pyhd3eb1b0_0
appdirs 1.4.4 py_0
argh 0.26.2 py39haa95532_0
arrow 0.13.1 py39haa95532_0
arviz 0.11.2 pypi_0 pypi
astroid 2.5 py39haa95532_1
async_generator 1.10 pyhd3eb1b0_0
atomicwrites 1.4.0 py_0
attrs 20.3.0 pyhd3eb1b0_0
autopep8 1.5.6 pyhd3eb1b0_0
babel 2.9.0 pyhd3eb1b0_0
backcall 0.2.0 pyhd3eb1b0_0
bcrypt 3.2.0 py39h196d8e1_0
binaryornot 0.4.4 pyhd3eb1b0_1
black 19.10b0 py_0
blas 1.0 mkl
bleach 3.3.0 pyhd3eb1b0_0
brotlipy 0.7.0 py39h2bbff1b_1003
ca-certificates 2020.12.5 h5b45459_0 conda-forge
cachetools 4.2.1 pypi_0 pypi
certifi 2020.12.5 py39hcbf5309_1 conda-forge
cffi 1.14.5 py39h0878f49_0 conda-forge
cftime 1.4.1 pypi_0 pypi
chardet 4.0.0 py39haa95532_1003
click 7.1.2 pyhd3eb1b0_0
cloudpickle 1.6.0 py_0
colorama 0.4.4 pyhd3eb1b0_0
cookiecutter 1.7.2 pyhd3eb1b0_0
cryptography 3.4.7 py39hd8d06c1_0 conda-forge
cycler 0.10.0 py_2 conda-forge
decorator 5.0.6 pyhd3eb1b0_0
defusedxml 0.7.1 pyhd3eb1b0_0
diff-match-patch 20200713 py_0
dill 0.3.3 pypi_0 pypi
docutils 0.17 py39haa95532_1
entrypoints 0.3 py39haa95532_0
fastprogress 1.0.0 pypi_0 pypi
filelock 3.0.12 pypi_0 pypi
flake8 3.9.0 pyhd3eb1b0_0
freetype 2.10.4 h546665d_1 conda-forge
future 0.18.2 py39haa95532_1
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 ha925a31_3
idna 2.10 pyhd3eb1b0_0
imagesize 1.2.0 pyhd3eb1b0_0
importlib-metadata 3.10.0 py39haa95532_0
importlib_metadata 3.10.0 hd3eb1b0_0
inflection 0.5.1 py39haa95532_0
intel-openmp 2021.2.0 h57928b3_616 conda-forge
intervaltree 3.1.0 py_0
ipykernel 5.3.4 py39h7b7c402_0
ipython 7.22.0 py39hd4e2768_0
ipython_genutils 0.2.0 pyhd3eb1b0_1
isort 5.8.0 pyhd3eb1b0_0
jedi 0.17.2 py39haa95532_1
jinja2 2.11.3 pyhd3eb1b0_0
jinja2-time 0.2.0 pyhd3eb1b0_2
joblib 1.0.1 pyhd3eb1b0_0
jpeg 9d h8ffe710_0 conda-forge
jsonschema 3.2.0 py_2
jupyter_client 6.1.12 pyhd3eb1b0_0
jupyter_core 4.7.1 py39haa95532_0
jupyterlab_pygments 0.1.2 py_0
keyring 22.3.0 py39haa95532_0
kiwisolver 1.3.1 py39h2e07f2f_1 conda-forge
lazy-object-proxy 1.6.0 py39h2bbff1b_0
lcms2 2.12 h2a16943_0 conda-forge
libblas 3.9.0 8_mkl conda-forge
libcblas 3.9.0 8_mkl conda-forge
libiconv 1.16 he774522_0 conda-forge
liblapack 3.9.0 8_mkl conda-forge
libpng 1.6.37 h1d00b33_2 conda-forge
libsodium 1.0.18 h62dcd97_0
libspatialindex 1.9.3 h6c2663c_0
libtiff 4.2.0 hc10be44_0 conda-forge
libxml2 2.9.10 hf5bbc77_4 conda-forge
libxslt 1.1.34 he774522_0
lxml 4.6.3 py39h4fd7cdf_0 conda-forge
lz4-c 1.9.3 h8ffe710_0 conda-forge
markupsafe 1.1.1 py39hb82d6ee_3 conda-forge
matplotlib 3.4.1 py39hcbf5309_0 conda-forge
matplotlib-base 3.4.1 py39h581301d_0 conda-forge
mccabe 0.6.1 py39haa95532_1
mistune 0.8.4 py39h2bbff1b_1000
mkl 2020.4 hb70f87d_311 conda-forge
mkl-service 2.3.0 py39h4cdbadb_2 conda-forge
mypy_extensions 0.4.1 py39haa95532_0
nbclient 0.5.3 pyhd3eb1b0_0
nbconvert 6.0.7 py39haa95532_0
nbformat 5.1.3 pyhd3eb1b0_0
nest-asyncio 1.5.1 pyhd3eb1b0_0
netcdf4 1.5.6 pypi_0 pypi
numpy 1.20.2 py39h6635163_0 conda-forge
numpydoc 1.1.0 pyhd3eb1b0_1
olefile 0.46 pyh9f0ad1d_1 conda-forge
openjpeg 2.4.0 h48faf41_0 conda-forge
openssl 1.1.1k h8ffe710_0 conda-forge
packaging 20.9 pyh44b312d_0 conda-forge
pandas 1.2.4 py39hd77b12b_0
pandas-datareader 0.9.0 pyh44b312d_0 conda-forge
pandoc 2.12 haa95532_0
pandocfilters 1.4.3 py39haa95532_1
paramiko 2.7.2 py_0
parso 0.7.0 py_0
pathspec 0.7.0 py_0
patsy 0.5.1 pypi_0 pypi
pexpect 4.8.0 pyhd3eb1b0_3
pickleshare 0.7.5 pyhd3eb1b0_1003
pillow 8.2.0 pypi_0 pypi
pip 21.0.1 py39haa95532_0
pluggy 0.13.1 py39haa95532_0
poyo 0.5.0 pyhd3eb1b0_0
prompt-toolkit 3.0.17 pyh06a4308_0
psutil 5.8.0 py39h2bbff1b_1
ptyprocess 0.7.0 pyhd3eb1b0_2
pycodestyle 2.6.0 pyhd3eb1b0_0
pycparser 2.20 py_2
pydocstyle 6.0.0 pyhd3eb1b0_0
pyflakes 2.2.0 pyhd3eb1b0_0
pygments 2.8.1 pyhd3eb1b0_0
pylint 2.7.4 py39haa95532_1
pyls-black 0.4.6 hd3eb1b0_0
pyls-spyder 0.3.2 pyhd3eb1b0_0
pymc3 3.11.2 pypi_0 pypi
pynacl 1.4.0 py39hbd8134f_1
pyopenssl 20.0.1 pyhd3eb1b0_1
pyparsing 2.4.7 pyhd3eb1b0_0
pyqt 5.9.2 py39hd77b12b_6
pyrsistent 0.17.3 py39h2bbff1b_0
pysocks 1.7.1 py39hcbf5309_3 conda-forge
python 3.9.4 h6244533_0
python-dateutil 2.8.1 pyhd3eb1b0_0
python-jsonrpc-server 0.4.0 py_0
python-language-server 0.36.2 pyhd3eb1b0_0
python-slugify 4.0.1 py_0
python_abi 3.9 1_cp39 conda-forge
pytz 2021.1 pyhd3eb1b0_0
pywin32 228 py39he774522_0
pywin32-ctypes 0.2.0 py39haa95532_1000
pyyaml 5.4.1 py39h2bbff1b_1
pyzmq 20.0.0 py39hd77b12b_1
qdarkstyle 3.0.2 pyhd3eb1b0_0
qstylizer 0.1.10 pyhd3eb1b0_0
qt 5.9.7 vc14h73c81de_0
qtawesome 1.0.2 pyhd3eb1b0_0
qtconsole 5.0.3 pyhd3eb1b0_0
qtpy 1.9.0 py_0
regex 2021.4.4 py39h2bbff1b_0
requests 2.25.1 pyhd3eb1b0_0
rope 0.18.0 py_0
rtree 0.9.7 py39h2eaa2aa_1
scikit-learn 0.24.1 py39he931e04_0 conda-forge
scipy 1.6.2 py39h14eb087_0
seaborn 0.11.1 pypi_0 pypi
semver 2.13.0 pypi_0 pypi
setuptools 52.0.0 py39haa95532_0
sip 4.19.13 py39hd77b12b_0
six 1.15.0 py39haa95532_0
snowballstemmer 2.1.0 pyhd3eb1b0_0
sortedcontainers 2.3.0 pyhd3eb1b0_0
sphinx 3.5.3 pyhd3eb1b0_0
sphinxcontrib-applehelp 1.0.2 pyhd3eb1b0_0
sphinxcontrib-devhelp 1.0.2 pyhd3eb1b0_0
sphinxcontrib-htmlhelp 1.0.3 pyhd3eb1b0_0
sphinxcontrib-jsmath 1.0.1 pyhd3eb1b0_0
sphinxcontrib-qthelp 1.0.3 pyhd3eb1b0_0
sphinxcontrib-serializinghtml 1.1.4 pyhd3eb1b0_0
spyder 5.0.0 py39haa95532_1
spyder-kernels 2.0.1 py39haa95532_0
sqlite 3.35.4 h2bbff1b_0
testpath 0.4.4 pyhd3eb1b0_0
text-unidecode 1.3 py_0
textdistance 4.2.1 pyhd3eb1b0_0
theano-pymc 1.1.2 pypi_0 pypi
threadpoolctl 2.1.0 pyh5ca1d4c_0
three-merge 0.1.1 pyhd3eb1b0_0
tinycss 0.4 pyhd3eb1b0_1002
tk 8.6.10 h8ffe710_1 conda-forge
toml 0.10.2 pyhd3eb1b0_0
tornado 6.1 py39hb82d6ee_1 conda-forge
traitlets 5.0.5 pyhd3eb1b0_0
typed-ast 1.4.2 py39h2bbff1b_1
typing_extensions 3.7.4.3 pyha847dfd_0
tzdata 2020f h52ac0ba_0
ujson 4.0.2 py39hd77b12b_0
unidecode 1.2.0 pyhd3eb1b0_0
urllib3 1.26.4 pyhd3eb1b0_0
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
watchdog 1.0.2 py39haa95532_1
wcwidth 0.2.5 py_0
webencodings 0.5.1 py39haa95532_1
wheel 0.36.2 pyhd3eb1b0_0
whichcraft 0.6.1 pyhd3eb1b0_0
win_inet_pton 1.1.0 py39hcbf5309_2 conda-forge
wincertstore 0.2 py39h2bbff1b_0
wrapt 1.12.1 py39h196d8e1_1
xarray 0.17.0 pypi_0 pypi
xz 5.2.5 h62dcd97_1 conda-forge
yaml 0.2.5 he774522_0
yapf 0.31.0 pyhd3eb1b0_0
zeromq 4.3.3 ha925a31_3
zipp 3.4.1 pyhd3eb1b0_0
zlib 1.2.11 h62dcd97_1010 conda-forge
zstd 1.4.9 h6255e5f_0 conda-forge

Thanks!

I think the issue comes from sigma. You are using a pm.Exponential for it, and then doing sigma**-2, but not only the exponential allows 0, it actually has the max density there. Can you try with an InverseGamma maybe? or a bound on 1e-7?