19 using namespace KKMLL;
58 for (
auto idx: pairList)
61 PushOnBack (
new ClassProb (*idx));
70 return ((kkint32)size ()) *
sizeof(ClassProb);
76 bool ClassProbList::CompairByClassName (
const ClassProbPtr left,
77 const ClassProbPtr right
86 sort (begin (), end (), CompairByClassName);
96 const ClassProbPtr right
117 const ClassProbPtr right
146 sort (begin (), end (), comparator);
154 sort (begin (), end (), comparator);
162 MLClassIndexType::const_iterator idx;
163 idx = classIndex.find (targetClass);
164 if (idx == classIndex.end ())
176 for (
kkint32 x = 0; x < (kkint32)size (); ++x)
178 if (IdxToPtr (x)->classLabel == targetClass)
189 MLClassIndexType::const_iterator idx;
190 idx = classIndex.find (cp->classLabel);
191 if (idx != classIndex.end ())
192 classIndex.erase (idx);
193 KKQueue<ClassProb>::DeleteEntry (cp);
202 KKStr errMsg =
"ClassProbList::DeleteEntry ***ERROR*** idx [" + StrFormatInt (idx,
"#,###,##0") +
"]";
203 cerr << endl << errMsg << endl << endl;
204 throw KKException (errMsg);
206 DeleteEntry (IdxToPtr (idx));
216 classIndex.insert (MLClassIndexPair (cp->classLabel, cp));
218 catch (
const std::exception&)
221 cerr << errMsg << endl;
224 KKQueue<ClassProb>::PushOnBack (cp);
233 classIndex.insert (MLClassIndexPair (cp->classLabel, cp));
235 catch (
const std::exception&)
238 cerr << errMsg << endl;
241 KKQueue<ClassProb>::PushOnFront (cp);
248 if (!otherPredictions)
251 ClassProbList::const_iterator idx;
252 for (idx = otherPredictions->begin (); idx != otherPredictions->end (); ++idx)
254 const ClassProbPtr otherPrediction = *idx;
281 ClassProbPtr existingEntry =
LookUp (target
);
305 ClassProbPtr existingEntry =
LookUp (target
);
309 float totalSubVotes = (
float)(subPredictions->size () - 1);
311 float baseVotes = existingEntry
->votes;
312 ClassProbList::const_iterator idx;
313 for (idx = subPredictions->begin (); idx != subPredictions->end (); ++idx)
315 const ClassProbPtr subPrediction = *idx;
316 double subProbability = baseProb * subPrediction
->probability;
317 float subVotes = baseVotes * (subPrediction
->votes / totalSubVotes);
323 ClassProbList::const_iterator idx;
324 for (idx = subPredictions->begin (); idx != subPredictions->end (); ++idx)
326 const ClassProbPtr subPrediction = *idx;
338 double totalProb = 0.0;
339 float totalVotes = 0.0f;
341 float expectedTotalNumOfVotes = (
float)(size () * (size () - 1) / 2);
344 for (idx = begin (); idx != end (); ++idx)
346 ClassProbPtr cp = *idx;
351 for (idx = begin (); idx != end (); ++idx)
353 ClassProbPtr cp = *idx;
410 for (
auto idx: *
this)
412 ClassProbPtr cp = idx;
413 o << cp->classLabel->Name () <<
"\t" << cp->probability <<
"\t" << cp->votes << endl;
430 while (
true && (!cancelFlag))
449 if ((probability < 0.0f) || (probability > 1.0f))
452 <<
"ClassProbList::ReadXML ***ERROR*** Probability: " << probability <<
" is out of range for Class: " << className << endl
XmlTag(const KKStr &_name, TagTypes _tagType)
void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
ClassProbList * ClassProbListPtr
void TrimWhiteSpace(const char *_whiteSpace=" ")
After this call all leading and trailing whitespace will be trimmed from tokens.
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
kkint32 MemoryConsumedEstimated() const
KKStr GetNextToken(const char *delStr="\n\t\r ")
Extract next Token from string, tokens will be separated by delimiter characters. ...
void MergeIn(const ClassProbPtr cp)
Adds the Prediction in 'cp' into this list.
virtual void PushOnBack(ClassProbPtr cp)
Represents a "Class" in the Machine Learning Sense.
XmlContent * XmlContentPtr
kkint32 LookUpPlace(MLClassPtr targetClass) const
Returns the position that 'targetClass' has in the order; good time to use would be after sorting by ...
KKStr operator+(const char *right) const
unsigned __int32 kkuint32
bool operator()(const ClassProbPtr left, const ClassProbPtr right)
float GetNextTokenFloat(const char *delStr="\n\t\r ")
KKStr & operator=(KKStr &&src)
void WriteXML(const KKStr &varName, std::ostream &o) const
KKStrParser(const KKStr &_str)
virtual void PushOnFront(ClassProbPtr cp)
KKStr operator+(const char *left, const KKStr &right)
const ClassProbPtr LookUp(MLClassPtr targetClass) const
double ExtractTokenDouble(const char *delStr)
void SortByProbability(bool highToLow=true)
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...
void MergeIn(MLClassPtr target, double probability, float votes)
Adds the prediction of 'target' with 'probability' into this list.
virtual void DeleteEntry(kkuint32 idx)
ClassProbList(bool owner)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
KKB::KKStr osReadRestOfLine2(std::istream &in, bool &eof)
ClassProbList(const ClassProbList &pairList)
void AddIn(const ClassProbListPtr otherPredictions)
Adds the contents of 'otherPredictions' to this list.
bool StartsWith(const char *value) const
double GetNextTokenDouble(const char *delStr="\n\t\r ")
void SortByVotes(bool highToLow=true)
const KKStr & UpperName() const
virtual void DeleteEntry(ClassProbPtr cp)
const KKStr & Name() const
void MergeIn(MLClassPtr target, const ClassProbListPtr subPredictions)
Merges in the predictions in 'subPredictions' by replacing the entry in our list with label 'target' ...
ClassProb(const ClassProb &_pair)
static MLClassPtr CreateNewMLClass(const KKStr &_name, kkint32 _classId=-1)
Static method used to create a new instance of a MLClass object.
static ClassProbListPtr CreateFromXMLStream(std::istream &i)
void NormalizeToOne()
Will normalize the list of predictions such that the total probability will equal 1...
void WriteXML(std::ostream &o)
bool operator()(const ClassProbPtr left, const ClassProbPtr right)
KKStrPtr const Content() const
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
bool operator<(const KKStr &right) const
VotesComparer(bool _highToLow)
ProbabilityComparer(bool _highToLow)
Class that manages the extraction of tokens from a String without being destructive to the original s...
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
KKException(const KKStr &_exceptionStr)
ClassProb(MLClassPtr _classLabel, double _probability, float _votes)
#define XmlFactoryMacro(NameOfClass)
volatile const bool VolConstBool