STK++ 0.9.13
STK_Kernel_IKernelBase.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::Stat::Kernel
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_IKERNELBASE_H
37#define STK_KERNEL_IKERNELBASE_H
38
39#include "STK_Kernel_IKernel.h"
40
41namespace STK
42{
43namespace Kernel
44{
48template<class Array>
49class IKernelBase: public IKernel
50{
51 public:
52 typedef typename Array::Type Type;
53 using IKernel::gram_;
54
58 IKernelBase(Array const* p_data): IKernel(), p_data_(p_data) {}
62 IKernelBase(Array const& data): IKernel(), p_data_(&data) {}
68 virtual ~IKernelBase() {}
69
71 Array const* p_data() const { return p_data_;}
72
75 virtual bool run();
77 virtual int nbSample() const { return (p_data_) ? p_data_->sizeRows() : 0;}
79 virtual int nbVariable() const { return (p_data_) ? p_data_->sizeCols() : 0;}
80
85 virtual Real value(Type const& v) const
86 { return 0;}
87
88 protected:
90 Array const* p_data_;
91};
92
93template<class Array>
95{
96 if(!p_data_) return false;
97 gram_.resize(p_data_->rows());
98 // upper part
99 for (int j= gram_.begin(); j < gram_.end(); ++j)
100 {
101 { gram_(j,j) = this->diag(j);}
102 for (int i= j+1; i < gram_.end(); ++i)
103 { gram_(i,j) = this->comp(i,j);}
104 }
105 // lower part
106 for (int j= gram_.begin(); j < gram_.end(); ++j)
107 {
108 for (int i= j+1; i < gram_.end(); ++i)
109 { gram_(j,i) = gram_(i,j);}
110 }
111 this->hasRun_ = true;
112 return true;
113}
114
115
116} // namespace Kernel
117
118} // namespace STK
119
120#endif /* STK_KERNEL_IKERNELBASE_H */
In this file we define the Interface base class for computing a Kernels.
Interface Base class for the kernels classes.
Array const * p_data_
pointer on the data set
IKernelBase(Array const *p_data)
constructor with a constant pointer on the data set
virtual Real value(Type const &v) const
compute the value of the kernel for the given value
IKernelBase(IKernelBase const &kernel)
copy constructor
IKernelBase(Array const &data)
constructor with a constant reference on the data set
virtual bool run()
compute Gram matrix
Interface class for the kernels classes.
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.