STK++ 0.9.13
STK_Kernel_Laplace.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::
27 * created on: 5 avr. 2015
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_KERNEL_LAPLACE_H
37#define STK_KERNEL_LAPLACE_H
38
40
41namespace STK
42{
43
44namespace Kernel
45{
53template<class Array>
54class Laplace: public IKernelBase<Array>
55{
56 public:
58 typedef typename Array::Type Type;
59 using Base::p_data_;
60 using Base::gram_;
61 using Base::hasRun_;
62
66 Laplace( Real const& width= 1.)
67 : Base(0), width_(width)
68 {}
73 Laplace( Array const* p_data, Real const& width= 1.)
74 : Base(p_data), width_(width) {}
79 Laplace( Array const& data, Real const& width= 1.)
80 : Base(data), width_(width) {}
85 template<class Derived>
86 Laplace( Array const* p_data, ExprBase<Derived> const& param)
87 : Base(p_data), width_(param.empty() ? 1. : param.front())
88 {}
93 template<class Derived>
94 Laplace( Array const& data, ExprBase<Derived> const& param)
95 : Base(data), width_(param.empty() ? 1. : param.front())
96 {}
97
99 virtual ~Laplace() {}
100
102 Real const& width() const {return width_;}
104 void setWidth(Real const& width) {width_ = width;}
108 template<class Derived>
109 void setParam( ExprBase<Derived> const& param)
110 { width_ = (param.empty() ? 1. : param.front());}
111
116 virtual inline Real diag(int i) const {return 1.;};
121 virtual Real comp(int i, int j) const;
126 virtual Real value(Type const& v) const;
127
128 private:
131};
132
133template<class Array>
134inline Real Laplace<Array>::comp(int i, int j) const
135{
136 return hasRun_ ? gram_(i,j)
137 : std::exp(-(p_data_->row(i) - p_data_->row(j)).norm()/width_);
138}
139
140template<class Array>
141inline Real Laplace<Array>::value(Type const& v) const
142{ return std::exp(-std::abs(v)/width_);}
143
151template<class Array>
152class Exponential: public IKernelBase<Array>
153{
154 public:
156 typedef typename Array::Type Type;
157 using Base::p_data_;
158 using Base::gram_;
159 using Base::hasRun_;
160
164 Exponential( Real const& width= 1.)
165 : Base(0), width_(width)
166 {}
171 Exponential( Array const* p_data, Real const& width= 1.)
172 : Base(p_data), width_(width) {}
177 Exponential( Array const& data, Real const& width= 1.)
178 : Base(data), width_(width) {}
183 template<class Derived>
184 Exponential( Array const* p_data, ExprBase<Derived> const& param)
185 : Base(p_data), width_(param.empty() ? 1. : param.front())
186 {}
191 template<class Derived>
192 Exponential( Array const& data, ExprBase<Derived> const& param)
193 : Base(data), width_(param.empty() ? 1. : param.front())
194 {}
195
197 virtual ~Exponential() {}
198
200 Real const& width() const {return width_;}
202 void setWidth(Real const& width) {width_ = width;}
206 template<class Derived>
207 void setParam( ExprBase<Derived> const& param)
208 { width_ = (param.empty() ? 1. : param.front());}
209
214 virtual inline Real diag(int i) const {return 1.;};
219 virtual Real comp(int i, int j) const;
224 virtual Real value(Type const& v) const;
225
226 private:
229};
230
231template<class Array>
232inline Real Exponential<Array>::comp(int i, int j) const
233{
234 return hasRun_ ? gram_(i,j)
235 : std::exp(-(p_data_->row(i) - p_data_->row(j)).norm()/width_);
236}
237
238template<class Array>
240{ return std::exp(-std::abs(v)/width_);}
241} // namespace Kernel
242
243} // namespace STK
244
245#endif /* STK_KERNEL_LAPLACE_H */
In this file we define the Interface base class for computing a Kernels.
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
[Deprecated] The Exponential Kernel is a kernel of the form
Exponential(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
virtual Real comp(int i, int j) const
virtual method implementation.
Real width_
bandwidth of the kernel
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
Real const & width() const
Exponential(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
Exponential(Array const &data, Real const &width=1.)
constructor with a constant pointer on the data set
void setWidth(Real const &width)
set the bandwidth of the kernel
IKernelBase< Array > Base
virtual Real diag(int i) const
virtual method.
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
Exponential(Array const *p_data, Real const &width=1.)
constructor with a constant pointer on the data set
virtual ~Exponential()
destructor
Exponential(Real const &width=1.)
Default constructor with the width.
Interface Base class for the kernels classes.
Array const * p_data_
pointer on the data set
CSquareX gram_
the resulting gram_ matrix
The Laplace Kernel is a kernel of the form.
IKernelBase< Array > Base
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
void setWidth(Real const &width)
set the bandwidth of the kernel
Real width_
bandwidth of the kernel
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
virtual ~Laplace()
destructor
Laplace(Array const &data, Real const &width=1.)
constructor with a constant pointer on the data set
Laplace(Real const &width=1.)
Default constructor with the width.
virtual Real comp(int i, int j) const
virtual method implementation.
Laplace(Array const *p_data, Real const &width=1.)
constructor with a constant pointer on the data set
Real const & width() const
Laplace(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
Laplace(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
virtual Real diag(int i) const
virtual method.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.