phoebe2 icon indicating copy to clipboard operation
phoebe2 copied to clipboard

init_from and priors

Open mkounkel opened this issue 4 years ago • 3 comments

Trying to run emcee, setting init_from and priors to two different distributions. b.set_value(qualifier='init_from', context='solver', solver='emcee_solver', value=['ball_around_guess']) b.set_value(qualifier='priors', context='solver', solver='emcee_solver', value=['prior_around_guess'])

If they are both set to the same value, everything runs fine. If only init_from is set, wit priors blank, everything also runs fine. But, setting both of them to the different value results in a long error that starts with emcee: Exception while calling your likelihood function: and ends with

~/opt/anaconda3/lib/python3.7/site-packages/phoebe/parameters/parameters.py in _send_if_client(self, *args, **kwargs) 399 400 else: --> 401 return fctn(self, *args, **kwargs) 402 403 return _send_if_client

~/opt/anaconda3/lib/python3.7/site-packages/phoebe/frontend/bundle.py in run_solver(self, solver, solution, detach, return_changes, **kwargs) 11537 11538 solver_class = getattr(_solverbackends, '{}Backend'.format(solver_ps.kind.title()))

11539 params = solver_class().run(self, solver_ps.solver, compute, solution=solution, **{k:v for k,v in kwargs.items() if k not in ['compute']}) 11540 metawargs = {'context': 'solution', 11541 'solver': solver_ps.solver,

~/opt/anaconda3/lib/python3.7/site-packages/phoebe/solverbackends/solverbackends.py in run(self, b, solver, compute, **kwargs) 509 510 else: --> 511 rpacketlists_per_worker = [self.run_worker(**packet)] 512 513 logger.debug("rank:{}/{} calling _fill_solution".format(mpi.myrank, mpi.nprocs))

~/opt/anaconda3/lib/python3.7/site-packages/phoebe/solverbackends/solverbackends.py in run_worker(self, b, solver, compute, **kwargs) 1356 1357 logger.debug("sampler.sample(p0, {})".format(sargs)) -> 1358 for sample in sampler.sample(p0.T, **sargs): 1359 # TODO: parameters and options for checking convergence 1360

~/opt/anaconda3/lib/python3.7/site-packages/emcee-3.0.2-py3.7.egg/emcee/ensemble.py in sample(self, initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress) 283 state.blobs = blobs0 284 if state.log_prob is None: --> 285 state.log_prob, state.blobs = self.compute_log_prob(state.coords) 286 if np.shape(state.log_prob) != (self.nwalkers,): 287 raise ValueError("incompatible input dimensions")

~/opt/anaconda3/lib/python3.7/site-packages/emcee-3.0.2-py3.7.egg/emcee/ensemble.py in compute_log_prob(self, coords) 425 map_func = map 426 results = list( --> 427 map_func(self.log_prob_fn, (p[i] for i in range(len(p)))) 428 ) 429

~/opt/anaconda3/lib/python3.7/site-packages/phoebe/pool/multipool.py in map(self, func, iterable, chunksize, callback) 108 while True: 109 try: --> 110 return r.get(self.wait_timeout) 111 112 except TimeoutError:

~/opt/anaconda3/lib/python3.7/multiprocessing/pool.py in get(self, timeout) 655 return self._value 656 else: --> 657 raise self._value 658 659 def _set(self, i, obj):

ValueError: value must be passed or set in order to create distl distribution object

This is setting up everything in python directly. The same issue is not present in ui exporting to a file (but it's rather painful to set up distributions in there, as they are not editable half the time). But, copying the same syntax from the ui via the exported logger, once again seems to break...

mkounkel avatar Feb 11 '21 20:02 mkounkel

I can't seem to reproduce this, at least not in a general case. My only guess is that maybe all the samples in the first iteration are outside the priors and are being rejected, is that possible?

If you can send me a script to reproduce, your bundle file, or at least the lines to create both your distribution sets, I can try to reproduce and fix the issue (at the least to raise a more informative error, if there isn't anything else that can be done). Thanks!

kecnry avatar Feb 12 '21 16:02 kecnry

I also just updated the emcee tutorial to show a case of using priors that does work on my end.

In case this might be something with emcee versioning, can you try running the notebook from that tutorial (ignore if you run into a plotting bug when doing the trace plot - I'm just about to push out a bugfix for that as well)? And also let me know the version of emcee you have installed (I have 3.0.2):

import emcee
print(emcee.__version__)

kecnry avatar Feb 12 '21 19:02 kecnry

I have the same emcee version.

I started up with the init_from distribution to be more constrained than the priors - so that they could walk away from where they were there, but not too far (working with ellc before has taught us to prior everything, no matter how insignificant, because it really liked to wander off into an unphysical territory, ending up with negative periods of all things... but that's neither here nor there). Doing it this way gives the error, though. But, if I flip them around, to have init_from wider than the priors - that somehow runs. I can send a notebook separately.

mkounkel avatar Feb 12 '21 20:02 mkounkel