31 using namespace KKMLL;
56 Model (_name
, _param
, _factoryFVProducer
),
104 MLClassPtr knownClass,
105 MLClassPtr& predClass1,
106 MLClassPtr& predClass2,
109 double& probOfKnownClass,
110 double& predClass1Prob,
111 double& predClass2Prob,
113 bool& knownClassOneOfTheWinners,
129 KKStr errMsg =
"ModelKnn::ProbabilitiesByClass ***ERROR*** (classLabelAssigments == NULL)";
130 log.Level (-1) << endl << endl << errMsg << endl << endl;
134 bool newExampleCreated =
false;
139 if (newExampleCreated)
141 delete encodedExample;
142 encodedExample = NULL;
162 double* _probabilities,
171 double* _probabilities,
181 bool _alreadyNormalized,
187 _log.Level (20) <<
"ModelKnn::TrainModel alreadyNormalized[" << _alreadyNormalized <<
"] _takeOwnership[" << _takeOwnership <<
"]." << endl;
232 while (t && (!cancelFlag))
239 if ((varName.EqualIgnoreCase (
"Param")) && (
typeid (*t) ==
typeid (XmlElementModelParamKnn)))
242 param =
dynamic_cast<XmlElementModelParamKnnPtr> (t)->TakeOwnership ();
247 errMsg <<
"Invalid XmlElement Encountered: Section: " << t->SectionName () <<
" VarName: " << varName;
248 log.Level (-1) << endl << errMsg << endl << endl;
249 AddErrorMsg (errMsg, 0);
265 errMsg <<
"ModelKnn::ReadXML ***ERROR*** Base class 'Model' does not have 'param' defined.";
267 log.Level (-1) << endl << errMsg << endl << endl;
275 log.Level (-1) << endl << errMsg << endl << endl;
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
XmlTag(const KKStr &_name, TagTypes _tagType)
Base class to all Learning Algorithms.
FeatureVector * FeatureVectorPtr
ModelKnn(const ModelKnn &_madel)
XmlTokenPtr ReadXMLModelToken(XmlTokenPtr t, RunLog &log)
Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed ...
virtual void PushOnBack(ClassProbPtr cp)
void AddErrorMsg(const KKStr &errMsg, kkint32 lineNum)
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 ...
virtual ClassProbListPtr ProbabilitiesByClass(FeatureVectorPtr example, RunLog &log)
void WriteModelXMLFields(std::ostream &o) const
The "WriteXML" method in Derived classes call this method to include the parents classes fields in th...
void WriteXML(const KKStr &varName, ostream &o) const
MLClassPtr GetMLClass(kkint16 classIndex)
Locates the MLClass that was assigned classIndex.
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
virtual ModelKnnPtr Duplicate() const
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
Used to record probability for a specified class; and a list of classes.
XmlTag const * XmlTagConstPtr
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
virtual void ProbabilitiesByClass(FeatureVectorPtr _example, const MLClassList &_mlClasses, double *_probabilities, RunLog &_log)
Derives predicted probabilities by class.
ModelKnn(const KKStr &_name, const ModelParamKnn &_param, FactoryFVProducerPtr _factoryFVProducer)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
ClassProbList * ClassProbListPtr
virtual MLClassPtr Predict(FeatureVectorPtr example, RunLog &log)
ModelKnn(FactoryFVProducerPtr _factoryFVProducer)
Model(const KKStr &_name, const ModelParam &_param, FactoryFVProducerPtr _factoryFVProducer)
Construct a instance of 'Model' using the parameters specified in '_param'.
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 ...
virtual void WriteXML(const KKStr &varName, ostream &o) const
void WriteXML(std::ostream &o)
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
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 ...
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)
void ReadXMLModelPost(RunLog &log)
virtual KKStr ModelParamTypeStr() const
Model(const Model &_madel)
Copy Constructor.
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
KKException(const KKStr &_exceptionStr)
ClassProb(MLClassPtr _classLabel, double _probability, float _votes)
virtual void ProbabilitiesByClass(FeatureVectorPtr example, const MLClassList &_mlClasses, kkint32 *_votes, double *_probabilities, RunLog &log)
Maintains a list of MLClass instances.
FeatureVectorList * FeatureVectorListPtr
virtual const KKStr & VarName() const
#define XmlFactoryMacro(NameOfClass)
MLClassIndexListPtr classesIndex
FactoryFVProducer * FactoryFVProducerPtr
Model(FactoryFVProducerPtr _factoryFVProducer)
Use this when you are planning on creating a empty model without parameters.
volatile const bool VolConstBool