FairRoot/PandaRoot
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
PndLVQTrain Class Reference

Interface definition for LVQ trainers. More...

#include <PndLVQTrain.h>

Inheritance diagram for PndLVQTrain:
PndMvaTrainer

Public Member Functions

 PndLVQTrain (std::vector< std::pair< std::string, std::vector< float > * > > const &InputEvtsParam, std::vector< std::string > const &ClassNames, std::vector< std::string > const &VarNames, bool trim=false)
 
 PndLVQTrain (std::string const &InPut, std::vector< std::string > const &ClassNames, std::vector< std::string > const &VarNames, bool trim=true)
 
virtual ~PndLVQTrain ()
 
void storeWeights ()
 
void Train ()
 
void Train21 ()
 
void setProtoInitType (ProtoInitType iniTypeVal=RAND_FROM_DATA)
 
void SetInitProtoFileName (std::string const &fileName)
 
void SetLearnPrameters (double const initConst, double const etZ, double const etF, unsigned int const Nswp)
 
void SetNumberOfProto (size_t const numProto)
 
void SetNumberOfProto (std::map< std::string, size_t > const &labelMap)
 
void SetErrorStepSize (unsigned int const val=1000)
 
void SetLVQ2_1WindowSize (float const Wsize=0.3)
 
void EvalClassifierError ()
 
void SetPerEpochEval (bool val)
 
bool GetPerEpochEval () const
 
void SetTestSetSize (size_t percent=50)
 
void SetTestSet (std::set< size_t > const &testSet)
 
void NormalizeData (NormType t=NONORM)
 
void PCATransForm ()
 
void SetOutPutFile (std::string const &outFile)
 
void WriteErroVect (std::string const &FileName) const
 
std::vector< StepError > const & GetErrorValues () const
 
virtual void Initialize ()
 
std::set< size_t > const & GetTestEvetIdx () const
 
std::vector< PndMvaClass > const & GetClasses () const
 Get the list of available classes (labels). More...
 
std::vector< PndMvaVariable >
const & 
GetVariables () const
 Get the list of available variables. More...
 
size_t GetRndSeed () const
 
void SetRndSeed (size_t const sd)
 

Protected Member Functions

void SetAppType (AppType t)
 
void WriteToWeightFile (std::vector< std::pair< std::string, std::vector< float > * > > const &weights) const
 
void splitTetsSet ()
 

Protected Attributes

std::set< size_t > m_testSet_indices
 Indices of the test set. More...
 
PndMvaDataSet m_dataSets
 Data set. Holds event values. More...
 
std::vector< StepErrorm_StepErro
 Container to keep per step error values. More...
 
std::string m_outFile
 Output filename. More...
 
size_t m_RND_seed
 Random seed. More...
 

Private Member Functions

 PndLVQTrain (PndLVQTrain const &other)
 
PndLVQTrainoperator= (PndLVQTrain const &other)
 
void EvalClassifierError (unsigned int stp)
 Evaluate the classifier, train and test error. More...
 
void InitProtoRand ()
 
void InitRandProtoFromData ()
 
void InitProtoK_Means ()
 
void InitProtoTypes ()
 
void cleanProtoList ()
 
void UpdateProto (std::vector< float > const &EvtData, std::vector< float > &proto, int const delta, double const ethaT)
 
void ValidateProtoUpdate (std::vector< float > &p)
 
void ReadProtoFromFile ()
 

Private Attributes

std::vector< std::pair
< std::string, std::vector
< float > * > > 
m_LVQProtos
 Holds the LVQ proto-types. More...
 
std::vector< PndMvaDistObjm_distances
 Container to store distances. More...
 
double m_initConst
 
double m_ethaZero
 
double m_ethaFinal
 
float m_WindowSize
 
unsigned int m_NumSweep
 Number of sweeps through example set. More...
 
ProtoInitType m_proto_init
 Proto init type. More...
 
std::string m_initProtoFile
 initial protypes, when reading from file. More...
 
unsigned int m_ErrorStep
 Each #ErrorStep, steps evaluate the trained classifier. More...
 
unsigned int m_ProgStep
 
std::map< std::string, size_t > m_numProtoPerClass
 Map labels (classes) to number of prototypes. More...
 
bool m_PerEpoch
 If evaluate per epoch. More...
 

Detailed Description

Interface definition for LVQ trainers.

Definition at line 33 of file PndLVQTrain.h.

Constructor & Destructor Documentation

PndLVQTrain::PndLVQTrain ( std::vector< std::pair< std::string, std::vector< float > * > > const &  InputEvtsParam,
std::vector< std::string > const &  ClassNames,
std::vector< std::string > const &  VarNames,
bool  trim = false 
)
explicit

Constructor:

Parameters
InputEvtsParamInput events vector.
ClassNamesclass names.
VarNamesvariable names of the features.
PndLVQTrain::PndLVQTrain ( std::string const &  InPut,
std::vector< std::string > const &  ClassNames,
std::vector< std::string > const &  VarNames,
bool  trim = true 
)
explicit

Constructor:

Parameters
InPutInput file name.
ClassNamesclass names.
VarNamesvariable names of the features.
virtual PndLVQTrain::~PndLVQTrain ( )
virtual

Destructor

PndLVQTrain::PndLVQTrain ( PndLVQTrain const &  other)
private

Member Function Documentation

void PndLVQTrain::cleanProtoList ( )
private

Clean prototype container.

void PndLVQTrain::EvalClassifierError ( )
virtual

Classifier evaluation.

Reimplemented from PndMvaTrainer.

void PndLVQTrain::EvalClassifierError ( unsigned int  stp)
private

Evaluate the classifier, train and test error.

std::vector< PndMvaClass > const & PndMvaTrainer::GetClasses ( ) const
inlineinherited

Get the list of available classes (labels).

Get the list of available classes (labels). Vector containing available labels.

Definition at line 226 of file PndMvaTrainer.h.

References PndMvaDataSet::GetClasses(), and PndMvaTrainer::m_dataSets.

227 {
228  return m_dataSets.GetClasses();
229 };
PndMvaDataSet m_dataSets
Data set. Holds event values.
std::vector< PndMvaClass > const & GetClasses() const
Get the list of available classes (labels).
std::vector< StepError > const & PndMvaTrainer::GetErrorValues ( ) const
inlineinherited

Get the list of objects that contain the classifier evaluation results.

Returns
List of evaluation objects.

Definition at line 238 of file PndMvaTrainer.h.

References PndMvaTrainer::m_StepErro.

239 {
240  return m_StepErro;
241 };
std::vector< StepError > m_StepErro
Container to keep per step error values.
bool PndLVQTrain::GetPerEpochEval ( ) const
inline

Getter for evaluation scheme.

Returns
Per epoch or per step.

Definition at line 309 of file PndLVQTrain.h.

References m_PerEpoch.

310 {
311  return m_PerEpoch;
312 };
bool m_PerEpoch
If evaluate per epoch.
Definition: PndLVQTrain.h:270
size_t PndMvaTrainer::GetRndSeed ( ) const
inlineinherited

Definition at line 200 of file PndMvaTrainer.h.

References PndMvaTrainer::m_RND_seed.

201 {
202  return this->m_RND_seed;
203 };
size_t m_RND_seed
Random seed.
std::set< size_t > const & PndMvaTrainer::GetTestEvetIdx ( ) const
inlineinherited

Get the indices of the events selected to be used for testing.

Returns
A set containing the indices of test events.

Definition at line 220 of file PndMvaTrainer.h.

References PndMvaTrainer::m_testSet_indices.

221 {
222  return m_testSet_indices;
223 };
std::set< size_t > m_testSet_indices
Indices of the test set.
std::vector< PndMvaVariable > const & PndMvaTrainer::GetVariables ( ) const
inlineinherited

Get the list of available variables.

Get the list of available variables. Vector containing available Parameters (features).

Definition at line 232 of file PndMvaTrainer.h.

References PndMvaDataSet::GetVars(), and PndMvaTrainer::m_dataSets.

233 {
234  return m_dataSets.GetVars();
235 };
PndMvaDataSet m_dataSets
Data set. Holds event values.
std::vector< PndMvaVariable > const & GetVars() const
Get the list of available variables.
virtual void PndMvaTrainer::Initialize ( )
virtualinherited

Initialize data structures.

Reimplemented in PndMultiClassBdtTrain, and PndMultiClassMlpTrain.

void PndLVQTrain::InitProtoK_Means ( )
private

Initialize LVQ prototypes (Code books) using K-Means clustering.

void PndLVQTrain::InitProtoRand ( )
private

Initialize LVQ prototypes (Code books) using class conditional means (CCM) vectors.

void PndLVQTrain::InitProtoTypes ( )
private

Initialize LVQ prototypes (Code books).

void PndLVQTrain::InitRandProtoFromData ( )
private

Initialize LVQ prototypes (Code books) using Randomly selected vectors from the original data set.

void PndMvaTrainer::NormalizeData ( NormType  t = NONORM)
inherited

Select input data normalization scheme.

PndLVQTrain& PndLVQTrain::operator= ( PndLVQTrain const &  other)
private
void PndMvaTrainer::PCATransForm ( )
inherited

Parameter decorrelation. Performs PCA (Principal component analysis) on the input dataset.

void PndLVQTrain::ReadProtoFromFile ( )
private

Read pre-initialized code books from file and store the vectors in LVQ prototype container.

void PndMvaTrainer::SetAppType ( AppType  t)
inlineprotectedinherited

Set application type for the current object

Definition at line 215 of file PndMvaTrainer.h.

References PndMvaTrainer::m_dataSets, and PndMvaDataSet::SetAppType().

216 {
218 };
PndMvaDataSet m_dataSets
Data set. Holds event values.
void SetAppType(AppType t)
TTree * t
Definition: bump_analys.C:13
void PndLVQTrain::SetErrorStepSize ( unsigned int const  val = 1000)
inline

Set how often the classifier has to be evaluated.

Parameters
valEvaluate after val steps. If (Val == 0) then the classifier is evaluated once at the end of the training prodecure.

Definition at line 294 of file PndLVQTrain.h.

References m_ErrorStep, and val.

295 {
296  m_ErrorStep = val;
297 };
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
unsigned int m_ErrorStep
Each #ErrorStep, steps evaluate the trained classifier.
Definition: PndLVQTrain.h:263
void PndLVQTrain::SetInitProtoFileName ( std::string const &  fileName)
inline

Set the file name which holds the pre-initialized code books.

Parameters
valThe name of the file which containes the pre initialized code books.

Definition at line 280 of file PndLVQTrain.h.

References m_initProtoFile.

281 {
282  m_initProtoFile = fileName;
283 };
std::string m_initProtoFile
initial protypes, when reading from file.
Definition: PndLVQTrain.h:260
void PndLVQTrain::SetLearnPrameters ( double const  initConst,
double const  etZ,
double const  etF,
unsigned int const  Nswp 
)
inline

Sets the learning parameters.

Parameters
initConstInitialization constant, used to initialize LVQ prototypes.
etZEthaZero, start value for the learning rate.
etFFinal value for Etha (learning rate)
NswpNumber of sweeps through the examples collection set.

Definition at line 285 of file PndLVQTrain.h.

References m_ethaFinal, m_ethaZero, m_initConst, and m_NumSweep.

287 {
288  m_initConst = initConst;
289  m_ethaZero = etZ;
290  m_ethaFinal = etF;
291  m_NumSweep = Nswp;
292 };
double m_ethaZero
Definition: PndLVQTrain.h:249
double m_ethaFinal
Definition: PndLVQTrain.h:250
unsigned int m_NumSweep
Number of sweeps through example set.
Definition: PndLVQTrain.h:254
double m_initConst
Definition: PndLVQTrain.h:248
void PndLVQTrain::SetLVQ2_1WindowSize ( float const  Wsize = 0.3)
inline

Set the window size for LVQ2.1 alg. A value between 0.2 & 0.3 is recommended.

Definition at line 299 of file PndLVQTrain.h.

References m_WindowSize.

300 {
301  m_WindowSize = Wsize;
302 };
float m_WindowSize
Definition: PndLVQTrain.h:251
void PndLVQTrain::SetNumberOfProto ( size_t const  numProto)

Set the number of protoTypes to be used for training. The same number of prototypes are initialized for all available labels(classes).

Parameters
numProtoNumber of prototypes.
void PndLVQTrain::SetNumberOfProto ( std::map< std::string, size_t > const &  labelMap)

Set the number of protoTypes to be used for training.

Parameters
labelMapMap containing number of prototypes for each class (label).
void PndMvaTrainer::SetOutPutFile ( std::string const &  outFile)
inlineinherited

Setter to set the weightfile name.

Parameters
outFileOutput filename.

Definition at line 210 of file PndMvaTrainer.h.

References PndMvaTrainer::m_outFile, and outFile.

211 {
212  m_outFile = outFile;
213 };
TString outFile
Definition: hit_dirc.C:17
std::string m_outFile
Output filename.
void PndLVQTrain::SetPerEpochEval ( bool  val)
inline

Select if we want to follow the training evaluation per epoch (sweeps) or per step. The number of steps = Sweeps * (#examples).

Parameters
valtrue = evaluate per epoch, false per step. Default is false.

Definition at line 304 of file PndLVQTrain.h.

References m_PerEpoch, and val.

305 {
306  m_PerEpoch = val;
307 };
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
bool m_PerEpoch
If evaluate per epoch.
Definition: PndLVQTrain.h:270
void PndLVQTrain::setProtoInitType ( ProtoInitType  iniTypeVal = RAND_FROM_DATA)
inline

Set CodeBook init type.

Parameters
iniTypeValInitialization type.

Definition at line 275 of file PndLVQTrain.h.

References m_proto_init.

276 {
277  m_proto_init = iniTypeVal;
278 };
ProtoInitType m_proto_init
Proto init type.
Definition: PndLVQTrain.h:257
void PndMvaTrainer::SetRndSeed ( size_t const  sd)
inlineinherited

Definition at line 205 of file PndMvaTrainer.h.

References PndMvaTrainer::m_RND_seed.

206 {
207  this->m_RND_seed = sd;
208 };
size_t m_RND_seed
Random seed.
void PndMvaTrainer::SetTestSet ( std::set< size_t > const &  testSet)
inherited

Set the indices of events that are going to be used for testing.

Parameters
testSetSet containing the indices of the test events.
void PndMvaTrainer::SetTestSetSize ( size_t  percent = 50)
inherited

Creates test and train data sets.

Parameters
percentPercent of the data set to be used for testing.
void PndMvaTrainer::splitTetsSet ( )
protectedinherited
void PndLVQTrain::storeWeights ( )
virtual

Store weights in the output File. If output file name is not specified, then write nothing.

Implements PndMvaTrainer.

void PndLVQTrain::Train ( )
virtual

Train the classifier accourding to LVQ1 algorithm.

Implements PndMvaTrainer.

void PndLVQTrain::Train21 ( )

Train the classifier accourding to LVQ2.1 algorithm.

void PndLVQTrain::UpdateProto ( std::vector< float > const &  EvtData,
std::vector< float > &  proto,
int const  delta,
double const  ethaT 
)
private

Updates the LVQ prototypes.

void PndLVQTrain::ValidateProtoUpdate ( std::vector< float > &  p)
private

Check if the current update creates an invalid codebook (If the vectore is placed outside the extrema). If after the update the codebook is out of boundary: reinitialize. Else: do nothing.

Parameters
pThe to be validated prototype.
void PndMvaTrainer::WriteErroVect ( std::string const &  FileName) const
inherited

Writes the train and test errors evaluations to a given file.

Parameters
FileNameOutput file name.
void PndMvaTrainer::WriteToWeightFile ( std::vector< std::pair< std::string, std::vector< float > * > > const &  weights) const
protectedinherited

Write the training and normalization data to outFile.

Member Data Documentation

PndMvaDataSet PndMvaTrainer::m_dataSets
protectedinherited

Data set. Holds event values.

Definition at line 175 of file PndMvaTrainer.h.

Referenced by PndMvaTrainer::GetClasses(), PndMvaTrainer::GetVariables(), and PndMvaTrainer::SetAppType().

std::vector<PndMvaDistObj> PndLVQTrain::m_distances
private

Container to store distances.

Definition at line 242 of file PndLVQTrain.h.

unsigned int PndLVQTrain::m_ErrorStep
private

Each #ErrorStep, steps evaluate the trained classifier.

Definition at line 263 of file PndLVQTrain.h.

Referenced by SetErrorStepSize().

double PndLVQTrain::m_ethaFinal
private

Definition at line 250 of file PndLVQTrain.h.

Referenced by SetLearnPrameters().

double PndLVQTrain::m_ethaZero
private

Definition at line 249 of file PndLVQTrain.h.

Referenced by SetLearnPrameters().

double PndLVQTrain::m_initConst
private

Learn parameters: Init constant, start learning rate, End learning rate.

Definition at line 248 of file PndLVQTrain.h.

Referenced by SetLearnPrameters().

std::string PndLVQTrain::m_initProtoFile
private

initial protypes, when reading from file.

Definition at line 260 of file PndLVQTrain.h.

Referenced by SetInitProtoFileName().

std::vector< std::pair<std::string, std::vector<float>*> > PndLVQTrain::m_LVQProtos
private

Holds the LVQ proto-types.

Definition at line 239 of file PndLVQTrain.h.

std::map< std::string, size_t> PndLVQTrain::m_numProtoPerClass
private

Map labels (classes) to number of prototypes.

Definition at line 267 of file PndLVQTrain.h.

unsigned int PndLVQTrain::m_NumSweep
private

Number of sweeps through example set.

Definition at line 254 of file PndLVQTrain.h.

Referenced by SetLearnPrameters().

std::string PndMvaTrainer::m_outFile
protectedinherited

Output filename.

Definition at line 181 of file PndMvaTrainer.h.

Referenced by PndMvaTrainer::SetOutPutFile().

bool PndLVQTrain::m_PerEpoch
private

If evaluate per epoch.

Definition at line 270 of file PndLVQTrain.h.

Referenced by GetPerEpochEval(), and SetPerEpochEval().

unsigned int PndLVQTrain::m_ProgStep
private

Definition at line 264 of file PndLVQTrain.h.

ProtoInitType PndLVQTrain::m_proto_init
private

Proto init type.

Definition at line 257 of file PndLVQTrain.h.

Referenced by setProtoInitType().

size_t PndMvaTrainer::m_RND_seed
protectedinherited

Random seed.

Definition at line 184 of file PndMvaTrainer.h.

Referenced by PndMvaTrainer::GetRndSeed(), and PndMvaTrainer::SetRndSeed().

std::vector<StepError> PndMvaTrainer::m_StepErro
protectedinherited

Container to keep per step error values.

Definition at line 178 of file PndMvaTrainer.h.

Referenced by PndMvaTrainer::GetErrorValues().

std::set<size_t> PndMvaTrainer::m_testSet_indices
protectedinherited

Indices of the test set.

Definition at line 172 of file PndMvaTrainer.h.

Referenced by PndMvaTrainer::GetTestEvetIdx().

float PndLVQTrain::m_WindowSize
private

Definition at line 251 of file PndLVQTrain.h.

Referenced by SetLVQ2_1WindowSize().


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