3 #include <Eigen/Eigenvalues>
10 Eigen::MatrixXd
const& seedPtsIn,
11 Eigen::VectorXd
const& seedWtsIn,
12 boost::property_tree::ptree options) : seedPts(seedPtsIn), seedWts(seedWtsIn), covKernel(kernelIn)
15 int numModes = options.get(
"KarhunenLoeve.NumModes",
seedWts.size());
18 Eigen::VectorXd sqrtWts =
seedWts.array().sqrt();
20 Eigen::MatrixXd seedCov = sqrtWts.asDiagonal()*
covKernel->BuildCovariance(
seedPts)*sqrtWts.asDiagonal();
21 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigSolver;
22 eigSolver.compute(seedCov);
24 double minEig = eigSolver.eigenvalues().minCoeff();
26 std::cerr <<
"YIKES! The covariance matrix wasn't positive definite.";
30 modeEigs = eigSolver.eigenvalues().tail(numModes).reverse();
31 modeVecs = eigSolver.eigenvectors().rightCols(numModes).rowwise().reverse();
41 return crossCov *
seedWts.array().sqrt().matrix().asDiagonal() *
modeVecs *
modeEigs.array().inverse().sqrt().matrix().asDiagonal();
virtual Eigen::MatrixXd GetModes(Eigen::Ref< const Eigen::MatrixXd > const &pts) const override
KarhunenLoeveExpansion(std::shared_ptr< KernelBase > kernelIn, Eigen::MatrixXd const &seedPtsIn, Eigen::VectorXd const &seedWtsIn, boost::property_tree::ptree options=boost::property_tree::ptree())
std::shared_ptr< KernelBase > covKernel
virtual unsigned int NumModes() const override