KSquare Utilities
FeatureVector.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <ctype.h>
3 #include <time.h>
4 #include <string>
5 #include <iostream>
6 #include <fstream>
7 #include <math.h>
8 #include <vector>
9 #include "MemoryDebug.h"
10 using namespace std;
11 
12 #include "KKBaseTypes.h"
13 #include "DateTime.h"
14 #include "KKException.h"
15 #include "OSservices.h"
16 #include "RunLog.h"
17 #include "KKStr.h"
18 using namespace KKB;
19 
20 #include "FeatureVector.h"
21 #include "ClassProb.h"
22 #include "DuplicateImages.h"
23 #include "FeatureNumList.h"
24 #include "FeatureFileIO.h"
25 #include "MLClass.h"
26 using namespace KKMLL;
27 
28 
29 
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 }
46 
47 
48 
49 
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 }
71 
72 
73 
75 {
76  delete[] featureData; featureData = NULL;
77 }
78 
79 
80 
82 {
83  kkint32 memoryConsumedEstimated = sizeof (FeatureVector)
84  + exampleFileName.MemoryConsumedEstimated ();
85 
86  if (featureData)
87  memoryConsumedEstimated += sizeof (float) * numOfFeatures;
88 
89  return memoryConsumedEstimated;
90 } /* MemoryConsumedEstimated */
91 
92 
93 
94 FeatureVectorPtr FeatureVector::Duplicate () const
95 {
96  return new FeatureVector (*this);
97 }
98 
99 
100 
101 
102 void FeatureVector::ResetNumOfFeatures (kkint32 newNumOfFeatures)
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 */
126 
127 
128 
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 */
141 
142 
143 
144 
145 float FeatureVector::FeatureData (kkint32 featureNum) const
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 */
157 
158 
159 
160 
161 void FeatureVector::FeatureData (kkint32 _featureNum,
162  float _featureValue
163  )
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 */
176 
177 
178 
179 
181 {
182  float totalOfFeatureData = 0.0f;
183  for (int x = 0; x < NumOfFeatures (); ++x)
184  totalOfFeatureData += featureData[x];
185  return totalOfFeatureData;
186 }
187 
188 
189 
190 
191 const
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 */
211 
212 
213 
214 
215 
217  float _featureData
218  )
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 */
230 
231 
232 
233 
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 */
246 
247 
248 
249 
250 
252 {
253  if (predictedClass)
254  return predictedClass->Name ();
255  else
256  return KKStr::EmptyStr ();
257 } /* PredictedClasseName */
258 
259 
260 
261 
263 {
264  if (mlClass)
265  return mlClass->Name ();
266  else
267  return KKStr::EmptyStr ();
268 } /* MLClassName */
269 
270 
271 
272 
273 bool FeatureVector::operator== (FeatureVector &other_image) const
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== */
288 
289 
290 
292  KKQueue<FeatureVector> (true),
293  curSortOrder (IFL_SortOrder::IFL_UnSorted),
294  fileDesc (NULL),
295  fileName (),
296  numOfFeatures (0),
297  version (-1)
298 {
299 }
300 
301 
302 
304  bool _owner
305  ):
307 
308  curSortOrder (IFL_SortOrder::IFL_UnSorted),
309  fileDesc (_fileDesc),
310  fileName (),
311  numOfFeatures (0),
312  version (-1)
313 {
314  if (!fileDesc)
315  {
316  KKStr errMsg = "FeatureVectorList::FeatureVectorList *** ERROR *** FileDesc == NULL";
317  cerr << endl << errMsg << endl <<endl;
318  throw KKException (errMsg);
319  }
320 
321  numOfFeatures = fileDesc->NumOfFields ();
322 }
323 
324 
325 
326 
327 FeatureVectorList::FeatureVectorList (FeatureVectorList& examples):
328  KKQueue<FeatureVector> (examples),
329 
330  curSortOrder (IFL_SortOrder::IFL_UnSorted),
331  fileDesc (examples.fileDesc),
332  fileName (examples.fileName),
333  numOfFeatures (examples.numOfFeatures),
334  version (examples.version)
335 {
336 }
337 
338 
339 /**
340  *@brief Constructor that create a duplicate list of FeatureVectors;
341  *@details
342  *if (owner == true) then will also
343  * -# duplicate the contents; that is each example in the list will be
344  * duplicated by calling the copy constructor.
345  * -# And the new list will own these newly created examples.
346  */
348  bool _owner
349  ):
351 
352  curSortOrder (IFL_SortOrder::IFL_UnSorted),
353  fileDesc (examples.fileDesc),
354  fileName (examples.fileName),
355  numOfFeatures (examples.numOfFeatures),
356  version (examples.version)
357 {
358 }
359 
360 
361 
362 /**
363  *@brief Constructs a list of examples that are a subset of the ones in _examples as dictated by _mlClasses
364  *@details
365  * The subset will consist of the examples who's mlClass is one of the ones in mlClasses. The new
366  * instance created will not own the contents; it will just point to the existing examples that were in
367  * '_examples'.
368  *
369  *@param[in] _mlClasses List of classes that the subset of examples will come from.
370  *@param[in] _examples Examples that the subset will be derived from.
371  */
373  FeatureVectorList& _examples
374  ):
375  KKQueue<FeatureVector> (false),
376 
377  curSortOrder (IFL_SortOrder::IFL_UnSorted),
378  fileDesc (_examples.fileDesc),
379  fileName (_examples.fileName),
380  numOfFeatures (_examples.numOfFeatures),
381  version (_examples.version)
382 {
383  MLClassIndexListPtr classIdx = new MLClassIndexList (_mlClasses);
384  for (auto idx: _examples)
385  {
386  if (classIdx->GetClassIndex (idx->MLClass ()) >= 0)
387  PushOnBack (idx);
388  }
389  delete classIdx;
390  classIdx = NULL;
391 }
392 
393 
394 
396 {
397 }
398 
399 
400 
402 {
403  kkint32 memoryConsumedEstimated = sizeof (FeatureVectorList) + fileName.MemoryConsumedEstimated ();
404  FeatureVectorList::const_iterator idx;
405  for (idx = begin (); idx != end (); ++idx)
406  {
407  FeatureVectorPtr fv = *idx;
408  memoryConsumedEstimated += fv->MemoryConsumedEstimated ();
409  }
410  return memoryConsumedEstimated;
411 } /* MemoryConsumedEstimated */
412 
413 
414 
415 
416 FeatureVectorListPtr FeatureVectorList::Duplicate (bool _owner) const
417 {
418  return new FeatureVectorList (*this, _owner);
419 }
420 
421 
422 
423 FeatureVectorListPtr FeatureVectorList::ManufactureEmptyList (bool _owner) const
424 {
425  return new FeatureVectorList (fileDesc, _owner);
426 }
427 
428 
429 
430 /**
431  *@details
432  * Determines if the other FeatreVectorList has the same underlining layout; that is each
433  * field is of the same type and meaning. This way we can determine if one list contains
434  * Apples while the other contains Oranges.
435  */
437  RunLog& log
438  ) const
439 {
440  return fileDesc->SameExceptForSymbolicData (*(otherData.FileDesc ()), log);
441 }
442 
443 
444 
446 {
447  log.Level (50) << "FeatureVectorList::RemoveEntriesWithMissingFeatures" << endl;
448 
449  vector<FeatureVectorPtr> entriesToBeDeleted;
450 
451  for (iterator idx = begin (); idx != end (); idx++)
452  {
453  FeatureVectorPtr example = *idx;
454  if (example->MissingData ())
455  entriesToBeDeleted.push_back (example);
456  }
457 
458  for (kkint32 x = 0; x < (kkint32)entriesToBeDeleted.size (); x++)
459  {
460  FeatureVectorPtr example = entriesToBeDeleted[x];
461  DeleteEntry (example);
462  if (Owner ())
463  delete example;
464  }
465 
466 } /* RemoveEntriesWithMissingFeatures */
467 
468 
469 
470 void FeatureVectorList::ValidateFileDescAndFieldNum (kkint32 fieldNum,
471  const char* funcName
472  ) const
473 {
474  if (!fileDesc)
475  {
476  // This should never ever be able to happen, but will check
477  // any way. If missing something has gone very wrong.
478  KKStr msg (200);
479  msg << "FeatureVectorList::" << funcName << " *** ERROR *** 'fileDesc == NULL'";
480  throw KKException (msg);
481  }
482 
483  if ((fieldNum < 0) || (fieldNum >= (kkint32)fileDesc->NumOfFields ()))
484  {
485  KKStr msg (200);
486  msg << "FeatureVectorList::" << funcName << " *** ERROR *** FeatureNum[" << fieldNum << "] is out of range.";
487  throw KKException (msg);
488  }
489 } /* ValidateFileDescAndFieldNum */
490 
491 
492 
494 {
495  return fileDesc->AllFieldsAreNumeric ();
496 }
497 
498 
499 
500 const KKStr& FeatureVectorList::FieldName (kkint32 featureNum) const
501 {
502  ValidateFileDescAndFieldNum (featureNum, "FieldName");
503  return fileDesc->FieldName (featureNum);
504 } /* FeatureName */
505 
506 
507 
508 
510 {
511  ValidateFileDescAndFieldNum (featureNum, "FeatureType");
512  return fileDesc->Type (featureNum);
513 } /* FeatureType */
514 
515 
516 
517 
519 {
520  ValidateFileDescAndFieldNum (featureNum, "FeatureTypeStr");
521  return AttributeTypeToStr (fileDesc->Type (featureNum));
522 } /* FeatureType */
523 
524 
525 
527 {
528  ValidateFileDescAndFieldNum (featureNum, "FeatureCardinality");
529  return fileDesc->Cardinality (featureNum);
530 }
531 
532 
533 
534 
536 {
537  ValidateFileDescAndFieldNum (0, "CreateAttributeTypeTable");
538  return fileDesc->CreateAttributeTypeTable ();
539 } /* CreateAttributeTypeTable */
540 
541 
542 
543 
545 {
546  ValidateFileDescAndFieldNum (0, "CreateCardinalityTable");
547  return fileDesc->CreateCardinalityTable ();
548 } /* CreateAttributeTypeTable */
549 
550 
551 
552 
553 
555 {
556  return FeatureNumList::AllFeatures (fileDesc);
557 }
558 
559 
560 
562 {
563  numOfFeatures = newNumOfFeatures;
564 
565  for (iterator idx = begin (); idx != end (); idx++)
566  {
567  FeatureVectorPtr i = *idx;
568  i->ResetNumOfFeatures (newNumOfFeatures);
569  }
570 } /* ResetNumOfFeaturs */
571 
572 
573 
574 
576 {
577  if (!newFileDesc)
578  {
579  KKStr errMsg = "FeatureVector::ResetFileDesc ***ERROR*** newFileDesc == NULL.";
580  cerr << endl << errMsg << endl << endl;
581  throw KKException (errMsg);
582  }
583 
584  fileDesc = newFileDesc;
585 
586  numOfFeatures = fileDesc->NumOfFields ();
587 
588  for (iterator idx = begin (); idx != end (); idx++)
589  {
590  FeatureVectorPtr i = *idx;
591  i->ResetNumOfFeatures (numOfFeatures);
592  }
593 } /* ResetFileDesc */
594 
595 
596 
597 
598 void FeatureVectorList::PushOnBack (FeatureVectorPtr example)
599 {
600  if (example->NumOfFeatures () != numOfFeatures)
601  {
602  KKStr errMsg (150);
603  errMsg << "FeatureVectorList::PushOnBack ***ERROR*** Mismatch numOfFeatures[" << numOfFeatures << "] example->NumOfFeaturess[" << example->NumOfFeatures () << "]";
604  cerr << endl << errMsg << endl << endl;
605  throw KKException (errMsg);
606  }
607 
608  KKQueue<FeatureVector>::PushOnBack (example);
609  curSortOrder = IFL_SortOrder::IFL_UnSorted;
610 } /* Push On Back */
611 
612 
613 
614 
615 void FeatureVectorList::PushOnFront (FeatureVectorPtr example)
616 {
617  if (example->NumOfFeatures () != numOfFeatures)
618  {
619  KKStr errMsg (150);
620  errMsg << "FeatureVectorList::PushOnFront ***ERROR*** Mismatch numOfFeatures[" << numOfFeatures << "] example->NumOfFeaturess[" << example->NumOfFeatures () << "]";
621  cerr << endl << errMsg << endl << endl;
622  throw KKException (errMsg);
623  }
624 
625  KKQueue<FeatureVector>::PushOnFront (example);
626  curSortOrder = IFL_SortOrder::IFL_UnSorted;
627 } /* PushOnFront */
628 
629 
630 
631 
633 {
634  MLClassPtr lastClass = NULL;
635  map<MLClassPtr,MLClassPtr> ptrIndex;
636  map<MLClassPtr,MLClassPtr>::iterator ptrIndexItr;
637  FeatureVectorList::const_iterator idx;
638  for (idx = begin (); idx != end (); ++idx)
639  {
640  FeatureVectorPtr example = *idx;
641  MLClassPtr newClass = example->MLClass ();
642  if (newClass == lastClass)
643  continue;
644 
645  lastClass = newClass;
646  ptrIndexItr = ptrIndex.find (newClass);
647  if (ptrIndexItr == ptrIndex.end ())
648  {
649  lastClass = newClass;
650  ptrIndex.insert (pair<MLClassPtr,MLClassPtr> (newClass, newClass));
651  }
652  }
653 
654  MLClassListPtr classes = new MLClassList ();
655  for (ptrIndexItr = ptrIndex.begin (); ptrIndexItr != ptrIndex.end (); ++ptrIndexItr)
656  classes->PushOnBack (ptrIndexItr->first);
657 
658  return classes;
659 } /* ExtractListOfClasses */
660 
661 
662 
663 
664 
665 void FeatureVectorList::AddSingleExample (FeatureVectorPtr _imageFeatures)
666 {
667  PushOnBack (_imageFeatures);
668  curSortOrder = IFL_SortOrder::IFL_UnSorted;
669 }
670 
671 
672 
673 void FeatureVectorList::RemoveDuplicateEntries (bool allowDupsInSameClass,
674  RunLog& runLog
675  )
676 {
677  DuplicateImages dupDetector (this, runLog);
678  dupDetector.PurgeDuplicates (this, allowDupsInSameClass, NULL);
679 } /* RemoveDuplicateEntries */
680 
681 
682 
683 void FeatureVectorList::AddQueue (const FeatureVectorList& examplesToAdd)
684 {
685  if (numOfFeatures != examplesToAdd.NumOfFeatures ())
686  {
687  KKStr errMsg = "FeatureVectorList::AddQueue ***ERROR*** 'examplesToAdd' has different 'NumOfFeatures'.";
688  errMsg << endl << " numOfFeatures [" << numOfFeatures << "]" << endl
689  << " examplesToAdd.numOfFeatures[" << examplesToAdd.numOfFeatures << "]";
690  cerr << endl << errMsg << endl << endl;
691  throw errMsg;
692  }
693 
694  if (QueueSize () < 1)
695  {
696  // Since we don't have any examples in the existing queue then the version number
697  // of the queue that we are adding will be our version number.
698  Version (examplesToAdd.Version ());
699  }
700  else
701  {
702  // Since there are examples in both queues, then they should have the same version number
703  // otherwise the version number of the resulting KKQueue will be undefined (-1).
704  if (examplesToAdd.Version () != Version ())
705  Version (-1);
706  }
707 
708  KKQueue<FeatureVector>::AddQueue (examplesToAdd);
709 } /* AddQueue */
710 
711 
712 
713 
715 {
716  kkint32 count =0;
717  FeatureVectorList::const_iterator idx;
718  for (idx = begin (); idx != end (); idx++)
719  {
720  if ((*idx)->MLClass () == c)
721  count++;
722  }
723 
724  return count;
725 } /* GetClassCount */
726 
727 
728 
729 
731 {
733  FeatureVectorList::const_iterator idx;
734  for (idx = begin (); idx != end (); idx++)
735  {
736  const FeatureVectorPtr fv = *idx;
737 
738  FeatureVectorPtr newFV = new FeatureVector (*fv);
740  examples->PushOnBack (newFV);
741  }
742 
743  return examples;
744 } /* ExtractExamplesForHierarchyLevel */
745 
746 
747 
748 
749 
751  kkint32 _maxToExtract,
752  float _minSize
753  ) const
754 {
755  kkint32 idx;
756  kkint32 qSize = QueueSize ();
757  FeatureVectorPtr example;
758  kkint32 numExtracted = 0;
759 
760  if (_maxToExtract < 1)
761  _maxToExtract = QueueSize ();
762 
763  // Create a new list structure that does not own the Images it contains. This way when
764  // this structure is deleted. The example it contains are not deleted.
765  FeatureVectorListPtr extractedImages = this->ManufactureEmptyList (false);
766 
767  if (!extractedImages)
768  {
769  KKStr err = "***ERROR***, ExtractExamplesForAGivenClass, Could not allocate more space.";
770  cerr << endl << err << endl;
771  osDisplayWarning (err);
772  exit (-1);
773  }
774 
775  for (idx = 0; ((idx < qSize)); idx++)
776  {
777  example = IdxToPtr (idx);
778  if (((example->MLClass () == _mlClass) || (!_mlClass)))
779  {
780  if (example->OrigSize () >= _minSize)
781  {
782  extractedImages->AddSingleExample (example);
783  numExtracted++;
784  if (numExtracted >= _maxToExtract)
785  break;
786  }
787  }
788  }
789 
790  return extractedImages;
791 } /* ExtractExamplesForAGivenClass */
792 
793 
794 
796 {
797  FeatureVectorListPtr subSetForClassList = ManufactureEmptyList (false);
798  for (auto idx: *classes)
799  {
800  FeatureVectorListPtr examplesForClass = ExtractExamplesForAGivenClass (idx);
801  if (examplesForClass)
802  subSetForClassList->AddQueue (*examplesForClass);
803  }
804  return subSetForClassList;
805 } /* ExtractExamplesForClassList */
806 
807 
808 
809 
811 {
813 
814  KKStrListPtr duplicateExamples = new KKStrList (true);
815 
816  if (QueueSize () < 2)
817  return duplicateExamples;
818 
819  FeatureVectorList::iterator iIDX = this->begin ();
820 
821  while (iIDX != end ())
822  {
823  FeatureVectorPtr example = *iIDX; ++iIDX;
824  if (!example)
825  continue;
826 
827  KKStr lastFileName = example->ExampleFileName ();
828 
829  if (example->ExampleFileName () == lastFileName)
830  {
831  duplicateExamples->PushOnBack (new KKStr (example->ExampleFileName ()));
832 
833  if (iIDX != end ())
834  {
835  example = *iIDX;
836  ++iIDX;
837  }
838  else
839  {
840  example = NULL;
841  }
842 
843  while ((example != NULL) && (example->ExampleFileName () == lastFileName))
844  {
845  if (iIDX != end ())
846  {
847  example = *iIDX;
848  ++iIDX;
849  }
850  else
851  {
852  example = NULL;
853  }
854  }
855  }
856  }
857 
858  return duplicateExamples;
859 } /* ExtractDuplicateImageFileNames */
860 
861 
862 
863 
864 
865 
866 FeatureVectorPtr FeatureVectorList::BinarySearchByName (const KKStr& _imageFileName) const
867 {
868  if ((curSortOrder != IFL_SortOrder::IFL_ByName) &&
869  (curSortOrder != IFL_SortOrder::IFL_ByRootName)
870  )
871  {
872  cerr << endl
873  << "FeatureVectorList::BinarySearchByName **** ERROR ****" << endl
874  << endl
875  << " List is Not sorted in ExampleFileName Order" << endl
876  << endl;
877  osDisplayWarning ("FeatureVectorList::BinarySearchByName Invalid Sort Order.");
878  exit (-1);
879  }
880 
881  kkint32 low = 0;
882  kkint32 high = QueueSize () - 1;
883  kkint32 mid;
884 
885  FeatureVectorPtr example = NULL;
886 
887  while (low <= high)
888  {
889  mid = (low + high) / 2;
890 
891  example = IdxToPtr (mid);
892 
893  if (example->ExampleFileName () < _imageFileName)
894  {
895  low = mid + 1;
896  }
897 
898  else if (example->ExampleFileName () > _imageFileName)
899  {
900  high = mid - 1;
901  }
902 
903  else
904  {
905  return example;
906  }
907  }
908 
909  return NULL;
910 } /* BinarySearchByName */
911 
912 
913 
914 
915 
916 FeatureVectorPtr FeatureVectorList::LookUpByRootName (const KKStr& _rootName)
917 {
918  FeatureVectorPtr example = NULL;
919 
920  if (curSortOrder != IFL_SortOrder::IFL_ByRootName)
921  {
922  cerr << endl
923  << "FeatureVectorList::LookUpByRootName ***WARNING*** List is NOT SORTED by RootName." << endl
924  << endl;
925 
926  FeatureVectorList::iterator idx;
927  for (idx = begin (); idx != end (); idx++)
928  {
929  example = *idx;
930  if (_rootName == osGetRootName (example->ExampleFileName ()))
931  return example;
932  }
933  return NULL;
934  }
935  else
936  {
937  kkint32 low = 0;
938  kkint32 high = QueueSize () - 1;
939  kkint32 mid;
940 
941  while (low <= high)
942  {
943  mid = (low + high) / 2;
944 
945  example = IdxToPtr (mid);
946 
947  KKStr tempName = osGetRootName (example->ExampleFileName ());
948 
949  if (tempName < _rootName)
950  {
951  low = mid + 1;
952  }
953 
954  else if (tempName > _rootName)
955  {
956  high = mid - 1;
957  }
958 
959  else
960  {
961  return example;
962  }
963  }
964  }
965 
966  return NULL;
967 } /* LookUpByRootName */
968 
969 
970 
971 
972 
973 
974 FeatureVectorPtr FeatureVectorList::LookUpByImageFileName (const KKStr& _imageFileName) const
975 {
976  if (curSortOrder == IFL_SortOrder::IFL_ByName)
977  return BinarySearchByName (_imageFileName);
978  else
979  {
980  FeatureVectorPtr example = NULL;
981  for (auto tempExample: *this)
982  {
983  if (tempExample->ExampleFileName () == _imageFileName)
984  example = tempExample;
985  }
986  return example;
987  }
988 } /* LookUpByImageFileName */
989 
990 
991 FeatureVectorListPtr FeatureVectorList::OrderUsingNamesFromAFile (const KKStr& fileName,
992  RunLog& log
993  )
994 {
995  FILE* in = osFOPEN (fileName.Str (), "r");
996  if (!in)
997  {
998  log.Level (-1) << endl
999  << "FeatureVectorList::OrderUsingNamesFromAFile *** ERROR ***" << endl
1000  << " Could not open file[" << fileName << "]." << endl
1001  << endl;
1002  return NULL;
1003  }
1004 
1005  FeatureVectorPtr example = NULL;
1006  FeatureVectorListPtr orderedImages = ManufactureEmptyList (false);
1007 
1008  char buff[1024];
1009  while (fgets (buff, sizeof (buff), in))
1010  {
1011  KKStr txtLine (buff);
1012 
1013  if (txtLine.SubStrPart (0, 1) == "//")
1014  {
1015  // Comment line, will ignore.
1016  continue;
1017  }
1018 
1019  KKStr exampleFileName = txtLine.ExtractToken ("\n\r\t");
1020  if (orderedImages->LookUpByImageFileName (exampleFileName))
1021  {
1022  // Image file name used more than once, will treat as error
1023  log.Level (-1) << endl
1024  << "FeatureVectorList::OrderUsingNamesFromAFile *** ERROR ***" << endl
1025  << " ExampleFileName[" << exampleFileName << "] occurred more than once in file." << endl
1026  << endl;
1027  fclose (in);
1028  delete orderedImages;
1029  return NULL;
1030  }
1031 
1032  example = LookUpByImageFileName (exampleFileName);
1033  if (!example)
1034  {
1035  // Image file name not in list, will treat as error.
1036  log.Level (-1) << endl
1037  << "FeatureVectorList::OrderUsingNamesFromAFile *** ERROR ***" << endl
1038  << " ExampleFileName[" << exampleFileName << "] Not in list." << endl
1039  << endl;
1040  fclose (in);
1041  delete orderedImages;
1042  return NULL;
1043  }
1044 
1045  orderedImages->PushOnBack (example);
1046  }
1047 
1048  fclose (in);
1049 
1050  return orderedImages;
1051 } /* OrderUsingNamesFromAFile */
1052 
1053 
1054 
1055 
1057  bool& _successful
1058  )
1059 {
1060  _successful = true;
1061 
1062  ofstream o (_fileName.Str ());
1063  if (!o.is_open ())
1064  {
1065  _successful = false;
1066  return;
1067  }
1068 
1069  o << "// " << "Time Written [" << osGetLocalDateTime () << "]" << endl;
1070  o << "// " << "File Name [" << _fileName << "]" << endl;
1071  o << "// " << "Size [" << QueueSize () << "]" << endl;
1072  o << "//" << endl;
1073 
1074 
1075  FeatureVectorList::iterator idx;
1076 
1077  for (idx = begin (); idx != end (); idx++)
1078  o << (*idx)->ExampleFileName () << endl;
1079 
1080  o.close ();
1081 
1082  return;
1083 } /* OrderUsingNamesFormAFile */
1084 
1085 
1086 
1087 
1088 
1089 
1090 
1091 /**
1092  *@brief Creates a duplicate of list and also duplicates it contents.
1093  *@return Duplicated list with hard copy of its contents.
1094  */
1095 FeatureVectorListPtr FeatureVectorList::DuplicateListAndContents () const
1096 {
1097  FeatureVectorListPtr copyiedList = ManufactureEmptyList (true);
1098  for (kkint32 idx = 0; idx < QueueSize (); idx++)
1099  {
1100  FeatureVectorPtr curImage = IdxToPtr (idx);
1101  copyiedList->AddSingleExample (new FeatureVector (*curImage));
1102  }
1103 
1104  return copyiedList;
1105 } /* DuplicateListAndContents */
1106 
1107 
1108 
1109 
1110 
1112 {
1114 
1115  KKStr s (stats->QueueSize () * 30 + 100);
1116 
1117  s << "Total_Images\t" << QueueSize () << endl;
1118  s << endl;
1119  s << "Total_Classes\t" << stats->QueueSize () << endl;
1120  s << endl;
1121 
1122  s << "Class_Name" << "\t" << "Count" << endl;
1123  ClassStatisticList::iterator statsIDX;
1124  for (statsIDX = stats->begin (); statsIDX != stats->end (); statsIDX++)
1125  {
1126  ClassStatisticPtr cs = *statsIDX;
1127  s << cs->Name () << "\t" << cs->Count () << endl;
1128  }
1129 
1130  delete stats;
1131  return s;
1132 } /* ClassStatisticsStr */
1133 
1134 
1135 
1136 
1137 
1139 {
1140  ClassStatisticListPtr classStatistics = new ClassStatisticList (true);
1141 
1142  MLClassPtr mlClass = NULL;
1143  FeatureVectorPtr example = NULL;
1144 
1145  FeatureVectorList::const_iterator idx;
1146 
1147  for (idx = begin (); idx != end (); ++idx)
1148  {
1149  example = *idx;
1150  mlClass = example->MLClass ();
1151 
1152  ClassStatisticPtr classStatistic = classStatistics->LookUpByMLClass (mlClass);
1153  if (classStatistic == NULL)
1154  {
1155  classStatistic = new ClassStatistic (mlClass, 0);
1156  classStatistics->PushOnBack (classStatistic);
1157  }
1158 
1159  classStatistic->Increment ();
1160  }
1161 
1162 
1163  classStatistics->SortByClassName ();
1164 
1165  return classStatistics;
1166 } /* GetClassStatistics */
1167 
1168 
1169 
1170 ClassProbListPtr FeatureVectorList::GetClassDistribution () const
1171 {
1173  ClassProbListPtr distribution = new ClassProbList (true);
1174 
1175  kkuint32 countTotal = 0;
1176  ClassStatisticList::const_iterator idx;
1177  for (idx = stats->begin (); idx != stats->end (); ++idx)
1178  {
1179  ClassStatisticPtr cs = *idx;
1180  countTotal += cs->Count ();
1181  }
1182 
1183  if (countTotal > 0)
1184  {
1185  for (idx = stats->begin (); idx != stats->end (); ++idx)
1186  {
1187  ClassStatisticPtr cs = *idx;
1188  distribution->PushOnBack (new ClassProb (cs->MLClass (), ((float)(cs->Count ()) / (float)countTotal), 0));
1189  }
1190  }
1191 
1192  delete stats;
1193  stats = NULL;
1194 
1195  return distribution;
1196 } /* GetClassDistribution */
1197 
1198 
1199 
1200 
1202 {
1203  FeatureVectorListPtr duplicateList = this->ManufactureEmptyList (false);
1204 
1205  if (QueueSize () < 2)
1206  {
1207  // Since there are less than 2 elements in the list,
1208  // There is no way that there can be any duplicates in the list.
1209  return duplicateList;
1210  }
1211 
1212  FeatureVectorList workList (*this,
1213  false // owner = false, only create a list of pointers to existing instances
1214  ); //
1215 
1216  workList.SortByRootName (false);
1217 
1218  FeatureVectorList::iterator idx;
1219  idx = workList.begin ();
1220 
1221  FeatureVectorPtr lastExample = *idx; ++idx;
1222  FeatureVectorPtr example = *idx; ++idx;
1223 
1224  KKStr lastRootName = osGetRootName (lastExample->ExampleFileName ());
1225  KKStr rootName;
1226 
1227  while (example)
1228  {
1229  rootName = osGetRootName (example->ExampleFileName ());
1230  if (rootName != lastRootName)
1231  {
1232  lastRootName = rootName;
1233  lastExample = example;
1234  if (idx == workList.end ())
1235  example = NULL;
1236  else
1237  {
1238  example = *idx;
1239  ++idx;
1240  }
1241  }
1242  else
1243  {
1244  duplicateList->PushOnBack (lastExample);
1245  while ((example != NULL) && (rootName == lastRootName))
1246  {
1247  duplicateList->PushOnBack (example);
1248  if (idx == workList.end ())
1249  example = NULL;
1250  else
1251  {
1252  example = *idx;
1253  ++idx;
1254  }
1255 
1256  if (example)
1257  rootName = osGetRootName (example->ExampleFileName ());
1258  }
1259  }
1260  }
1261 
1262  return duplicateList;
1263 } /* ExtractDuplicatesByRootImageFileName */
1264 
1265 
1266 
1267 
1269  kkint32 maxImagesPerClass,
1270  FeatureVectorListPtr* folds,
1271  FeatureVectorListPtr src
1272  )
1273 {
1274  src->RandomizeOrder ();
1275  src->RandomizeOrder ();
1276 
1277  kkint32 imagesInThisList = src->QueueSize ();
1278  if (maxImagesPerClass > 0)
1279  imagesInThisList = Min (imagesInThisList, maxImagesPerClass);
1280 
1281  kkint32 x;
1282 
1283  for (x = 0; x < imagesInThisList; x++)
1284  {
1285  folds[x % numOfFolds]->AddSingleExample (src->IdxToPtr (x));
1286  }
1287 } /* SplitImagesAmongstFolds */
1288 
1289 
1290 
1291 
1293  kkint32& _count,
1294  float& _total,
1295  float& _mean,
1296  float& _var,
1297  float& _stdDev
1298  )
1299 {
1300  _count = 0;
1301  _total = 0.0f;
1302  _mean = 0.0f;
1303  _var = 0.0f;
1304  _stdDev = 0.0f;
1305 
1306  if ((_featureNum < 0) || (_featureNum >= NumOfFeatures ()))
1307  {
1308  cerr << endl
1309  << "FeatureVectorList::CalcStatsForFeatureNum *** ERROR *** Invalid FeatureNum[" << _featureNum << "]" << endl
1310  << " FeatureNum [" << _featureNum << "]" << endl
1311  << " NumOfFeatures[" << NumOfFeatures () << "]" << endl
1312  << endl;
1313  _count = -1;
1314  return;
1315  }
1316 
1317  if (QueueSize () == 0)
1318  return;
1319 
1320 
1321  iterator idx;
1322 
1323  for (idx = begin (); idx != end (); idx++)
1324  {
1325  FeatureVectorPtr i = *idx;
1326  _total += i->FeatureData (_featureNum);
1327  _count++;
1328  }
1329 
1330  if (_count < 1)
1331  {
1332  _mean = 0.0f;
1333  _var = 0.0f;
1334  _stdDev = 0.0f;
1335  return;
1336  }
1337 
1338  _mean = _total / (float)_count;
1339 
1340  float totalSquareDelta = 0.0f;
1341  for (idx = begin (); idx != end (); idx++)
1342  {
1343  FeatureVectorPtr i = *idx;
1344  float delta = i->FeatureData (_featureNum) - _mean;
1345  totalSquareDelta += delta * delta;
1346  }
1347 
1348  _var = totalSquareDelta / _count;
1349  _stdDev = sqrt (_var);
1350 } /* CalcStatsForFeatureNum */
1351 
1352 
1353 
1354 FeatureVectorListPtr FeatureVectorList::StratifyAmoungstClasses (kkint32 numOfFolds,
1355  RunLog& log
1356  )
1357 {
1359 
1360  FeatureVectorListPtr stratifiedExamples = StratifyAmoungstClasses (classes, -1, numOfFolds, log);
1361  delete classes; classes = NULL;
1362 
1363  return stratifiedExamples;
1364 } /* StratifyAmoungstClasses */
1365 
1366 
1367 
1368 
1369 
1371  kkint32 maxImagesPerClass,
1372  kkint32 numOfFolds,
1373  RunLog& log
1374  )
1375 {
1376  log.Level (10) << "FeatureVectorList::StratifyAmoungstClasses" << endl;
1377 
1378  kkint32 foldNum;
1379  kkint32 x;
1380 
1381  FeatureVectorListPtr* folds = new FeatureVectorListPtr[numOfFolds];
1382  for (x = 0; x < numOfFolds; x++)
1383  folds[x] = ManufactureEmptyList (false);
1384 
1385  MLClassPtr mlClass = NULL;
1386  MLClassList::iterator icIDX;
1387 
1388  for (icIDX = mlClasses->begin (); icIDX != mlClasses->end (); ++icIDX)
1389  {
1390  mlClass = *icIDX;
1391  FeatureVectorListPtr imagesInClass = ExtractExamplesForAGivenClass (mlClass);
1392 
1393  if (imagesInClass->QueueSize () < numOfFolds)
1394  {
1395  log.Level (-1) << endl
1396  << "FeatureVectorList::DistributesImagesRandomlyWithInFolds ***ERROR***" << endl
1397  << endl
1398  << "*** ERROR ***, Not enough examples to split amongst the different folds." << endl
1399  << " Class [" << mlClass->Name () << "]." << endl
1400  << " Number of Images[" << imagesInClass->QueueSize () << "]." << endl
1401  << " Number of Folds [" << numOfFolds << "]." << endl
1402  << endl;
1403 
1404 
1405  KKStr msg;
1406  msg << "Not enough Images[" << imagesInClass->QueueSize () << "] "
1407  << "for Class[" << mlClass->Name () << "] "
1408  << "to distribute in Folds.";
1409 
1410  if (!osIsBackGroundProcess ())
1411  osDisplayWarning (msg);
1412  }
1413 
1414  imagesInClass->RandomizeOrder ();
1415  imagesInClass->RandomizeOrder ();
1416 
1417  SplitImagesAmongstFolds (numOfFolds, maxImagesPerClass, folds, imagesInClass);
1418  delete imagesInClass;
1419  imagesInClass = NULL;
1420  }
1421 
1422  FeatureVectorListPtr stratafiedImages = ManufactureEmptyList (false);
1423 
1424  for (foldNum = 0; foldNum < numOfFolds; foldNum++)
1425  {
1426  folds[foldNum]->RandomizeOrder ();
1427  folds[foldNum]->RandomizeOrder ();
1428  stratafiedImages->AddQueue (*folds[foldNum]);
1429  delete folds[foldNum];
1430  folds[foldNum] = NULL;
1431  }
1432 
1433  delete[] folds;
1434  folds = NULL;
1435  return stratafiedImages;
1436 } /* StratifyAmoungstClasses */
1437 
1438 
1439 
1440 
1442 {
1444 
1445  if (!classStats)
1446  return 0.0f;
1447 
1448 
1449  ClassStatisticPtr largestClassStat = NULL;
1450  kkuint32 largestClassSize = 0;
1451 
1452  ClassStatisticList::const_iterator idx;
1453  for (idx = classStats->begin (); idx != classStats->end (); idx++)
1454  {
1455  ClassStatisticPtr classStats = *idx;
1456  if (classStats->Count () > largestClassSize)
1457  {
1458  largestClassSize = classStats->Count ();
1459  largestClassStat = classStats;
1460  }
1461  }
1462 
1463  float fraction = float (largestClassSize) / float (size ());
1464 
1465  delete classStats;
1466 
1467  return fraction;
1468 } /* MajorityClassFraction */
1469 
1470 
1471 
1472 
1473 void FeatureVectorList::PrintClassStatistics (ostream& o) const
1474 {
1476 
1477  o << "Total_Images\t" << QueueSize () << endl;
1478  o << endl;
1479  o << "Total_Classes\t" << stats->QueueSize () << endl;
1480  o << endl;
1481 
1482  ClassStatisticList::const_iterator statsIDX;
1483  kkint32 index = 0;
1484 
1485  o << "Class_Name" << "\t" << "Index" << "\t" << "Count" << endl;
1486  for (statsIDX = stats->begin (); statsIDX != stats->end (); ++statsIDX)
1487  {
1488  o << (*statsIDX)->Name () << "\t" << index << "\t" << (*statsIDX)->Count () << endl;
1489  index++;
1490  }
1491 
1492  delete stats;
1493  stats = NULL;
1494  return;
1495 } /* PrintClassStatistics */
1496 
1497 
1498 
1500 {
1502 
1503  o << "<table align=\"center\" border=\"2\" cellpadding=\"4\">" << endl
1504  << "<thead>" << endl;
1505 
1506  o << "<tr>"
1507  << "<th align=\"left\">Class<br />Name</th>"
1508  << "<th align=\"center\">Index</th>"
1509  << "<th align=\"center\">Count</th>"
1510  << "</tr>"
1511  << endl
1512  << "</thead>" << endl;
1513 
1514  o << "<tbody>" << endl;
1515 
1516  ClassStatisticList::iterator statsIDX;
1517  kkint32 index = 0;
1518  for (statsIDX = stats->begin (); statsIDX != stats->end (); statsIDX++)
1519  {
1520  ClassStatistic& statistic = **statsIDX;
1521  o << "<tr>"
1522  << "<td align=\"left\">" << statistic.Name () << "</td>"
1523  << "<td align=\"center\">" << index << "</td>"
1524  << "<td align=\"center\">" << statistic.Count () << "</td>"
1525  << "</tr>"
1526  << endl;
1527  index++;
1528  }
1529 
1530  o << "<tr>"
1531  << "<td align=\"left\">" << "Total" << "</td>"
1532  << "<td align=\"center\">" << "&nbsp" << "</td>"
1533  << "<td align=\"center\">" << QueueSize () << "</td>"
1534  << "</tr>"
1535  << endl;
1536 
1537  o << "</tbody>" << endl;
1538  o << "</table>" << endl;
1539 
1540 
1541  delete stats;
1542  return;
1543 } /* PrintClassStatisticsHTML */
1544 
1545 
1546 
1548 {
1549  o << "Class" << "\t"
1550  << "ClassIdx" << "\t"
1551  << "FeatureNum" << "\t"
1552  << "FieldName" << "\t"
1553  << "Type" << "\t"
1554  << "Count" << "\t"
1555  << "Total" << "\t"
1556  << "Mean" << "\t"
1557  << "Var" << "\t"
1558  << "StdDev"
1559  << endl;
1560 
1562 
1563  MLClassList::const_iterator cIDX;
1564 
1565  kkint32 classIdx = 0;
1566 
1567  for (cIDX = mlClasses->begin (); cIDX != mlClasses->end (); cIDX++)
1568  {
1569  MLClassPtr mlClass = *cIDX;
1570  FeatureVectorListPtr imagesThisClass = ExtractExamplesForAGivenClass (mlClass);
1571 
1572  kkint32 featureNum;
1573  for (featureNum = 0; featureNum < imagesThisClass->NumOfFeatures (); featureNum++)
1574  {
1575  kkint32 count;
1576  float total, mean, var, stdDev;
1577  imagesThisClass->CalcStatsForFeatureNum (featureNum, count, total, mean, var, stdDev);
1578  o << mlClass->Name () << "\t"
1579  << classIdx << "\t"
1580  << featureNum << "\t"
1581  << FieldName (featureNum) << "\t"
1582  << FeatureTypeStr (featureNum) << "\t"
1583  << count << "\t"
1584  << total << "\t"
1585  << mean << "\t"
1586  << var << "\t"
1587  << stdDev
1588  << endl;
1589  }
1590 
1591  delete imagesThisClass;
1592  o << endl;
1593 
1594  classIdx++;
1595  }
1596 
1597  delete mlClasses;
1598  mlClasses = NULL;
1599 } /* PrintFeatureStatisticsByClass */
1600 
1601 
1602 
1603 
1605 {
1606  kkint32 fn = 0;
1607  FeatureVectorList::const_iterator idx;
1608  VectorDouble totals (this->NumOfFeatures (), 0.0);
1609  VectorDouble means (this->NumOfFeatures (), 0.0);
1610  for (idx = begin (); idx != end (); idx++)
1611  {
1612  const FeatureVectorPtr fv = *idx;
1613  const float* fd = fv->FeatureDataConst ();
1614 
1615  for (fn = 0; fn < NumOfFeatures (); fn++)
1616  totals[fn] += fd[fn];
1617  }
1618 
1619 
1620  for (fn = 0; fn < NumOfFeatures (); fn++)
1621  means[fn] = totals[fn] / (double)this->QueueSize ();
1622 
1623  return means;
1624 } /* ExtractMeanFeatureValues */
1625 
1626 
1627 
1628 
1629 FeatureVectorListPtr FeatureVectorList::ExtractRandomSampling (float percentage, // 0.0 -> 100.0
1630  kkint32 minClassCount
1631  )
1632 {
1633 
1634 
1635  if (percentage <= 0.0f)
1636  {
1637  percentage = 0.0f;
1638  }
1639 
1640  if (percentage > 100.0f)
1641  {
1642  percentage = 1.0f;
1643  }
1644 
1645  kkint32 newSize = (kkint32)(0.5f + (float)QueueSize () * percentage / 100.0f);
1646  FeatureVectorListPtr randomSampled = ManufactureEmptyList (false);
1647 
1649  classes->SortByName ();
1650  MLClassList::iterator idx;
1651  for (idx = classes->begin (); idx != classes->end (); idx++)
1652  {
1653  MLClassPtr ic = *idx;
1655  examplesThisClass->RandomizeOrder ();
1656 
1657  kkint32 numExamplesThisClass = Max (minClassCount, ((kkint32)(0.5f + (float)(examplesThisClass->QueueSize ()) * percentage / 100.0f)));
1658  if (numExamplesThisClass > examplesThisClass->QueueSize ())
1659  numExamplesThisClass = examplesThisClass->QueueSize ();
1660  for (kkint32 zed = 0; zed < numExamplesThisClass; zed++)
1661  randomSampled->PushOnBack (examplesThisClass->IdxToPtr (zed));
1662  delete examplesThisClass; examplesThisClass = NULL;
1663  }
1664 
1665  delete classes; classes = NULL;
1666 
1667  randomSampled->RandomizeOrder ();
1668  return randomSampled;
1669 } /* ExtractRandomSampling */
1670 
1671 
1672 
1673 
1674 bool FeatureVectorList::MissingData () const // Returns true if 1 or more entries have missing data.
1675 {
1676  FeatureVectorList::const_iterator idx;
1677 
1678  FeatureVectorPtr i = NULL;
1679 
1680  for (idx = begin (); idx != end (); idx++)
1681  {
1682  i = *idx;
1683  if (i->MissingData ())
1684  return true;
1685  }
1686 
1687  return false;
1688 } /* MissingData */
1689 
1690 
1691 
1692 
1693 
1695 
1696 {
1697  kkint32 fieldNum;
1698 
1699  VectorInt symbolicFields;
1700  vector<VectorInt> lookUpTables;
1701 
1702  for (fieldNum = 0; fieldNum < (kkint32)newFileDesc->NumOfFields (); fieldNum++)
1703  {
1704  if (newFileDesc->Type (fieldNum) == AttributeType::Symbolic)
1705  {
1706  symbolicFields.push_back (fieldNum);
1707  VectorInt lookUpTable;
1708 
1709  kkint32 x;
1710  for (x = 0; x < fileDesc->Cardinality (fieldNum); x++)
1711  {
1712  const KKStr& nominalValue = fileDesc->GetNominalValue (fieldNum, x);
1713  kkint32 newCd = newFileDesc->LookUpNominalCode (fieldNum, nominalValue);
1714  if (newCd < 0)
1715  {
1716  KKStr errMsg;
1717  errMsg << "FeatureVectorList::ReSyncSymbolicData ***ERROR*** FieldNum[" << fieldNum << "] FieldName[" << newFileDesc->FieldName (fieldNum) << "] Nominal Value[" << nominalValue << "] is missing.";
1718  cerr << errMsg;
1719  throw KKException (errMsg);
1720  }
1721 
1722  lookUpTable.push_back (newCd);
1723  }
1724 
1725  lookUpTables.push_back (lookUpTable);
1726  }
1727  }
1728 
1729  FeatureVectorList::iterator idx;
1730  for (idx = begin (); idx != end (); idx++)
1731  {
1732  FeatureVectorPtr i = *idx;
1733 
1734  kkuint32 x;
1735 
1736  for (x = 0; x < symbolicFields.size (); x++)
1737  {
1738  fieldNum = symbolicFields[x];
1739  kkint32 oldCode = kkint32 (0.5f + i->FeatureData (fieldNum));
1740  kkint32 newCode = lookUpTables[x][oldCode];
1741  i->AddFeatureData (fieldNum, float (newCode));
1742  }
1743  }
1744 
1745  fileDesc = newFileDesc;
1746 } /* ReSyncSymbolicData */
1747 
1748 
1749 
1751  RunLog& log
1752  )
1753 {
1754  if (!fileDesc->SameExceptForSymbolicData (*(otherData.FileDesc ()), log))
1755  {
1756  KKStr errMsg;
1757  errMsg = "FeatureVectorList::SynchronizeSymbolicData ***ERROR*** The two datasets have more than SymbolicData differences.";
1758  log.Level (-1) << endl << errMsg << endl << endl;
1759  throw KKException (errMsg);
1760  }
1761 
1762  FileDescPtr newFileDesc = FileDesc::MergeSymbolicFields (*fileDesc, *(otherData.FileDesc ()), log);
1763 
1764  ReSyncSymbolicData (newFileDesc);
1765  otherData.ReSyncSymbolicData (newFileDesc);
1766 } /* SynchronizeSymbolicData */
1767 
1768 
1769 
1771  kkint32 level
1772  )
1773 {
1774  kkint32 curLevel = 0;
1775  KKStr fullLevelName = "";
1776  KKStr nextLevelName = className.ExtractToken ("_");
1777  while ((curLevel < level) && (!nextLevelName.Empty ()))
1778  {
1779  curLevel++;
1780  if (!fullLevelName.Empty ())
1781  fullLevelName << "_";
1782  fullLevelName << nextLevelName;
1783  nextLevelName = className.ExtractToken ("_");
1784  }
1785 
1786  return fullLevelName;
1787 } /* GetClassNameByHierarchyLevel */
1788 
1789 
1790 
1792 {
1793  FeatureVectorListPtr examplesLabeledForAppropriateLevel = ManufactureEmptyList (true);
1794 
1795  MLClassListPtr allClasses = ExtractListOfClasses ();
1796  allClasses->SortByName ();
1797 
1798  MLClassList::iterator idx;
1799  idx = allClasses->begin ();
1800 
1801  while (idx != allClasses->end ())
1802  {
1803  MLClassPtr curClass = *idx;
1804  KKStr curClassNameForThisLevel = GetClassNameByHierarchyLevel (curClass->Name (), level);
1805  if (curClassNameForThisLevel.Empty ())
1806  {
1807  idx++;
1808  continue;
1809  }
1810  else
1811  {
1812  MLClassPtr curClassForThisLevel = MLClass::CreateNewMLClass (curClassNameForThisLevel);
1813  MLClassPtr nextClassForThisLevel = curClassForThisLevel;
1814 
1815  while ((idx != allClasses->end ()) && (nextClassForThisLevel == curClassForThisLevel))
1816  {
1817  {
1818  FeatureVectorListPtr examplesForCurClass = ExtractExamplesForAGivenClass (curClass);
1819  FeatureVectorListPtr reLabeledExamples = examplesForCurClass->DuplicateListAndContents ();
1820  delete examplesForCurClass; examplesForCurClass = NULL;
1821 
1822  FeatureVectorList::iterator idx2;
1823  for (idx2 = reLabeledExamples->begin (); idx2 != reLabeledExamples->end (); idx2++)
1824  {
1825  FeatureVectorPtr fv = *idx2;
1826  fv->MLClass (curClassForThisLevel);
1827  }
1828  examplesLabeledForAppropriateLevel->AddQueue (*reLabeledExamples);
1829  reLabeledExamples->Owner (false);
1830  delete reLabeledExamples; reLabeledExamples = NULL;
1831  }
1832 
1833  // Get next Class to process.
1834  idx++;
1835  if (idx != allClasses->end ())
1836  {
1837  curClass = *idx;
1838  curClassNameForThisLevel = GetClassNameByHierarchyLevel (curClass->Name (), level);
1839  nextClassForThisLevel = MLClass::CreateNewMLClass (curClassNameForThisLevel);
1840  }
1841  }
1842  }
1843  }
1844 
1845  delete allClasses; allClasses = NULL;
1846 
1847  return examplesLabeledForAppropriateLevel;
1848 } /* CreateListForAGivenLevel */
1849 
1850 
1851 
1852 
1853 
1854 
1856 {
1857 
1858 public:
1860  {}
1861 
1862  bool operator() (FeatureVectorPtr p1,
1863  FeatureVectorPtr p2
1864  )
1865  {
1866  return (p1->BreakTie () < p2->BreakTie ());
1867  }
1868 }; /* BreakTieComparison */
1869 
1870 
1871 
1873 {
1874 
1875 public:
1877  {}
1878 
1879  bool operator() (FeatureVectorPtr p1,
1880  FeatureVectorPtr p2
1881  )
1882  {
1883  return (p1->BreakTie () > p2->BreakTie ());
1884  }
1885 }; /* BreakTieComparisonReversed */
1886 
1887 
1888 
1889 
1890 
1892 {
1893 
1894 public:
1896  {}
1897 
1898  bool operator() (FeatureVectorPtr p1,
1899  FeatureVectorPtr p2
1900  )
1901  {
1902  return (p1->Probability () < p2->Probability ());
1903  }
1904 }; /* ProbabilityComparison */
1905 
1906 
1907 
1909 {
1910 
1911 public:
1913  {}
1914 
1915  bool operator() (FeatureVectorPtr p1,
1916  FeatureVectorPtr p2
1917  )
1918  {
1919  return (p1->Probability () > p2->Probability ());
1920  }
1921 }; /* ProbabilityComparisonReversed */
1922 
1923 
1924 
1925 
1927 {
1928 public:
1930 
1931 
1932  bool operator () (FeatureVectorPtr p1,
1933  FeatureVectorPtr p2
1934  )
1935  {
1936  return (p1->ExampleFileName () < p2->ExampleFileName ());
1937  }
1938 }; /* ImageFileNameComparison */
1939 
1940 
1941 
1942 
1944 {
1945 public:
1947 
1948 
1949  bool operator () (FeatureVectorPtr p1,
1950  FeatureVectorPtr p2
1951  )
1952  {
1953  return (p1->ExampleFileName () > p2->ExampleFileName ());
1954  }
1955 
1956 }; /* ImageFileNameComparison */
1957 
1958 
1959 
1960 
1961 
1962 
1964 {
1965 public:
1967 
1968  bool operator () (FeatureVectorPtr p1,
1969  FeatureVectorPtr p2
1970  )
1971  {
1974 
1975  return (root1 < root2);
1976  }
1977 }; /* RootNameComparrison */
1978 
1979 
1980 
1982 {
1983 public:
1985 
1986  bool operator() (FeatureVectorPtr p1,
1987  FeatureVectorPtr p2
1988  )
1989  {
1992 
1993  return root1 > root2;
1994  }
1995 }; /* RootNameComparrisonReversed */
1996 
1997 
1998 
1999 
2000 
2002 {
2003 public:
2005 
2006  bool operator() (FeatureVectorPtr p1,
2007  FeatureVectorPtr p2
2008  )
2009  {
2010  if (p1->MLClass () == NULL)
2011  {
2012  if (p2->MLClass () != NULL)
2013  return true;
2014  }
2015 
2016  else if (p2->MLClass () != NULL)
2017  {
2018  const KKStr& n1 = p1->MLClass ()->UpperName ();
2019  const KKStr& n2 = p2->MLClass ()->UpperName ();
2020 
2021  if (n1 < n2)
2022  return true;
2023 
2024  else if (n1 > n2)
2025  return false;
2026  }
2027 
2029  }
2030 }; /* ClassNameComparrison */
2031 
2032 
2033 
2034 
2035 
2037 {
2038 public:
2040 
2041 
2042  bool operator() (FeatureVectorPtr p1,
2043  FeatureVectorPtr p2
2044  )
2045  {
2046  if (p1->MLClass () == NULL)
2047  {
2048  if (p2->MLClass () != NULL)
2049  return false;
2050  }
2051 
2052  else if (p2->MLClass () != NULL)
2053  {
2054  const KKStr& n1 = p1->MLClass ()->UpperName ();
2055  const KKStr& n2 = p2->MLClass ()->UpperName ();
2056 
2057  if (n1 < n2)
2058  return false;
2059 
2060  else if (n1 > n2)
2061  return true;
2062  }
2063 
2065  }
2066 }; /* ClassNameComparrisonReversed */
2067 
2068 
2069 
2070 
2071 
2072 
2073 
2074 
2075 void FeatureVectorList::SortByRootName (bool reversedOrder)
2076 {
2077  if (!reversedOrder)
2078  {
2080  sort (begin (), end (), c);
2081  }
2082  else
2083  {
2085  sort (begin (), end (), c);
2086  }
2087 
2088  curSortOrder = IFL_SortOrder::IFL_ByRootName;
2089 } /* SortByRootName */
2090 
2091 
2092 
2093 void FeatureVectorList::SortByClass (bool reversedOrder)
2094 {
2095  if (!reversedOrder)
2096  {
2098  sort (begin (), end (), c);
2099  }
2100  else
2101  {
2103  sort (begin (), end (), c);
2104  }
2105 
2106  curSortOrder = IFL_SortOrder::IFL_ByClassName;
2107 } /* SortByClass */
2108 
2109 
2110 
2111 
2112 
2113 void FeatureVectorList::SortByProbability (bool reversedOrder)
2114 {
2115  if (!reversedOrder)
2116  {
2118  sort (begin (), end (), c);
2119  }
2120  else
2121  {
2123  sort (begin (), end (), c);
2124  }
2125 
2126  curSortOrder = IFL_SortOrder::IFL_ByProbability;
2127 } /* SortByProbability */
2128 
2129 
2130 
2131 
2132 void FeatureVectorList::SortByBreakTie (bool reversedOrder)
2133 {
2134  if (!reversedOrder)
2135  {
2137  sort (begin (), end (), c);
2138  }
2139  else
2140  {
2142  sort (begin (), end (), c);
2143  }
2144 
2145  curSortOrder = IFL_SortOrder::IFL_ByBreakTie;
2146 } /* SortByProbability */
2147 
2148 
2149 
2150 
2151 
2152 void FeatureVectorList::SortByImageFileName (bool reversedOrder)
2153 {
2154  if (!reversedOrder)
2155  {
2157  sort (begin (), end (), c);
2158  }
2159  else
2160  {
2162  sort (begin (), end (), c);
2163  }
2164 
2165  curSortOrder = IFL_SortOrder::IFL_ByName;
2166 } /* SortByImageFileName */
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
void PushOnBack(FeatureVectorPtr image)
Overloading the PushOnBack function in KKQueue so we can monitor the Version and Sort Order...
MLClass * MLClassPtr
Definition: MLClass.h:46
void PushOnFront(FeatureVectorPtr image)
Overloading the PushOnFront function in KKQueue so we can monitor the Version and Sort Order...
void AddQueue(const FeatureVectorList &examplesToAdd)
Add the contents of &#39;examplesToAdd&#39; to the end of this list.
void ResetNumOfFeatures(kkint32 newNumOfFeatures)
KKMLL::AttributeTypeVector CreateAttributeTypeTable() const
FeatureVectorListPtr StratifyAmoungstClasses(kkint32 numOfFolds, RunLog &log)
KKStrListPtr ExtractDuplicatesByExampleFileName()
Provides a detailed description of the attributes of a dataset.
Definition: FileDesc.h:72
void SortByBreakTie(bool reversedOrder=false)
void AddSingleExample(FeatureVectorPtr _imageFeatures)
Same as PushOnBack.
kkint32 MemoryConsumedEstimated() const
Definition: KKStr.cpp:766
__int32 kkint32
Definition: KKBaseTypes.h:88
float FloatMin
Definition: KKBaseTypes.cpp:21
Maintains a list of classes and their associated integer index.
Definition: MLClass.h:459
MLClassPtr MLClass() const
bool AllFieldsAreNumeric() const
Returns true if all fields are numeric, no nominal fields.
kkuint32 NumOfFields() const
Definition: FileDesc.h:197
FeatureVectorList(const FeatureVectorList &examples, bool _owner)
Create a duplicate list, depending on the &#39;_owner&#39; parameter may also duplicate the contents...
virtual FeatureVectorListPtr Duplicate(bool _owner) const
Creates a duplicate of list using the same container.
kkint32 GetClassCount(MLClassPtr c) const
Returns number of examples for a specific Class (MLClass).
FeatureVectorPtr BinarySearchByName(const KKStr &_imageFileName) const
Will search for the example with the same name as &#39;_imageFileName&#39;.
float FeatureData(kkint32 featureNum) const
virtual kkint32 MemoryConsumedEstimated() const
ClassProbListPtr GetClassDistribution() const
Keeps track of selected features.
bool MissingData() const
True indicates that one or more features were missing.
FeatureVector(kkint32 _numOfFeatures)
KKMLL::AttributeType Type(kkint32 fieldNum) const
Definition: FileDesc.cpp:370
KKStr ExtractToken(const char *delStr="\n\t\r ")
Definition: KKStr.cpp:2969
kkint32 NumOfFeatures() const
Number of features in this FeatureVector.
virtual void PushOnBack(ClassProbPtr cp)
Definition: ClassProb.cpp:212
DuplicateImages(FeatureVectorListPtr _examples, RunLog &_log)
You would use this instance to search for duplicates in the list of &#39;examples&#39;.
float FloatMax
Definition: KKBaseTypes.cpp:20
std::vector< int > VectorInt
Definition: KKBaseTypes.h:138
float OrigSize() const
The value of Feature[0] before normalization.
MLClassListPtr ExtractListOfClasses() const
bool operator>(const KKStr &right) const
Definition: KKStr.cpp:1619
KKStr & operator=(const char *src)
Definition: KKStr.cpp:1442
void PushOnBack(ClassStatisticPtr stat)
FeatureNumList AllFeatures()
Will return a FeatureNumList instance with all features selected.
const FileDescPtr FileDesc() const
ClassStatisticPtr LookUpByMLClass(MLClassPtr mlClass) const
void PrintClassStatisticsHTML(std::ostream &o) const
float Probability() const
The probability assigned by classifier to the predicted class.
const KKStr & MLClassName() const
Name of class that this example is assigned to.
bool SameExceptForSymbolicData(const FileDesc &otherFd, RunLog &log) const
Definition: FileDesc.cpp:472
void RemoveEntriesWithMissingFeatures(RunLog &log)
ClassStatistic * ClassStatisticPtr
virtual FeatureVectorListPtr DuplicateListAndContents() const
Creates a duplicate of list and also duplicates it contents.
void SortByProbability(bool reversedOrder=false)
KKMLL::AttributeType FeatureType(kkint32 featureNum) const
Returns the type of attribute for specified &#39;featureNum&#39;.
virtual FeatureVectorListPtr ManufactureEmptyList(bool _owner) const
Creates an instance of a Empty FeatureVectorList.
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
const KKStr & FieldName(kkint32 fieldNum) const
Definition: FileDesc.cpp:387
void SortByImageFileName(bool reversedOrder=false)
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
VectorDouble ExtractMeanFeatureValues()
void AddFeatureData(kkint32 _featureNum, float _featureData)
float BreakTie() const
The difference in probability between the two most likely classes.
VectorInt32 CreateCardinalityTable() const
Definition: FileDesc.cpp:430
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector&#39;s.
kkint32 LookUpNominalCode(kkint32 fieldNum, const KKStr &nominalValue) const
Definition: FileDesc.cpp:321
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
virtual FeatureVectorPtr Duplicate() const
MLClassIndexList(const MLClassList &_classes)
Definition: MLClass.cpp:1544
FeatureVector(const FeatureVector &_example)
Container class for FeatureVector derived objects.
void PrintFeatureStatisticsByClass(std::ostream &o) const
void CalcStatsForFeatureNum(kkint32 _featureNum, kkint32 &_count, float &_total, float &_mean, float &_var, float &_stdDev)
KKTHread * KKTHreadPtr
const float * FeatureDataConst() const
const KKStr & GetNominalValue(kkint32 fieldNum, kkint32 code) const
Definition: FileDesc.cpp:395
bool AllFieldsAreNumeric() const
Allows the user to quickly determine if there are no nominal fields.
Definition: FileDesc.cpp:706
void AllocateFeatureDataArray()
Used by container classes such as &#39;FeatureVectorList&#39;. This way they can determine real underlying cl...
kkuint32 Count() const
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
Used to record probability for a specified class; and a list of classes.
Definition: ClassProb.h:25
bool Empty() const
Definition: KKStr.h:241
FeatureVectorListPtr ExtractExamplesForAGivenClass(MLClassPtr _mlClass, kkint32 _maxToExtract=-1, float _minSize=-1.0f) const
kkint32 NumOfFeatures() const
void SplitImagesAmongstFolds(kkint32 numOfFolds, kkint32 maxImagesPerClass, FeatureVectorListPtr *folds, FeatureVectorListPtr src)
void SortByRootName(bool reversedOrder=false)
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
vector< kkint32 > CreateCardinalityTable() const
FeatureVectorList(MLClassList &_mlClasses, FeatureVectorList &_examples)
Will create a list of consisting of the subset of examples in &#39;_examples&#39; which are members of Images...
void ResetFileDesc(FileDescPtr newFileDesc)
ClassProbList(bool owner)
Definition: ClassProb.cpp:48
void SaveOrderingOfImages(const KKStr &fileName, bool &successful)
Will save into a file the current ordering of FeatureVector instances in list.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
ClassStatisticListPtr GetClassStatistics() const
Returns the number of FeatureVectors per class.
static const KKStr & EmptyStr()
Static method that returns an Empty String.
Definition: KKStr.cpp:3453
AttributeType
Definition: Attribute.h:36
MLClassPtr MLClass() const
Class that is example is assigned to.
FeatureVectorListPtr OrderUsingNamesFromAFile(const KKStr &fileName, RunLog &log)
Using list of ImageFileNames in a file(&#39;fileName&#39;) create a new FeatureVectorList instance with examp...
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
void MLClass(MLClassPtr _mlClass)
Assign a class to this example.
Definition: FeatureVector.h:74
FeatureVectorListPtr StratifyAmoungstClasses(MLClassListPtr mlClasses, kkint32 maxImagesPerClass, kkint32 numOfFolds, RunLog &log)
bool SameExceptForSymbolicData(const FeatureVectorList &otherData, RunLog &log) const
FileDesc * FileDescPtr
void FeatureData(kkint32 _featureNum, float _featureValue)
Assign a value to a specific feature number for the feature vector.
bool operator!=(const KKStr &right) const
Definition: KKStr.cpp:1558
static FeatureNumList AllFeatures(FileDescPtr fileDesc)
Create a FeatureNumList object where all features are selected, except ones that are flagged as Ignor...
void PurgeDuplicates(FeatureVectorListPtr examples, bool allowDupsInSameClass, std::ostream *report)
Delete duplicate examples from FeatureVectorList structure provided in constructor.
float TotalOfFeatureData() const
Returns the total of all Feature Attributes for this feature vector.
bool operator==(const KKStr &right) const
Definition: KKStr.cpp:1550
const KKStr & UpperName() const
Definition: MLClass.h:155
ClassStatisticList * ClassStatisticListPtr
const KKStr & Name() const
Definition: MLClass.h:154
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
FeatureVectorListPtr ExtractRandomSampling(float percentage, kkint32 minClassCount)
Will return a random sampling by class of our FeatureVector&#39;s; with a minimum per class of &#39;minClassC...
FeatureVectorPtr LookUpByRootName(const KKStr &_rootName)
Returns a pointer to the FeatureVector who&#39;s ExampleFileName rootname = _rootName *...
Used by routines that retrieve Class statistics from FeatureVectorList instances. ...
bool operator==(FeatureVector &other_example) const
IFL_SortOrder
Represents the different orders that a list of FeatureVector instances in a FeatureVectorList object ...
FeatureVectorListPtr ExtractExamplesForHierarchyLevel(kkuint32 level)
Will create a list of FeatureVectors where the class assignment will reflect the specified Hierarchy ...
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
FeatureVectorListPtr ExtractDuplicatesByRootImageFileName()
Returns: a list of &#39;FeatureVector&#39; objects that have duplicate root file names.
float MajorityClassFraction() const
KKStr GetClassNameByHierarchyLevel(KKStr className, kkint32 level)
void ReSyncSymbolicData(FileDescPtr newFileDesc)
AttributeTypeVector CreateAttributeTypeTable() const
Definition: FileDesc.cpp:419
FILE * osFOPEN(const char *fileName, const char *mode)
Definition: OSservices.cpp:74
const KKStr & FieldName(kkint32 featureNum) const
Returns name of Attribute Field.
KKStrList(bool owner)
Definition: KKStr.cpp:4485
ClassStatistic(MLClassPtr _mlClass, kkuint32 _count)
FeatureVectorListPtr CreateListForAGivenLevel(kkint32 level)
Will create a list of FeatureVectors where the class assignment will reflect the specified Hierarchy ...
Detects duplicate images in a given FeaureVectorList objects.
KKStr & operator=(const KKStr &src)
Definition: KKStr.cpp:1390
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)
bool operator<(const KKStr &right) const
Definition: KKStr.cpp:1635
kkint32 FeatureCardinality(kkint32 featureNum) const
Returns the number of values defined for a Nominal Field.
MLClassList * MLClassListPtr
Definition: MLClass.h:49
const KKStr & PredictedClassName() const
KKStr osGetRootNameWithExtension(const KKStr &fullFileName)
void RemoveDuplicateEntries(bool allowDupsInSameClass, RunLog &runLog)
const KKStr & ClassName() const
Name of class that this example is assigned to.
KKStr ClassStatisticsStr() const
kkint32 Cardinality(kkint32 fieldNum) const
Definition: FileDesc.cpp:341
KKException(const KKStr &_exceptionStr)
Definition: KKException.cpp:45
ClassProb(MLClassPtr _classLabel, double _probability, float _votes)
Definition: ClassProb.cpp:22
void SynchronizeSymbolicData(FeatureVectorList &otherData, RunLog &log)
Maintains a list of MLClass instances.
Definition: MLClass.h:233
virtual kkint32 MemoryConsumedEstimated() const
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
static FileDescPtr MergeSymbolicFields(const FileDesc &left, const FileDesc &right, RunLog &log)
Merges the Symbolic fields of two different &#39;FileDesc&#39; instances producing a new instance of &#39;FileDes...
Definition: FileDesc.cpp:723
FeatureVectorPtr LookUpByImageFileName(const KKStr &_imageFileName) const
Returns a pointer to the FeatureVector which has &#39;_imageFileName&#39;.
FeatureVectorListPtr ExtractExamplesForClassList(MLClassListPtr classes)
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
MLClassPtr MLClassForGivenHierarchialLevel(KKB::kkuint16 level) const
Definition: MLClass.cpp:427
const KKStr & AttributeTypeToStr(AttributeType type)
Definition: Attribute.cpp:422
void SortByClass(bool reversedOrder=false)
KKStr FeatureTypeStr(kkint32 featureNum) const
std::vector< double > VectorDouble
Vector of doubles.
Definition: KKBaseTypes.h:148
FeatureVectorList * FeatureVectorListPtr
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
const KKStr & ExampleFileName() const
Name of file that this FeatureVector was computed from.
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
KKStr osGetRootName(const KKStr &fullFileName)
void ResetNumOfFeaturs(kkint32 newNumOfFeatures)
void osDisplayWarning(KKStr _message)
bool operator()(FeatureVectorPtr p1, FeatureVectorPtr p2)
void PrintClassStatistics(std::ostream &o) const