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(α0,α1) estimated from a Bayesian update of a prior Beta distribution B(α0,α1) given the observed counts.

The mean and variance of the Beta distribution B(α0,α1) are:

E[p]=α0α0+α1,Var[p]=E[p](1E[p])α0+α1+1

Given a prior Beta distribution B(α0,α1), the posterior distribution for the observation of F counts of a given outcome out of N total shots is a B(α0,α1):math: with

α0=α0+F,α1=α1+NF.

Note

The default value for the prior distribution is Jeffery’s Prior α0=α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

E[p]=F+0.5N+1,Var[p]=E[p](1E[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