Bug when passing return_logprobs=True
Closed this issue · 1 comments
adrn commented
Nathan De Lee said:
There is a longer standing problem that my student and I have been trying to figure out. The joker returns a series of periods, but how do we get a sense of the likelihood of each one? I found the parameter return_logprobs=True, but when I use it I get the following error below. Are we going about this the right way?
from thejoker.sampler import TheJoker
pool = schwimmbad.MultiPool()
joker = TheJoker(params, pool=pool)
samples = joker.rejection_sample(data, n_prior_samples=65536,return_logprobs=True)
INFO: 45 good samples after rejection sampling [thejoker.sampler.sampler]
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/lib/student/anaconda3/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/local/lib/student/anaconda3/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/thejoker/sampler/multiproc_helpers.py", line 215, in _sample_vector_worker
ln_prior = np.array(f['ln_prior_probs'][tmp])
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/h5py_1496889914775/work/h5py/_objects.c:2846)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/h5py_1496889914775/work/h5py/_objects.c:2804)
File "/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/h5py/_hl/group.py", line 169, in __getitem__
oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/h5py_1496889914775/work/h5py/_objects.c:2846)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/home/ilan/minonda/conda-bld/h5py_1496889914775/work/h5py/_objects.c:2804)
File "h5py/h5o.pyx", line 190, in h5py.h5o.open (/home/ilan/minonda/conda-bld/h5py_1496889914775/work/h5py/h5o.c:3740)
KeyError: "Unable to open object (Object 'ln_prior_probs' doesn't exist)"
"""
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
<ipython-input-3-e1973fc29e8f> in <module>()
3 joker = TheJoker(params, pool=pool)
4 #joker = TheJoker(params)
----> 5 samples = joker.rejection_sample(data, n_prior_samples=65536,return_logprobs=True) #, return_logprobs=True
6 #n_prior_samples this many random values, find likilood for each of these should be a power of 2.
/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/thejoker/sampler/sampler.py in rejection_sample(self, data, n_prior_samples, prior_cache_file, return_logprobs, start_idx)
335 result = self._rejection_sample_from_cache(
336 data, n_prior_samples, prior_cache_file, start_idx,
--> 337 seed=seed, return_logprobs=return_logprobs)
338
339 return self._unpack_full_samples(result, prior_units, t0=data.t0,
/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/thejoker/sampler/sampler.py in _rejection_sample_from_cache(self, data, n_prior_samples, cache_file, start_idx, seed, return_logprobs)
241 result = sample_indices_to_full_samples(
242 good_samples_idx, cache_file, data, self.params,
--> 243 pool=self.pool, global_seed=seed, return_logprobs=return_logprobs)
244
245 return result
/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/thejoker/sampler/multiproc_helpers.py in sample_indices_to_full_samples(good_samples_idx, prior_cache_file, data, joker_params, pool, global_seed, return_logprobs, n_batches)
265 args=args)
266
--> 267 samples = [r for r in pool.map(_sample_vector_worker, tasks)]
268 samples = np.concatenate(samples)
269
/usr/local/lib/student/anaconda3/lib/python3.6/site-packages/schwimmbad/multiprocessing.py in map(self, func, iterable, chunksize, callback)
104 while True:
105 try:
--> 106 return r.get(self.wait_timeout)
107
108 except multiprocessing.TimeoutError:
/usr/local/lib/student/anaconda3/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
642 return self._value
643 else:
--> 644 raise self._value
645
646 def _set(self, i, obj):
KeyError: "Unable to open object (Object 'ln_prior_probs' doesn't exist)"
(also remember to deal with #73 !!)
benjaminpope commented
Seconded - would be useful to have!