Skip to content

Commit

Permalink
cc
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnitz committed Oct 7, 2024
1 parent efbcd89 commit e261090
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pycbc/inference/sampler/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
from pycbc.pool import choose_pool
from .dummy import DummySampler


def call_likelihood(params):
""" Accessor to update the global model
"""
models._global_instance.update(**params)
return models._global_instance.loglikelihood


class OutOfSamples(Exception):
"""Exception if we ran out of samples"""
pass


class GameSampler(DummySampler):
"""Direct importance sampling using a preconstructed parameter space
mapping file.
Expand Down Expand Up @@ -154,7 +158,7 @@ def run(self):
with h5py.File(self.mapfile, 'r') as mapfile:
bparams = {p: mapfile['bank'][p][:] for p in self.variable_params}
num_nodes = len(bparams[list(bparams.keys())[0]])
lengths = numpy.array([len(mapfile['map'][str(x)])
lengths = numpy.array([len(mapfile['map'][str(x)])
for x in range(num_nodes)])
self.dtype = mapfile['map']['0'].dtype

Expand All @@ -172,12 +176,11 @@ def run(self):

logging.info('Drawing proposal samples from node regions')
logw = node_loglrs + numpy.log(lengths)
passed = (node_loglrs > loglr_bound) & ~numpy.isnan(node_loglrs)
passed = (node_loglrs > loglr_bound) & ~numpy.isnan(node_loglrs)
passed = numpy.where(passed)[0]
logw2 = logw[passed]
logw2 -= logsumexp(logw2)
weight = numpy.exp(logw2)
node_loglrsp = node_loglrs[passed]

logging.info("...reading template bins")
with h5py.File(self.mapfile, 'r') as f:
Expand Down Expand Up @@ -215,8 +218,6 @@ def run(self):
weight2 = numpy.concatenate([weight2_v, weight2])
bin_ids = numpy.concatenate([bin_id, bin_ids])

uniq = numpy.unique(psamp)

ess = 1.0 / ((weight2/weight2.sum()) ** 2.0).sum()
logging.info("ESS = %s", ess)

Expand Down

0 comments on commit e261090

Please sign in to comment.