ℓ-risk (loss-based Bayes risk)¶
qif.measure.l_risk
A loss function \(\ell(w,x)\) gives the adversary’s loss when she takes action \(w \in \mathcal W\) and the secret is \(x\). The \(\ell\)-risk \(U_\ell(\pi) = \min_w \sum_x \pi_x\, \ell(w,x)\) is her expected loss when she takes the best action; it is an uncertainty measure, so leakage is computed as prior minus (or divided by) posterior risk.
As for g-vulnerability, a loss function is given either as a loss matrix L, with one row per action and one column per
secret, or as a function l(w, x), in which case the actions are assumed to be the secrets.
Functions¶
- prior(L: ndarray, pi: ndarray) FloatOrRat¶
- prior(l: Metric[int, FloatOrRat], pi: ndarray) FloatOrRat
The \(\ell\)-risk \(U_\ell(\pi) = \min_w \sum_x \pi_x\, \ell(w,x)\).
- posterior(L: ndarray, pi: ndarray, C: ndarray) FloatOrRat¶
- posterior(l: Metric[int, FloatOrRat], pi: ndarray, C: ndarray) FloatOrRat
The posterior \(\ell\)-risk \(U_\ell[\pi\triangleright C] = \sum_y \min_w \sum_x \pi_x C_{x,y}\, \ell(w,x)\).
- add_leakage(L: ndarray, pi: ndarray, C: ndarray) FloatOrRat¶
- add_leakage(l: Metric[int, FloatOrRat], pi: ndarray, C: ndarray) FloatOrRat
The additive leakage \(U_\ell(\pi) - U_\ell[\pi\triangleright C]\).
- mult_leakage(L: ndarray, pi: ndarray, C: ndarray) FloatOrRat¶
- mult_leakage(l: Metric[int, FloatOrRat], pi: ndarray, C: ndarray) FloatOrRat
The multiplicative leakage \(U_\ell(\pi) / U_\ell[\pi\triangleright C]\).
- strategy(L: ndarray, pi: ndarray, C: ndarray) ndarray¶
- strategy(l: Metric[int, FloatOrRat], pi: ndarray, C: ndarray) ndarray
The optimal action for each observation: an array whose element \(y\) is the \(w\) minimizing \(\sum_x \pi_x C_{x,y}\, \ell(w,x)\).
- add_capacity(pi: ndarray, C: ndarray, one_spanning_g: bool = False) FloatOrRat¶
The additive capacity for a fixed prior, over a class of loss functions. Since the additive leakage of \(\ell\) is the same as that of the gain function \(k - \ell\) (for any constant \(k\)), this is equal to
qif.measure.g_vuln.add_capacity(): the class contains the loss functions with \(\max U_\ell - \min U_\ell \le 1\), or, ifone_spanning_gis true, those with \(\max \ell - \min \ell \le 1\).
- loss_to_gain(n_secrets: int, n_guesses: int, l: Metric[int, FloatOrRat]) Metric[int, FloatOrRat]¶
Converts a loss function into a gain function \(g(w,x) = k - \ell(w,x)\), where \(k\) is the maximum of \(\ell\) over
n_guessesactions andn_secretssecrets. Then \(V_g = k - U_\ell\).