STK++ 0.9.13
STK_Kernel_Linear.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_LINEAR_H
37#define STK_KERNEL_LINEAR_H
38
40
41namespace STK
42{
43
44namespace Kernel
45{
52template<class Array>
53class Linear: public IKernelBase<Array>
54{
55 public:
57 typedef typename Array::Type Type;
58 using Base::p_data_;
59 using Base::gram_;
60 using Base::hasRun_;
61
63 Linear(): Base(0) {}
67 Linear(Array const* p_data): Base(p_data) {}
71 Linear(Array const& data): Base(data) {}
76 template<class Derived>
77 Linear( Array const* p_data, ExprBase<Derived> const& param): Base(p_data)
78 {}
83 template<class Derived>
84 Linear( Array const& data, ExprBase<Derived> const& param): Base(data)
85 {}
86
88 virtual ~Linear() {}
92 template<class Derived>
93 void setParam( ExprBase<Derived> const& param) {}
94
99 virtual Real diag(int i) const;
104 virtual Real comp(int i, int j) const;
105};
106
107/* virtual method.
108 * @return diagonal value of the kernel for the ith individuals.
109 * @param i index of the individual
110 **/
111template<class Array>
112inline Real Linear<Array>::diag(int i) const
113{ return hasRun_ ? gram_(i,i)
114 : p_data_->row(i).norm2();
115}
116
117template<class Array>
119{ return hasRun_ ? gram_(i,j)
120 : p_data_->row(i).dot(p_data_->row(j));}
121
122} // namespace Kernel
123
124} // namespace STK
125
126#endif /* STK_KERNEL_LINEAR_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
Interface Base class for the kernels classes.
Array const * p_data_
pointer on the data set
CSquareX gram_
the resulting gram_ matrix
The Linear Kernel is a kernel of the form.
Linear(Array const *p_data, ExprBase< Derived > const &param)
constructor with an array of parameter.
virtual ~Linear()
destructor
virtual Real diag(int i) const
virtual method.
Linear(Array const &data)
constructor with a constant pointer on the data set
virtual Real comp(int i, int j) const
virtual method implementation.
IKernelBase< Array > Base
void setParam(ExprBase< Derived > const &param)
Set parameter using an array.
Linear()
Default constructor.
Linear(Array const &data, ExprBase< Derived > const &param)
constructor with a constant pointer on the data set
Linear(Array const *p_data)
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.