20 #ifndef _CONFUSIONMATRIX_H_ 21 #define _CONFUSIONMATRIX_H_ 25 #include "base/Vector2d.h" 26 #include "base/Optionpk.h" 30 enum CM_FORMAT { ASCII = 0, LATEX = 1, HTML = 2 };
39 short size()
const {
return m_results.size();};
40 void resize(
short nclass);
41 void setClassNames(
const std::vector<std::string>& classNames,
bool doSort=
false);
42 void pushBackClassName(
const std::string& className,
bool doSort=
false);
44 void setResult(
const std::string& theRef,
const std::string& theClass,
double theResult);
45 void incrementResult(
const std::string& theRef,
const std::string& theClass,
double theIncrement);
47 double nReference(
const std::string& theRef)
const;
48 double nReference()
const;
49 double nClassified(
const std::string& theRef)
const;
50 int nClasses()
const {
return m_classes.size();};
51 std::string getClass(
int iclass)
const {assert(iclass>=0);assert(iclass<m_classes.size());
return m_classes[iclass];};
52 int getClassIndex(std::string className)
const {
54 for(index=0;index<m_classes.size();++index){
55 if(m_classes[index]==className)
58 if(index>=m_classes.size())
68 std::vector<std::string> getClassNames()
const {
return m_classes;};
70 double pa(
const std::string& theClass,
double* se95=NULL)
const;
71 double ua(
const std::string& theClass,
double* se95=NULL)
const;
72 double oa(
double* se95=NULL)
const;
73 int pa_pct(
const std::string& theClass,
double* se95=NULL)
const;
74 int ua_pct(
const std::string& theClass,
double* se95=NULL)
const;
75 int oa_pct(
double* se95=NULL)
const;
83 void sortClassNames();
85 void reportSE95(
bool doReport) {m_se95=doReport;};
86 void setFormat(
const CM_FORMAT& theFormat) {m_format=theFormat;};
87 void setFormat(
const std::string theFormat) {m_format=getFormat(theFormat);};
88 CM_FORMAT getFormat()
const {
return m_format;};
90 static const CM_FORMAT getFormat(
const std::string theFormat){
91 if(theFormat==
"ascii")
return(ASCII);
92 else if(theFormat==
"latex")
return(LATEX);
94 std::string errorString=
"Format not supported: ";
95 errorString+=theFormat;
96 errorString+=
" use ascii or latex";
101 friend std::ostream& operator<<(std::ostream& os,
const ConfusionMatrix &cm){
102 std::ostringstream streamLine;
106 std::string fieldSeparator=
" ";
107 std::string lineSeparator=
"";
108 std::string mathMode=
"";
109 switch(cm.getFormat()){
111 fieldSeparator=
" & ";
112 lineSeparator=
"\\\\";
130 doa = cm.oa(&se95_oa);
132 if(cm.getFormat()==LATEX){
133 os <<
"\\documentclass{article}" << std::endl;
134 os <<
"\\begin{document}" << std::endl;
136 os <<
"Kappa = " << mathMode << cm.kappa() << mathMode ;
137 os <<
", Overall Acc. = " << mathMode << 100.0*cm.oa() << mathMode ;
139 os <<
" (" << mathMode << se95_oa << mathMode <<
")";
142 if(cm.getFormat()==LATEX){
143 os <<
"\\begin{tabular}{@{}l";
144 for(
int iclass=0;iclass<cm.nClasses();++iclass)
146 os <<
"}" << std::endl;
147 os <<
"\\hline" << std::endl;
151 for(
int iclass=0;iclass<cm.nClasses();++iclass)
152 os << fieldSeparator << cm.m_classes[iclass];
153 os << lineSeparator << std::endl;
154 if(cm.getFormat()==LATEX)
155 os <<
"\\hline" << std::endl;
156 assert(cm.m_classes.size()==cm.m_results.size());
157 for(
int irow=0;irow<cm.m_results.size();++irow){
158 os << cm.m_classes[irow];
159 for(
int icol=0;icol<cm.m_results[irow].size();++icol)
160 os << fieldSeparator << cm.m_results[irow][icol];
161 os << lineSeparator<< std::endl;
163 if(cm.getFormat()==LATEX){
164 os <<
"\\hline" << std::endl;
170 for(
int iclass=0;iclass<cm.nClasses();++iclass){
171 dua=cm.ua_pct(cm.m_classes[iclass],&se95_ua);
172 os << fieldSeparator << dua;
174 os <<
" (" << se95_ua <<
")";
176 os << lineSeparator<< std::endl;
178 for(
int iclass=0;iclass<cm.nClasses();++iclass){
179 dpa=cm.pa_pct(cm.m_classes[iclass],&se95_ua);
180 os << fieldSeparator << dpa;
182 os <<
" (" << se95_pa <<
")";
184 os << lineSeparator<< std::endl;
185 if(cm.getFormat()==LATEX){
186 os <<
"\\end{tabular}" << std::endl;
187 os <<
"\\end{document}" << std::endl;
192 std::vector<std::string> m_classes;