Bayes risk

qif.measure.bayes_risk

Bayes risk \(1 - V_1(\pi)\) is the probability that the adversary guesses the secret wrongly in one try (see Bayes vulnerability). It is an uncertainty measure: lower values are worse for the user.

Functions

prior(pi: ndarray) → FloatOrRat

The Bayes risk \(1 - V_1(\pi)\).

posterior(pi: ndarray, C: ndarray) → FloatOrRat

The posterior Bayes risk \(1 - V_1[\pi\triangleright C]\).

add_leakage(pi: ndarray, C: ndarray) → FloatOrRat

The additive leakage: prior minus posterior risk (equal to the additive Bayes leakage).

mult_leakage(pi: ndarray, C: ndarray) → FloatOrRat

The multiplicative leakage: prior risk divided by posterior risk. It is \(1\) if the prior risk is \(0\), and infinity if only the posterior risk is \(0\).

mult_capacity(C: ndarray, method: str = 'direct') → Tuple[FloatOrRat, ndarray]

The multiplicative capacity: the maximum of mult_leakage() over all priors. Returns (capacity, pi), where pi is a prior achieving it.

The capacity is \(1/(1 - \frac12 \max_{x,x'} \lVert C_{x,-} - C_{x',-}\rVert_1)\), achieved by the uniform prior on the two secrets \(x, x'\) whose rows are furthest apart. With method="direct" all pairs of rows are compared; method="linf" uses an embedding in \(\ell_\infty\), faster when C has few columns.

strategy(pi: ndarray, C: ndarray) → ndarray

The optimal guess for each observation (same as qif.measure.bayes_vuln.strategy()).