Skip to content

Commit

Permalink
add maxl stats to brute force marginalization model (#3464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Collin Capano authored Sep 23, 2020
1 parent 08945c8 commit 7d01119
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pycbc/inference/models/brute_marg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self, model):
def __call__(self, params):
global _model
_model.update(**params)
return _model.loglr
loglr = _model.loglr
return loglr, _model.current_stats

class BruteParallelGaussianMarginalize(BaseGaussianNoise):
name = "brute_parallel_gaussian_marginalize"
Expand All @@ -58,12 +59,27 @@ def __init__(self, variable_params,
samples = int(marginalize_phase)
self.phase = numpy.linspace(0, 2.0 * numpy.pi, samples)

@property
def _extra_stats(self):
return self.model._extra_stats + ['maxl_phase', 'maxl_loglr']

def _loglr(self):
if self.phase is not None:
params = []
for p in self.phase:
pref = self.current_params.copy()
pref['coa_phase'] = p
params.append(pref)
loglr = numpy.array(list(self.pool.map(self.call, params)))
vals = list(self.pool.map(self.call, params))
loglr = numpy.array([v[0] for v in vals])
# get the maxl values
maxidx = loglr.argmax()
maxstats = vals[maxidx][1]
maxphase = self.phase[maxidx]
# set the stats
for stat in maxstats:
setattr(self._current_stats, stat, maxstats[stat])
self._current_stats.maxl_phase = maxphase
self._current_stats.maxl_loglr = loglr[maxidx]
# calculate the marginal loglr and return
return logsumexp(loglr) - numpy.log(len(self.phase))

0 comments on commit 7d01119

Please sign in to comment.