scalib.metrics.Ttest#
- class scalib.metrics.Ttest(d)[source]#
Univariate (higher order) \(t\)-test.
Concretely, \(\mu[j]\)’s and \(v[j]\)’s are computed for the d-th statistical moment to test at all the indexes (j) in the traces. These are derived based on all the provided traces \(l[:,j]\), that can be provided through multiple calls to fit_u.
The statistic t[j] is then derived as:
for d=1:
\[\mu[j] = \frac{1}{n} \sum_{i=0}^{n-1} l[i,j]\]for d=2:
\[\mu[j] = \frac{1}{n} \sum_{i=0}^{n-1} (l[i,j] - \bar{l}[:,j])^2\]for d>2:
\[\mu[j] = \frac{1}{n} \sum_{i=0}^{n-1} \left(\frac{l[i,j] - \bar{l}[:,j])}{\sigma_{l[:,j]}}\right)^d\]where, \(\bar{l}\) denotes the estimated mean of l and \(\sigma_l\) its standard deviation.
A \(d\)-th order t-test automatically includes the computation of all the lower order t-tests.
Example
>>> from scalib.metrics import Ttest >>> import numpy as np >>> traces = np.random.randint(0,256,(100,200),dtype=np.int16) >>> x = np.random.randint(0,2,100,dtype=np.uint16) >>> ttest = Ttest(d=3) >>> ttest.fit_u(traces,x) >>> t = ttest.get_ttest()
- Parameters:
d (int) – Maximal statistical order of the \(t\)-test.
Methods
fit_u(traces, x)Updates the Ttest estimation with new data.
Return the current Ttest estimation with an array of shape
(d,ns).- fit_u(traces, x)[source]#
Updates the Ttest estimation with new data.
This method may be called multiple times.
- Parameters:
traces (numpy.typing.NDArray.numpy.int16) – Array that contains the traces. The array must be of dimension
(n, ns).x (numpy.typing.NDArray.numpy.uint16) – Set in which each trace belongs. Must be of shape
(n,)and must contain only 0 and 1.