pyfli.simulator.calibration.optimizer#
Simulation-based calibration of the pyfli simulator config.
Functions
|
|
|
|
|
Expected share of signal photons that land in active time bins, for the prior-mean lifetimes of state (photons in inactive bins are zeroed in data and simulation). |
|
Simulate with |
|
One bank round: simulate, global search (differential evolution), Nelder-Mead polish. |
|
|
|
Move |
|
|
|
Alternate prior fits (bank) and IRF / detector fits (real simulations). |
|
(nuisance names searched with real simulations, prior names searched on the re-weighted bank). |
Classes
|
|
|
|
|
Maps a flat unconstrained vector to a |
|
Simulated pixels from a broad proposal, re-weighted to any candidate set of Beta priors. |
- class CalibrationState(irf: IRFEstimate, priors: PriorSet, dcr: float, photon_scale: float = 1.0)[source]#
Bases:
object- Parameters:
irf (IRFEstimate)
priors (PriorSet)
dcr (float)
photon_scale (float)
- irf: IRFEstimate#
- class ObjectiveContext(fm: DecayForwardModel, detector_type: str, laser_freq_mhz: float, jitter: bool, comparator: StatsComparator, bg_bins: ndarray, exp_counts: ndarray, exp_peaks: ndarray, data_max: float, bit_depth: int | None, prior_inflation: float, n_sim: int, seed: int, reference_moments: dict = <factory>, reference_weight: float = 0.0, fixed_photon_prior: bool = False, inactive_bins: ndarray = <factory>)[source]#
Bases:
object- Parameters:
fm (DecayForwardModel)
detector_type (str)
laser_freq_mhz (float)
jitter (bool)
comparator (StatsComparator)
bg_bins (ndarray)
exp_counts (ndarray)
exp_peaks (ndarray)
data_max (float)
bit_depth (int | None)
prior_inflation (float)
n_sim (int)
seed (int)
reference_moments (dict)
reference_weight (float)
fixed_photon_prior (bool)
inactive_bins (ndarray)
- comparator: StatsComparator#
- active_photon_fraction(state, ctx)[source]#
Expected share of signal photons that land in active time bins, for the prior-mean lifetimes of state (photons in inactive bins are zeroed in data and simulation). 1 for continuous detectors or when every bin is active.
- Parameters:
state (CalibrationState)
ctx (ObjectiveContext)
- Return type:
- refresh_photon_prior(state, ctx)[source]#
- Parameters:
state (CalibrationState)
ctx (ObjectiveContext)
- Return type:
- class ParameterVector(base, ctx, names)[source]#
Bases:
objectMaps a flat unconstrained vector to a
CalibrationStateand back.- Parameters:
base (CalibrationState)
ctx (ObjectiveContext)
- evaluate(state, ctx, n=None, seed=None)[source]#
Simulate with
stateand return(distance, parts, sim_batch, sim_stats).- Parameters:
state (CalibrationState)
ctx (ObjectiveContext)
n (int | None)
seed (int | None)
- optimize_stage(base, ctx, names, max_evals, label)[source]#
- Parameters:
base (CalibrationState)
ctx (ObjectiveContext)
max_evals (int)
label (str)
- Return type:
- stage_parameter_names(state, ctx, optimize_irf, optimize_noise, optimize_priors, is_bi)[source]#
(nuisance names searched with real simulations, prior names searched on the re-weighted bank).
- class PriorBank(state, ctx, n, seed, uniform_share=0.3)[source]#
Bases:
objectSimulated pixels from a broad proposal, re-weighted to any candidate set of Beta priors.
The bank is a defensive mixture:
uniform_shareof the pixels come from flat Beta(1, 1) priors on the current supports, the rest from the current priors widened about 4x in variance. For target priorspieach pixel gets the weightpi(theta) / q(theta), so the statistics of any candidate prior are obtained without re-simulating. IRF, noise and photon priors stay fixed inside one bank.- Parameters:
state (CalibrationState)
ctx (ObjectiveContext)
n (int)
seed (int)
uniform_share (float)
- recenter_tau2_support(state, margin=0.3)[source]#
Move
tau2_beta_rangeto the fitted prior’s 0.1-99.9 % range plusmarginon each side, keeping the prior’s mean and SD. Initial supports from noisy per-pixel fits are usually far too wide, which wastes the bank and makes the Beta very skewed.- Parameters:
state (CalibrationState)
margin (float)
- Return type:
- fit_priors_on_bank(base, ctx, names, n_bank, max_evals, round_idx, min_ess=300.0)[source]#
One bank round: simulate, global search (differential evolution), Nelder-Mead polish.
- Parameters:
base (CalibrationState)
ctx (ObjectiveContext)
n_bank (int)
max_evals (int)
round_idx (int)
min_ess (float)
- Return type:
- run_calibration_rounds(state, ctx, nuisance, prior_names, n_bank, rounds, max_evals_nuisance, max_evals_priors)[source]#
Alternate prior fits (bank) and IRF / detector fits (real simulations).
- Parameters:
state (CalibrationState)
ctx (ObjectiveContext)
n_bank (int)
rounds (int)
max_evals_nuisance (int)
max_evals_priors (int)
- Return type: