Derived Models

Introduction

QInfer provides several models which decorate other models, providing additional functionality or changing the behaviors of underlying models.

PoisonedModel - Model corrupted by likelihood errors

class qinfer.derived_models.PoisonedModel(underlying_model, tol=None, n_samples=None, hedge=None)[source]

Bases: qinfer.derived_models.DerivedModel

Model that simulates sampling error incurred by the MLE or ALE methods of reconstructing likelihoods from sample data. The true likelihood given by an underlying model is perturbed by a normally distributed random variable \(\epsilon\), and then truncated to the interval \([0, 1]\).

The variance of \(\epsilon\) can be specified either as a constant, to simulate ALE (in which samples are collected until a given threshold is met), or as proportional to the variance of a possibly-hedged binomial estimator, to simulate MLE.

Parameters:
  • underlying_model (Model) – The “true” model to be poisoned.
  • tol (float) – For ALE, specifies the given error tolerance to simulate.
  • n_samples (int) – For MLE, specifies the number of samples collected.
  • hedge (float) – For MLE, specifies the hedging used in estimating the true likelihood.
likelihood(outcomes, modelparams, expparams)[source]
simulate_experiment(modelparams, expparams, repeat=1)[source]

Simulates experimental data according to the original (unpoisoned) model. Note that this explicitly causes the simulated data and the likelihood function to disagree. This is, strictly speaking, a violation of the assumptions made about Model subclasses. This violation is by intention, and allows for testing the robustness of inference algorithms against errors in that assumption.

BinomialModel - Model over batches of two-outcome experiments

class qinfer.derived_models.BinomialModel(underlying_model)[source]

Bases: qinfer.derived_models.DerivedModel

Model representing finite numbers of iid samples from another model, using the binomial distribution to calculate the new likelihood function.

Parameters:underlying_model (qinfer.abstract_model.Model) – An instance of a two- outcome model to be decorated by the binomial distribution.

Note that a new experimental parameter field n_meas is added by this model. This parameter field represents how many times a measurement should be made at a given set of experimental parameters. To ensure the correct operation of this model, it is important that the decorated model does not also admit a field with the name n_meas.

decorated_model
expparams_dtype
is_n_outcomes_constant

Returns True if and only if the number of outcomes for each experiment is independent of the experiment being performed.

This property is assumed by inference engines to be constant for the lifetime of a Model instance.

n_outcomes(expparams)[source]

Returns an array of dtype uint describing the number of outcomes for each experiment specified by expparams.

Parameters:expparams (numpy.ndarray) – Array of experimental parameters. This array must be of dtype agreeing with the expparams_dtype property.
likelihood(outcomes, modelparams, expparams)[source]
simulate_experiment(modelparams, expparams, repeat=1)[source]
update_timestep(modelparams, expparams)[source]