zblz / naima

Derivation of non-thermal particle distributions through MCMC spectral fitting
http://naima.readthedocs.io
BSD 3-Clause "New" or "Revised" License
45 stars 54 forks source link

Cannot save results table #147

Closed wrijupan closed 7 years ago

wrijupan commented 7 years ago

Hello, I am trying to save the results of a model fitting using naima.save_results_table. But after the burn-in and run phase it displays this error message :

INFO: Saving results table in ./results_ssc_fit/data_fit_table_results.ecsv [naima.analysis] {...} File "/Users/wriju/miniconda3/envs/cta/lib/python3.6/site-packages/naima/analysis.py", line 295, in save_results_table nblobs = len(sampler.blobs[-1][0]) TypeError: object of type 'NoneType' has no len()

Then I tried again to re-run without any change in the code (i.e. same prior function, same initial parameter vector, same no. of walkers, burn-in and run steps etc) and the error message is no longer displayed the second time and the code executes smoothly.

Is this due to convergence problem due to less number of samples?

zblz commented 7 years ago

The method to check how many blobs are returned for each sampling step is overly simple in save_results_table, and here it failed because the last sample returned a probability of -Inf and the blobs were not stored. I'll make the logic to check the blob number bit more robust.

Thanks for the catch, @wrijupan!

zblz commented 7 years ago

On review, I'm not sure why this has happened, since whenever the log probability is -Inf emcee will not store the result of the sample, and that is the only case when a blob from the model will be None.

zblz commented 7 years ago

@wrijupan - As I have not been able to reproduce this and can't understand how it may have happened, I'm going to close this issue and consider the time it failed for you a fluke. If it happens again, please re-open the issue and try to copy a minimal example of how it was triggered.