Kstars

covariance_functions.h
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: 2014-2017 Max Planck Society.
3  All rights reserved.
4 
5  SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 /**
9  * @file
10  * @date 2014-2017
11  * @copyright Max Planck Society
12  *
13  * @author Edgar D. Klenske <[email protected]>
14  * @author Stephan Wenninger <[email protected]>
15  * @author Raffi Enficiaud <[email protected]>
16  *
17  * @brief The file holds the covariance functions that can be used with the GP class.
18  */
19 
20 #ifndef COVARIANCE_FUNCTIONS_H
21 #define COVARIANCE_FUNCTIONS_H
22 
23 #include <Eigen/Dense>
24 #include <vector>
25 #include <list>
26 #include <utility>
27 #include <cstdint>
28 
29 // HY: Added all the "override" qualifiers below to silence the compiler.
30 
31 namespace covariance_functions
32 {
33  /*!@brief Base class definition for covariance functions
34  */
35  class CovFunc
36  {
37  public:
38  CovFunc() {}
39  virtual ~CovFunc() {}
40 
41  /*!
42  * Evaluates the covariance function, caches the quantities that are needed
43  * to calculate gradient and Hessian.
44  */
45  virtual Eigen::MatrixXd evaluate(const Eigen::VectorXd& x1, const Eigen::VectorXd& x2) = 0;
46 
47  //! Method to set the hyper-parameters.
48  virtual void setParameters(const Eigen::VectorXd& params) = 0;
49  virtual void setExtraParameters(const Eigen::VectorXd& params) = 0;
50 
51  //! Returns the hyper-parameters.
52  virtual const Eigen::VectorXd& getParameters() const = 0;
53  virtual const Eigen::VectorXd& getExtraParameters() const = 0;
54 
55  //! Returns the number of hyper-parameters.
56  virtual int getParameterCount() const = 0;
57  virtual int getExtraParameterCount() const = 0;
58 
59  //! Produces a clone to be able to copy the object.
60  virtual CovFunc* clone() const = 0;
61  };
62 
63  /*!
64  * The function computes a combined covariance function. It is a periodic
65  * covariance function with an additional square exponential. This
66  * combination makes it possible to learn a signal that consists of both
67  * periodic and aperiodic parts.
68  *
69  * Square Exponential Component:
70  * @f[
71  * k _{\textsc{se}}(t,t';\theta_\textsc{se},\ell_\textsc{se}) =
72  * \theta_\textsc{se} \cdot
73  * \exp\left(-\frac{(t-t')^2}{2\ell_\textsc{se}^{2}}\right)
74  * @f]
75  *
76  * Periodic Component:
77  * @f[
78  * k_\textsc{p}(t,t';\theta_\textsc{p},\ell_\textsc{p},\lambda) =
79  * \theta_\textsc{p} \cdot
80  * \exp\left(-\frac{2\sin^2\left(\frac{\pi}{\lambda}
81  * (t-t')\right)}{\ell_\textsc{p}^2}\right)
82  * @f]
83  *
84  * Kernel Combination:
85  * @f[
86  * k _\textsc{c}(t,t';\theta_\textsc{se},\ell_\textsc{se},\theta_\textsc{p},
87  * \ell_\textsc{p},\lambda) =
88  * k_{\textsc{se}}(t,t';\theta_\textsc{se},\ell_\textsc{se})
89  * +
90  * k_\textsc{p}(t,t';\theta_\textsc{p},\ell_\textsc{p},\lambda)
91  * @f]
92  */
94  {
95  private:
96  Eigen::VectorXd hyperParameters;
97  Eigen::VectorXd extraParameters;
98 
99  public:
101  explicit PeriodicSquareExponential(const Eigen::VectorXd& hyperParameters);
102 
103  /*!
104  * Evaluates the covariance function, caches the quantities that are needed
105  * to calculate gradient and Hessian.
106  */
107  Eigen::MatrixXd evaluate(const Eigen::VectorXd& x1, const Eigen::VectorXd& x2) override;
108 
109  //! Method to set the hyper-parameters.
110  void setParameters(const Eigen::VectorXd& params) override;
111  void setExtraParameters(const Eigen::VectorXd& params) override;
112 
113  //! Returns the hyper-parameters.
114  const Eigen::VectorXd& getParameters() const override;
115  const Eigen::VectorXd& getExtraParameters() const override;
116 
117  //! Returns the number of hyper-parameters.
118  int getParameterCount() const override;
119  int getExtraParameterCount() const override;
120 
121  /**
122  * Produces a clone to be able to copy the object.
123  */
124  virtual CovFunc* clone() const override
125  {
126  return new PeriodicSquareExponential(*this);
127  }
128  };
129 
130 
131  /*!
132  * The function computes a combined covariance function. It is a periodic
133  * covariance function with two additional square exponential components.
134  * This combination makes it possible to learn a signal that consists of
135  * periodic parts, long-range aperiodic parts and small-range deformations.
136  *
137  * Square Exponential Component:
138  * @f[
139  * k _{\textsc{se}}(t,t';\theta_\textsc{se},\ell_\textsc{se}) =
140  * \theta_\textsc{se} \cdot
141  * \exp\left(-\frac{(t-t')^2}{2\ell_\textsc{se}^{2}}\right)
142  * @f]
143  *
144  * Periodic Component:
145  * @f[
146  * k_\textsc{p}(t,t';\theta_\textsc{p},\ell_\textsc{p},\lambda) =
147  * \theta_\textsc{p} \cdot
148  * \exp\left(-\frac{2\sin^2\left(\frac{\pi}{\lambda}
149  * (t-t')\right)}{\ell_\textsc{p}^2}\right)
150  * @f]
151  *
152  * Kernel Combination:
153  * @f[
154  * k _\textsc{c}(t,t';\theta_\textsc{se},\ell_\textsc{se},\theta_\textsc{p},
155  * \ell_\textsc{p},\lambda) =
156  * k_{\textsc{se},1}(t,t';\theta_{\textsc{se},1},\ell_{\textsc{se},1})
157  * +
158  * k_\textsc{p}(t,t';\theta_\textsc{p},\ell_\textsc{p},\lambda)
159  * +
160  * k_{\textsc{se},2}(t,t';\theta_{\textsc{se},2},\ell_{\textsc{se},2})
161  * @f]
162  */
164  {
165  private:
166  Eigen::VectorXd hyperParameters;
167  Eigen::VectorXd extraParameters;
168 
169  public:
171  explicit PeriodicSquareExponential2(const Eigen::VectorXd& hyperParameters);
172 
173  Eigen::MatrixXd evaluate(const Eigen::VectorXd& x1, const Eigen::VectorXd& x2) override;
174 
175  //! Method to set the hyper-parameters.
176  void setParameters(const Eigen::VectorXd& params) override;
177  void setExtraParameters(const Eigen::VectorXd& params) override;
178 
179  //! Returns the hyper-parameters.
180  const Eigen::VectorXd& getParameters() const override;
181  const Eigen::VectorXd& getExtraParameters() const override;
182 
183  //! Returns the number of hyper-parameters.
184  int getParameterCount() const override;
185  int getExtraParameterCount() const override;
186 
187  /**
188  * Produces a clone to be able to copy the object.
189  */
190  virtual CovFunc* clone() const override
191  {
192  return new PeriodicSquareExponential2(*this);
193  }
194  };
195 } // namespace covariance_functions
196 #endif // ifndef COVARIANCE_FUNCTIONS_H
const Eigen::VectorXd & getParameters() const override
Returns the hyper-parameters.
int getParameterCount() const override
Returns the number of hyper-parameters.
virtual Eigen::MatrixXd evaluate(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2)=0
Base class definition for covariance functions.
int getParameterCount() const override
Returns the number of hyper-parameters.
Eigen::MatrixXd evaluate(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2) override
void setParameters(const Eigen::VectorXd &params) override
Method to set the hyper-parameters.
virtual const Eigen::VectorXd & getParameters() const =0
Returns the hyper-parameters.
virtual CovFunc * clone() const override
Produces a clone to be able to copy the object.
const Eigen::VectorXd & getParameters() const override
Returns the hyper-parameters.
Eigen::MatrixXd evaluate(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2) override
virtual CovFunc * clone() const =0
Produces a clone to be able to copy the object.
virtual CovFunc * clone() const override
Produces a clone to be able to copy the object.
virtual int getParameterCount() const =0
Returns the number of hyper-parameters.
virtual void setParameters(const Eigen::VectorXd &params)=0
Method to set the hyper-parameters.
void setParameters(const Eigen::VectorXd &params) override
Method to set the hyper-parameters.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 04:02:38 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.