STK++ 0.9.13
STK::KernelHandler Class Reference

implementation of the DataHandlerBase class for kernel mixture models. More...

#include <STK_KernelHandler.h>

Inheritance diagram for STK::KernelHandler:
Inheritance graph

Public Types

typedef DataHandlerBase< KernelHandlerBase
 
typedef DataHandlerBase< KernelHandler >::InfoMap InfoMap
 
typedef std::pair< Kernel::IKernel *, StringTaggedKernel
 
typedef Array1D< TaggedKernel >::iterator Iterator
 
typedef Array1D< TaggedKernel >::const_iterator ConstIterator
 
- Public Types inherited from STK::DataHandlerBase< KernelHandler >
typedef std::map< std::string, std::string > InfoMap
 

Public Member Functions

 KernelHandler ()
 default constructor
 
 KernelHandler (Kernel::IKernel *p_kernel, String const &idData, String const &idModel)
 constructor with an instance of a kernel to handle
 
 ~KernelHandler ()
 destructor.
 
int nbSample () const
 
bool addKernel (Kernel::IKernel *p_kernel, String const &idData, String const &idModel)
 add an instance of a kernel to the handler
 
template<class Derived , class Array >
bool addKernel (String const &kernelName, Array const &data, ExprBase< Derived > const &param, String const &idData, String const &idModel)
 add an instance of a kernel to the handler
 
Kernel::IKernel constgetKernel (String const &idData) const
 get an instance of a kernel from the handler
 
void removeKernel (String const &idData)
 remove an instance of a kernel to the handler
 
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.
 
- Public Member Functions inherited from STK::DataHandlerBase< KernelHandler >
 ~DataHandlerBase ()
 destructor
 
InfoMap constinfo () const
 
bool addInfo (std::string const &idData, std::string const &idModel)
 Add an info descriptor to the data handler.
 
bool getIdModelName (std::string const &idData, std::string &idModel) const
 Giving the Id of a data set, find the Id of the model.
 
void writeInfo (ostream &os) const
 write infoMap on os
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Protected Attributes

int nbSample_
 Number of sample.
 
Array1D< TaggedKernelv_kernel_
 Array of the kernels.
 
- Protected Attributes inherited from STK::DataHandlerBase< KernelHandler >
InfoMap info_
 Store the informations of the mixtures in the form (idData, idModel) with.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::DataHandlerBase< KernelHandler >
 DataHandlerBase ()
 default constructor
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Detailed Description

implementation of the DataHandlerBase class for kernel mixture models.

This class stores the kernels and the idData, allow to add them and to remvoe them.

Definition at line 75 of file STK_KernelHandler.h.

Member Typedef Documentation

◆ Base

◆ ConstIterator

◆ InfoMap

◆ Iterator

◆ TaggedKernel

Constructor & Destructor Documentation

◆ KernelHandler() [1/2]

STK::KernelHandler::KernelHandler ( )

default constructor

Definition at line 41 of file STK_KernelHandler.cpp.

41: Base(), nbSample_(0) {}
int nbSample_
Number of sample.
DataHandlerBase< KernelHandler > Base

◆ KernelHandler() [2/2]

STK::KernelHandler::KernelHandler ( Kernel::IKernel p_kernel,
String const idData,
String const idModel 
)

constructor with an instance of a kernel to handle

Definition at line 43 of file STK_KernelHandler.cpp.

44 : Base()
45 , nbSample_(p_kernel->nbSample())
46{}

◆ ~KernelHandler()

STK::KernelHandler::~KernelHandler ( )

destructor.

All pointer on kernels will be deleted.

Definition at line 48 of file STK_KernelHandler.cpp.

49{
50 for(Iterator it = v_kernel_.beginIterator(); it != v_kernel_.endIterator(); ++it)
51 {
52 if (it->first)
53 {
54 Kernel::IKernel* p = it->first;
55 it->first = 0;
56 if (!isHandled(p)) delete p;
57 }
58 }
59}
Array1D< TaggedKernel >::iterator Iterator
Array1D< TaggedKernel > v_kernel_
Array of the kernels.
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.

References STK::ITContainer1D< Derived >::beginIterator(), STK::ITContainer1D< Derived >::endIterator(), isHandled(), and v_kernel_.

Member Function Documentation

◆ addKernel() [1/2]

bool STK::KernelHandler::addKernel ( Kernel::IKernel p_kernel,
String const idData,
String const idModel 
)

add an instance of a kernel to the handler

Parameters
p_kernelan instance of a kernel
idDatacan be any string given by the user for identifying data.
idModelrepresent the idModel of a given model (can be defined inside or outside STK++).
Returns
true if the pair (idData,idModel) has been successfully added to the handler

Definition at line 69 of file STK_KernelHandler.cpp.

70{
71 if (!p_kernel) return false;
72 if (!addInfo(idData, idModel)) return false; // there exists an idData with an other idModel
73
74 // check if idData already exists
77 { if (it->second == idData) { break;}}
78
79 // add kernel if it does not exist otherwise do nothing
80 if (it == v_kernel_.endConstIterator())
81 {
82 v_kernel_.push_back(TaggedKernel(p_kernel, idData));
83 nbSample_ = p_kernel->nbSample();
84 }
85 return true;
86}
hidden::Traits< Array1D< TaggedKernel, Size_ > >::ConstIterator ConstIterator
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.
ConstIterator endConstIterator() const
ConstIterator beginConstIterator() const
std::pair< Kernel::IKernel *, String > TaggedKernel

References STK::DataHandlerBase< KernelHandler >::addInfo(), STK::ITContainer1D< Derived >::beginConstIterator(), STK::ITContainer1D< Derived >::endConstIterator(), STK::Kernel::IKernel::nbSample(), nbSample_, STK::IArray1D< Derived >::push_back(), and v_kernel_.

◆ addKernel() [2/2]

template<class Derived , class Array >
bool STK::KernelHandler::addKernel ( String const kernelName,
Array const data,
ExprBase< Derived > const param,
String const idData,
String const idModel 
)

add an instance of a kernel to the handler

Parameters
kernelNamename of the kernel
datadata set associated to the kernel
paramparameters of the kernel
idDatacan be any string given by the user for identifying data.
idModelrepresent the idModel of a given model (can be defined inside or outside STK++).
Returns
true if the pair (idData,idModel) has been successfully added to the handler

Definition at line 141 of file STK_KernelHandler.h.

146{
147 // check if the idData already exists
149 for (it = v_kernel_.beginIterator() ; it!=v_kernel_.endIterator(); ++it)
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}
hidden::Traits< Array1D< TaggedKernel, Size_ > >::Iterator Iterator
kernelType stringToKernelType(std::string const &type)
Convert a String to a kernelType.
kernelType
kernel types.

References STK::DataHandlerBase< KernelHandler >::addInfo(), STK::ITContainer1D< Derived >::beginIterator(), STK::ITContainer1D< Derived >::endIterator(), STK::Kernel::gaussian_, STK::Kernel::hamming_, STK::Kernel::laplace_, STK::Kernel::linear_, STK::Kernel::IKernel::nbSample(), nbSample_, STK::Kernel::polynomial_, STK::IArray1D< Derived >::push_back(), STK::Kernel::rationalQuadratic_, STK::Kernel::stringToKernelType(), and v_kernel_.

◆ getKernel()

Kernel::IKernel const * STK::KernelHandler::getKernel ( String const idData) const

get an instance of a kernel from the handler

Parameters
idDatacan be any string given by the user for identifying data.
Returns
0 if the idData has not been found, a pointer to the kernel otherwise

Definition at line 92 of file STK_KernelHandler.cpp.

93{
94 // check if the idData already exists
97 { if (it->second == idData) { break;}}
98 // no data set found
99 if (it == v_kernel_.endConstIterator()) { return 0;}
100 return it->first;
101}

References STK::ITContainer1D< Derived >::beginConstIterator(), STK::ITContainer1D< Derived >::endConstIterator(), and v_kernel_.

◆ isHandled()

bool STK::KernelHandler::isHandled ( Kernel::IKernel *const  p_kernel) const

utility lookup function allowing to know if some pointer on a kernel is handled by the KernelHandler.

Returns
true if the pointed kernel is found, false otherwise

Definition at line 126 of file STK_KernelHandler.cpp.

127{
129 { if (it->first == p_kernel) return true;}
130 return false;
131}
Array1D< TaggedKernel >::const_iterator ConstIterator

References STK::ITContainer1D< Derived >::beginConstIterator(), STK::ITContainer1D< Derived >::endConstIterator(), and v_kernel_.

Referenced by removeKernel(), and ~KernelHandler().

◆ nbSample()

int STK::KernelHandler::nbSample ( ) const
inline
Returns
the number of sample (the number of rows of the data)

Definition at line 91 of file STK_KernelHandler.h.

91{ return nbSample_;}

References nbSample_.

◆ removeKernel()

void STK::KernelHandler::removeKernel ( String const idData)

remove an instance of a kernel to the handler

Parameters
idDatacan be any string given by the user for identifying data.

Definition at line 105 of file STK_KernelHandler.cpp.

106{
107 // check if the idData exists
109 for (it = v_kernel_.beginIterator() ; it!=v_kernel_.endIterator(); ++it)
110 { if (it->second == idData) { break;}
111 }
112 // check if kernel has been found
113 if (it != v_kernel_.endIterator())
114 {
115 Kernel::IKernel* p = it->first;
116 it->first = 0;
117 if (!isHandled(p)) delete p;
118 v_kernel_.erase(it.pos(), 1);
119 }
120}
Derived & erase(int pos, int n=1)
Delete n elements at the pos index to the container.

References STK::ITContainer1D< Derived >::beginIterator(), STK::ITContainer1D< Derived >::endIterator(), STK::IArray1D< Derived >::erase(), isHandled(), and v_kernel_.

Member Data Documentation

◆ nbSample_

int STK::KernelHandler::nbSample_
protected

Number of sample.

Definition at line 135 of file STK_KernelHandler.h.

Referenced by addKernel(), addKernel(), and nbSample().

◆ v_kernel_

Array1D< TaggedKernel > STK::KernelHandler::v_kernel_
protected

Array of the kernels.

Definition at line 137 of file STK_KernelHandler.h.

Referenced by addKernel(), addKernel(), getKernel(), isHandled(), removeKernel(), and ~KernelHandler().


The documentation for this class was generated from the following files: