STK++ 0.9.13
STK_Kernel_Gaussian.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_GAUSSIAN_H
37#define STK_KERNEL_GAUSSIAN_H
38
40
41namespace STK
42{
43
44namespace Kernel
45{
53template<class Array>
54class Gaussian: 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 Gaussian( Real const& width= 1.)
67 : Base(0), width_(width)
68 {}
73 Gaussian( Array const* p_data, Real const& width= 1.)
75 {}
80 Gaussian( Array const& data, Real const& width= 1.)
81 : Base(data), width_(width)
82 {}
83
88 template<class Derived>
89 Gaussian( Array const* p_data, ExprBase<Derived> const& param)
90 : Base(p_data), width_(param.empty() ? 1. : param.front())
91 {}
96 template<class Derived>
97 Gaussian( Array const& data, ExprBase<Derived> const& param)
98 : Base(data), width_(param.empty() ? 1. : param.front())
99 {}
100
102 virtual ~Gaussian() {}
104 Real const& width() const {return width_;}
106 void setWidth(Real const& width) {width_ = width;}
110 template<class Derived>
111 void setParam( ExprBase<Derived> const& param)
112 { width_ = (param.empty() ? 1. : param.front());}
113
118 virtual inline Real diag(int i) const {return 1.;};
123 virtual Real comp(int i, int j) const;
124
129 virtual Real value(Type const& v) const;
130
131 private:
134};
135
136template<class Array>
138{ return hasRun_ ? gram_(i,j)
139 : std::exp(-(p_data_->row(i) - p_data_->row(j)).norm2()/(2.*width_));
140}
141
142template<class Array>
144{ return std::exp(-v*v/(2.*width_));}
145
146} // namespace Kernel
147
148} // namespace STK
149
150#endif /* STK_KERNEL_GAUSSIAN_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
The Gaussian Kernel is a kernel of the form.
Gaussian(Array const &data, Real const &width=1.)
constructor with a constant pointer on the data set
virtual Real diag(int i) const
virtual method.
Gaussian(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
virtual ~Gaussian()
destructor
void setWidth(Real const &width)
set the bandwidth of the kernel
Real const & width() const
IKernelBase< Array > Base
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
Gaussian(Real const &width=1.)
Default constructor with the width.
Gaussian(Array const *p_data, Real const &width=1.)
constructor with a constant pointer on the data set
virtual Real comp(int i, int j) const
virtual method implementation.
Gaussian(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
Real width_
bandwidth of the kernel
Interface Base class for the kernels classes.
Array const * p_data_
pointer on the data set
CSquareX gram_
the resulting gram_ matrix
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.