MUQ  0.4.3
muq::Approximation::KarhunenLoeveExpansion Class Reference

Used to compute and evaluate the Karhunen-Loeve decomposition of a zero mean Gaussian process. @sealso SeperableKarhunenLoeve. More...

#include <KarhunenLoeveExpansion.h>

Inheritance diagram for muq::Approximation::KarhunenLoeveExpansion:

Detailed Description

Used to compute and evaluate the Karhunen-Loeve decomposition of a zero mean Gaussian process. @sealso SeperableKarhunenLoeve.

Background

According to the Karhunen-Loeve theorem, under mild technical conditions, a zero mean (i.e., centered) stochastic process admits a decomposition of the form

\[ u(x) = \sum_{k=1}^\infty \phi_k(x) z_k, \]

where \(u(x)\) is the original stochastic process, \(\phi_k(x)\) is deterministic basis function, and \(z_k\) are uncorrelated random variables. Notice that this Karhunen-Loeve decomposition is a continuous analog of standard principle component decompositions for finite dimensional random variables.

For a Gaussian process, the basis functions \(\phi_k(x)\) can be calculated from the covariance kernel defining the process. In particular, each \(z_k\) will be an indepedent standard normal random variable and \(\phi_k(x)\) will be given by

\[ \phi_k(x) = \sqrt{\lambda_k} e_k(x), \]

where \(\lambda_k\) and \(e_k(x)\) are the \(k^{th}\) eigenvalue and eigenvector of the covariance kernel \(k(x,x^\prime)\). In particular, \(\lambda_k\) and \(e_k(x)\) satisfy

\[ \int_\Omega k(x,x^\prime) e_k(x) dx = \lambda_k e_k(x^\prime). \]

The constructor of this class uses the Nystrom method to approximately solve for \(\lambda_k\) and \(e_k(x)\). The method starts with a set of \(N\) seed (quadrature) points \(x_i\) and a set of weights \(w_i\) that satisfy

\[ \int_\Omega k(x,x^\prime) e_k(x) dx \approx \sum_{i=1}^N w_i k(x_i,x^\prime) e_k(x^\prime), \]

which allows us to approximately solve for \(e_k(x)\) and \(\lambda_k\) by replacing \(x^\prime\) with $ \(x_i\) for each \(i\) and solving the resulting \(N\times N\) matrix eigenproblem. Once the matrix problem is solved, we will have approximations of \(e_k(x_i)\). The value of the eigenfunction at other locations is approximated using the covariance kernel

\[ e_k(x^\prime) = \frac{1}{\lambda_k} \sum_{i=1}^N w_i k(x_i, x^\prime) e_k(x_i). \]

Notice that the approximation quality largely depends on how well the seed points and weights approximate the integral. For simple domains (e.g., rectangular), it is thus useful to choose the seed points and weights from efficient quadrature rules.

Typical Usage

using namespace muq::Approximation;
// other setup...
int main(){
// first, create the covariance kernel
double sigma2 = 1.0;
double length = 0.2;
double nu = 3.0/2.0;
auto kernel = std::make_shared<MaternKernel>(1, sigma2, length, nu);
// Define some seed points and weights -- quadrature points and weights would be a great choice
const int numSeeds = 10;
Eigen::MatrixXd seedPts(1,numSeeds);
for(int i=0; i<numSeeds; ++i)
seedPts(0, i) = static_cast<double>(i)/static_cast<double>(numSeeds);
Eigen::VectorXd seedWts = (ub-lb)/double(numSeeds)*Eigen::VectorXd::Ones(numSeeds);
// Construct the Karhunen-Loeve decomposition based on a discrete eigenvalue problem at the seed points
// Evaluate the KL modes at a bunch of other points
const int numEval = 200;
Eigen::MatrixXd evalPts(1,numEval);
for(int i=0; i<numEval; ++i)
evalPts(0, i) = static_cast<double>(i)/static_cast<double>(numEval);
// Each column of the modes matrix contains a basis function from the KL expansion
Eigen::MatrixXd modes = kl.GetModes(evalPts);
return 0;
}
int main()
KarhunenLoeveExpansion(std::shared_ptr< KernelBase > kernelIn, Eigen::MatrixXd const &seedPtsIn, Eigen::VectorXd const &seedWtsIn, boost::property_tree::ptree options=boost::property_tree::ptree())

Definition at line 98 of file KarhunenLoeveExpansion.h.

Public Member Functions

 KarhunenLoeveExpansion (std::shared_ptr< KernelBase > kernelIn, Eigen::MatrixXd const &seedPtsIn, Eigen::VectorXd const &seedWtsIn, boost::property_tree::ptree options=boost::property_tree::ptree())
 
virtual ~KarhunenLoeveExpansion ()=default
 
virtual Eigen::MatrixXd GetModes (Eigen::Ref< const Eigen::MatrixXd > const &pts) const override
 
virtual unsigned int NumModes () const override
 
- Public Member Functions inherited from muq::Approximation::KarhunenLoeveBase
virtual ~KarhunenLoeveBase ()=default
 
virtual Eigen::VectorXd Evaluate (Eigen::Ref< const Eigen::MatrixXd > const &pts, Eigen::Ref< const Eigen::VectorXd > const &coeffs) const
 Evaluate the KL expansion at a new pt given known coefficients. More...
 

Constructor & Destructor Documentation

◆ KarhunenLoeveExpansion()

KarhunenLoeveExpansion::KarhunenLoeveExpansion ( std::shared_ptr< KernelBase kernelIn,
Eigen::MatrixXd const &  seedPtsIn,
Eigen::VectorXd const &  seedWtsIn,
boost::property_tree::ptree  options = boost::property_tree::ptree() 
)

Definition at line 9 of file KarhunenLoeveExpansion.cpp.

References covKernel, modeEigs, modeVecs, seedPts, and seedWts.

◆ ~KarhunenLoeveExpansion()

virtual muq::Approximation::KarhunenLoeveExpansion::~KarhunenLoeveExpansion ( )
virtualdefault

Member Function Documentation

◆ GetModes()

Eigen::MatrixXd KarhunenLoeveExpansion::GetModes ( Eigen::Ref< const Eigen::MatrixXd > const &  pts) const
overridevirtual

Evaluates the KL modes at one or more locations. Each column of the pts matrix contains a point where we want to evaluate the modes. Each column of the output contains a mode. Each row of the output corresponds to an input point.

Implements muq::Approximation::KarhunenLoeveBase.

Definition at line 34 of file KarhunenLoeveExpansion.cpp.

References covKernel, modeEigs, modeVecs, seedPts, and seedWts.

Referenced by ConstructDensity().

◆ NumModes()

unsigned int KarhunenLoeveExpansion::NumModes ( ) const
overridevirtual

Implements muq::Approximation::KarhunenLoeveBase.

Definition at line 45 of file KarhunenLoeveExpansion.cpp.

References modeEigs.

Member Data Documentation

◆ covKernel

std::shared_ptr<KernelBase> muq::Approximation::KarhunenLoeveExpansion::covKernel
private

Definition at line 124 of file KarhunenLoeveExpansion.h.

Referenced by GetModes(), and KarhunenLoeveExpansion().

◆ modeEigs

Eigen::VectorXd muq::Approximation::KarhunenLoeveExpansion::modeEigs
private

Definition at line 128 of file KarhunenLoeveExpansion.h.

Referenced by GetModes(), KarhunenLoeveExpansion(), and NumModes().

◆ modeVecs

Eigen::MatrixXd muq::Approximation::KarhunenLoeveExpansion::modeVecs
private

Definition at line 127 of file KarhunenLoeveExpansion.h.

Referenced by GetModes(), and KarhunenLoeveExpansion().

◆ seedPts

Eigen::MatrixXd muq::Approximation::KarhunenLoeveExpansion::seedPts
private

Definition at line 120 of file KarhunenLoeveExpansion.h.

Referenced by GetModes(), and KarhunenLoeveExpansion().

◆ seedWts

Eigen::VectorXd muq::Approximation::KarhunenLoeveExpansion::seedWts
private

Definition at line 121 of file KarhunenLoeveExpansion.h.

Referenced by GetModes(), and KarhunenLoeveExpansion().


The documentation for this class was generated from the following files: