STK++ 0.9.13
STK_Kernel_Polynomial.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_POLYNOMIAL_H
37#define STK_KERNEL_POLYNOMIAL_H
38
40
41namespace STK
42{
43
44namespace Kernel
45{
54template<class Array>
55class Polynomial: public IKernelBase<Array>
56{
57 public:
59 typedef typename Array::Type Type;
60 using Base::p_data_;
61 using Base::gram_;
62 using Base::hasRun_;
63
68 Polynomial( Real const& d=2., Real const& shift= 0)
69 : Base(0), d_(d), shift_(shift)
70 {}
76 Polynomial( Array const* p_data, Real const& d=2., Real const& shift= 0)
77 : Base(p_data), d_(d), shift_(shift)
78 { if (d_ <= 0.)
80 }
86 Polynomial( Array const& data, Real const& d=2., Real const& shift= 0.)
87 : Base(data), d_(d), shift_(shift)
88 { if (d_ <= 0.)
90 }
95 template<class Derived>
96 Polynomial( Array const* p_data, ExprBase<Derived> const& param)
97 : Base(p_data)
98 , d_(param.empty() ? 2. : param.front())
99 , shift_(param.empty() ? 2. : param.elt(param.begin()+1))
100 {}
105 template<class Derived>
106 Polynomial( Array const& data, ExprBase<Derived> const& param)
107 : Base(data)
108 , d_(param.empty() ? 2. : param.front())
109 , shift_(param.empty() ? 2. : param.elt(param.begin()+1))
110 {}
111
113 virtual ~Polynomial() {}
115 Real const& degree() const {return d_;}
117 void setDegree(Real const& d) {d_ = d;}
119 Real const& shift() const {return shift_;}
121 void setShift(Real const& shift) { shift_ = shift;}
125 template<class Derived>
126 void setParam( ExprBase<Derived> const& param)
127 { d_ = (param.empty() ? 2. : param.front());
128 shift_ = (param.empty() ? 0. : param.elt(param.begin()+1));
129 }
130
135 virtual Real diag(int i) const;
140 virtual Real comp(int i, int j) const;
141
142 private:
147};
148
149/* virtual method.
150 * @return diagonal value of the kernel for the ith individuals.
151 * @param i index of the individual
152 **/
153template<class Array>
155{ return hasRun_ ? gram_(i,i)
156 : std::pow(p_data_->row(i).norm2() + shift_, d_);
157}
158
159template<class Array>
160inline Real Polynomial<Array>::comp(int i, int j) const
161{ return hasRun_ ? gram_(i,j)
162 : std::pow(p_data_->row(i).dot(p_data_->row(j)) + shift_, d_);}
163
164
165} // namespace Kernel
166
167} // namespace STK
168
169#endif /* STK_KERNEL_POLYNOMIAL_H */
In this file we define the Interface base class for computing a Kernels.
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
Interface Base class for the kernels classes.
Array const * p_data_
pointer on the data set
CSquareX gram_
the resulting gram_ matrix
The Polynomial Kernel is a kernel of the form.
Polynomial(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
virtual Real diag(int i) const
virtual method.
Polynomial(Real const &d=2., Real const &shift=0)
Default constructor with the degree and the shift.
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
Real d_
degree of the kernel
Polynomial(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
virtual ~Polynomial()
destructor
void setDegree(Real const &d)
set the degree of the kernel
virtual Real comp(int i, int j) const
virtual method implementation.
Polynomial(Array const &data, Real const &d=2., Real const &shift=0.)
constructor with a constant reference on the data set
Real shift_
shift of the kernel
Polynomial(Array const *p_data, Real const &d=2., Real const &shift=0)
constructor with a constant pointer on the data set
void setShift(Real const &shift)
set the shift of the kernel
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.