=[1,2], n=[3,4], p=0.1), [0.243 , 0.0486], eps=1e-05) test_close(binom(k
Math
comb
comb (n, k)
Vectorized combination: comb(n,k)
= n! / ((n-k)!k!)
Type | Details | |
---|---|---|
n | int or np.array of int | First parameter of combination |
k | int or np.array of int | Second parameter of combination |
Returns | np.array | Combination (choose k out of n) |
/home/dw/.local/lib/python3.10/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Example
else: warn(msg)
binom
binom (k, n, p)
Vectorized binomial distribution: binom(k,n,p)
=comb(n,k)
p^k (1-p)^n-k
Type | Details | |
---|---|---|
k | int or list of int | Second parameter of combination |
n | int or list of int | First parameter of combination |
p | float or list of float | Probability |
Returns | np.array | Value(s) of binomial distribution evaluated at k,n,p. |
joint_binom
joint_binom (k, n, p)
Product of independent binomial distributions with parameters k
, n
and p
(can be list of lists), i.e.:
joint_binom(k,n,p)
=binom(k[0],n[0],p[0])
×…×binom(k[-1],n[-1],p[-1])
see Eq. 26 in paper
Type | Details | |
---|---|---|
k | list of int | List of second parameters of combination |
n | list of int | List of first parameters of combination |
p | list of list, list of float, or float | Probability |
Returns | np.array | Joint probability |
=[1,2], n=[3,4], p=[0.1,0.2]), binom(k=1,n=3,p=0.1) * binom(k=2,n=4,p=0.2))
test_close(joint_binom(k=[1,2], n=[2,3], p=[[0.1,0.2],[.3,.4]]), [binom(1,2,0.1)*binom(2,3,0.2), binom(1,2,0.3)*binom(2,3,0.4)]) test_close(joint_binom(k
Wilson_var
Wilson_var (p, N)
Wilson estimator of binomial variance
The formula for the Wilson interval is:
CI = p+z^2/(2n) \pm z\sqrt{pq/n + z^2/(4n^2)}/(1 + z^2/n)
we can extract the var (z=1) as:
Var(p) = (CI/2)^2 = (npq + 0.25) / (1 + n)^2
see Eq. C12 in paper
Type | Details | |
---|---|---|
p | float | Estimator of probability |
N | int | Sample size |
Returns | float | Estimated variance of Wilson CI |
Wald_var
Wald_var (p, N)
Wald estimation of binomial variance
see Eq. C11 in paper
Type | Details | |
---|---|---|
p | float | Estimator of probability |
N | int | Sample size |
Returns | float | Estimated variance of Wald CI |
subset_cards
subset_cards (superset)
Calculate cardinalities of all possible subsets of superset
Type | Details | |
---|---|---|
superset | set | Input set |
Returns | list of int | All possible cardinalities of subsets in superset |
assert(subset_cards({1,2,3}) == {0,1,2,3})
assert(subset_cards({(0,0), (0,1), (0,2)}) == {0,1,2,3})
cartesian_product
cartesian_product (list_of_sets)
Calculate cartesian product between all members of sets
Type | Details | |
---|---|---|
list_of_sets | list | List of sets between which to calculate Cartesian product |
Returns | list of tuple | Cartesian products |
assert(cartesian_product([{1,2},{3,4}]) == [(1,3), (1,4), (2,3), (2,4)])
subset_probs
subset_probs (circuit, error_model, prob)
Calculate occurence probability of subsets in circuit
with physical error rate prob
. error_model
defines how the circuit is to be partitioned before occurence probabilities are calculated.
Type | Details | |
---|---|---|
circuit | Circuit | Circuit wrt. which subset probabilities are calculated |
error_model | ErrorModel | Error model by which to partition circuit |
prob | float or list of float | Physical error probabilities |