scalib.metrics.MTtest#

class scalib.metrics.MTtest(d, pois)[source]#

Multivariate \(t\)-test.

Concretely, \(\mu[j]\)’s and \(v[j]\)’s are computed to use in the \(t\)-test definition. Especially, \(\mu[j]\)’s is derived such as:

For d=2:

\[\mu[j] = \frac{1}{n} \sum_{i=0}^{n-1} \prod_{d'=0}^{1}l[i,pois[d',j]] - \bar{l}[:,pois[d',j]]\]

For d>2:

\[\mu[j] = \frac{1}{n} \sum_{i=0}^{n-1} \prod_{d'=0}^{d-1} \frac{l[i,pois[d',j]] - \bar{l}[:,pois[d',j]]}{\sigma_{l[:,pois[d',j]]}}\]

Especially, \(\bar{l}\) denotes the estimated mean of l and \(\sigma_l\) its standard deviation. pois defines the points in the traces for which the (normalized) product will be tested.

Parameters:
  • d (int) – Number of variables of the \(t\)-test.

  • pois (array_like, uint32) – Array of shape (d,n_pois). Each column in pois will result in a \(t\)-test of the product of the traces at these \(d\) indexes (each index is between 0 and ns-1). If an index is repeated in a column, the corresponding test uses a higher-order moment for the corresponding point in the trace.

Examples

>>> from scalib.metrics import MTtest
>>> import numpy as np
>>> traces = np.random.randint(0,256,(100,200),dtype=np.int16)
>>> # Take as POIs each point in the trace combined with any of the 10 following samples.
>>> pois = np.array([[x, x+d] for x in range(200) for d in range(10) if x + d < 200], dtype=np.uint32).T
>>> x = np.random.randint(0,2,100,dtype=np.uint16)
>>> mttest = MTtest(d=2,pois=pois)
>>> mttest.fit_u(traces,x)
>>> t = mttest.get_ttest()

Methods

fit_u(traces, x)

Updates the MTtest estimation with new traces.

get_ttest()

Return the current MTtest estimation with an array of shape (n_pois,).

fit_u(traces, x)[source]#

Updates the MTtest estimation with new traces. This method may be called multiple times.

Parameters:
  • traces (numpy.typing.NDArray.numpy.int16) – Array that contains the signal. 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.

get_ttest()[source]#

Return the current MTtest estimation with an array of shape (n_pois,). Each element in that array corresponds to a test defined by pois.

Return type:

numpy.typing.NDArray.numpy.float64