Closed stephengreen closed 1 year ago
I've made various additional improvements to the code:
IterationTracker
and remove_init_outliers
options again for the GNPESampler
.Result.importance_sampling_metadata
. We should also use this to store calibration information and updates to priors, data conditioning, etc.
This splits off importance sampling and related functionality from the
Sampler
class into theResult
class (previouslySamplesDataset
). The purpose is to simplify and streamline the code, to make it easier to maintain and to write a new inference interface.Key changes / methods in each class:
core.result.Result(DingoDataset)
samples
,context
,event_metadata
,log_evidence
, andlog_evidence_std
.importance_sample()
subset(parameters)
: Returns a newResult
with a subset of parameters (and dropping weights, log probs, etc.). This is called before training an unconditional flow.train_unconditional_flow(parameters, nde_settings)
: Trains an unconditional flow model and returns it.gw.result.Result(core.result.Result)
sample_synthetic_phase()
Sampler
and subclassesrun_sampler(num_samples)
log_prob(samples)
: I still have to check whether this works, but I'm not sure it's really needed. I think it can wait until later.unconditional_model
attribute specifies whether the model is unconditional, and if so sampling ignores any event context. This information is stored and accessed from the model metadata.UnconditionalSampler
classes were removed.GNPESampler
use_gnpe_proxy_sampler
flag. Instead, wheninit_sampler
gives proxy variables, these are recognized by the GNPE transform and used directly rather than resampled from the kernel.num_iterations = 1
, and then thelog_prob
will be included in the final result.PosteriorModel
context
andevent_metadata
are now attributes. I found that it was more straightforward to store this information directly rather than deep within a hierarchy of metadata.Action required
For detector-time GNPE, I introduced new parameter names
L1_time_proxy_relative
, etc., to denote theL1_time_proxy
after having subtracted off the relative time shifts. This is needed in order to separately preserveL1_time_proxy
for training unconditional flows, etc. (This replacesGNPE:L1_time_proxy
, etc.) Consequently the GNPE networks are conditioned onL1_time_proxy_relative
rather thanL1_time_proxy
.To make existing networks compatible with the new
GNPEDetectorTimes
class, it is necessary to rename the context variables in the.pt
files. This can be done using the compatibility script,update_saved_model_gnpe_context_names.py
.Still to-do
IterationTracker
back intoGNPESampler._run_sampler()
.