STK++ 0.9.13
STK_KernelHandler.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::DManager
27 * created on: 15 nov. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_KERNELHANDLER_H
37#define STK_KERNELHANDLER_H
38
42
50
51
52namespace STK
53{
54// forward declaration
55class KernelHandler;
56
57namespace hidden
58{
62template<typename Type>
64{
66};
67
68} // namespace hidden
69
75class KernelHandler: public DataHandlerBase<KernelHandler>
76{
77 public:
80 typedef std::pair<Kernel::IKernel*, String> TaggedKernel;
83
87 KernelHandler(Kernel::IKernel* p_kernel, String const& idData, String const& idModel);
91 inline int nbSample() const { return nbSample_;}
100 bool addKernel(Kernel::IKernel* p_kernel, String const& idData, String const& idModel);
111 template<class Derived, class Array>
112 bool addKernel( String const& kernelName
113 , Array const& data
114 , ExprBase<Derived> const& param
115 , String const& idData
116 , String const& idModel);
122 Kernel::IKernel const* getKernel( String const& idData) const;
126 void removeKernel( String const& idData);
131 bool isHandled(Kernel::IKernel* const p_kernel) const;
132
133 protected:
138};
139
140template<class Derived, class Array>
142 , Array const& data
143 , ExprBase<Derived> const& param
144 , String const& idData
145 , String const& idModel)
146{
147 // check if the idData already exists
150 { if (it->second == idData) { break;}}
151 // if idData already exists return false
152 if (it != v_kernel_.endIterator()) return false;
153
154 // create kernel
156 Kernel::IKernel* p_kernel = 0;
157 switch (kt)
158 {
159 case Kernel::laplace_:
160 p_kernel = new Kernel::Laplace<Array>(data, param);
161 break;
163 p_kernel = new Kernel::Gaussian<Array>(data, param);
164 break;
165 case Kernel::hamming_:
166 p_kernel = new Kernel::Hamming<Array>(data, param);
167 break;
168 case Kernel::linear_:
169 p_kernel = new Kernel::Linear<Array>(data, param);
170 break;
172 p_kernel = new Kernel::Polynomial<Array>(data, param);
173 break;
175 p_kernel = new Kernel::RationalQuadratic<Array>(data, param);
176 break;
177 default:
178 break;
179 }
180 // not an existing kernel
181 if (!p_kernel) return false;
182 // add kernel to
183 v_kernel_.push_back(TaggedKernel(p_kernel, idData));
184 nbSample_ = p_kernel->nbSample();
185 return addInfo(idData, idModel);
186}
187
188} // namespace STK
189
190#endif /* STK_KERNELHANDLER_H */
In this file we define and implement the final class Array1D.
In this file we implement the final class CArray.
In this file we define the class and methods for computing a Gaussian Kernel.
In this file we define the class and methods for computing a Hamming Kernel.
In this file we define the class and methods for computing a Laplace Kernel.
In this file we define the class and methods for computing a Linear Kernel.
In this file we define the class and methods for computing a Polynomial Kernel.
In this file we define the class and methods for computing a RationalQuadratic Kernel.
In this file we define the enum and utilites method for the kernels.
A class derived from a DataHandlerBase allows to store various data sets identified by an idData and ...
std::map< std::string, std::string > InfoMap
bool addInfo(std::string const &idData, std::string const &idModel)
Add an info descriptor to the data handler.
Derived & push_back(Type const &v)
STL compatibility: append an element v.
implementation of the DataHandlerBase class for kernel mixture models.
Array1D< TaggedKernel >::iterator Iterator
Kernel::IKernel const * getKernel(String const &idData) const
get an instance of a kernel from the handler
Array1D< TaggedKernel > v_kernel_
Array of the kernels.
int nbSample_
Number of sample.
DataHandlerBase< KernelHandler >::InfoMap InfoMap
DataHandlerBase< KernelHandler > Base
bool isHandled(Kernel::IKernel *const p_kernel) const
utility lookup function allowing to know if some pointer on a kernel is handled by the KernelHandler.
void removeKernel(String const &idData)
remove an instance of a kernel to the handler
bool addKernel(Kernel::IKernel *p_kernel, String const &idData, String const &idModel)
add an instance of a kernel to the handler
std::pair< Kernel::IKernel *, String > TaggedKernel
KernelHandler()
default constructor
Array1D< TaggedKernel >::const_iterator ConstIterator
The Gaussian Kernel is a kernel of the form.
The Hamming Kernel is a kernel of the form.
Interface class for the kernels classes.
virtual int nbSample() const =0
pure virtual method.
The Laplace Kernel is a kernel of the form.
The Linear Kernel is a kernel of the form.
The Polynomial Kernel is a kernel of the form.
The RationalQuadratic Kernel is a kernel of the form.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
kernelType stringToKernelType(std::string const &type)
Convert a String to a kernelType.
kernelType
kernel types.
std::basic_string< Char > String
STK fundamental type of a String.
The namespace STK is the main domain space of the Statistical ToolKit project.
The DataHandlerTraits will give the type of container furnished by the concrete implementations of th...