Skip to content

Commit

Permalink
Changes random seed behaviour and includes likelihood logging
Browse files Browse the repository at this point in the history
On every call of `pipeline._core_likelihood` the seeds are reset using the `pipeline._randomness()` method. This allows the same seeds to be used for the stochastic fields on every point in the parameter space (except for the free case).
Basic logging, which prints the value of the liklihood on every evaluation, can be achieved using `logging.basicConfig(filename=FOO/BAR,level=logging.INFO)`.
  • Loading branch information
luizfelippesr committed Sep 3, 2020
1 parent b2a847b commit 7045112
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions imagine/pipelines/pipeline.py
Expand Up @@ -149,6 +149,8 @@ def chains_directory(self, chains_directory):

def clean_chains_directory(self):
"""Removes the contents of the chains directory"""
log.debug('@ pipeline::clean_chains_directory')

if mpirank==0:
for f in os.listdir(self.chains_directory):
fullpath = path.join(self.chains_directory, f)
Expand Down Expand Up @@ -477,6 +479,8 @@ def tidy_up(self):
"""
Resets internal state before a new run
"""
log.debug('@ pipeline::tidy_up')

self.results = None
self._evidence = None
self._evidence_err = None
Expand Down Expand Up @@ -506,6 +510,7 @@ def _randomness(self):
else:
self.ensemble_seeds = None


# This function returns all parameter names of all factories in order
def get_par_names(self):
# Create list of names
Expand Down Expand Up @@ -561,6 +566,9 @@ def _core_likelihood(self, cube):
log.debug('@ pipeline::_core_likelihood')
log.debug('sampler at %s' % str(cube))

# Resets the seeds
self._randomness()

# Obtain observables for provided cube
observables = self._get_observables(cube)

Expand All @@ -569,6 +577,9 @@ def _core_likelihood(self, cube):
# check likelihood value until negative (or no larger than given threshold)
if self.check_threshold and current_likelihood > self.likelihood_threshold:
raise ValueError('log-likelihood beyond threshold')

log.info('Likelihood evaluation at point:'
' {0} value: {1}'.format(cube, current_likelihood))
return current_likelihood * self.likelihood_rescaler

def _mpi_likelihood(self, cube):
Expand Down

0 comments on commit 7045112

Please sign in to comment.