BayesOpt
kernel_linear.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_LINEAR_HPP_
24 #define _KERNEL_LINEAR_HPP_
25 
27 
28 namespace bayesopt
29 {
30 
33 
35  class LinKernel: public AtomicKernel
36  {
37  public:
38  void init(size_t input_dim)
39  { n_params = 0; n_inputs = input_dim; };
40 
41  double operator()(const vectord &x1, const vectord &x2)
42  {
43  assert(x1.size() == x2.size());
44  return boost::numeric::ublas::inner_prod(x1,x2);
45  };
46 
47  // TODO:
48  double gradient(const vectord &x1, const vectord &x2,
49  size_t component)
50  { assert(false); return 0.0; };
51  };
52 
54  class LinKernelARD: public AtomicKernel
55  {
56  public:
57  void init(size_t input_dim)
58  { n_params = input_dim; n_inputs = input_dim; };
59 
60  double operator()(const vectord &x1, const vectord &x2)
61  {
62  assert(x1.size() == x2.size());
63  vectord v1 = utils::ublas_elementwise_div(x1, params);
64  vectord v2 = utils::ublas_elementwise_div(x2, params);
65  return boost::numeric::ublas::inner_prod(v1,v2);
66  };
67 
68  // TODO:
69  double gradient(const vectord &x1, const vectord &x2,
70  size_t component)
71  { assert(false); return 0.0; };
72  };
73 
75 
76 } //namespace bayesopt
77 
78 #endif
Namespace of the library interface.
Definition: using.dox:1
Linear kernel.
v1 ublas_elementwise_div(const v1 &a, const v2 &b)
Computes the elementwise division of two vectors or matrices.
Atomic (simple) kernel functions.
Abstract class for an atomic kernel.