MUQ  0.4.3
MaternKernel.h
Go to the documentation of this file.
1 #ifndef MATERNKERNEL_H
2 #define MATERNKERNEL_H
3 
5 
6 #include <cmath>
7 #include <stdexcept>
8 
9 #include <boost/property_tree/ptree_fwd.hpp>
10 
11 #include <boost/math/constants/constants.hpp>
12 
13 
14 
15 namespace muq
16 {
17 namespace Approximation
18 {
19 
20 
33 class MaternKernel : public KernelImpl<MaternKernel>
34 {
35 
36 public:
37 
38  MaternKernel(unsigned dimIn,
39  std::vector<unsigned> dimInds,
40  double sigma2In,
41  double lengthIn,
42  double nuIn) : MaternKernel(dimIn,
43  dimInds,
44  sigma2In,
45  lengthIn,
46  nuIn,
47  {0.0, std::numeric_limits<double>::infinity()},
48  {1e-10, std::numeric_limits<double>::infinity()})
49  {};
50 
51  MaternKernel(unsigned dimIn,
52  std::vector<unsigned> dimInds,
53  double sigma2In,
54  double lengthIn,
55  double nuIn,
56  Eigen::Vector2d sigmaBounds,
57  Eigen::Vector2d lengthBounds);
58 
59 
60  MaternKernel(unsigned dimIn,
61  double sigma2In,
62  double lengthIn,
63  double nuIn) : MaternKernel(dimIn,
64  sigma2In,
65  lengthIn,
66  nuIn,
67  {0.0, std::numeric_limits<double>::infinity()},
68  {1e-10, std::numeric_limits<double>::infinity()})
69  {};
70 
71  MaternKernel(unsigned dimIn,
72  double sigma2In,
73  double lengthIn,
74  double nuIn,
75  Eigen::Vector2d sigmaBounds,
76  Eigen::Vector2d lengthBounds);
77 
78 
79  virtual ~MaternKernel(){};
80 
81 
82  template<typename ScalarType1, typename ScalarType2, typename ScalarType3>
83  void FillBlockImpl(Eigen::Ref<const Eigen::Matrix<ScalarType1, Eigen::Dynamic, 1>> const& x1,
84  Eigen::Ref<const Eigen::Matrix<ScalarType1, Eigen::Dynamic, 1>> const& x2,
85  Eigen::Ref<const Eigen::Matrix<ScalarType2, Eigen::Dynamic, 1>> const& params,
86  Eigen::Ref<Eigen::Matrix<ScalarType3,Eigen::Dynamic, Eigen::Dynamic>> block) const
87  {
88  int p = round(nu-0.5);
89 
90  ScalarType1 dist = (x1-x2).norm();
91 
92  block(0,0) = 0.0;
93  for(int i=0; i<=p; ++i)
94  block(0,0) += weights(i) * pow(sqrt(8.0*nu)*dist/params(1), p-i);
95 
96  block(0,0) *= params(0)*exp(-sqrt(2.0*nu)*dist / params(1)) * scale;
97  }
98 
99  virtual std::tuple<std::shared_ptr<muq::Modeling::LinearSDE>, std::shared_ptr<muq::Modeling::LinearOperator>, Eigen::MatrixXd> GetStateSpace(boost::property_tree::ptree sdeOptions = boost::property_tree::ptree()) const override;
100 
101 private:
102 
103  const double nu;
104  const double scale; // std::pow(2.0, 1.0-nu)/boost::math::tgamma(nu)
105 
106  const Eigen::VectorXd weights;
107 
108  void CheckNu() const;
109 
110  static Eigen::VectorXd BuildWeights(int p);
111 
112  static inline int Factorial(int n){
113  return (n == 1 || n == 0) ? 1 : Factorial(n - 1) * n;
114  }
115 };
116 
117 }
118 }
119 
120 
121 #endif
const std::vector< unsigned int > dimInds
Definition: KernelBase.h:126
Base class in CRTP pattern for covariance kernels.
Definition: KernelImpl.h:26
static Eigen::VectorXd BuildWeights(int p)
virtual std::tuple< std::shared_ptr< muq::Modeling::LinearSDE >, std::shared_ptr< muq::Modeling::LinearOperator >, Eigen::MatrixXd > GetStateSpace(boost::property_tree::ptree sdeOptions=boost::property_tree::ptree()) const override
Returns a state space representation of the covariance kernel.
MaternKernel(unsigned dimIn, double sigma2In, double lengthIn, double nuIn)
Definition: MaternKernel.h:60
void FillBlockImpl(Eigen::Ref< const Eigen::Matrix< ScalarType1, Eigen::Dynamic, 1 >> const &x1, Eigen::Ref< const Eigen::Matrix< ScalarType1, Eigen::Dynamic, 1 >> const &x2, Eigen::Ref< const Eigen::Matrix< ScalarType2, Eigen::Dynamic, 1 >> const &params, Eigen::Ref< Eigen::Matrix< ScalarType3, Eigen::Dynamic, Eigen::Dynamic >> block) const
Definition: MaternKernel.h:83
MaternKernel(unsigned dimIn, std::vector< unsigned > dimInds, double sigma2In, double lengthIn, double nuIn)
Definition: MaternKernel.h:38
const Eigen::VectorXd weights
Definition: MaternKernel.h:106