![]() |
KSquare Utilities
|
Will implement the Dual Classifier Model. More...
#include <ModelDual.h>
Inheritance diagram for KKMLL::ModelDual:Public Types | |
| typedef ModelDual * | ModelDualPtr |
Public Types inherited from KKMLL::Model | |
| typedef Model * | ModelPtr |
| enum | ModelTypes : int { ModelTypes::Null = 0, ModelTypes::OldSVM = 1, ModelTypes::SvmBase = 2, ModelTypes::KNN = 3, ModelTypes::UsfCasCor = 4, ModelTypes::Dual = 5 } |
Public Member Functions | |
| ModelDual () | |
| ModelDual (FactoryFVProducerPtr _factoryFVProducer) | |
| ModelDual (const KKStr &_name, const ModelParamDual &_param, FactoryFVProducerPtr _factoryFVProducer) | |
| ModelDual (const ModelDual &_model) | |
| virtual | ~ModelDual () |
| Frees any memory allocated by, and owned by the ModelDual. More... | |
| virtual KKStr | Description () const |
| virtual ModelDualPtr | Duplicate () const |
| virtual kkint32 | MemoryConsumedEstimated () const |
| virtual ModelTypes | ModelType () const |
| virtual kkint32 | NumOfSupportVectors () const |
| ModelParamDualPtr | Param () |
| virtual MLClassPtr | Predict (FeatureVectorPtr example, RunLog &log) |
| virtual void | Predict (FeatureVectorPtr example, MLClassPtr knownClass, MLClassPtr &predClass1, MLClassPtr &predClass2, kkint32 &predClass1Votes, kkint32 &predClass2Votes, double &probOfKnownClass, double &predClass1Prob, double &predClass2Prob, kkint32 &numOfWinners, bool &knownClassOneOfTheWinners, double &breakTie, RunLog &log) |
| virtual ClassProbListPtr | ProbabilitiesByClass (FeatureVectorPtr example, RunLog &log) |
| virtual void | ProbabilitiesByClass (FeatureVectorPtr example, const MLClassList &_mlClasses, kkint32 *_votes, double *_probabilities, RunLog &log) |
| virtual void | ProbabilitiesByClass (FeatureVectorPtr _example, const MLClassList &_mlClasses, double *_probabilities, RunLog &_log) |
| Derives predicted probabilities by class. More... | |
| virtual void | ProbabilitiesByClassDual (FeatureVectorPtr example, KKStr &classifier1Desc, KKStr &classifier2Desc, ClassProbListPtr &classifier1Results, ClassProbListPtr &classifier2Results, RunLog &log) |
| Only applied to ModelDual classifier. More... | |
| virtual void | ReadXML (XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log) |
| To be implemented by derived classes; the parent classes fields will be updated by the derived class calling ReadXMLModelToken. More... | |
| virtual void | RetrieveCrossProbTable (MLClassList &classes, double **crossProbTable, RunLog &log) |
| TrainingProcess2Ptr | Trainer1 () |
| TrainingProcess2Ptr | Trainer2 () |
| virtual void | TrainModel (FeatureVectorListPtr _trainExamples, bool _alreadyNormalized, bool _takeOwnership, VolConstBool &_cancelFlag, RunLog &_log) |
| Performs operations such as FeatureEncoding, and Normalization. The actual training of models occurs in the specific derived implementation of 'Model'. More... | |
| virtual void | WriteXML (const KKStr &varName, ostream &o) const |
Public Member Functions inherited from KKMLL::Model | |
| Model () | |
| Model (FactoryFVProducerPtr _factoryFVProducer) | |
| Use this when you are planning on creating a empty model without parameters. More... | |
| Model (const KKStr &_name, const ModelParam &_param, FactoryFVProducerPtr _factoryFVProducer) | |
| Construct a instance of 'Model' using the parameters specified in '_param'. More... | |
| Model (const Model &_madel) | |
| Copy Constructor. More... | |
| virtual | ~Model () |
| Frees any memory allocated by, and owned by the Model. More... | |
| bool | AlreadyNormalized () const |
| const FeatureEncoder2 & | Encoder () const |
| FactoryFVProducerPtr | FactoryFVProducer () const |
| virtual FeatureNumListConstPtr | GetFeatureNums () const |
| MLClassListPtr | MLClasses () const |
| MLClassListPtr | MLClassesNewInstance () const |
| virtual KKStr | ModelTypeStr () const |
| const KKStr & | Name () const |
| void | Name (const KKStr &_name) |
| virtual bool | NormalizeNominalAttributes () const |
| ModelParamPtr | Param () const |
| virtual void | PredictRaw (FeatureVectorPtr example, MLClassPtr &predClass, double &dist) |
| virtual FeatureVectorPtr | PrepExampleForPrediction (FeatureVectorPtr fv, bool &newExampleCreated) |
| Every prediction method in every class that is inherited from this class should call this method before performing there prediction. Such things as Normalization and Feature Encoding. More... | |
| const KKStr & | RootFileName () const |
| void | RootFileName (const KKStr &_rootFileName) |
| virtual FeatureNumListConstPtr | SelectedFeatures () const |
| const KKB::DateTime & | TimeSaved () const |
| double | TrainingTime () const |
| void | TrainingTimeEnd () |
| Derived classes call this method to stop the clock for 'trainingTime'. More... | |
| void | TrainingTimeStart () |
| Derived classes call this method to start the clock for 'trainingTime'. More... | |
| double | TrianingPrepTime () const |
| bool | ValidModel () const |
| void | WriteModelXMLFields (std::ostream &o) const |
| The "WriteXML" method in Derived classes call this method to include the parents classes fields in the XML data. More... | |
| virtual void | WriteXML (const KKStr &varName, std::ostream &o) const =0 |
Protected Member Functions | |
| void | DeleteExistingClassifiers () |
| MLClassPtr | ReconcilePredictions (MLClassPtr pred1, MLClassPtr pred2, RunLog &log) |
| void | ReconcileProbAndVotes (Classifier2Ptr classifier, MLClassPtr predClass, FeatureVectorPtr encodedExample, double &predClassProb, kkint32 &predClassVotes) |
Protected Member Functions inherited from KKMLL::Model | |
| void | AddErrorMsg (const KKStr &errMsg, kkint32 lineNum) |
| void | AllocatePredictionVariables () |
| void | DeAllocateSpace () |
| void | NormalizeProbabilitiesWithAMinumum (kkint32 numClasses, double *probabilities, double minProbability) |
| void | ReadXMLModelPost (RunLog &log) |
| XmlTokenPtr | ReadXMLModelToken (XmlTokenPtr t, RunLog &log) |
| Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed back. More... | |
| void | ReduceTrainExamples (RunLog &log) |
| Reduces the Training Images down to the size dictated by the 'examplesPerClass' parameter. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from KKMLL::Model | |
| static ModelPtr | CreateAModel (ModelTypes _modelType, const KKStr &_name, const ModelParam &_param, FactoryFVProducerPtr _factoryFVProducer, VolConstBool &_cancelFlag, RunLog &_log) |
| A factory method that will instantiate the appropriate class of training model based off '_modelType'. More... | |
| static ModelTypes | ModelTypeFromStr (const KKStr &_modelingTypeStr) |
| static KKStr | ModelTypeToStr (ModelTypes _modelingType) |
Will implement the Dual Classifier Model.
This model will actually load two different training models specified in the parameters field. It will utilize both classifiers for to make a prediction. Unknown examples will be submitted to both classifiers. The returned class will be the common part of the class hierarchy of the two predictions. If there is nothing in common between the two predictions then it will return the "Other class.
Definition at line 66 of file ModelDual.h.
| typedef ModelDual* KKMLL::ModelDual::ModelDualPtr |
Definition at line 70 of file ModelDual.h.
| ModelDual::ModelDual | ( | ) |
Definition at line 39 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, KKMLL::Model::Model(), param, trainer1, and trainer2.
| ModelDual::ModelDual | ( | FactoryFVProducerPtr | _factoryFVProducer | ) |
Definition at line 54 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, KKMLL::Model::Model(), param, trainer1, and trainer2.
| ModelDual::ModelDual | ( | const KKStr & | _name, |
| const ModelParamDual & | _param, | ||
| FactoryFVProducerPtr | _factoryFVProducer | ||
| ) |
Definition at line 67 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, KKMLL::Model::Model(), param, KKMLL::Model::param, trainer1, and trainer2.
Referenced by KKMLL::Model::CreateAModel().
| ModelDual::ModelDual | ( | const ModelDual & | _model | ) |
Definition at line 86 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, KKMLL::Model::Model(), param, KKMLL::Model::param, trainer1, and trainer2.
Referenced by Duplicate().
|
virtual |
Frees any memory allocated by, and owned by the ModelDual.
Definition at line 106 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, DeleteExistingClassifiers(), trainer1, and trainer2.
|
protected |
Definition at line 164 of file ModelDual.cpp.
References classifier1, classifier2, config1, config2, trainer1, and trainer2.
Referenced by TrainModel(), and ~ModelDual().
|
virtual |
Return short user readable description of model.
Reimplemented from KKMLL::Model.
Definition at line 133 of file ModelDual.cpp.
References KKB::KKStr::Concat(), KKMLL::TrainingProcess2::ConfigFileName(), KKMLL::TrainingProcess2::ModelTypeStr(), KKMLL::Model::Name(), KKB::KKStr::operator+(), KKB::operator+(), KKB::osGetRootName(), trainer1, and trainer2.
|
virtual |
|
virtual |
Reimplemented from KKMLL::Model.
Definition at line 120 of file ModelDual.cpp.
References classifier1, classifier2, KKMLL::Classifier2::MemoryConsumedEstimated(), KKMLL::Model::MemoryConsumedEstimated(), KKMLL::TrainingProcess2::MemoryConsumedEstimated(), trainer1, and trainer2.
|
inlinevirtual |
|
virtual |
Definition at line 847 of file ModelDual.cpp.
References KKMLL::TrainingProcess2::NumOfSupportVectors(), trainer1, and trainer2.
| ModelParamDualPtr ModelDual::Param | ( | ) |
|
virtual |
Implements KKMLL::Model.
Definition at line 430 of file ModelDual.cpp.
References classifier1, classifier2, KKMLL::Classifier2::ClassifyAExample(), KKMLL::Model::PrepExampleForPrediction(), and ReconcilePredictions().
|
virtual |
Implements KKMLL::Model.
Definition at line 462 of file ModelDual.cpp.
References classifier1, classifier2, KKMLL::Classifier2::ClassifyAExample(), KKMLL::Model::PrepExampleForPrediction(), ReconcilePredictions(), and ReconcileProbAndVotes().
|
virtual |
Implements KKMLL::Model.
Definition at line 591 of file ModelDual.cpp.
References classifier1, classifier2, KKMLL::ClassProbList::MergeIn(), KKMLL::ClassProbList::NormalizeToOne(), and KKMLL::Classifier2::ProbabilitiesByClass().
|
virtual |
Implements KKMLL::Model.
Definition at line 676 of file ModelDual.cpp.
References KKMLL::ClassProbList::AddIn(), classifier1, classifier2, KKMLL::ClassProbList::LookUp(), KKMLL::ClassProbList::NormalizeToOne(), KKMLL::Classifier2::ProbabilitiesByClass(), KKMLL::ClassProb::probability, and KKMLL::ClassProb::votes.
|
virtual |
Derives predicted probabilities by class.
Will get the probabilities assigned to each class by the classifier. The '_mlClasses' parameter dictates the order of the classes. That is the probabilities for any given index in '_probabilities' will be for the class specified in the same index in '_mlClasses'.
| [in] | _example | FeatureVector object to calculate predicted probabilities for. |
| [in] | _mlClasses | List of classes that caller is aware of. This should be the same list that was used when constructing this Model object. The list must be the same but not necessarily in the same order as when Model was 1st constructed. |
| [out] | _probabilities | An array that must be as big as the number of classes as in mlClasses. The probability of class in mlClasses[x] will be returned in probabilities[x]. |
Implements KKMLL::Model.
Definition at line 741 of file ModelDual.cpp.
References KKMLL::ClassProbList::AddIn(), classifier1, classifier2, KKMLL::ClassProbList::LookUp(), KKMLL::ClassProbList::NormalizeToOne(), KKMLL::Classifier2::ProbabilitiesByClass(), and KKMLL::ClassProb::probability.
|
virtual |
Only applied to ModelDual classifier.
Reimplemented from KKMLL::Model.
Definition at line 628 of file ModelDual.cpp.
References classifier1, classifier2, KKMLL::TrainingProcess2::ModelDescription(), KKB::KKStr::operator=(), KKMLL::Model::PrepExampleForPrediction(), KKMLL::Classifier2::ProbabilitiesByClass(), trainer1, and trainer2.
|
virtual |
To be implemented by derived classes; the parent classes fields will be updated by the derived class calling ReadXMLModelToken.
Implements KKMLL::Model.
Definition at line 902 of file ModelDual.cpp.
References KKMLL::Model::AddErrorMsg(), classifier1, KKMLL::Classifier2::Classifier2(), classifier2, KKB::KKStr::Concat(), config1, config2, KKB::XmlStream::GetNextToken(), KKB::KKStr::KKStr(), KKMLL::ModelParam::ModelParamTypeStr(), param, KKMLL::Model::param, KKMLL::Model::ReadXMLModelPost(), KKMLL::Model::ReadXMLModelToken(), KKB::XmlToken::SectionName(), KKB::XmlElement::SectionName(), KKB::XmlToken::tokElement, KKB::XmlToken::TokenType(), trainer1, trainer2, KKMLL::Model::validModel, KKB::XmlToken::VarName(), and KKB::XmlElement::VarName().
|
protected |
Definition at line 320 of file ModelDual.cpp.
References KKB::KKStr::Append(), KKB::KKStr::Concat(), KKMLL::MLClass::CreateNewMLClass(), KKB::KKStr::Empty(), KKB::KKStr::ExtractToken2(), KKMLL::ModelParamDual::FullHierarchyMustMatch(), KKB::KKStr::KKStr(), KKB::KKStr::Len(), KKMLL::MLClass::Name(), KKB::KKStr::operator+=(), KKB::KKStr::operator==(), KKMLL::ModelParamDual::OtherClass(), and param.
Referenced by Predict().
|
protected |
Definition at line 396 of file ModelDual.cpp.
References KKMLL::ClassProb::classLabel, KKB::KKStr::Concat(), KKMLL::MLClass::Name(), KKMLL::Classifier2::ProbabilitiesByClass(), KKMLL::ClassProb::probability, KKB::KKStr::StartsWith(), and KKMLL::ClassProb::votes.
Referenced by Predict().
|
virtual |
| crossProbTable | two dimension matrix that needs to be classes.QueueSize () squared. |
Reimplemented from KKMLL::Model.
Definition at line 800 of file ModelDual.cpp.
References classifier1, classifier2, and KKMLL::Classifier2::RetrieveCrossProbTable().
|
inline |
Definition at line 98 of file ModelDual.h.
References trainer1.
Referenced by KKMLL::TrainingProcess2::TrainingProcessLeft().
|
inline |
Definition at line 100 of file ModelDual.h.
References trainer2.
Referenced by KKMLL::TrainingProcess2::TrainingProcessRight().
|
virtual |
Performs operations such as FeatureEncoding, and Normalization. The actual training of models occurs in the specific derived implementation of 'Model'.
Performs operations such as FeatureEncoding, and Normalization; the actual training of models occurs in the specific implementation of 'Model'.
| [in] | _trainExamples | Training data that classifier will be built from. If the examples need to be normalized or encoded and we are not taking ownership then a duplicate list of examples will be created that this method and class will be free to modify. |
| [in] | _alreadyNormalized | Indicates if contents of '_trainExamples' are normalized already; if not they will be normalized. |
| [in] | _takeOwnership | This instance of Model will take ownership of '_examples' and is free to modify its contents. |
< false = DON'T take ownership of 'trainExamples'.
< true = Features are already normalized.
< false = DON'T take ownership of 'trainExamples'.
< true = Features are already normalized.
| _takeOwnership | Model will take ownership of these examples |
Reimplemented from KKMLL::Model.
Definition at line 177 of file ModelDual.cpp.
References KKMLL::TrainingProcess2::Abort(), classifier1, KKMLL::Classifier2::Classifier2(), classifier2, KKB::KKStr::Concat(), config1, config2, KKMLL::TrainingConfiguration2::ConfigFileExists(), KKMLL::ModelParamDual::ConfigFileName1(), KKMLL::ModelParamDual::ConfigFileName2(), KKMLL::TrainingProcess2::CreateTrainingProcessFromTrainingExamples(), DeleteExistingClassifiers(), KKMLL::Model::factoryFVProducer, KKB::KKException::KKException(), KKMLL::TrainingConfiguration2::Load(), KKMLL::FactoryFVProducer::ManufacturTrainingConfiguration(), KKB::KKStr::operator+(), KKB::operator+(), param, trainer1, trainer2, KKMLL::Model::trainExamples, KKMLL::Model::TrainingTimeEnd(), KKMLL::Model::TrainingTimeStart(), KKMLL::Model::TrainModel(), and KKMLL::Model::validModel.
|
virtual |
Definition at line 875 of file ModelDual.cpp.
References KKB::XmlTag::AddAtribute(), config1, config2, KKB::KKStr::Empty(), KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, trainer1, trainer2, KKMLL::Model::WriteModelXMLFields(), KKB::XmlTag::WriteXML(), KKMLL::TrainingProcess2::WriteXML(), KKMLL::TrainingConfiguration2::WriteXML(), and KKB::XmlTag::XmlTag().
|
protected |
Definition at line 223 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), MemoryConsumedEstimated(), ModelDual(), Predict(), ProbabilitiesByClass(), ProbabilitiesByClassDual(), ReadXML(), RetrieveCrossProbTable(), TrainModel(), and ~ModelDual().
|
protected |
Definition at line 224 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), MemoryConsumedEstimated(), ModelDual(), Predict(), ProbabilitiesByClass(), ProbabilitiesByClassDual(), ReadXML(), RetrieveCrossProbTable(), TrainModel(), and ~ModelDual().
|
protected |
Definition at line 217 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), ModelDual(), ReadXML(), TrainModel(), WriteXML(), and ~ModelDual().
|
protected |
Definition at line 218 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), ModelDual(), ReadXML(), TrainModel(), WriteXML(), and ~ModelDual().
|
protected |
We will NOT own this instance. It will point to same instance defined in parent class Model.
Definition at line 229 of file ModelDual.h.
Referenced by ModelDual(), Param(), ReadXML(), ReconcilePredictions(), and TrainModel().
|
protected |
Definition at line 220 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), Description(), MemoryConsumedEstimated(), ModelDual(), NumOfSupportVectors(), ProbabilitiesByClassDual(), ReadXML(), Trainer1(), TrainModel(), WriteXML(), and ~ModelDual().
|
protected |
Definition at line 226 of file ModelDual.h.
|
protected |
Definition at line 221 of file ModelDual.h.
Referenced by DeleteExistingClassifiers(), Description(), MemoryConsumedEstimated(), ModelDual(), NumOfSupportVectors(), ProbabilitiesByClassDual(), ReadXML(), Trainer2(), TrainModel(), WriteXML(), and ~ModelDual().
|
protected |
Definition at line 227 of file ModelDual.h.