1import numpy as np
2from pyssaBSS import SPSSA_COMB
3from pyssaBSS.kernels import ScaledBallKernel
4from pyssaBSS.spatial import partition_coordinates
5# data: (n_signals, n_samples), coords: (n_samples, 2)
6data = np.random.randn(5, 400)
7coords = np.random.uniform(0, 20, (400, 2))
8
9# Partition the spatial domain
10partition = partition_coordinates(coords, 3, 3, 20)
11
12# Add nonstationarity in the mean to the last signal
13for part in partition:
14 data[-1, part] += np.random.uniform(low=-5, high=5)
15
16# Decompose
17model = SPSSA_COMB(data, coords, partition=partition, kernel=ScaledBallKernel(2.2))
18
19# Estimate rank of non-stationary subspace
20q = model.estimate_rank()
21print(f"Estimated rank: {q}")
22
23# Extract subspaces
24stationary, non_stationary = model.subspaces(q)
25print(f"Stationary subspace: {stationary.shape}")
26print(f"Non-stationary subspace: {non_stationary.shape}")