Testing Models

Introduction

QInfer provides several premade models for quickly learning how to use the library, for making demonstrations, or to test new algorithms and approaches built on top of QInfer.

SimplePrecessionModel - Model of a single qubit undergoing Larmor precession

class qinfer.SimplePrecessionModel(min_freq=0)[source]

Bases: qinfer.test_models.SimpleInversionModel

Describes the free evolution of a single qubit prepared in the \(\left|+\right\rangle\) state under a Hamiltonian \(H = \omega \sigma_z / 2\), as explored in [GFWC12].

Parameters:min_freq (float) – Minimum value for \(\omega\) to accept as valid. This is used for testing techniques that mitigate the effects of degenerate models; there is no “good” reason to ever set this to be less than zero, other than to test with an explicitly broken model.
Model Parameters:
 omega – The precession frequency \(\omega\).
Experiment Parameter float:
 The evolution time \(t\).
expparams_dtype
likelihood(outcomes, modelparams, expparams)[source]
score(outcomes, modelparams, expparams, return_L=False)[source]

NoisyCoinModel - Classical coin flip model corrupted by a noisy process

class qinfer.NoisyCoinModel[source]

Bases: qinfer.abstract_model.FiniteOutcomeModel

Implements the “noisy coin” model of [FB12], where the model parameter \(p\) is the probability of the noisy coin. This model has two experiment parameters, \(\alpha\) and \(\beta\), which are the probabilities of observing a “0” outcome conditoned on the “true” outcome being 0 and 1, respectively. That is, for an ideal coin, \(\alpha = 1\) and \(\beta = 0\).

Note that \(\alpha\) and \(\beta\) are implemented as experiment parameters not because we expect to design over those values, but because a specification of each is necessary to honestly describe an experiment that was performed.

Model Parameters:
 

p – “Heads” probability \(p\).

Experiment Parameters:
 
  • alpha (float) – Visibility parameter \(\alpha\).
  • beta (float) – Visibility parameter \(\beta\).
n_modelparams
expparams_dtype
is_n_outcomes_constant
static are_models_valid(modelparams)[source]
n_outcomes(expparams)[source]
likelihood(outcomes, modelparams, expparams)[source]

NDieModel

class qinfer.NDieModel(n=6, threshold=1e-07)[source]

Bases: qinfer.abstract_model.FiniteOutcomeModel

Implements a model of rolling a die with n sides, whose unknown model parameters are the weights of each side; a generalization of CoinModel. An experiment consists of rolling the die once. The faces of the die are zero indexed, labeled 0,1,2,...,n-1.

Parameters:
  • n (int) – Number of sides on the die.
  • threshold (float) – How close to 1 the probabilites of the sides of the die must be.
n_modelparams
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.

are_models_valid(modelparams)[source]
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]