prmiles / pymcmcstat

Python implementation of MATLAB toolbox "mcmcstat"
https://github.com/prmiles/pymcmcstat/wiki
MIT License
70 stars 10 forks source link

FloatingPointError: divide by zero encountered in reciprocal #98

Closed XiaoyuHy closed 1 year ago

XiaoyuHy commented 1 year ago

Describe the bug If I run the dram_sampling.py in the attached folder, the following error would occur if the chain runs for some time (in case the error doesn't occur, please re-run dram_sampling.py, the error will reproduce) : mcstat.run_simulation() File "/Users//anaconda3/lib/python3.9/site-packages/pymcmcstat/MCMC.py", line 109, in run_simulation self.__execute_simulator() File "/Users//anaconda3/lib/python3.9/site-packages/pymcmcstat/MCMC.py", line 363, in __execute_simulator sigma2 = self._error_variance.update_error_variance(self.__old_set.ss, self.model_settings) File "/Users/*/anaconda3/lib/python3.9/site-packages/pymcmcstat/procedures/ErrorVarianceEstimator.py", line 61, in update_error_variance sigma2[jj] = (self.gammar(1, 1, 0.5(N0[jj]+N[jj]), FloatingPointError: divide by zero encountered in reciprocal

dram_code.zip

Expected behavior I am not familiar with the "DRAM" algorithm, so I don't know the details about the equations in ErrorVarianceEstimator.py. But the above "FloatingPointError: divide by zero encountered in reciprocal" occurred.

I was wondering whether there is a way to avoid this in the "DRAM" algorithm or could just reject the proposed sample and continue the dram sampling?

Desktop (please complete the following information):

prmiles commented 1 year ago

Sorry for the delay - This package is not actively supported. I'm not in a position to reproduce the error, so I will be unable to help debug.

If you are looking for a more flexible framework, I would recommend PyMC3. If you really want to use the DRAM algorithm, then I'd also recommend PyApprox. Hope that helps, and sorry again for the delay!