KSquare Utilities
ClassStatistic.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <algorithm>
3 #include <iostream>
4 #include <map>
5 #include <vector>
6 #include <fstream>
7 #include "MemoryDebug.h"
8 using namespace std;
9 
10 
11 #include "KKBaseTypes.h"
12 #include "KKQueue.h"
13 using namespace KKB;
14 
15 
16 #include "ClassStatistic.h"
17 #include "MLClass.h"
18 using namespace KKMLL;
19 
20 
21 
23  mlClass (right.mlClass),
24  count (right.count)
25 {
26 }
27 
28 
30  kkuint32 _count
31  ):
32  mlClass (_mlClass),
33  count (_count)
34 {}
35 
36 
37 
38 const KKStr& ClassStatistic::Name () const
39 {
40  if (mlClass)
41  return mlClass->Name ();
42  else
43  return KKStr::EmptyStr ();
44 } /* Name */
45 
46 
47 
49 {
50  if (mlClass != right.MLClass ())
51  {
52  cerr << std::endl << std::endl << std::endl
53  << "ClassStatistic::operator+= Class Names Do Not Match" << std::endl
54  << " LeftClass[" << mlClass->Name () << "] RightClass[" << right.Name () << "[" << std::endl
55  << std::endl;
56  return *this;
57  }
58 
59  count += right.Count ();
60 
61  return *this;
62 }
63 
64 
65 
66 
69 {
70 }
71 
72 
73 
75 {
76  KKQueue<ClassStatistic>::PushOnBack (stat);
77  imageClassIndex.insert (pair<MLClassPtr, ClassStatisticPtr> (stat->MLClass (), stat));
78 }
79 
80 
81 
83 {
84  KKQueue<ClassStatistic>::PushOnFront (stat);
85  imageClassIndex.insert (pair<MLClassPtr, ClassStatisticPtr> (stat->MLClass (), stat));
86 }
87 
88 
89 
90 
92 {
93  ClassStatisticList::const_iterator idx;
94  for (idx = right.begin (); idx != right.end (); idx++)
95  {
96  ClassStatisticPtr rightStat = *idx;
97  ClassStatisticPtr leftStat = LookUpByMLClass (rightStat->MLClass ());
98 
99  if (leftStat)
100  (*leftStat) += (*rightStat);
101  else
102  PushOnBack (new ClassStatistic (*rightStat));
103  }
104 
105  return *this;
106 } /* operator+= */
107 
108 
109 
110 
111 
113 {
114  map<MLClassPtr, ClassStatisticPtr>::const_iterator idx;
115  idx = imageClassIndex.find (mlClass);
116  if (idx == imageClassIndex.end ())
117  return NULL;
118  else
119  return idx->second;
120 }
121 
122 
123 
124 
126 {
127 public:
129 
132  )
133  {
135  }
136 }; /* ClassStatisticSortComparrison */
137 
138 
139 
141 {
142 public:
144 
147  )
148  {
149  if (p1->Count () > p2->Count ())
150  return true;
151 
152  else if (p1->Count () < p2->Count ())
153  return false;
154 
156  }
157 }; /* ManagedClasssesSortByImageCount */
158 
159 
160 
161 
162 
164 {
166  //KKQueue<ClassStatistic>::Sort (&c);
167  sort (begin (), end (), c);
168 } /* Sort */
169 
170 
171 
172 
174 {
176  //KKQueue<ClassStatistic>::Sort (&c);
177  sort (begin (), end (), c);
178 }
179 
180 
181 
182 void ClassStatisticList::PrintReport (ostream& r)
183 {
184  r << endl
185  << "Class Name" << "\t" << "Count" << endl;
186 
188  iterator idx;
189  for (idx = begin (); idx != end (); idx++)
190  {
191  ClassStatisticPtr cs = *idx;
192  r << cs->Name () << "\t" << cs->Count () << endl;
193  }
194  r << endl;
195 }
196 
197 
199 {
200  std::map<MLClassPtr, ClassStatisticPtr>::const_iterator idx;
201  idx = imageClassIndex.find (mlClass);
202  if (idx == imageClassIndex.end ())
203  return -1;
204  else
205  return idx->second->Count ();
206 }
MLClass * MLClassPtr
Definition: MLClass.h:46
const KKStr & Name() const
bool operator()(ClassStatisticPtr p1, ClassStatisticPtr p2)
__int32 kkint32
Definition: KKBaseTypes.h:88
MLClassPtr MLClass() const
const ClassStatistic & operator+=(const ClassStatistic &right)
void PushOnBack(ClassStatisticPtr stat)
ClassStatisticPtr LookUpByMLClass(MLClassPtr mlClass) const
ClassStatistic(const ClassStatistic &right)
ClassStatistic * ClassStatisticPtr
void PrintReport(std::ostream &r)
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
KKTHread * KKTHreadPtr
kkuint32 Count() const
const ClassStatisticList & operator+=(const ClassStatisticList &right)
kkint32 operator[](MLClassPtr mlClass)
void PushOnFront(ClassStatisticPtr stat)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
static const KKStr & EmptyStr()
Static method that returns an Empty String.
Definition: KKStr.cpp:3453
const KKStr & UpperName() const
Definition: MLClass.h:155
const KKStr & Name() const
Definition: MLClass.h:154
Used by routines that retrieve Class statistics from FeatureVectorList instances. ...
bool operator()(ClassStatisticPtr p1, ClassStatisticPtr p2)
ClassStatistic(MLClassPtr _mlClass, kkuint32 _count)
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