Note
Go to the end to download the full example code
Simulation of clusters of univariate functional data#
Examples of simulation of clusters of univariate functional data.
# Author: Steven Golovkine <steven_golovkine@icloud.com>
# License: MIT
# Load packages
import numpy as np
from FDApy.simulation.karhunen import KarhunenLoeve
from FDApy.visualization.plot import plot
# Set general parameters
rng = 42
n_obs = 20
# Define the random state
random_state = np.random.default_rng(rng)
# Parameters of the basis
name = 'fourier'
n_functions = 25
# Parameters of the clusters
n_clusters = 2
mean = np.array([0, 0])
covariance = np.array([[1, -0.6], [-0.6, 1]])
centers = random_state.multivariate_normal(mean, covariance, size=n_functions)
We simulate \(N = 20\) curves on the one-dimensional observation grid \(\{0, 0.01, 0.02, \cdots, 1\}\), based on the first \(K = 25\) Fourier basis functions on \([0, 1]\). The clusters are defined through the coefficients in the Karhunen-Loève decomposition. The centers of the clusters are generated as Gaussian random variables with parameters defined by mean and covariance. We also consider an exponential decreasing of the eigenvalues.

Total running time of the script: (0 minutes 0.165 seconds)