Qiflib modules
Core QIF objects.
Submodules: - channel: channel matrices / mechanisms - gvulnerability: g-vulnerability and related leakage quantities - hyper: hyper-distributions over secrets - luncertainty: L-uncertainty measures - secrets: priors / secret spaces
- class qiflib.core.Channel(secrets, outputs, channel)[source]
Bases:
objectClass used to represent a channel. To create an instance of this class it is necessary to have an instance of
Secretsclass and a channel matrix C \(n{\times}m\) where \(n\) is the number of secrets, \(m\) is the number of outputs in the channel andC[x][y]is the conditional probability \(p(y|x)\) of the channel outputs \(y\) when the value of the secret is \(x\).- Parameters:
secrets (core.Secrets) – Secrets object.
outputs (list) – Outputs labels.
channel (numpy.ndarray) – Channel matrix. Each line must be a probability distribution.
- secrets
Set of secrets.
- Type:
- matrix
Channel matrix where
C[x][y]is the conditional probability \(p(y|x)\) of the channel outputs \(y\) when the value of the secret is \(x\).- Type:
list, numpy.ndarray
- update_prior(prior)[source]
Update the prior distribution on set of secrets. The number of secrets must match the current number of rows of the channel.
- Parameters:
prior (list, numpy.ndarray) – Prior distribution on the set of secrets. prior[i] is the probability of secret named labels[i] beeing the real secret.
- class qiflib.core.GVulnerability(secrets, actions, gfunction)[source]
Bases:
object\(g\)-vulnerability. To create an instance of this class it is necessary to have an instance of
Secretsclass and a gain function, that can be a matrix or a pointer to a function. The matrix G must be G \(w{\times}n\) where \(w\) is the number of actions, \(n\) is the number of secrets andG[w][x]is the adversary’s gain when she takes the actionwand the secret’s value isx. The function must have two input parameters (action w and secret x, in this order) and outputs a real value.- Parameters:
secrets (core.Secrets) – Set of secrets.
actions (list) – Set of actions.
gfunction (list, numpy.ndarray, pointer to a function) – A 2d matrix or a pointer to a gain function. If the value is a matrix, its shape must match with the actions and secrets sets size. If the value is a pointer to a function, the function must have 2 input parameters (w,x), where w is the index of an element from the set of actions and x is an index of an element from the set of secrets.
- secrets
Secrets object.
- Type:
- matrix
Gain function matrix.
gain[w][x]is the adversary’s gain when she takes the action of indexw(that has the labelactions[w]) and the secret is the one from indexx(and has the labelsecrets.labels[x]).- Type:
numpy.ndarray
- leakage(hyper)[source]
Calculates the additive and multiplicative leakages.
- Parameters:
hyper (core.hyper.Hyper) – Hyper-distribution
- Returns:
add_leakage, mult_leakage – Additive and multiplicative leakage
- Return type:
- posterior_vulnerability(hyper)[source]
Posterior vulnerability.
- Parameters:
hyper (core.Hyper) – Hyper-distribution.
- Returns:
posterior_vulnerability – Posterior vulnerability.
- Return type:
- class qiflib.core.Hyper(channel)[source]
Bases:
objectHyper-distribution. To create an instance of this class it is class it is necessary to have an instance of
Channelclass. Once created an instance ofHyper, the constructor generates the joint, outer and inner distributions.- Parameters:
channel (core.Channel) – Channel object.
- channel
Channel object.
- Type:
- joint
Matrix of joint distribution.
- Type:
numpy.ndarray
- outer
Outer distribution.
- Type:
numpy.ndarray
- inners
Matrix of inner distributions.
- Type:
numpy.ndarray
- num_posteriors
Number of posterior distributions resulted by reducing the hyper-distribution, i.e., remove columns that contains only zeros and merge columns which one of them a linear combination of the other.
- Type:
- update_prior(prior)[source]
Update the prior distribution on set of secrets. The number of secrets must match the current number of rows of the channel.
- Parameters:
prior (list, numpy.ndarray) – Prior distribution on the set of secrets. prior[i] is the probability of secret named labels[i] beeing the real secret.
- class qiflib.core.LUncertainty(secrets, actions, lfunction)[source]
Bases:
object\(\ell\)-uncertainty. To create an instance of this class it is necessary to have an instance of
Secretsclass and a loss function, that can be a matrix or a pointer to a function. The matrix G must be G \(w{\times}n\) where \(w\) is the number of actions, \(n\) is the number of secrets andG[w][x]is the adversary’s loss when she takes the actionwand the secret’s value isx. The function must have two input parameters (action w and secret x, in this order) and outputs a real value.- Parameters:
secrets (core.Secrets) – Set of secrets.
actions (list) – Set of actions.
lfunction (list, numpy.ndarray, pointer to a function) – A 2d matrix or a pointer to a loss function. If the value is a matrix, its shape must match with the actions and secrets sets size. If the value is a pointer to a function, the function must have 2 input parameters (w,x), where w is the index of an element from the set of actions and x is an index of an element from the set of secrets.
- secrets
Secrets object.
- Type:
- matrix
Loss function matrix.
loss[w][x]is the adversary’s loss when she takes the action of indexw(that has the labelactions[w]) and the secret is the one from indexx(and has the labelsecrets.labels[x]).- Type:
numpy.ndarray
- leakage(hyper)[source]
Calculates the additive and multiplicative leakages.
- Parameters:
hyper (core.hyper.Hyper) – Hyper-distribution
- Returns:
add_leakage, mult_leakage – Additive and multiplicative leakage
- Return type:
- posterior_uncertainty(hyper)[source]
Posterior uncertainty.
- Parameters:
hyper (core.Hyper) – Hyper-distribution.
- Returns:
posterior_uncertainty – Posterior uncertainty.
- Return type:
- class qiflib.core.Secrets(secrets, prior)[source]
Bases:
objectClass used to represent a set of secrets. To create an instance of this class it is necessary a set of labels and a probability distribution to be set as the prior distribution on the set of secrets.
- Parameters:
- prior
Prior distribution on the set of secrets.
prior[i]is the probability of secret namedlabels[i]beeing the real secret.- Type:
numpy.ndarray
- update_prior(prior)[source]
Update prior distribution array. The number of elements in the array must be the same as the current number of secrets.
- Parameters:
prior (list, numpy.ndarray) – Prior distribution on the set of secrets. prior[i] is the probability of secret named labels[i] beeing the real secret.