|
| Eigen::VectorXd | mean (const Eigen::Ref< const Eigen::MatrixXd > &data) |
| | Computes the empirical mean vector of a dataset.
|
| |
| Eigen::MatrixXd | covariance (const Eigen::Ref< const Eigen::MatrixXd > &data) |
| | Computes the sample covariance matrix of a dataset.
|
| |
| double | quantile (const Eigen::Ref< const Eigen::VectorXd > &data, double quantile) |
| | Computes a specific quantile of a 1D vector of data.
|
| |
| Eigen::VectorXd | interQuantileRange (const Eigen::Ref< const Eigen::MatrixXd > &data, double lowerQuantile, double upperQuantile) |
| | Computes the interquartile range (IQR) column-wise for a dataset.
|
| |
| Eigen::MatrixXd | pearsonCorrelation (const Eigen::Ref< const Eigen::MatrixXd > &data1, const Eigen::Ref< const Eigen::MatrixXd > &data2) |
| | Computes the Pearson correlation matrix between two datasets.
|
| |
| Eigen::MatrixXd | laggedCorrelation (const Eigen::Ref< const Eigen::MatrixXd > &data1, const Eigen::Ref< const Eigen::MatrixXd > &data2, int lag) |
| | Computes the cross-correlation matrix between two datasets with a specified temporal lag.
|
| |
| std::vector< Eigen::MatrixXd > | laggedCorrelation (const Eigen::Ref< const Eigen::MatrixXd > &data1, const Eigen::Ref< const Eigen::MatrixXd > &data2, int minLag, int maxLag) |
| | Returns the cross-correlation matrices between two datasets for a sequence of lags.
|
| |
| std::pair< Eigen::VectorXd, double > | selfCorrelationLength (const Eigen::Ref< const Eigen::MatrixXd > &data) |
| | Computes the self-correlation (autocorrelation) length and the effective sample size.
|
| |
| std::vector< Eigen::MatrixXd > | selfCrossCorrelationFFT (const Eigen::Ref< const Eigen::MatrixXd > &data) |
| | Computes the complete auto- and cross-correlation functions across all lags efficiently using the Fast Fourier Transform (FFT).
|
| |
| Eigen::MatrixXd cmp::statistics::covariance |
( |
const Eigen::Ref< const Eigen::MatrixXd > & |
data | ) |
|
Computes the sample covariance matrix of a dataset.
Mathematical Formulation
Given a dataset matrix \(\mathbf{X} \in \mathbb{R}^{N \times D}\) with mean vector \(\boldsymbol{\mu}\), the unbiased sample covariance matrix \(\mathbf{\Sigma} \in \mathbb{R}^{D \times D}\) is:
\[
\mathbf{\Sigma} = \frac{1}{N-1} (\mathbf{X} - \mathbf{1}\boldsymbol{\mu}^T)^T (\mathbf{X} - \mathbf{1}\boldsymbol{\mu}^T)
\]
- Parameters
-
| data | A reference to an Eigen matrix containing the data (points in rows). |
- Returns
- The covariance matrix of the data.
- Exceptions
-
| std::invalid_argument | if the input matrix has fewer than 2 rows. |
| Eigen::VectorXd cmp::statistics::interQuantileRange |
( |
const Eigen::Ref< const Eigen::MatrixXd > & |
data, |
|
|
double |
lowerQuantile, |
|
|
double |
upperQuantile |
|
) |
| |
Computes the interquartile range (IQR) column-wise for a dataset.
Mathematical Formulation
For each feature column \( j \):
\[
\text{IQR}_j = Q_{\text{upper}, j} - Q_{\text{lower}, j}
\]
where \(Q\) represents the value at the specified quantile probabilities.
- Parameters
-
| data | A reference to an Eigen matrix containing the data (points in rows). |
| lowerQuantile | The lower probability bound (e.g., 0.25). |
| upperQuantile | The upper probability bound (e.g., 0.75). |
- Returns
- A vector containing the IQR for each feature column.
- Exceptions
-
| std::invalid_argument | if the input matrix is empty or the quantiles are invalid. |
| Eigen::MatrixXd cmp::statistics::pearsonCorrelation |
( |
const Eigen::Ref< const Eigen::MatrixXd > & |
data1, |
|
|
const Eigen::Ref< const Eigen::MatrixXd > & |
data2 |
|
) |
| |
Computes the Pearson correlation matrix between two datasets.
Mathematical Formulation
For columns \(X_i\) from data1 and \(Y_j\) from data2, the correlation coefficient is:
\[
\rho_{ij} = \frac{\mathrm{cov}(X_i, Y_j)}{\sigma_{X_i} \sigma_{Y_j}}
\]
Manages the case where the datasets have different numbers of points by aligning them appropriately if supported by the implementation.
- Parameters
-
| data1 | First dataset (points in rows). |
| data2 | Second dataset (points in rows). |
- Returns
- The Pearson correlation matrix \( \mathbf{R} \in \mathbb{R}^{D_1 \times D_2} \).
| std::vector< Eigen::MatrixXd > cmp::statistics::selfCrossCorrelationFFT |
( |
const Eigen::Ref< const Eigen::MatrixXd > & |
data | ) |
|
|
inline |
Computes the complete auto- and cross-correlation functions across all lags efficiently using the Fast Fourier Transform (FFT).
Mathematical Formulation (Wiener-Khinchin Theorem)
The cross-correlation \(R_{ij}(\tau)\) between feature \(i\) and \(j\) can be computed in the frequency domain:
\[
R_{ij}(\tau) = \mathcal{F}^{-1}\left\{ \mathcal{F}\{x_i\} \cdot \mathcal{F}\{x_j\}^* \right\}
\]
where \(\mathcal{F}\) is the discrete Fourier transform. Data is mean-centered, zero-padded to the next power of 2 to avoid circular convolution artifacts, and properly normalized by sample variances.
- Parameters
-
| data | A reference to the dataset matrix (time points in rows, features in columns). |
- Returns
- A vector of length
nPoints. Each element is a nFeatures x nFeatures matrix representing the correlation at lag \(\tau\).