![]() |
KSquare Utilities
|
#include <ModelSvmBase.h>
Inheritance diagram for KKMLL::ModelSvmBase:Public Types | |
| typedef ModelSvmBase * | ModelSvmBasePtr |
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 | |
| ModelSvmBase () | |
| ModelSvmBase (FactoryFVProducerPtr _factoryFVProducer) | |
| ModelSvmBase (const KKStr &_name, const ModelParamSvmBase &_param, FactoryFVProducerPtr _factoryFVProducer) | |
| ModelSvmBase (const ModelSvmBase &_model) | |
| virtual | ~ModelSvmBase () |
| Frees any memory allocated by, and owned by the ModelSvmBase. More... | |
| virtual KKStr | Description () const |
| virtual ModelSvmBasePtr | Duplicate () const |
| virtual kkint32 | MemoryConsumedEstimated () const |
| virtual ModelTypes | ModelType () const |
| virtual kkint32 | NumOfSupportVectors () const |
| ModelParamSvmBasePtr | Param () |
| virtual MLClassPtr | Predict (FeatureVectorPtr image, 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 | 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) |
| 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... | |
| virtual void | ProbabilitiesByClassDual (FeatureVectorPtr example, KKStr &classifier1Desc, KKStr &classifier2Desc, ClassProbListPtr &classifier1Results, ClassProbListPtr &classifier2Results, RunLog &log) |
| Only applied to ModelDual classifier. 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 Attributes | |
| ModelParamSvmBasePtr | param |
| SVM289_MFS::Svm_Model * | svmModel |
Protected Attributes inherited from KKMLL::Model | |
| bool | alreadyNormalized |
| MLClassListPtr | classes |
| MLClassIndexListPtr | classesIndex |
| double * | classProbs |
| double ** | crossClassProbTable |
| kkint32 | crossClassProbTableSize |
| FeatureEncoder2Ptr | encoder |
| VectorKKStr | errors |
| FactoryFVProducerPtr | factoryFVProducer |
| FileDescPtr | fileDesc |
| NormalizationParmsPtr | normParms |
| kkint32 | numOfClasses |
| ModelParamPtr | param |
| KKStr | rootFileName |
| FeatureVectorListPtr | trainExamples |
| bool | validModel |
| kkint32 * | votes |
| bool | weOwnTrainExamples |
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) |
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... | |
Definition at line 22 of file ModelSvmBase.h.
Definition at line 26 of file ModelSvmBase.h.
| ModelSvmBase::ModelSvmBase | ( | ) |
Definition at line 35 of file ModelSvmBase.cpp.
References KKMLL::Model::Model(), param, and svmModel.
| ModelSvmBase::ModelSvmBase | ( | FactoryFVProducerPtr | _factoryFVProducer | ) |
Definition at line 43 of file ModelSvmBase.cpp.
References KKMLL::Model::Model(), param, and svmModel.
| ModelSvmBase::ModelSvmBase | ( | const KKStr & | _name, |
| const ModelParamSvmBase & | _param, | ||
| FactoryFVProducerPtr | _factoryFVProducer | ||
| ) |
Definition at line 52 of file ModelSvmBase.cpp.
References KKMLL::Model::Model(), param, KKMLL::Model::param, and svmModel.
Referenced by KKMLL::Model::CreateAModel().
| ModelSvmBase::ModelSvmBase | ( | const ModelSvmBase & | _model | ) |
Definition at line 66 of file ModelSvmBase.cpp.
References KKMLL::Model::fileDesc, KKMLL::Model::Model(), param, KKMLL::Model::param, SVM289_MFS::Svm_Model::Svm_Model(), and svmModel.
Referenced by Duplicate().
|
virtual |
Frees any memory allocated by, and owned by the ModelSvmBase.
Definition at line 85 of file ModelSvmBase.cpp.
References SVM289_MFS::svm_destroy_model(), and svmModel.
|
virtual |
Return short user readable description of model.
Reimplemented from KKMLL::Model.
Definition at line 121 of file ModelSvmBase.cpp.
References KKB::KKStr::Concat(), KKMLL::Model::Name(), KKB::KKStr::operator+(), KKB::operator+(), param, and KKMLL::ModelParamSvmBase::SvmParam().
|
virtual |
Implements KKMLL::Model.
Definition at line 113 of file ModelSvmBase.cpp.
References ModelSvmBase().
|
virtual |
Reimplemented from KKMLL::Model.
Definition at line 99 of file ModelSvmBase.cpp.
References KKMLL::Model::MemoryConsumedEstimated(), SVM289_MFS::Svm_Model::MemoryConsumedEstimated(), and svmModel.
|
inlinevirtual |
Implements KKMLL::Model.
Definition at line 48 of file ModelSvmBase.h.
References KKMLL::Model::SvmBase.
|
virtual |
Definition at line 608 of file ModelSvmBase.cpp.
References SVM289_MFS::Svm_Model::numSVs, and svmModel.
| ModelParamSvmBasePtr ModelSvmBase::Param | ( | ) |
|
virtual |
Implements KKMLL::Model.
Definition at line 252 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKMLL::MLClassIndexList::GetMLClass(), KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict(), and svmModel.
|
virtual |
Implements KKMLL::Model.
Definition at line 289 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKMLL::MLClassIndexList::GetMLClass(), KKB::KKException::KKException(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.
|
virtual |
Implements KKMLL::Model.
Definition at line 398 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKMLL::ClassProb::ClassProb(), KKMLL::ClassProbList::ClassProbList(), KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetMLClass(), KKB::KKException::KKException(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), KKMLL::ClassProbList::PushOnBack(), KKMLL::ClassProbList::SortByVotes(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.
|
virtual |
Implements KKMLL::Model.
Definition at line 443 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKB::KKException::KKException(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::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 image 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 502 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKB::KKException::KKException(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.
|
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 648 of file ModelSvmBase.cpp.
References KKMLL::Model::AddErrorMsg(), KKB::KKStr::Concat(), KKB::XmlStream::GetNextToken(), KKB::KKStr::KKStr(), KKMLL::ModelParam::ModelParamTypeStr(), param, KKMLL::Model::param, KKMLL::Model::ReadXMLModelPost(), KKMLL::Model::ReadXMLModelToken(), and svmModel.
|
virtual |
| crossProbTable | two dimension matrix that needs to be classes.QueueSize () squared. |
Reimplemented from KKMLL::Model.
Definition at line 557 of file ModelSvmBase.cpp.
References KKMLL::Model::classesIndex, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, SVM289_MFS::Svm_Model::PairwiseProb(), and svmModel.
|
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. |
| _takeOwnership | Model will take ownership of these examples |
Reimplemented from KKMLL::Model.
Definition at line 144 of file ModelSvmBase.cpp.
References KKB::KKStr::Concat(), KKB::KKException::KKException(), KKB::KKStr::operator+(), KKB::operator+(), param, KKMLL::Model::rootFileName, KKMLL::ModelParam::SelectedFeatures(), SVM289_MFS::svm_destroy_model(), SVM289_MFS::svm_problem::svm_problem(), SVM289_MFS::svm_train(), svmModel, KKMLL::ModelParamSvmBase::SvmParam(), KKMLL::Model::trainExamples, KKMLL::Model::TrainingTimeEnd(), KKMLL::Model::TrainingTimeStart(), KKMLL::Model::TrainModel(), and KKMLL::Model::validModel.
|
virtual |
Definition at line 621 of file ModelSvmBase.cpp.
References KKB::XmlTag::AddAtribute(), KKB::KKStr::Empty(), svmModel, KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, KKMLL::Model::WriteModelXMLFields(), SVM289_MFS::Svm_Model::WriteXML(), KKB::XmlTag::WriteXML(), and KKB::XmlTag::XmlTag().
|
protected |
We will NOT own this instance. It will point to same instance defined in parent class Model.
Definition at line 144 of file ModelSvmBase.h.
Referenced by Description(), ModelSvmBase(), Param(), ReadXML(), and TrainModel().
|
protected |
Definition at line 143 of file ModelSvmBase.h.
Referenced by MemoryConsumedEstimated(), ModelSvmBase(), NumOfSupportVectors(), Predict(), ProbabilitiesByClass(), ReadXML(), RetrieveCrossProbTable(), TrainModel(), WriteXML(), and ~ModelSvmBase().