BasisFunctionalData#
- class FDApy.representation.BasisFunctionalData(basis, coefficients)[source]#
Represent functional data with a basis.
A class used to defined functional data with a basis expansion. We denote by \(n\), the number of observations and by \(p\), the number of input dimensions. Here, we are in the case of univariate functional data, and so the output dimension will be \(\mathbb{R}\). We note by \(X\) an observation, while we use \(X_1, \dots, X_n\) if we refer to a particular set of observations. The observations are defined as:
\[X(t) = \sum_{k = 1}^K c_k \phi_k(t), \quad t \in \mathcal{T},\]where \(\mathcal{T} \subset \mathbb{R}^p\) and the \(\phi_k(t)\) is a set of functions.
- Parameters:
basis (Basis) – The basis of the functional data.
coefficients (npt.NDArray[np.float64]) – The set of coefficients.
- Attributes:
n_obs (int) – Number of observations of the functional data.
n_dimension (int) – Number of input dimension of the functional data.
n_points (Tuple[int, …]) – Number of sampling points.
Methods
center([mean, method_smoothing])Center the data.
concatenate(*fdata)Concatenate FunctionalData objects.
covariance([points, method_smoothing])Compute an estimate of the covariance.
inner_product([method_integration, ...])Compute an estimate of the inner product matrix.
mean([points, method_smoothing])Compute an estimate of the mean.
noise_variance([order])Estimate the variance of the noise.
norm([squared, method_integration, ...])Norm of each observation of the data.
normalize(**kwargs)Normalize the data.
rescale([weights, method_integration, ...])Rescale the data.
smooth([points, method, bandwidth, penalty])Smooth the data.
standardize([center])Standardize the data.
to_grid()Convert the data to grid format.
to_long([reindex])Convert the data to long format.
- center(mean=None, method_smoothing=None, **kwargs)[source]#
Center the data.
- Parameters:
mean (None) – Not used here.
method_smoothing (None) – Not used here.
kwargs – Not used here.
- Returns:
The centered version of the data.
- Return type:
- static concatenate(*fdata)[source]#
Concatenate FunctionalData objects.
- Parameters:
fdata (BasisFunctionalData) – Functional data to concatenate.
- Returns:
Concatenated data.
- Return type:
- Raises:
NotImplementedError – Not implemented for BasisFunctionalData.
- covariance(points=None, method_smoothing=None, **kwargs)[source]#
Compute an estimate of the covariance.
- Parameters:
points (None) – Not used here.
method_smoothing (None) – Not used here.
kwargs – Not used here.
- Returns:
An estimate of the covariance as a two-dimensional BasisFunctionalData object.
- Return type:
- inner_product(method_integration='trapz', method_smoothing=None, noise_variance=None, **kwargs)[source]#
Compute an estimate of the inner product matrix.
- Parameters:
method_integration (str) – The method used to integrated.
method_smoothing (str | None) – The method to used for the smoothing of the mean. If ‘None’, no smoothing is performed. If ‘PS’, the method is P-splines. If ‘LP’, the method is local polynomials.
noise_variance (float | None) – An estimation of the variance of the noise. If None, an estimation is computed using the methodology.
kwargs – Other keyword arguments are passed to the following function:
BasisFunctionalData.center().
- Returns:
Inner product matrix of the data.
- Return type:
npt.NDArray[np.float64], shape=(n_obs, n_obs)
- mean(points=None, method_smoothing=None, **kwargs)[source]#
Compute an estimate of the mean.
- Parameters:
points (DenseArgvals | None) – The sampling points at which the mean is estimated. If None, the DenseArgvals of the DenseFunctionalData is used.
method_smoothing (str | None) – The method to used for the smoothing. If ‘None’, no smoothing is performed. If ‘PS’, the method is P-splines. If ‘LP’, the method is local polynomials.
kwargs – Other keyword arguments are passed to the following function
FunctionalData.smooth().
- Returns:
An estimate of the mean as a DenseFunctionalData object.
- Return type:
- noise_variance(order=2)[source]#
Estimate the variance of the noise.
- Parameters:
order (int) – Order of the difference sequence. The order has to be between 1 and 10.
- Returns:
The estimation of the variance of the noise.
- Return type:
- Raises:
NotImplementedError – Not implemented for BasisFunctionalData.
- norm(squared=False, method_integration='trapz', use_argvals_stand=False)[source]#
Norm of each observation of the data.
For each observation in the data, it computes its norm defined as
\[\| X \| = \left\{\int_{\mathcal{T}} X(t)^2dt\right\}^{\frac12}.\]- Parameters:
- Returns:
The norm of each observations.
- Return type:
npt.NDArray[np.float64], shape=(n_obs,)
- normalize(**kwargs)[source]#
Normalize the data.
- Parameters:
kwargs – Other keyword arguments are passed to the following function:
BasisFunctionalData.norm().- Returns:
The normalized data.
- Return type:
- rescale(weights=0.0, method_integration='trapz', use_argvals_stand=False, **kwargs)[source]#
Rescale the data.
- Parameters:
weights (float) – The weights used to normalize the data. If weights = 0.0, the weights are estimated by integrating the variance function.
method_integration (str) – The method used to estimate the integral.
use_argvals_stand (bool) – Use standardized argvals to compute the normalization of the data.
- Returns:
The rescaled data and the weight.
- Return type:
Tuple[BasisFunctionalData, float]
- smooth(points=None, method='PS', bandwidth=None, penalty=None, **kwargs)[source]#
Smooth the data.
- Parameters:
points (DenseArgvals | None) – Points at which the curves are estimated. The default is None, meaning we use the argvals as estimation points.
method (str) – The method to used for the smoothing. If ‘PS’, the method is P-splines. If ‘LP’, the method is local polynomials. Otherwise, it raises an error.
bandwidth (float | None) – Strictly positive. Control the size of the associated neighborhood. If
bandwidth=None, it is assumed that the curves are twice differentiable and the bandwidth is set to \(n^{-1/5}\) where \(n\) is the number of sampling points per curve. Be careful with the results if the curves are not sampled on \([0, 1]\).penalty (float | None) – Strictly positive. Penalty used in the P-splined fitting of the data.
kwargs – Other keyword arguments are passed to one of the following functions
preprocessing.smoothing.PSplines()(method='PS') andpreprocessing.smoothing.LocalPolynomial()(method='LP').
- Returns:
Smoothed data.
- Return type:
- Raises:
NotImplementedError – Not implemented for BasisFunctionalData.
- standardize(center=True, **kwargs)[source]#
Standardize the data.
- Parameters:
center (bool) – Should the data be centered?
kwargs – Other keyword arguments are passed to the following function:
BasisFunctionalData.center().
- Returns:
The standardized data.
- Return type:
- to_long(reindex=False)[source]#
Convert the data to long format.
- Parameters:
reindex (bool) – Not used here.
- Returns:
The data in a long format.
- Return type:
pd.DataFrame
- Raises:
NotImplementedError – Not implemented for BasisFunctionalData.