forked from mblum/libgp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgp.h
executable file
·114 lines (80 loc) · 2.77 KB
/
gp.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
111
112
113
114
// libgp - Gaussian process library for Machine Learning
// Copyright (c) 2013, Manuel Blum <[email protected]>
// All rights reserved.
/*!
*
* \page licence Licensing
*
* libgp - Gaussian process library for Machine Learning
*
* \verbinclude "../COPYING"
*/
#ifndef __GP_H__
#define __GP_H__
#define _USE_MATH_DEFINES
#include <cmath>
#include <Eigen/Dense>
#include "cov.h"
#include "sampleset.h"
namespace libgp {
/** Gaussian process regression.
* @author Manuel Blum */
class GaussianProcess
{
public:
/** Create and instance of GaussianProcess with given input dimensionality
* and covariance function. */
GaussianProcess (size_t input_dim, std::string covf_def);
/** Create and instance of GaussianProcess from file. */
GaussianProcess (const char * filename);
virtual ~GaussianProcess ();
/** Write current gp model to file. */
void write(const char * filename);
/** Predict target value for given input.
* @param x input vector
* @return predicted value */
virtual double f(const double x[]);
/** Predict variance of prediction for given input.
* @param x input vector
* @return predicted variance */
virtual double var(const double x[]);
/** Add input-output-pair to sample set.
* Add a copy of the given input-output-pair to sample set.
* @param x input array
* @param y output value
*/
void add_pattern(const double x[], double y);
bool set_y(size_t i, double y);
/** Get number of samples in the training set. */
size_t get_sampleset_size();
/** Clear sample set and free memory. */
void clear_sampleset();
/** Get reference on currently used covariance function. */
CovarianceFunction & covf();
/** Get input vector dimensionality. */
size_t get_input_dim();
double log_likelihood();
Eigen::VectorXd log_likelihood_gradient();
protected:
/** The covariance function of this Gaussian process. */
CovarianceFunction * cf;
/** The training sample set. */
SampleSet * sampleset;
/** Alpha is cached for performance. */
Eigen::VectorXd alpha;
/** Last test kernel vector. */
Eigen::VectorXd k_star;
/** Linear solver used to invert the covariance matrix. */
// Eigen::LLT<Eigen::MatrixXd> solver;
Eigen::MatrixXd L;
/** Input vector dimensionality. */
size_t input_dim;
/** Update test input and cache kernel vector. */
void update_k_star(const Eigen::VectorXd &x_star);
void update_alpha();
/** Compute covariance matrix and perform cholesky decomposition. */
virtual void compute();
bool alpha_needs_update;
};
}
#endif /* __GP_H__ */