KSquare Utilities
ClassAssignments.h
Go to the documentation of this file.
1 #if !defined(_CLASSASSIGNMENTS_)
2 #define _CLASSASSIGNMENTS_
3 
4 /**
5  *@class KKMLL::ClassAssignments
6  *@author Kurt Kramer
7  *@brief Binds MLClass objects to the appropriate number that the Learning Algorithm expects.
8  *@details This class will bind MLClass objects to the appropriate number that the learning
9  * algorithm knows for this class. When originally implementing this system, this info was
10  * kept in the MLClass object. This would cause problems when doing multilevel
11  * classification. The same MLClass might be known to the L.A. as one number in one level
12  * and another number in a different level. This caused us to have to maintain a separate
13  * instantiation of these classes on the SvmModel objects.
14  *
15  * It is sub-classed from multimap<kkint16, MLClassPtr>. This allows for fast lookup by
16  * number. There is also a secondary index by MLClass. This allows us to do a fast
17  * lookup by class.
18  */
19 
20 #include <map>
21 #include "KKQueue.h"
22 #include "RunLog.h"
23 #include "KKStr.h"
24 
25 namespace KKMLL
26 {
27 
28  #ifndef _MLCLASS_
29  class MLClass;
30  typedef MLClass* MLClassPtr;
31  class MLClassList;
32  typedef MLClassList* MLClassListPtr;
33  #endif
34 
35 
37  {
38  public:
40 
41 
42  /**
43  *@brief Creates assignment for all classes in 'classes.
44  *@details Constructs a list assigning a number to each class sequentially from 'classes'.
45  * Use this constructor if each class is treated uniquely by the learning algorithm.
46  *@param[in] classes, List of classes to make assignments for.
47  *@param[in,out] _log, Run log to write messages to
48  */
49  ClassAssignments (const MLClassList& classes);
50 
51 
52  void AddMLClass (MLClassPtr mlClass,
53  kkint16 num,
54  RunLog& log
55  );
56 
57  MLClassPtr GetMLClassByIndex (size_t idx);
58 
59  MLClassPtr GetMLClass (kkint16 num) const;
60 
61  MLClassList GetMLClasses (kkint16 num) const;
62 
63  kkint16 GetNumForClass (MLClassPtr mlClass) const;
64 
66 
68 
69  /**
70  *@brief Loads class assignments from string that was originally generated by ToString
71  *@param[in] _toString, KKStr containing class assignments info, will expect to be formated
72  * the way ToString() creates them.
73  */
74  void ParseToString (const KKStr& _toString,
75  RunLog& _log
76  );
77 
78 
79  void Save (const KKStr& fileName,
80  bool& successful
81  );
82 
83  KKStr ToString () const;
84 
85  private:
86  typedef std::map<MLClassPtr, kkint16> ClassLookUp;
87  typedef ClassLookUp::iterator ClassLookUpIterator;
88 
89  ClassLookUp classLookUp;
90  }; /* ClassAssignments */;
91 
92 
94 
95 } /* namespace KKMLL */
96 
97 #endif
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
VectorShort GetUniqueListOfAssignments() const
ClassAssignments * ClassAssignmentsPtr
__int32 kkint32
Definition: KKBaseTypes.h:88
void Save(const KKStr &fileName, bool &successful)
MLClassPtr GetMLClass(kkint16 num) const
kkint16 GetNumForClass(MLClassPtr mlClass) const
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
MLClassList GetMLClasses(kkint16 num) const
kkint32 MemoryConsumedEstimated() const
Binds MLClass objects to the appropriate number that the Learning Algorithm expects.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
void AddMLClass(MLClassPtr mlClass, kkint16 num, RunLog &log)
MLClassPtr GetMLClassByIndex(size_t idx)
void ParseToString(const KKStr &_toString, RunLog &_log)
Loads class assignments from string that was originally generated by ToString.
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
ClassAssignments(const MLClassList &classes)
Creates assignment for all classes in &#39;classes.
std::vector< short > VectorShort
Definition: KKBaseTypes.h:142
Maintains a list of MLClass instances.
Definition: MLClass.h:233