Probability

class Probability(outcome, alpha_prior=0.5, validate=True)[source]

Compute the mean probability of a single measurement outcome from counts.

This node returns the mean and standard deviation of a single measurement outcome probability \(p\) estimated from the observed counts. The mean and variance are computed from the posterior Beta distribution \(B(\alpha_0^\prime,\alpha_1^\prime)\) estimated from a Bayesian update of a prior Beta distribution \(B(\alpha_0, \alpha_1)\) given the observed counts.

The mean and variance of the Beta distribution \(B(\alpha_0, \alpha_1)\) are:

\[\text{E}[p] = \frac{\alpha_0}{\alpha_0 + \alpha_1}, \quad \text{Var}[p] = \frac{\text{E}[p] (1 - \text{E}[p])}{\alpha_0 + \alpha_1 + 1}\]

Given a prior Beta distribution \(B(\alpha_0, \alpha_1)\), the posterior distribution for the observation of \(F\) counts of a given outcome out of \(N\) total shots is a \(B(\alpha_0^\prime,\alpha_1^\prime):math:\) with

\[\alpha_0^\prime = \alpha_0 + F, \quad \alpha_1^\prime = \alpha_1 + N - F.\]

Note

The default value for the prior distribution is Jeffery’s Prior \(\alpha_0 = \alpha_1 = 0.5\) which represents ignorance about the true probability value. Note that for this prior the mean probability estimate from a finite number of counts can never be exactly 0 or 1. The estimated mean and variance are given by

\[\text{E}[p] = \frac{F + 0.5}{N + 1}, \quad \text{Var}[p] = \frac{\text{E}[p] (1 - \text{E}[p])}{N + 2}\]

This node will deprecate standard error provided by the previous node.

Initialize a counts to probability data conversion.

Parameters:
  • outcome (str) – The bitstring for which to return the probability and variance.

  • alpha_prior (float | Sequence[float]) – A prior Beta distribution parameter [alpha0, alpha1]. If specified as float this will use the same value for alpha0 and alpha1 (Default: 0.5).

  • validate (bool) – If set to False the DataAction will not validate its input.

Raises:

DataProcessorError – When the dimension of the prior and expected parameter vector do not match.

Methods

__call__(data)

Call the data action of this node on the data.

Parameters:

data (ndarray) – A numpy array with arbitrary dtype. If the elements are ufloat objects consisting of a nominal value and a standard error, then the error propagation is done automatically.

Returns:

The processed data.

Return type:

ndarray