zblz / naima

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

Number of samples, -63, must be non-negative. #203

Closed Jongsu020509 closed 2 years ago

Jongsu020509 commented 4 years ago

I got this error. What's the meaning of the message. How do I solve that? Sometimes, I got a similar error for another case. Also, I could get the result for some sources. Later that code could not run and get the same error.

I used only X-ray data points (8 points in 2-10 keV range) and calculated the sed of SYN+IC.

ValueError: Number of samples, -63, must be non-negative.

: Detail state

Burning in the 32 walkers with 100 steps...

Progress of the run: 0 percent (0 of 100 steps) -----norm------ -----index----- ---Bemission--- -----Emax------ Last ensemble median : 6.57e+34 4.18 0.399 117
Last ensemble std : 7.66e+33 0.431 0.0342 12.4
Last ensemble lnprob : avg: -230792.641, max: -58.090 emcee: Exception while calling your likelihood function: params: [6.50071740e+34 5.24159828e-01 5.76878126e-01 2.30941885e-01] args: [ energy flux flux_error_lo ... energy_error_hi ul cl
eV erg / (cm2 s) erg / (cm2 s) ... eV
float64 float64 float64 ... float64 bool float64 ------- ----------------- ----------------- ... --------------- ----- ------- 2500.0 4.44221935471e-16 1.03131563233e-16 ... 458.03989155 False 0.9 3500.0 1.51914769845e-16 3.5290418964e-17 ... 468.626966597 False 0.9 4500.0 6.91353236038e-17 1.60641153617e-17 ... 474.937185533 False 0.9 5500.0 3.70851465876e-17 8.60778876131e-18 ... 479.130371551 False 0.9 6500.0 2.21156648583e-17 5.13442247366e-18 ... 482.120021884 False 0.9 7500.0 1.42200132152e-17 3.30336691127e-18 ... 484.359711336 False 0.9 8500.0 9.66941054609e-18 2.24538905144e-18 ... 486.100377806 False 0.9 9500.0 6.86752106149e-18 1.59535307694e-18 ... 513.899622194 False 0.9, <function ElectronSynIC at 0x7f07399aeb18>, <function lnprior at 0x7f072e262b18>] kwargs: {} exception: Traceback (most recent call last): File "/home/lee/.local/lib/python2.7/site-packages/emcee/ensemble.py", line 519, in call return self.f(x, *self.args, self.kwargs) File "/home/lee/.local/lib/python2.7/site-packages/naima/core.py", line 117, in lnprob modelout = modelfunc(pars, data) File "SynIC_SED_a11.py", line 36, in ElectronSynIC model = SYN.flux(data, distance=dist) + IC.flux(data, distance=dist) File "/home/lee/.local/lib/python2.7/site-packages/naima/radiative.py", line 787, in flux photon_energy, distance=distance File "/home/lee/.local/lib/python2.7/site-packages/naima/model_utils.py", line 68, in model result = func(cls, energy, *args, *kwargs) File "/home/lee/.local/lib/python2.7/site-packages/naima/radiative.py", line 112, in flux spec = self._spectrum(photon_energy) File "/home/lee/.local/lib/python2.7/site-packages/naima/radiative.py", line 763, in _spectrum self._calc_specic(seed, outspecene).to("1/(s eV)") File "/home/lee/.local/lib/python2.7/site-packages/naima/radiative.py", line 720, in _calc_specic self._gam, T.to("K").value, Eph File "/home/lee/.local/lib/python2.7/site-packages/naima/radiative.py", line 169, in _gam log10gmin, log10gmax, int(self.nEed (log10gmax - log10gmin)) File "/usr/local/lib/python2.7/dist-packages/numpy/core/function_base.py", line 277, in logspace y = linspace(start, stop, num=num, endpoint=endpoint, axis=axis) File "/usr/local/lib/python2.7/dist-packages/numpy/core/function_base.py", line 130, in linspace raise ValueError("Number of samples, %s, must be non-negative." % num) ValueError: Number of samples, -63, must be non-negative. Traceback (most recent call last): File "SynIC_SED_a11.py", line 78, in interactive=False File "/home/lee/.local/lib/python2.7/site-packages/naima/core.py", line 556, in run_sampler sampler, pos = get_sampler(kwargs) File "/home/lee/.local/lib/python2.7/site-packages/naima/core.py", line 517, in get_sampler sampler, pos = _run_mcmc(sampler, p0, nburn) File "/home/lee/.local/lib/python2.7/site-packages/naima/core.py", line 153, in _run_mcmc for i, out in enumerate(sampler.sample(pos, iterations=nrun)): File "/home/lee/.local/lib/python2.7/site-packages/emcee/ensemble.py", line 259, in sample lnprob[S0]) File "/home/lee/.local/lib/python2.7/site-packages/emcee/ensemble.py", line 332, in _propose_stretch newlnprob, blob = self._get_lnprob(q) File "/home/lee/.local/lib/python2.7/site-packages/emcee/ensemble.py", line 382, in _get_lnprob results = list(M(self.lnprobfn, [p[i] for i in range(len(p))])) File "/home/lee/.local/lib/python2.7/site-packages/emcee/interruptible_pool.py", line 94, in map return r.get(self.wait_timeout) File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value ValueError: Number of samples, -63, must be non-negative.

zblz commented 2 years ago

From the error message it seems like the value you are using for the maximum electron energy is lower than that of the minimum electron energy. If this is still a problem, could you share the Eemin and Eemax attributes of the particle distribution instance you are using?