BayesOpt
kernel_matern.hpp
1 /*
2 -------------------------------------------------------------------------
3  This file is part of BayesOpt, an efficient C++ library for
4  Bayesian optimization.
5 
6  Copyright (C) 2011-2015 Ruben Martinez-Cantin <rmcantin@unizar.es>
7 
8  BayesOpt is free software: you can redistribute it and/or modify it
9  under the terms of the GNU Affero General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BayesOpt is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Affero General Public License for more details.
17 
18  You should have received a copy of the GNU Affero General Public License
19  along with BayesOpt. If not, see <http://www.gnu.org/licenses/>.
20 ------------------------------------------------------------------------
21 */
22 
23 #ifndef _KERNEL_MATERN_HPP_
24 #define _KERNEL_MATERN_HPP_
25 
27 
28 namespace bayesopt
29 {
30 
33 
34 
36  class MaternIso1: public ISOkernel
37  {
38  public:
39  void init(size_t input_dim)
40  { n_params = 1; n_inputs = input_dim; };
41 
42  double operator()(const vectord &x1, const vectord &x2)
43  {
44  double r = computeWeightedNorm2(x1,x2);
45  return exp(-r);
46  };
47 
48  double gradient(const vectord &x1, const vectord &x2,
49  size_t component)
50  {
51  double r = computeWeightedNorm2(x1,x2);
52  return r*exp(-r);
53  };
54  };
55 
56 
58  class MaternARD1: public ARDkernel
59  {
60  public:
61  void init(size_t input_dim)
62  { n_params = input_dim; n_inputs = input_dim; };
63 
64  double operator()(const vectord &x1, const vectord &x2)
65  {
66  double r = computeWeightedNorm2(x1,x2);
67  return exp(-r);
68  };
69 
70  //TODO:
71  double gradient(const vectord &x1, const vectord &x2,
72  size_t component)
73  { assert(false); return 0.0; };
74  };
75 
76 
78  class MaternIso3: public ISOkernel
79  {
80  public:
81  void init(size_t input_dim)
82  { n_params = 1; n_inputs = input_dim; };
83 
84  double operator()( const vectord &x1, const vectord &x2)
85  {
86  double r = sqrt(3.0) * computeWeightedNorm2(x1,x2);
87  double er = exp(-r);
88  return (1+r)*er;
89  };
90 
91  double gradient( const vectord &x1, const vectord &x2,
92  size_t component)
93  {
94  double r = sqrt(3.0) * computeWeightedNorm2(x1,x2);
95  double er = exp(-r);
96  return r*r*er;
97  };
98  };
99 
101  class MaternARD3: public ARDkernel
102  {
103  public:
104  void init(size_t input_dim)
105  { n_params = input_dim; n_inputs = input_dim; };
106 
107  double operator()( const vectord &x1, const vectord &x2)
108  {
109  double r = sqrt(3.0) * computeWeightedNorm2(x1,x2);
110  double er = exp(-r);
111  return (1+r)*er;
112  };
113 
114  double gradient( const vectord &x1, const vectord &x2,
115  size_t component)
116  {
117  assert(false); return 0.0;
118  };
119  };
120 
121 
123  class MaternIso5: public ISOkernel
124  {
125  public:
126  void init(size_t input_dim)
127  { n_params = 1; n_inputs = input_dim; };
128 
129  double operator()( const vectord &x1, const vectord &x2)
130  {
131  double r = sqrt(5.0) * computeWeightedNorm2(x1,x2);
132  double er = exp(-r);
133  return (1+r*(1+r/3))*er;
134  };
135  double gradient( const vectord &x1, const vectord &x2,
136  size_t component)
137  {
138  double r = sqrt(5.0) * computeWeightedNorm2(x1,x2);
139  double er = exp(-r);
140  return r*(1+r)/3*r*er;
141  };
142  };
143 
144 
146  class MaternARD5: public ARDkernel
147  {
148  public:
149  void init(size_t input_dim)
150  { n_params = input_dim; n_inputs = input_dim; };
151 
152  double operator()( const vectord &x1, const vectord &x2)
153  {
154  double r = sqrt(5.0) * computeWeightedNorm2(x1,x2);
155  double er = exp(-r);
156  return (1+r*(1+r/3))*er;
157  };
158 
159  //TODO:
160  double gradient( const vectord &x1, const vectord &x2,
161  size_t component)
162  { assert(false); return 0.0; };
163  };
164 
166 
167 } //namespace bayesopt
168 
169 #endif
Matern ARD kernel of 1st order.
Matern isotropic kernel of 5th order.
Abstract class for isotropic kernel functors.
Namespace of the library interface.
Definition: using.dox:1
Matern isotropic kernel of 1st order.
Matern ARD kernel of 3rd order.
Abstract class for anisotropic kernel functors using ARD (Automatic Relevance Determination) ...
Matern kernel of 3rd order.
Atomic (simple) kernel functions.
Matern ARD kernel of 5th order.