forked from mblum/libgp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcov.h
executable file
·110 lines (84 loc) · 3.37 KB
/
cov.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// libgp - Gaussian process library for Machine Learning
// Copyright (c) 2013, Manuel Blum <[email protected]>
// All rights reserved.
#ifndef __COV_H__
#define __COV_H__
#include <iostream>
#include <vector>
#include <Eigen/Dense>
namespace libgp
{
/** Covariance function base class.
* @author Manuel Blum
* @ingroup cov_group
* @todo implement more covariance functions */
class CovarianceFunction
{
public:
/** Constructor. */
CovarianceFunction() {};
/** Destructor. */
virtual ~CovarianceFunction() {};
/** Initialization method for atomic covariance functions.
* @param input_dim dimensionality of the input vectors */
virtual bool init(int input_dim)
{
return false;
};
/** Initialization method for compound covariance functions.
* @param input_dim dimensionality of the input vectors
* @param first first covariance function of compound
* @param second second covariance function of compound */
virtual bool init(int input_dim, CovarianceFunction * first, CovarianceFunction * second)
{
return false;
};
virtual bool init(int input_dim, int filter, CovarianceFunction * covf)
{
return false;
};
/** Computes the covariance of two input vectors.
* @param x1 first input vector
* @param x2 second input vector
* @return covariance of x1 and x2 */
virtual double get(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2) = 0;
/** Covariance gradient of two input vectors with respect to the hyperparameters.
* @param x1 first input vector
* @param x2 second input vector
* @param grad covariance gradient */
virtual void grad(const Eigen::VectorXd &x1, const Eigen::VectorXd &x2, Eigen::VectorXd &grad) = 0;
/** Update parameter vector.
* @param p new parameter vector */
virtual void set_loghyper(const Eigen::VectorXd &p);
/** Update parameter vector.
* @param p new parameter vector */
virtual void set_loghyper(const double p[]);
/** Get number of parameters for this covariance function.
* @return parameter vector dimensionality */
size_t get_param_dim();
/** Get input dimensionality.
* @return input dimensionality */
size_t get_input_dim();
/** Get log-hyperparameter of covariance function.
* @return log-hyperparameter */
Eigen::VectorXd get_loghyper();
/** Returns a string representation of this covariance function.
* @return string containing the name of this covariance function */
virtual std::string to_string() = 0;
/** Draw random target values from this covariance function for input X. */
Eigen::VectorXd draw_random_sample(Eigen::MatrixXd &X);
bool loghyper_changed;
protected:
/** Input dimensionality. */
size_t input_dim;
/** Size of parameter vector. */
size_t param_dim;
/** Parameter vector containing the log hyperparameters of the covariance function.
* The number of necessary parameters is given in param_dim. */
Eigen::VectorXd loghyper;
};
}
#endif /* __COV_H__ */
/** Covariance functions available for Gaussian process models.
* There are atomic and composite covariance functions.
* @defgroup cov_group Covariance Functions */