KSquare Utilities
FeatureEncoder2.h
Go to the documentation of this file.
1 #if !defined(_FEATUREENCODER2_)
2 #define _FEATUREENCODER2_
3 /**
4  *@class KKMLL::FeatureEncoder2
5  *@code
6  ***********************************************************************
7  * FeatureEncoder2 *
8  * *
9  * This will eventually replace "FeatureEncoder" when we shift over *
10  * to the new paradigm where all Machine Learning Algorithms will be *
11  * derived from 'Model'. *
12  ***********************************************************************
13  *@endcode
14  */
15 #include "RunLog.h"
16 
17 #include "Attribute.h"
18 #include "FeatureVector.h"
19 #include "FileDesc.h"
20 #include "MLClass.h"
21 #include "ModelParam.h"
22 
23 
24 
25 namespace KKMLL
26 {
28  {
29  public:
31 
34 
35 
36  /**
37  * @brief Constructs a Feature Encoder object.
38  * @param[in] _param
39  * @param[in] _fileDesc
40  * @param[in] _log A log-file stream. All important events will be output to this stream
41  */
42  FeatureEncoder2 (const ModelParam& _param,
43  FileDescPtr _fileDesc
44  );
45 
46  FeatureEncoder2 (const FeatureEncoder2& _encoder);
47 
48 
49  /**
50  * @brief Frees any memory allocated by, and owned by the FeatureEncoder2
51  */
52  ~FeatureEncoder2 ();
53 
54 
55  kkint32 CodedNumOfFeatures () const {return codedNumOfFeatures;}
56 
58  RunLog& log
59  ) const; /**< If 'o' is not NULL will write out a table showing assignments from old to new. */
60 
61  FeatureVectorListPtr EncodedFeatureVectorList (const FeatureVectorList& srcData) const;
62 
63  FeatureVectorListPtr EncodeAllExamples (const FeatureVectorListPtr srcData);
64 
65  FeatureVectorPtr EncodeAExample (FeatureVectorPtr src) const;
66 
68 
69  kkint32 NumEncodedFeatures () const;
70 
71  void ReadXML (istream& i);
72 
73  void WriteXML (istream& o);
74 
75 
76  private:
77  const AttributeTypeVector& attributeVector;
78  kkint32* cardinalityDest;
79  const VectorInt32& cardinalityVector; /**< Will not own, passed in by creator. */
80  kkint32 codedNumOfFeatures;
81  kkint32* destFeatureNums;
82  FeWhatToDoPtr destWhatToDo;
83  FileDescPtr encodedFileDesc;
84  ModelParam::EncodingMethodType encodingMethod;
85  FileDescPtr fileDesc;
86  kkint32 numOfFeatures;
87  kkuint16* srcFeatureNums;
88  const ModelParam& param;
89 
90  struct FeatureVar2;
91  typedef FeatureVar2* FeatureVar2Ptr;
92  class FeatureVar2List;
93  typedef FeatureVar2List* FeatureVar2ListPtr;
94  }; /* FeatureEncoder2 */
95 
96 #define _FeatureEncoder2_Defined_
97 
98  typedef FeatureEncoder2::FeatureEncoder2Ptr FeatureEncoder2Ptr;
99 
100 } /* namespace KKMLL */
101 
102 #endif
FileDescPtr CreateEncodedFileDesc(ostream *o, RunLog &log) const
FeatureEncoder2(const ModelParam &_param, FileDescPtr _fileDesc)
Constructs a Feature Encoder object.
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 NumEncodedFeatures() const
kkint32 MemoryConsumedEstimated() const
void WriteXML(istream &o)
unsigned __int16 kkuint16
16 bit unsigned integer.
Definition: KKBaseTypes.h:86
FeatureVectorListPtr EncodedFeatureVectorList(const FeatureVectorList &srcData) const
~FeatureEncoder2()
Frees any memory allocated by, and owned by the FeatureEncoder2.
FeatureEncoder2 * FeatureEncoder2Ptr
Container class for FeatureVector derived objects.
FeWhatToDo * FeWhatToDoPtr
void ReadXML(istream &i)
FeatureEncoder2(const FeatureEncoder2 &_encoder)
kkint32 CodedNumOfFeatures() const
std::vector< kkint32 > VectorInt32
Vector of signed 32 bit integers.
Definition: KKBaseTypes.h:144
FileDesc * FileDescPtr
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)
Abstract Base class for Machine Learning parameters.
Definition: ModelParam.h:35
FeatureVectorPtr EncodeAExample(FeatureVectorPtr src) const
FeatureVectorListPtr EncodeAllExamples(const FeatureVectorListPtr srcData)