KSquare Utilities
KKMLL::FeatureVector Class Reference

Represents a Feature Vector of a single example, labeled or unlabeled. More...

#include <FeatureVector.h>

+ Inheritance diagram for KKMLL::FeatureVector:

Public Types

typedef FeatureVectorFeatureVectorPtr
 
typedef float FVFloat
 

Public Member Functions

 FeatureVector (kkint32 _numOfFeatures)
 
 FeatureVector (const FeatureVector &_example)
 
virtual ~FeatureVector ()
 
void AddFeatureData (kkint32 _featureNum, float _featureData)
 
void BreakTie (float _breakTie)
 Update the BreakTie value. More...
 
float BreakTie () const
 The difference in probability between the two most likely classes. More...
 
const KKStrClassName () const
 Name of class that this example is assigned to. More...
 
virtual FeatureVectorPtr Duplicate () const
 
void ExampleFileName (const KKStr &_exampleFileName)
 Name of source of feature vector, ex: file name of image that the feature vector was computed from. More...
 
const KKStrExampleFileName () const
 Name of file that this FeatureVector was computed from. More...
 
void FeatureData (kkint32 _featureNum, float _featureValue)
 Assign a value to a specific feature number for the feature vector. More...
 
float FeatureData (kkint32 featureNum) const
 
const float * FeatureData () const
 Returns as a pointer to the feature data itself. More...
 
float * FeatureDataAlter ()
 Same as 'FeatureData() except you can modify the data. More...
 
const float * FeatureDataConst () const
 
bool FeatureDataValid ()
 
virtual kkint32 MemoryConsumedEstimated () const
 
void MissingData (bool _missingData)
 True indicates that not all the feature data was present when this example was loaded from a data file. More...
 
bool MissingData () const
 True indicates that one or more features were missing. More...
 
void MLClass (MLClassPtr _mlClass)
 Assign a class to this example. More...
 
MLClassPtr MLClass () const
 Class that is example is assigned to. More...
 
const KKStrMLClassName () const
 Name of class that this example is assigned to. More...
 
kkint32 NumOfFeatures () const
 Number of features in this FeatureVector. More...
 
bool operator== (FeatureVector &other_example) const
 
void OrigSize (float _origSize)
 The value of Feature[0] before normalization. More...
 
float OrigSize () const
 The value of Feature[0] before normalization. More...
 
void PredictedClass (MLClassPtr _predictedClass)
 
MLClassPtr PredictedClass () const
 
const KKStrPredictedClassName () const
 
void Probability (float _probability)
 Assign a prediction probability to this example. More...
 
float Probability () const
 The probability assigned by classifier to the predicted class. More...
 
void ResetNumOfFeatures (kkint32 newNumOfFeatures)
 
float TotalOfFeatureData () const
 Returns the total of all Feature Attributes for this feature vector. More...
 
void TrainWeight (float _trainWeight)
 Assign a specific example a higher weight for training purposes. More...
 
float TrainWeight () const
 
void Validated (bool _validated)
 Indicated whether an expert has validated the class assignment. More...
 
bool Validated () const
 
void Version (kkint16 _version)
 
kkint16 Version () const
 

Protected Member Functions

void AllocateFeatureDataArray ()
 Used by container classes such as 'FeatureVectorList'. This way they can determine real underlying class. More...
 

Protected Attributes

float * featureData
 
kkint32 numOfFeatures
 

Detailed Description

Represents a Feature Vector of a single example, labeled or unlabeled.

Author
Kurt Kramer

Used for the representation of a Single example. You create an instance of this object for each single feature vector. You can subclass from this Class to make a specialized FeatureVector as in the PostLarvaeFV class. Besides keeping track of feature data this class will also track other fields such as ExampleFileName which should indicate where the FeatureVector was derived from, probability, breakTie, and others.

See also
FeatureVectorList
PostLarvaeFV
FeatureFileIO

Used for the representation of a Single example. You create an instance of this object for each single feature vector. You can subclass from this Class to make a specialized FeatureVector as in the PostLarvaeFV class. Besides keeping track of feature data this class will also track other fields such as ExampleFileName which should indicate where the FeatureVector was derived from, probability, breakTie, and others.

See also
FeatureVectorList
PostLarvaeFV
FeatureFileIO

Definition at line 59 of file FeatureVector.h.

Member Typedef Documentation

Definition at line 62 of file FeatureVector.h.

Constructor & Destructor Documentation

FeatureVector::FeatureVector ( kkint32  _numOfFeatures)

Definition at line 30 of file FeatureVector.cpp.

References AllocateFeatureDataArray(), featureData, KKB::KKStr::KKStr(), and numOfFeatures.

Referenced by KKMLL::GrayScaleImagesFVProducer::ComputeFeatureVector(), KKMLL::FeatureEncoder::CreateEncodedFeatureVector(), KKMLL::FeatureEncoder2::EncodeAExample(), KKMLL::FeatureEncoder::EncodeAExample(), KKMLL::GrayScaleImagesFV::GrayScaleImagesFV(), KKMLL::FeatureFileIODstWeb::LoadFile(), KKMLL::FeatureFileIOColumn::LoadFile(), KKMLL::FeatureFileIOUCI::LoadFile(), KKMLL::FeatureFileIOC45::LoadFile(), and KKMLL::FactoryFVProducer::ManufacturFeatureVector().

30  :
31  featureData (NULL),
32  numOfFeatures (_numOfFeatures),
33  breakTie (0.0f),
34  mlClass (NULL),
35  exampleFileName (),
36  missingData (false),
37  origSize (0.0f),
38  predictedClass (NULL),
39  probability (-1.0),
40  trainWeight (1.0f),
41  validated (false),
42  version (-1)
43 {
45 }
void AllocateFeatureDataArray()
Used by container classes such as &#39;FeatureVectorList&#39;. This way they can determine real underlying cl...
FeatureVector::FeatureVector ( const FeatureVector _example)

Definition at line 50 of file FeatureVector.cpp.

References AllocateFeatureDataArray(), featureData, KKB::KKStr::KKStr(), and numOfFeatures.

Referenced by Duplicate(), KKMLL::FeatureVectorList::DuplicateListAndContents(), KKMLL::FeatureVectorList::ExtractExamplesForHierarchyLevel(), KKMLL::GrayScaleImagesFV::GrayScaleImagesFV(), and KKMLL::NormalizationParms::ToNormalized().

50  :
51  featureData (NULL),
52  numOfFeatures (_example.numOfFeatures),
53  breakTie (_example.breakTie),
54  mlClass (_example.mlClass),
55  exampleFileName (_example.exampleFileName),
56  missingData (false),
57  origSize (_example.origSize),
58  predictedClass (_example.predictedClass),
59  probability (_example.probability),
60  trainWeight (_example.trainWeight),
61  validated (_example.validated),
62  version (-1)
63 {
64  if (_example.featureData)
65  {
67  for (kkint32 x = 0; x < numOfFeatures; x++)
68  featureData[x] = _example.featureData[x];
69  }
70 }
__int32 kkint32
Definition: KKBaseTypes.h:88
void AllocateFeatureDataArray()
Used by container classes such as &#39;FeatureVectorList&#39;. This way they can determine real underlying cl...
FeatureVector::~FeatureVector ( )
virtual

Definition at line 74 of file FeatureVector.cpp.

References featureData.

75 {
76  delete[] featureData; featureData = NULL;
77 }

Member Function Documentation

void FeatureVector::AddFeatureData ( kkint32  _featureNum,
float  _featureData 
)
Parameters
_featureNumIndicates which feature number to update.
_featureDataNew value to assign to '_featureNum'.

Definition at line 216 of file FeatureVector.cpp.

References KKB::KKStr::Concat(), featureData, KKB::KKException::KKException(), KKB::KKStr::KKStr(), and numOfFeatures.

Referenced by KKMLL::FeatureEncoder::CreateEncodedFeatureVector(), KKMLL::FeatureEncoder2::EncodeAExample(), KKMLL::FeatureEncoder::EncodeAExample(), KKMLL::FeatureFileIODstWeb::LoadFile(), KKMLL::FeatureFileIOC45::LoadFile(), and KKMLL::FeatureVectorList::ReSyncSymbolicData().

219 {
220  if ((_featureNum < 0) || (_featureNum >= numOfFeatures))
221  {
222  KKStr errMsg (128);
223  errMsg << "FeatureVector::AddFeatureData ***ERROR*** FeatureNum[" << _featureNum << "] exceeds maximum allowed Feature Number["<< numOfFeatures << "].";
224  cerr << endl << errMsg << endl << endl;
225  throw KKException (errMsg);
226  }
227 
228  featureData[_featureNum] = _featureData;
229 } /* AddFeatureData */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void FeatureVector::AllocateFeatureDataArray ( )
protected

Used by container classes such as 'FeatureVectorList'. This way they can determine real underlying class.

Definition at line 129 of file FeatureVector.cpp.

References featureData, and numOfFeatures.

Referenced by FeatureVector().

130 {
131  if (featureData)
132  delete featureData;
133 
134  featureData = new float [numOfFeatures];
135 
136  kkint32 x;
137 
138  for (x = 0; x < numOfFeatures; x++)
139  featureData[x] = 0;
140 } /* AllocateFeatureDataArray */
__int32 kkint32
Definition: KKBaseTypes.h:88
void KKMLL::FeatureVector::BreakTie ( float  _breakTie)
inline

Update the BreakTie value.

Definition at line 73 of file FeatureVector.h.

float KKMLL::FeatureVector::BreakTie ( ) const
inline

The difference in probability between the two most likely classes.

Definition at line 112 of file FeatureVector.h.

Referenced by KKMLL::FeatureVectorList::BreakTieComparison::operator()(), and KKMLL::FeatureVectorList::BreakTieComparisonReversed::operator()().

const KKStr & FeatureVector::ClassName ( ) const

Name of class that this example is assigned to.

Definition at line 192 of file FeatureVector.cpp.

References KKB::KKStr::Concat(), and KKMLL::MLClass::Name().

Referenced by KKMLL::FeatureFileIORoberts::SaveFile(), KKMLL::FeatureFileIOUCI::SaveFile(), KKMLL::FeatureFileIOC45::SaveFile(), and KKMLL::FeatureFileIOSparse::SaveFile().

193 {
194  static const
195  KKStr imageFeaturesClassNameInvalid = "*INVALID*";
196 
197  if (!mlClass)
198  {
199  cerr << endl
200  << "FeatureVector::ClassName *** ERROR ***" << endl
201  << endl
202  << " Attempt to get ClassName, But not pointing to valid MLClass Object" << endl
203  << endl;
204  return imageFeaturesClassNameInvalid;
205  }
206  else
207  {
208  return mlClass->Name ();
209  }
210 } /* ClassName */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
FeatureVectorPtr FeatureVector::Duplicate ( ) const
virtual

Reimplemented in KKMLL::GrayScaleImagesFV.

Definition at line 94 of file FeatureVector.cpp.

References FeatureVector().

95 {
96  return new FeatureVector (*this);
97 }
FeatureVector(kkint32 _numOfFeatures)
void KKMLL::FeatureVector::ExampleFileName ( const KKStr _exampleFileName)
inline
void FeatureVector::FeatureData ( kkint32  _featureNum,
float  _featureValue 
)

Assign a value to a specific feature number for the feature vector.

This method will validate that '_featureNum' is not out of range (0 - 'numOfFeatures'). This will prevent the caller from corrupting memory.

Parameters
[in]_featureNumFeature Number to assign '_featureValue' to.
[in]_featureValueValue to assign to feature '_featureNum'.

Definition at line 161 of file FeatureVector.cpp.

References featureData, and NumOfFeatures().

Referenced by KKMLL::GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree().

164 {
165  if ((_featureNum < 0) || (_featureNum >= NumOfFeatures ()))
166  {
167  cerr << endl
168  << endl
169  << "*** ERROR *** FeatureVector::FeatureData(" << _featureNum << ") Index out of bounds, no value set." << endl
170  << endl;
171  return;
172  }
173 
174  featureData[_featureNum] = _featureValue;
175 } /* FeatureData */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
float FeatureVector::FeatureData ( kkint32  featureNum) const
Returns
The value of 'featureNum'

Definition at line 145 of file FeatureVector.cpp.

References featureData, and NumOfFeatures().

Referenced by KKMLL::FeatureVectorList::CalcStatsForFeatureNum(), KKMLL::GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree(), KKMLL::FeatureVectorList::ReSyncSymbolicData(), KKMLL::FeatureFileIORoberts::SaveFile(), KKMLL::FeatureFileIOC45::SaveFile(), KKMLL::FeatureFileIOSparse::SaveFile(), and SVM289_MFS::Svm_Model::WriteXML().

146 {
147  if ((featureNum < 0) || (featureNum >= NumOfFeatures ()))
148  {
149  cerr << endl
150  << "*** ERROR *** FeatureVector::FeatureData(" << featureNum << ") Index out of bounds." << endl
151  << endl;
152  return 0.0f;
153  }
154 
155  return featureData[featureNum];
156 } /* FeatureData */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
const float* KKMLL::FeatureVector::FeatureData ( ) const
inline
float* KKMLL::FeatureVector::FeatureDataAlter ( )
inline
const float* KKMLL::FeatureVector::FeatureDataConst ( ) const
inline
bool FeatureVector::FeatureDataValid ( )

Definition at line 234 of file FeatureVector.cpp.

References featureData, KKB::FloatMax, KKB::FloatMin, and numOfFeatures.

235 {
236  kkint32 featureNum;
237 
238  for (featureNum = 0; featureNum < numOfFeatures; featureNum++)
239  {
240  if ((featureData[featureNum] == KKB::FloatMin) || (featureData[featureNum] == KKB::FloatMax))
241  return false;
242  }
243 
244  return true;
245 } /* FeatureDataValid */
__int32 kkint32
Definition: KKBaseTypes.h:88
float FloatMin
Definition: KKBaseTypes.cpp:21
float FloatMax
Definition: KKBaseTypes.cpp:20
kkint32 FeatureVector::MemoryConsumedEstimated ( ) const
virtual

Definition at line 81 of file FeatureVector.cpp.

References featureData, KKB::KKStr::MemoryConsumedEstimated(), and numOfFeatures.

Referenced by KKMLL::FeatureVectorList::MemoryConsumedEstimated().

82 {
83  kkint32 memoryConsumedEstimated = sizeof (FeatureVector)
84  + exampleFileName.MemoryConsumedEstimated ();
85 
86  if (featureData)
87  memoryConsumedEstimated += sizeof (float) * numOfFeatures;
88 
89  return memoryConsumedEstimated;
90 } /* MemoryConsumedEstimated */
kkint32 MemoryConsumedEstimated() const
Definition: KKStr.cpp:766
__int32 kkint32
Definition: KKBaseTypes.h:88
FeatureVector(kkint32 _numOfFeatures)
void KKMLL::FeatureVector::MissingData ( bool  _missingData)
inline

True indicates that not all the feature data was present when this example was loaded from a data file.

Definition at line 76 of file FeatureVector.h.

Referenced by KKMLL::FeatureFileIOC45::LoadFile().

bool KKMLL::FeatureVector::MissingData ( ) const
inline

True indicates that one or more features were missing.

Definition at line 117 of file FeatureVector.h.

Referenced by KKMLL::FeatureVectorList::MissingData().

const KKStr & FeatureVector::MLClassName ( ) const

Name of class that this example is assigned to.

Definition at line 262 of file FeatureVector.cpp.

References KKB::KKStr::Concat(), KKB::KKStr::EmptyStr(), and KKMLL::MLClass::Name().

263 {
264  if (mlClass)
265  return mlClass->Name ();
266  else
267  return KKStr::EmptyStr ();
268 } /* MLClassName */
bool FeatureVector::operator== ( FeatureVector other_example) const

Definition at line 273 of file FeatureVector.cpp.

References featureData, and numOfFeatures.

274 {
275  if (numOfFeatures != other_image.numOfFeatures)
276  return false;
277 
278  for (kkint32 i = 0; i < numOfFeatures; i++)
279  {
280  if (featureData[i] != other_image.featureData[i])
281  {
282  return false;
283  }
284  }
285 
286  return true;
287 } /* operator== */
__int32 kkint32
Definition: KKBaseTypes.h:88
void KKMLL::FeatureVector::OrigSize ( float  _origSize)
inline

The value of Feature[0] before normalization.

Definition at line 77 of file FeatureVector.h.

Referenced by KKMLL::GrayScaleImagesFVProducer::ComputeFeatureVector(), and KKMLL::GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree().

float KKMLL::FeatureVector::OrigSize ( ) const
inline

The value of Feature[0] before normalization.

Definition at line 119 of file FeatureVector.h.

Referenced by KKMLL::FeatureVectorList::ExtractExamplesForAGivenClass(), and KKMLL::GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree().

void KKMLL::FeatureVector::PredictedClass ( MLClassPtr  _predictedClass)
inline

Definition at line 78 of file FeatureVector.h.

Referenced by KKMLL::FeatureEncoder2::EncodeAExample(), and KKMLL::FeatureEncoder::EncodeAExample().

78 {predictedClass = _predictedClass;}
MLClassPtr KKMLL::FeatureVector::PredictedClass ( ) const
inline

Definition at line 120 of file FeatureVector.h.

Referenced by KKMLL::FeatureEncoder2::EncodeAExample(), and KKMLL::FeatureEncoder::EncodeAExample().

120 {return predictedClass;}
const KKStr & FeatureVector::PredictedClassName ( ) const

Definition at line 251 of file FeatureVector.cpp.

References KKB::KKStr::Concat(), KKB::KKStr::EmptyStr(), and KKMLL::MLClass::Name().

252 {
253  if (predictedClass)
254  return predictedClass->Name ();
255  else
256  return KKStr::EmptyStr ();
257 } /* PredictedClasseName */
void KKMLL::FeatureVector::Probability ( float  _probability)
inline

Assign a prediction probability to this example.

Definition at line 79 of file FeatureVector.h.

float KKMLL::FeatureVector::Probability ( ) const
inline

The probability assigned by classifier to the predicted class.

Definition at line 122 of file FeatureVector.h.

Referenced by KKMLL::FeatureVectorList::ProbabilityComparison::operator()(), and KKMLL::FeatureVectorList::ProbabilityComparisonReversed::operator()().

void FeatureVector::ResetNumOfFeatures ( kkint32  newNumOfFeatures)

Used to reallocate memory for feature data.

Definition at line 102 of file FeatureVector.cpp.

References KKB::KKStr::Concat(), featureData, KKB::KKException::KKException(), KKB::KKStr::KKStr(), and numOfFeatures.

Referenced by KKMLL::FeatureVectorList::ResetFileDesc(), and KKMLL::FeatureVectorList::ResetNumOfFeaturs().

103 {
104  if (newNumOfFeatures < 1)
105  {
106  KKStr errMsg (128);
107  errMsg << "FeatureVector::ResetNumOfFeatures ***ERROR*** NewNumOfFeatures[" << newNumOfFeatures << "] is invalid.";
108  cerr << endl << errMsg << endl << endl;
109  throw KKException (errMsg);
110  }
111 
112  kkint32 x;
113  float* newFeatureData = new float[newNumOfFeatures];
114  for (x = 0; x < newNumOfFeatures; x++)
115  {
116  if (x < numOfFeatures)
117  newFeatureData[x] = featureData[x];
118  else
119  newFeatureData[x] = 0.0f;
120  }
121 
122  delete featureData;
123  featureData = newFeatureData;
124  numOfFeatures = newNumOfFeatures;
125 } /* ResetNumOfFeatures */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
float FeatureVector::TotalOfFeatureData ( ) const

Returns the total of all Feature Attributes for this feature vector.

Definition at line 180 of file FeatureVector.cpp.

References featureData, and NumOfFeatures().

181 {
182  float totalOfFeatureData = 0.0f;
183  for (int x = 0; x < NumOfFeatures (); ++x)
184  totalOfFeatureData += featureData[x];
185  return totalOfFeatureData;
186 }
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
void KKMLL::FeatureVector::TrainWeight ( float  _trainWeight)
inline

Assign a specific example a higher weight for training purposes.

The SVM will multiply the cost parameter by this amount when training the classifier for this specific example.

Definition at line 105 of file FeatureVector.h.

Referenced by KKMLL::FeatureEncoder2::EncodeAExample(), and KKMLL::FeatureEncoder::EncodeAExample().

105 {trainWeight = _trainWeight;}
float KKMLL::FeatureVector::TrainWeight ( ) const
inline
void KKMLL::FeatureVector::Validated ( bool  _validated)
inline

Indicated whether an expert has validated the class assignment.

Definition at line 109 of file FeatureVector.h.

109 {validated = _validated;}
bool KKMLL::FeatureVector::Validated ( ) const
inline

Definition at line 124 of file FeatureVector.h.

124 {return validated;}
void KKMLL::FeatureVector::Version ( kkint16  _version)
inline
kkint16 KKMLL::FeatureVector::Version ( ) const
inline

Definition at line 125 of file FeatureVector.h.

Referenced by KKMLL::GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree().

125 {return version;}

Member Data Documentation


The documentation for this class was generated from the following files: