Experiment Design Algorithms¶
Optimization¶
ExperimentDesigner
 Greedy Risk Minimization Algorithm¶
Class Reference¶

class
qinfer.
ExperimentDesigner
(updater, opt_algo=1)[source]¶ Bases:
object
Designs new experiments using the current best information provided by a Bayesian updater.
Parameters:  updater (qinfer.smc.SMCUpdater) – A Bayesian updater to design experiments for.
 opt_algo (OptimizationAlgorithms) – Algorithm to be used to perform local optimization.

new_exp
()[source]¶ Resets this
ExperimentDesigner
instance and prepares for designing the next experiment.

design_expparams_field
(guess, field, cost_scale_k=1.0, disp=False, maxiter=None, maxfun=None, store_guess=False, grad_h=None, cost_mult=False)[source]¶ Designs a new experiment by varying a single field of a shape
(1,)
record array and minimizing the objective function\[O(\vec{e}) = r(\vec{e}) + k \$(\vec{e}),\]where \(r\) is the Bayes risk as calculated by the updater, and where \(\$\) is the cost function specified by the model. Here, \(k\) is a parameter specified to relate the units of the risk and the cost. See Experiment Design Algorithms for more details.
Parameters:  guess (Instance of
Heuristic
,callable
orndarray
ofdtype
expparams_dtype
) – Either a record array with a single guess, or a callable function that generates guesses.  field (str) – The name of the
expparams
field to be optimized. All other fields ofguess
will be held constant.  cost_scale_k (float) – A scale parameter \(k\) relating the Bayes risk to the experiment cost. See Experiment Design Algorithms.
 disp (bool) – If
True
, the optimization will print additional information as it proceeds.  maxiter (int) – For those optimization algorithms which support it (currently, only CG and NELDER_MEAD), limits the number of optimization iterations used for each guess.
 maxfun (int) – For those optimization algorithms which support it (currently, only NCG and NELDER_MEAD), limits the number of objective calls that can be made.
 store_guess (bool) – If
True
, will compare the outcome of this guess to previous guesses and then either store the optimization of this experiment, or the previous bestknown experiment design.  grad_h (float) – Step size to use in estimating gradients. Used
only if
opt_algo
is NCG.
Returns: An array representing the best experiment design found so far for the current experiment.
 guess (Instance of
Heuristics¶
Heuristic
 Base class for heuristic experiment designers.¶

class
qinfer.
Heuristic
(updater)[source]¶ Bases:
object
Defines a heuristic used for selecting new experiments without explicit optimization of the risk. As an example, the \(t_k = (9/8)^k\) heuristic discussed by [FGC12] does not make explicit reference to the risk, and so would be appropriate as a
Heuristic
subclass. In particular, the [FGC12] heuristic is implemented by theExpSparseHeuristic
class.Note that the design of this abstract base class is still being decided, such that it is a placeholder for now.
ExpSparseHeuristic
 Exponentiallysparse timesampling heuristic.¶

class
qinfer.
ExpSparseHeuristic
(updater, scale=1, base=1.125, t_field=None, other_fields=None)[source]¶ Bases:
qinfer.expdesign.Heuristic
Implements the exponentiallysparse time evolution heuristic of [FGC12], under which \(t_k = A b^k\), where \(A\) and \(b\) are parameters of the heuristic.
Parameters:  updater (qinfer.smc.SMCUpdater) – Posterior updater for which experiments should be heuristicly designed.
 scale (float) – The value of \(A\), implicitly setting the frequency scale for the problem.
 base (float) – The base of the exponent; in general, should be closer to 1 for higherdimensional models.
 t_field (str) – Name of the expparams field representing time. If None, then the generated expparams are taken to be scalar, and not a record.
 other_fields (dict) – Values of the other fields to be used in designed experiments.
PGH
 Particle Guess Heuristic¶

class
qinfer.
PGH
(updater, inv_field='x_', t_field='t', inv_func=<function identity>, t_func=<function identity>, maxiters=10, other_fields=None)[source]¶ Bases:
qinfer.expdesign.Heuristic
Implements the particle guess heuristic (PGH) of [WGFC13a], which selects two particles from the current posterior, selects one as an inversion hypothesis and sets the time parameter to be the inverse of the distance between the particles. In this way, the PGH adapts to the current uncertianty without additional simulation resources.
Parameters:  updater (qinfer.smc.SMCUpdater) – Posterior updater for which experiments should be heuristicly designed.
 inv_field (str) – Name of the
expparams
field corresponding to the inversion hypothesis.  t_field (str) – Name of the
expparams
field corresponding to the evolution time.  inv_func (callable) – Function to be applied to modelparameter vectors
to produce an inversion field
x_
.  t_func (callable) – Function to be applied to the evolution time to produce a
time field
t
.  maxiters (int) – Number of times to try and choose distinct particles before giving up.
 other_fields (dict) – Values to set for fields not given by the PGH.
Once initialized, a
PGH
object can be called to generate a new experiment parameter vector:>>> pgh = PGH(updater) >>> expparams = pgh()
If the posterior weights are very highly peaked (that is, if the effective sample size is too small, as measured by
n_ess
), then it may be the case that the two particles chosen by the PGH are identical, such that the time would be determined by1 / 0
. In this case, thePGH
class will instead draw new pairs of particles until they are not identical, up tomaxiters
attempts. If that limit is reached, aRuntimeError
will be raised.