# 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.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.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.
domain(expparams)[source]

Returns a list of Domains, one for each input expparam.

Parameters: expparams (numpy.ndarray) – Array of experimental parameters. This array must be of dtype agreeing with the expparams_dtype property, or, in the case where n_outcomes_constant is True, None should be a valid input. list of Domain
are_expparam_dtypes_consistent(expparams)[source]

Returns True iff all of the given expparams correspond to outcome domains with the same dtype. For efficiency, concrete subclasses should override this method if the result is always True.

Parameters: expparams (np.ndarray) – Array of expparamms of type expparams_dtype bool
likelihood(outcomes, modelparams, expparams)[source]
simulate_experiment(modelparams, expparams, repeat=1)[source]
update_timestep(modelparams, expparams)[source]

## MultinomialModel - Model over batches of D-outcome experiments¶

class qinfer.MultinomialModel(underlying_model)[source]

Bases: qinfer.derived_models.DerivedModel

Model representing finite numbers of iid samples from another model with a fixed and finite number of outcomes, using the multinomial distribution to calculate the new likelihood function.

Parameters: underlying_model (qinfer.abstract_model.FiniteOutcomeModel) – An instance of a D-outcome model to be decorated by the multinomial distribution. This underlying model must have is_n_outcomes_constant as True.

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_sides

Returns the number of possible outcomes of the underlying model.

underlying_domain

Returns the Domain of the underlying model.

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.
domain(expparams)[source]

Returns a list of Domain objects, one for each input expparam. :param numpy.ndarray expparams: Array of experimental parameters. This

array must be of dtype agreeing with the expparams_dtype property.
Return type: list of Domain
are_expparam_dtypes_consistent(expparams)[source]

Returns True iff all of the given expparams correspond to outcome domains with the same dtype. For efficiency, concrete subclasses should override this method if the result is always True.

Parameters: expparams (np.ndarray) – Array of expparamms of type expparams_dtype bool
likelihood(outcomes, modelparams, expparams)[source]
simulate_experiment(modelparams, expparams, repeat=1)[source]

## MLEModel - Model for approximating maximum-likelihood estimation¶

class qinfer.MLEModel(underlying_model, likelihood_power)[source]

Bases: qinfer.derived_models.DerivedModel

Uses the method of [JDD08] to approximate the maximum likelihood estimator as the mean of a fictional posterior formed by amplifying the Bayes update by a given power $$\gamma$$. As $$\gamma \to \infty$$, this approximation to the MLE improves, but at the cost of numerical stability.

Parameters: likelihood_power (float) – Power to which the likelihood calls should be rasied in order to amplify the Bayes update.
simulate_experiment(modelparams, expparams, repeat=1)[source]
likelihood(outcomes, modelparams, expparams)[source]