scalib.modeling.MultiLDA#

class scalib.modeling.MultiLDA(ncs, ps, pois, gemm_mode=None)[source]#

Perform LDA on nv distinct variables for the same leakage traces.

Deprecated since version 0.6.1: Use LdaAcc instead.

While functionally similar to a simple for loop, this enables solving the LDA problems in parallel in a simple fashion. This also enable easy handling of Points Of Interest (POIs) in long traces.

Parameters:
  • ncs (array_like, int) – Number of classes for each variable. Shape (nv,).

  • ps (array_like, int) – Number of dimensions to keep after dimensionality reduction for each variable. Shape (nv,).

  • pois (list of array_like, int) – Indices of the POIs in the traces for each variable. That is, for variable i, and training trace t, t[pois[i]] is the input datapoints for the LDA.

  • gemm_mode (int | None) – See LDACLassifier.fit_u().

Examples

>>> from scalib.modeling import MultiLDA
>>> import numpy as np
>>> # 5000 traces with 50 points each
>>> traces = np.random.randint(0, 256, (5000,50),dtype=np.int16)
>>> # 5 variables (8-bit), and 5000 traces
>>> x = np.random.randint(0, 256, (5000, 5),dtype=np.uint16)
>>> # 10 POIs for each of the 5 variables
>>> pois = [list(range(7*i, 7*i+10)) for i in range(5)]
>>> # Keep 3 dimensions after dimensionality reduction
>>> lda = MultiLDA(5*[256], 5*[3], pois)
>>> lda.fit_u(traces, x)
>>> lda.solve()
>>> # Predict the class for 20 traces.
>>> nt = np.random.randint(0, 256, (20, 50), dtype=np.int16)
>>> predicted_proba = lda.predict_proba(nt)

Methods

fit_u(traces, x)

Update the LDA estimates with new training data.

get_mus()

get_sb()

get_sw()

predict_proba(traces)

Predict probabilities for all variables.

solve([done])

See LDAClassifier.solve.

fit_u(traces, x)[source]#

Update the LDA estimates with new training data.

Parameters:
  • traces (array_like, int16) – Array that contains the traces. The array must be of dimension (n,ns) and its type must be int16.

  • x (array_like, uint16) – Labels for each trace. Must be of shape (n, nv) and must be uint16.

solve(done=False)[source]#

See LDAClassifier.solve.

Parameters:

done (bool) –

predict_proba(traces)[source]#

Predict probabilities for all variables.

See LDAClassifier.predict_proba.

Parameters:

traces (array_like, int16) – Array that contains the traces. The array must be of dimension (n,ns).

Returns:

Probabilities. nv arrays of shape (n, nc).

Return type:

list of array_like, f64

get_sw()[source]#
get_sb()[source]#
get_mus()[source]#