pyssaBSS

class pyssaBSS.AugmentationRankEstimator(noise_dim, num_rep=10, random_state=None)[source]

Bases: object

Rank estimator based on data augmentation.

Parameters:
  • noise_dim (int) – Number of Gaussian noise components to append.

  • num_rep (int) – Number of augmentation trials.

  • random_state (int or None) – Random seed for reproducibility.

estimate(model)[source]

Estimate rank by combining measurements of norms of augmented eigenvectors and normalised scree plot of eigenvalues.

Parameters:

model (SSA) – An SSA model to compute the eigendecompositions.

Return type:

RankResult

class pyssaBSS.PolygonDrawer(ax, points, filename='polygons.json')[source]

Bases: object

Polygon drawer

This can be used to construct polygonal partitions of data points on a given map. The partition can then be saved a JSON file and used for the SPSSA methods.

Usage

  1. Initialize:

    drawer = PolygonDrawer(ax, points)

  2. Draw polygons:

    plt.show()

  3. Save polygons:

    drawer.save(“polygons.json”)

type ax:

an ax object from pyplot

param ax:

this is the map on which we draw. The drawer assumes that this is already constructed (e.g. from png and a bounding box)

type ax:

an ax object from pyplot

type points:

ndarray of shape (n, 2)

param points:

the coordinates of the points we want to partition. The points should lie inside the bounding box of the ax figure.

type points:

ndarray of shape (n, 2)

MOVE_THRESHOLD = 2
SNAP_RADIUS_PX = 10
get_polygons()[source]
on_click(event)[source]
on_key(event)[source]
on_move(event)[source]
on_scroll(event)[source]
save(filename)[source]
class pyssaBSS.SPSSA(data, coords, partition, scatter, dim_estimator=None)[source]

Bases: SSA

Spatial Stationary Subspace Analysis (SPSSA)

Examples

Initialize the model:

model = SPSSA(data, coords, scatter=scatter, partition=partition)

Optionally estimate the rank of the nonstationary subspace:

q = model.estimate_rank()

Extract stationary and nonstationary subspaces:

ss, ns = model.subspaces(q)
Parameters:
  • data (ndarray of shape (n_signals, n_samples)) – Observed data matrix. Decomposition is performed immediately on construction.

  • coords (ndarray, optional) – Spatial coordinates passed to the segmentation function. Required when no pre-computed partition are provided.

  • partition (ndarray, optional) – Pre-computed segment labels.

  • scatter (dict, list, or scatter object) – Scatter matrices or operators for subspace analysis.

  • dim_estimator (AugmentationRankEstimator, optional) – An object to compute an estimate of the nonstationary dimension. Currently only support one kind of estimator but could be easily extended to include different estimators.

whitener_

Whitening matrix from data standardization.

Type:

ndarray

diagonalizer_

Matrix that diagonalizes the scatter matrices.

Type:

ndarray

eigenvalues_

Eigenvalues from the diagonalization.

Type:

ndarray

individual_models_

Decomposed models for individual scatters.

Type:

dict[str, SPSSA]

estimated_rank_

Rank estimated by estimate_rank(), if called.

Type:

int or None

pyssaBSS.SPSSA_COMB(data, coords, partition, kernel=None, s=10, r=10, **kwargs)[source]
Return type:

SPSSA

pyssaBSS.SPSSA_LCOR(data, coords, partition, kernel=None, s=10, r=10, **kwargs)[source]
Return type:

SPSSA

pyssaBSS.SPSSA_SAVE(data, coords, partition, s=10, r=10, **kwargs)[source]
Return type:

SPSSA

pyssaBSS.SPSSA_SIR(data, coords, partition, s=10, r=10, **kwargs)[source]
Return type:

SPSSA

class pyssaBSS.SSA(data, partition, scatter, dim_estimator=None)[source]

Bases: object

Stationary Subspace Analysis (SSA)

Examples

Initialize the model:

model = SSA(data, coords, scatter=scatter, partition=partition)

Optionally estimate the rank of the nonstationary subspace:

q = model.estimate_rank()

Extract stationary and nonstationary subspaces:

ss, ns = model.subspaces(q)
Parameters:
  • data (ndarray of shape (n_signals, n_samples)) – Observed data matrix. Decomposition is performed immediately on construction.

  • partition (ndarray, optional) – Partition labels for observations.

  • scatter (dict, list, or scatter object) – Scatter matrices or operators for subspace analysis.

  • dim_estimator (AugmentationRankEstimator, optional) – An object to compute an estimate of the nonstationary dimension. Currently only support one kind of estimator but could be easily extended to include different estimators.

whitener_

Whitening matrix from data standardization.

Type:

ndarray

diagonalizer_

Matrix that diagonalizes the scatter matrices.

Type:

ndarray

eigenvalues_

Eigenvalues from the diagonalization.

Type:

ndarray

individual_models_

Decomposed models for individual scatters.

Type:

dict[str, SSA]

estimated_rank_

Rank estimated by estimate_rank(), if called.

Type:

int or None

rank_summary_

Full rank estimation diagnostics, if estimate_rank() has been called.

Type:

SSARankSummary or RankResult

property eigenvalues: ndarray[tuple[Any, ...], dtype[float64]]

Eigenvalues from the scatter decomposition (copy).

estimate_rank(individual=False)[source]

Estimate the rank (dimension) of the nonstationary subspace.

Parameters:

individual (bool, default False) – If True, also estimate rank for each individual scatter and store full results in rank_summary_. Slower but more informative.

Returns:

Estimated rank of the nonstationary subspace.

Return type:

int

subspaces(q=None)[source]

Return the stationary and nonstationary subspace projection matrices.

Parameters:

q (int, optional) – Dimension of the nonstationary subspace. If omitted, uses the rank stored by a prior call to estimate_rank().

Return type:

Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

  • stationary (ndarray of shape (n_signals - q, n_signals)) – Projection onto the stationary subspace.

  • non_stationary (ndarray of shape (q, n_signals)) – Projection onto the nonstationary subspace.

property whitener: ndarray[tuple[Any, ...], dtype[float64]]

Whitening matrix (copy).

pyssaBSS.SSA_COMB(data, partition, lag=1, s=10, r=10, **kwargs)[source]
Return type:

SSA

pyssaBSS.SSA_COR(data, partition, lag=1, s=10, r=10, **kwargs)[source]
Return type:

SSA

pyssaBSS.SSA_SAVE(data, partition, s=10, r=10, **kwargs)[source]
Return type:

SSA

pyssaBSS.SSA_SIR(data, partition, s=10, r=10, **kwargs)[source]
Return type:

SSA

pyssaBSS.joint_diagonalization(X, weight=None, maxiter=1000, eps=1e-06)[source]

Approximate joint diagonalization

Parameters:
  • X (ndarray of shape (kp, p)) – A concatenation of the k p-by-p matrices to be jointly diagonalized

  • weight (list(float), optional) – A list of weights given to each matrix, prior to diagonalization

  • maxiter (int) – maximum number of iteration in the algorithm before finishing. An assertion is raised if no convergence is found in this time.

  • eps (float) – convergence tolerance

Returns:

  • V (ndarray of shape (p, p)) – joint diagonalized

  • D (list of ndarrays of shape (p, p)) – Gives the “diagonalized” matrices from the procedure in a list

  • iter (int) – total number of iterations

Modules

jdc

joint_diag

kernels

polygon

scatter

spatial

spssa

ssa

types

utils