STK++ 0.9.13
STK_Kernel_RationalQuadratic.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_RATIONALQUADRATIC_H
37#define STK_KERNEL_RATIONALQUADRATIC_H
38
40
41namespace STK
42{
43
44namespace Kernel
45{
53template<class Array>
54class RationalQuadratic: 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
67 : Base(0), shift_(shift)
68 {}
82 RationalQuadratic( Array const& data, Real const& shift= 1.)
83 : Base(data),shift_(shift)
84 { if (shift_ == 0.)
86 }
91 template<class Derived>
92 RationalQuadratic( Array const* p_data, ExprBase<Derived> const& param)
93 : Base(p_data), shift_(param.empty() ? 1. : param.front())
94 {}
99 template<class Derived>
100 RationalQuadratic( Array const& data, ExprBase<Derived> const& param)
101 : Base(data), shift_(param.empty() ? 1. : param.front())
102 {}
103
107 Real const& shift() const {return shift_;}
109 void setShift(Real const& shift) { shift_ = shift;}
113 template<class Derived>
114 void setParam( ExprBase<Derived> const& param)
115 { shift_ = (param.empty() ? 1. : param.front());}
116
121 virtual inline Real diag(int i) const {return 1.;};
124 virtual Real comp(int i, int j) const;
129 virtual Real value(Type const& v) const;
130
131 private:
134};
135
136template<class Array>
138{
139 if (hasRun_) return gram_(i,j);
140 Real aux = (p_data_->row(i) - p_data_->row(j)).norm2();
141 return 1. - aux/(aux + shift_);
142}
143
144template<class Array>
146{ return 1- v*v/(v*v + shift_);}
147
148} // namespace Kernel
149
150} // namespace STK
151
152#endif /* STK_KERNEL_RATIONALQUADRATIC_H */
In this file we define the Interface base class for computing a Kernels.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
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 RationalQuadratic Kernel is a kernel of the form.
void setShift(Real const &shift)
set the shift of the kernel
RationalQuadratic(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
virtual Real comp(int i, int j) const
compute the kernel value between two individuals
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
virtual Real diag(int i) const
virtual method.
RationalQuadratic(Array const &data, Real const &shift=1.)
constructor with a constant pointer on the data set
RationalQuadratic(Real const &shift=1.)
Default constructor with the width.
RationalQuadratic(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
RationalQuadratic(Array const *p_data, Real const &shift=1.)
constructor with a constant pointer on the data set
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.