BayesOpt
kernel_gaussian.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_GAUSSIAN_HPP_
24 #define _KERNEL_GAUSSIAN_HPP_
25 
27 
28 namespace bayesopt
29 {
30 
33 
35  class SEIso: public ISOkernel
36  {
37  public:
38  void init(size_t input_dim)
39  { n_params = 1; n_inputs = input_dim; };
40 
41  double operator()( const vectord &x1, const vectord &x2)
42  {
43  double rl = computeWeightedNorm2(x1,x2);
44  double k = rl*rl;
45  return exp(-k/2);
46  };
47 
48  double gradient(const vectord &x1, const vectord &x2,
49  size_t component)
50  {
51  double rl = computeWeightedNorm2(x1,x2);
52  double k = rl*rl;
53  return exp(-k/2)*k;
54  };
55  };
56 
57 
59  class SEArd: public ARDkernel
60  {
61  public:
62  void init(size_t input_dim)
63  { n_params = input_dim; n_inputs = input_dim; };
64 
65  double operator()( const vectord &x1, const vectord &x2 )
66  {
67  double rl = computeWeightedNorm2(x1,x2);
68  double k = rl*rl;
69  return exp(-k/2);
70  };
71 
72  double gradient(const vectord &x1, const vectord &x2,
73  size_t component)
74  {
75  double rl = computeWeightedNorm2(x1,x2);
76  double k = rl*rl;
77  double r = (x1(component) - x2(component))/params(component);
78  return exp(-k/2)*r*r;
79  };
80  };
81 
82 
84 
85 } //namespace bayesopt
86 
87 #endif
Abstract class for isotropic kernel functors.
Namespace of the library interface.
Definition: using.dox:1
Abstract class for anisotropic kernel functors using ARD (Automatic Relevance Determination) ...
Square exponential (Gaussian) kernel.
Atomic (simple) kernel functions.
Square exponential (Gaussian) kernel.