KarhunenLoeve#
- class FDApy.simulation.KarhunenLoeve(n_functions=5, basis_name='fourier', argvals=None, basis=None, random_state=None, **kwargs_basis)[source]#
Simulate based on Karhunen-Loève decomposition.
This class is used to simulate functional data \(X_1, \dots, X_N\) based on a truncated Karhunen-Loève decomposition:
\[X_i(t) = \sum_{K = 1}^K c_{i, k}\phi_{k}(t), i = 1, \dots, N,\]on one- or higher-dimensional domains. The eigenfunctions \(\phi_{k}(t)\) could be generated using different basis functions or be user-defined. The scores \(c_{i, k}\) are simulated independently from a normal distribution with zero mean and decreasing variance. For higher-dimensional domains, the eigenfunctions are constructed as tensors of marginal orthonormal function systems.
- Parameters:
n_functions (List[Tuple[int] | int]) – Number of functions to use to generate the basis. See Basis and MultivariateBasis for more information.
basis_name (List[Tuple[str] | str] | None) – Name of the basis to use. See Basis and MultivariateBasis for more information.
argvals (List[DenseArgvals] | None) – The sampling points of the functional data.
basis (Basis | Sequence[Basis] | None) – Basis of functions as a Basis object. Used to have a user-defined basis of function.
random_state (int | None) – A seed to initialize the random number generator.
kwargs_basis (Any) – Basis parameters.
- Attributes:
data (DenseFunctionalData | MultivariateFunctionalData) – An object that represents the simulated data.
noisy_data (DenseFunctionalData | MultivariateFunctionalData) – An object that represents a noisy version of the simulated data.
sparse_data (IrregularFunctionalData | MultivariateFunctionalData) – An object that represents a sparse version of the simulated data.
labels (npt.NDArray[np.float64], shape=(n_obs,)) – The integer labels for cluster membership of each sample.
basis (Basis | MultivariateBasis) – The eigenfunctions used to simulate the data.
eigenvalues (npt.NDArray[np.float64], shape=(n_functions,)) – The eigenvalues used to simulate the data.
Notes
In the case of multivariate functional data, \(X_i\) and \(\phi_{k}\) are vectors and according to the multivariate Karhunen-Loève theorem (see, e.g, [1]), the coefficients do not depend on the component \(p\).
If the basis is user-defined, the object has to be an element of the class Basis and not just DenseFunctionalData or MultivariateFunctionalData.
References
Methods
add_noise([noise_variance])Add noise to functional data objects.
add_noise_and_sparsify([noise_variance, ...])Generate a noisy and sparse version of functional data objects.
new(n_obs[, n_clusters, argvals])Simulate realizations from Karhunen-Loève decomposition.
sparsify([percentage, epsilon])Generate a sparse version of functional data objects.
- add_noise(noise_variance=1.0)[source]#
Add noise to functional data objects.
This function generates an artificial noisy version of a functional data object of class
DenseFunctionalDataby adding realizations of Gaussian random variables \(\epsilon \sim \mathcal{N}(0, \sigma^2)\) to the observations. The variance \(\sigma^2\) can be supplied by the user. The generated data are given by\[Y(t) = X(t) + \epsilon.\]- Parameters:
noise_variance (float) – The variance \(\sigma^2\) of the Gaussian noise that is added to the data.
- Returns:
Create the class attribute noisy_data.
- Return type:
None
- add_noise_and_sparsify(noise_variance=1.0, percentage=0.9, epsilon=0.05)[source]#
Generate a noisy and sparse version of functional data objects.
This function generates an artificially noisy and sparse version of a functional datasets. From a functional dataset, it first generates the noisy version and then the sparse version based on the noisy one.
- Parameters:
- Returns:
Create the class attributes noisy_data and sparse_data.
- Return type:
None
- new(n_obs, n_clusters=1, argvals=None, **kwargs)[source]#
Simulate realizations from Karhunen-Loève decomposition.
This function generates
n_obsrealizations of a Gaussian process using the Karhunen-Loève decomposition on a common gridargvals.- Parameters:
n_obs (int) – Number of observations to simulate.
n_clusters (int) – Number of clusters to generate.
argvals (ndarray[Any, dtype[float64]] | None) – Not used in this context. We will use the
argvalsfrom theBasisobject asargvalsof the simulation. Here to be compliant with the classSimulation.kwargs – See below
- Keyword Arguments:
centers (npt.NDArray[np.float64], shape=(n_features, n_clusters)) – The centers of the clusters to generate. The
n_featurescorrespond to the number of functions within the basis.cluster_std (npt.NDArray[np.float64],shape=(n_features, n_clusters)) – The standard deviation of the clusters to generate. The
n_featurescorrespond to the number of functions within the basis.
- Returns:
Create the class attributes data.
- Return type:
None
- sparsify(percentage=0.9, epsilon=0.05)[source]#
Generate a sparse version of functional data objects.
This function generates an artificially sparsified version of a functional data object of class
DenseFunctionalData. The percentage (and the uncertainty around it) of the number of observation points retained can be supplied by the user. Let \(p\) be the defined percentage and \(\epsilon\) be the uncertainty value. The retained number of observations will be different for each curve and be between \(p - \epsilon\) and \(p + \epsilon\).
Examples using FDApy.simulation.KarhunenLoeve#
Smoothing of dense one-dimensional functional data
Smoothing of dense two-dimensional functional data
Simulation using multivariate Karhunen-Loève decomposition
Simulation of clusters of univariate functional data
Simulation of clusters of multivariate functional data