MvarModel
Namespace: CONNECTIVITYLIB · Library: Connectivity Library
#include <connectivity/mvar_model.h>
class CONNECTIVITYLIB::MvarModel
Multivariate autoregressive (MVAR) model fit and its frequency-domain decomposition into transfer function H(f) and spectral matrix S(f).
The model order p is either supplied by the caller or selected automatically by Bayesian Information Criterion over [1, 20]; the coefficient matrices are estimated by Levinson-Durbin recursion on the Yule-Walker equations. The resulting H and S are consumed by the three directed-connectivity metrics in this library (Granger Causality, DTF, PDC) and are exposed via transferFunction and spectralMatrix at arbitrary normalised frequencies.
MVAR model fit; provides H(f) and S(f) for Granger Causality, DTF and PDC.
MatrixXd average = MatrixXd::Zero(3, kSamples);
for (int i = 0; i < settings.size(); ++i) {
average += settings.at(i).matData / settings.size();
}
MvarModel mvar;
mvar.fit(average, 4); // pass 0 to select the order by BIC
const QVector<MatrixXd> coefficients = mvar.coefficients(); // A_1 .. A_p
const QVector<MatrixXcd> transfer = mvar.transferFunction(VectorXd::LinSpaced(5, 0.0, 0.5));
Public Methods
MvarModel()
Constructs a default MvarModel object.
fit(data, p)
Fits an MVAR model of order p to multi-channel data.
Parameters:
-
data : const Eigen::MatrixXd & The input data matrix (nChannels x nSamples).
-
p : int The model order. If 0, the order is auto-selected via BIC.
coefficients()
Returns the fitted coefficient matrices A_1 .
. A_p (each nChannels x nChannels).
Returns:
- QVector< Eigen::MatrixXd > — The MVAR coefficient matrices.
noiseCov()
Returns the noise covariance matrix (nChannels x nChannels).
Returns:
- Eigen::MatrixXd — The noise covariance matrix.
order()
Returns the fitted model order.
Returns:
- int — The model order p.
transferFunction(freqs)
Computes the transfer function H(f) at the given normalized frequencies.
H(f) = (I - sum_{k=1}^{p} A_k * exp(-2piifk))^{-1}
Parameters:
- freqs : const Eigen::VectorXd & Vector of normalized frequencies in [0, 0.5].
Returns:
- QVector< Eigen::MatrixXcd > — Vector of nChannels x nChannels complex matrices, one per frequency.
spectralMatrix(freqs)
Computes the spectral matrix S(f) = H(f) * Sigma * H(f)^H.
Parameters:
- freqs : const Eigen::VectorXd & Vector of normalized frequencies in [0, 0.5].
Returns:
- QVector< Eigen::MatrixXcd > — Vector of nChannels x nChannels complex matrices, one per frequency.
Example
- Full source:
src/examples/ex_connectivity_metrics/main.cpp - Build target:
ex_connectivity_metrics(runs under CTest)
Used in examples
ex_connectivity_metrics
Connectivity metrics on synthetic data with a known coupling.
MvarModel mvar;
mvar.fit(average, 4); // pass 0 to select the order by BIC
const QVector<MatrixXd> coefficients = mvar.coefficients(); // A_1 .. A_p
const QVector<MatrixXcd> transfer = mvar.transferFunction(VectorXd::LinSpaced(5, 0.0, 0.5));
ok &= expect(mvar.order() == 4 && coefficients.size() == 4 && transfer.size() == 5,
"MvarModel stores order 4 and evaluates H(f) at 5 frequencies");
ok &= expect(std::fabs(coefficients[kDelay - 1](1, 0)) > 0.5,
QString("|A_3(1,0)| %1 > 0.5: channel 1 depends on channel 0 three samples back")
.arg(std::fabs(coefficients[kDelay - 1](1, 0))));
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>