![]() |
KSquare Utilities
|
#include <ModelKnn.h>
Inheritance diagram for KKMLL::ModelKnn:Public Types | |
| typedef ModelKnn * | ModelKnnPtr |
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 | |
| ModelKnn () | |
| ModelKnn (FactoryFVProducerPtr _factoryFVProducer) | |
| ModelKnn (const KKStr &_name, const ModelParamKnn &_param, FactoryFVProducerPtr _factoryFVProducer) | |
| ModelKnn (const ModelKnn &_madel) | |
| virtual | ~ModelKnn () |
| virtual ModelKnnPtr | Duplicate () const |
| virtual ModelTypes | ModelType () const |
| ModelParamKnnPtr | 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... | |
| 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 | 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... | |
| 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 |
| virtual KKStr | Description () const |
| const FeatureEncoder2 & | Encoder () const |
| FactoryFVProducerPtr | FactoryFVProducer () const |
| virtual FeatureNumListConstPtr | GetFeatureNums () const |
| virtual kkint32 | MemoryConsumedEstimated () 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... | |
| virtual void | RetrieveCrossProbTable (MLClassList &classes, double **crossProbTable, RunLog &log) |
| 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 |
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... | |
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 |
Definition at line 10 of file ModelKnn.h.
| typedef ModelKnn* KKMLL::ModelKnn::ModelKnnPtr |
Definition at line 13 of file ModelKnn.h.
| ModelKnn::ModelKnn | ( | ) |
Definition at line 35 of file ModelKnn.cpp.
References KKMLL::Model::Model().
| ModelKnn::ModelKnn | ( | FactoryFVProducerPtr | _factoryFVProducer | ) |
| ModelKnn::ModelKnn | ( | const KKStr & | _name, |
| const ModelParamKnn & | _param, | ||
| FactoryFVProducerPtr | _factoryFVProducer | ||
| ) |
Definition at line 52 of file ModelKnn.cpp.
References KKMLL::Model::Model(), and KKMLL::Model::param.
Referenced by KKMLL::Model::CreateAModel().
| ModelKnn::ModelKnn | ( | const ModelKnn & | _madel | ) |
Definition at line 65 of file ModelKnn.cpp.
References KKMLL::Model::Model(), and KKMLL::Model::param.
Referenced by Duplicate().
|
virtual |
Definition at line 74 of file ModelKnn.cpp.
|
virtual |
|
inlinevirtual |
| ModelParamKnnPtr ModelKnn::Param | ( | ) |
Definition at line 88 of file ModelKnn.cpp.
|
virtual |
|
virtual |
|
virtual |
Implements KKMLL::Model.
Definition at line 123 of file ModelKnn.cpp.
References KKMLL::Model::classesIndex, KKMLL::ClassProb::ClassProb(), KKMLL::ClassProbList::ClassProbList(), KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetMLClass(), KKB::KKException::KKException(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), and KKMLL::ClassProbList::PushOnBack().
|
virtual |
|
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 169 of file ModelKnn.cpp.
|
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 225 of file ModelKnn.cpp.
References KKMLL::Model::AddErrorMsg(), KKB::KKStr::Concat(), KKB::XmlStream::GetNextToken(), KKB::KKStr::KKStr(), KKMLL::ModelParam::ModelParamTypeStr(), KKMLL::Model::param, KKMLL::Model::ReadXMLModelPost(), KKMLL::Model::ReadXMLModelToken(), and KKB::XmlToken::VarName().
|
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 180 of file ModelKnn.cpp.
References KKMLL::Model::TrainModel(), and KKMLL::Model::validModel.
| void ModelKnn::WriteXML | ( | const KKStr & | varName, |
| ostream & | o | ||
| ) | const |
Definition at line 202 of file ModelKnn.cpp.
References KKB::XmlTag::AddAtribute(), KKB::KKStr::Empty(), KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, KKMLL::Model::WriteModelXMLFields(), KKMLL::ModelParamKnn::WriteXML(), KKB::XmlTag::WriteXML(), and KKB::XmlTag::XmlTag().