KSquare Utilities
KKMLL::ClassificationBiasMatrix Class Reference

Assists in adjusting a Classifiers output for bias of a classifier. More...

#include <ClassificationBiasMatrix.h>

Public Types

typedef ClassificationBiasMatrixClassificationBiasMatrixPtr
 
typedef KKB::DateTime DateTime
 
typedef KKB::KKStr KKStr
 
typedef KKB::Matrix Matrix
 
typedef KKB::MatrixPtr MatrixPtr
 
typedef KKB::RunLog RunLog
 

Public Member Functions

 ClassificationBiasMatrix (RunLog &_runLog)
 Will construct an instance as defined in the Paper. More...
 
 ClassificationBiasMatrix (const ClassificationBiasMatrix &cbm)
 
 ClassificationBiasMatrix (MLClassList &classes, RunLog &_runLog)
 
 ClassificationBiasMatrix (const KKStr &_configFileName, MLClassList &_classes, RunLog &_runLog)
 Construct a ClassificationBiasMatrix instance from the parameter file for '_configFileName'. More...
 
 ClassificationBiasMatrix (const ConfusionMatrix2 &cm, RunLog &_runLog)
 Construct a ClassificationBiasMatrix instance from a ConfusionMatrix object. More...
 
 ~ClassificationBiasMatrix ()
 
DateTime DateTimeFileWritten () const
 
void PerformAdjustmnts (const VectorDouble &classifiedCounts, VectorDouble &adjCounts, VectorDouble &stdErrors)
 
void PrintAdjustedResults (ostream &sw, const VectorDouble &classifiedCounts)
 
void PrintBiasMatrix (ostream &sw)
 
void TestPaperResults (ostream &sw)
 
void WriteXML (ostream &o)
 

Static Public Member Functions

static ClassificationBiasMatrixPtr BuildFromIstreamXML (istream &f, MLClassList &classes, RunLog &log)
 Will construct a ClassificationBiasMatrix instance from a input stream. More...
 

Detailed Description

Assists in adjusting a Classifiers output for bias of a classifier.

See the paper:

"Estimating the Taxonomic composition of a sample when individuals are classified with error"
by Andrew Solow, Cabll Davis, Qiao Hu
Woods Hole Ocanographic Institution, Woods Hole Massachusetts
Marine Ecology Progresss Series
published 2006-july-06; vol 216:309-311

This class uses the results of a previous 10 fold cross validation confusion matrix to adjust the results of a classification run. The application CrossValidation will create a parameter file in the directory "${xxxxxHomeDir}\\Classifier\\TrainingModels\\Save" that contains the confusion matrix. The option "-BiasMatrix" tells the CrossValidation program to generate this parameter file. It will have the same name as the Configuration file with the extension ".BiasMatrix.txt" appended to the end. There is a managed version of this class in PicesInterface called PicesInterface::ClassificationBiasMatrix

Definition at line 44 of file ClassificationBiasMatrix.h.

Member Typedef Documentation

Constructor & Destructor Documentation

ClassificationBiasMatrix::ClassificationBiasMatrix ( RunLog _runLog)

Will construct an instance as defined in the Paper.

Definition at line 159 of file ClassificationBiasMatrix.cpp.

References KKB::DateTime::DateTime(), KKB::KKStr::KKStr(), KKMLL::MLClassList::MLClassList(), and KKB::VectorKKStr::VectorKKStr().

159  :
160  biasFileName (),
161  classes (new MLClassList ()),
162  configFileName (),
163  configFileNameFromMatrixBiasFile (),
164  configDateTime (),
165  counts (NULL),
166  dateTimeFileWritten (),
167  errMsgs (),
168  numClasses (0),
169  probabilities (NULL),
170  runLog (_runLog),
171  valid (true)
172 {
173  BuildTestMatrix ();
174 
175  //ofstream sw ("c:\\Temp\\ClassificationBiasMatrix_Test.txt");
176  //TestPaperResults (sw);
177  //sw.close ();
178 }
Maintains a list of MLClass instances.
Definition: MLClass.h:233
ClassificationBiasMatrix::ClassificationBiasMatrix ( const ClassificationBiasMatrix cbm)

Definition at line 84 of file ClassificationBiasMatrix.cpp.

References KKB::DateTime::DateTime(), KKB::KKStr::KKStr(), KKB::Matrix::Matrix(), KKMLL::MLClassList::MLClassList(), and KKB::VectorKKStr::VectorKKStr().

84  :
85  biasFileName (cbm.biasFileName),
86  classes (NULL),
87  configFileName (cbm.configFileName),
88  configFileNameFromMatrixBiasFile (cbm.configFileNameFromMatrixBiasFile),
89  configDateTime (cbm.configDateTime),
90  counts (NULL),
91  dateTimeFileWritten (cbm.dateTimeFileWritten),
92  errMsgs (),
93  numClasses (cbm.numClasses),
94  probabilities (NULL),
95  runLog (cbm.runLog),
96  valid (true)
97 
98 {
99  if (cbm.counts)
100  counts = new Matrix (*cbm.counts);
101 
102  if (cbm.classes)
103  classes = new MLClassList (*cbm.classes);
104 
105  if (cbm.probabilities)
106  probabilities = new Matrix (*cbm.probabilities);
107 }
Maintains a list of MLClass instances.
Definition: MLClass.h:233
ClassificationBiasMatrix::ClassificationBiasMatrix ( MLClassList classes,
RunLog _runLog 
)

Definition at line 136 of file ClassificationBiasMatrix.cpp.

References KKB::DateTime::DateTime(), KKB::KKStr::KKStr(), KKMLL::MLClassList::MLClassList(), and KKB::VectorKKStr::VectorKKStr().

Referenced by BuildFromIstreamXML().

138  :
139  biasFileName (),
140  classes (new MLClassList (_classes)),
141  configFileName (),
142  configFileNameFromMatrixBiasFile (),
143  configDateTime (),
144  counts (NULL),
145  dateTimeFileWritten (),
146  errMsgs (),
147  numClasses (0),
148  probabilities (NULL),
149  runLog (_runLog),
150  valid (true)
151 
152 {
153  numClasses = classes->QueueSize ();
154  DeclareMatrix ();
155 }
kkint32 QueueSize() const
Definition: KKQueue.h:313
Maintains a list of MLClass instances.
Definition: MLClass.h:233
ClassificationBiasMatrix::ClassificationBiasMatrix ( const KKStr _configFileName,
MLClassList _classes,
RunLog _runLog 
)

Construct a ClassificationBiasMatrix instance from the parameter file for '_configFileName'.

Parameters
[in]_configFileNameThe name of the BiasMatrix file will be derived from the configuration file name. the term '_BiasMatrix.txt' will be appended onto the end.
[in]_classesList of classes that you are expecting to be in the 'BiasMatrix' file.
[in,out]_runLogLogging file to use.

Definition at line 34 of file ClassificationBiasMatrix.cpp.

References KKB::DateTime::DateTime(), KKB::KKStr::KKStr(), KKMLL::MLClassList::MLClassList(), KKB::KKStr::operator+(), KKB::KKStr::operator=(), KKB::osRemoveExtension(), and KKB::VectorKKStr::VectorKKStr().

37  :
38  biasFileName (),
39  classes (new MLClassList (_classes)),
40  configFileName (_configFileName),
41  configFileNameFromMatrixBiasFile (),
42  configDateTime (),
43  counts (NULL),
44  dateTimeFileWritten (),
45  errMsgs (),
46  numClasses (0),
47  probabilities (NULL),
48  runLog (_runLog),
49  valid (true)
50 {
51  biasFileName = osRemoveExtension (configFileName) + ".BiasMatrix.txt";
52 
53  ifstream sr (biasFileName.Str ());
54 
55  if (!sr.is_open ())
56  {
57  valid = false;
58  KKStr errorMsg = "Error opening ConfigFileName[" + configFileName + "]";
59  errMsgs.push_back (errorMsg);
60  return;
61  }
62 
63  DeclareMatrix ();
64 
65  try
66  {
67  ReadXML (sr);
68  }
69  catch (const exception& e)
70  {
71  valid = false;
72  errMsgs.push_back (e.what ());
73  }
74  catch (...)
75  {
76  valid = false;
77  errMsgs.push_back ("ClassificationBiasMatrix Exception occurred reading XML File");
78  }
79  sr.close ();
80 }
KKStr osRemoveExtension(const KKStr &_fullFileName)
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
Maintains a list of MLClass instances.
Definition: MLClass.h:233
ClassificationBiasMatrix::ClassificationBiasMatrix ( const ConfusionMatrix2 cm,
RunLog _runLog 
)

Construct a ClassificationBiasMatrix instance from a ConfusionMatrix object.

Parameters
[in]cmConfusion Matrix to get parameters from.
[in,out]_runLogLogging file to use.

Definition at line 112 of file ClassificationBiasMatrix.cpp.

References KKB::DateTime::DateTime(), KKB::KKStr::KKStr(), KKMLL::ConfusionMatrix2::MLClasses(), KKMLL::MLClassList::MLClassList(), and KKB::VectorKKStr::VectorKKStr().

114  :
115  biasFileName (),
116  classes (NULL),
117  configFileName (),
118  configFileNameFromMatrixBiasFile (),
119  configDateTime (),
120  counts (NULL),
121  dateTimeFileWritten (),
122  errMsgs (),
123  numClasses (0),
124  probabilities (NULL),
125  runLog (_runLog),
126  valid (true)
127 {
128  classes = new MLClassList (cm.MLClasses ());
129  numClasses = classes->QueueSize ();
130  DeclareMatrix ();
131  BuildFromConfusionMatrix (cm);
132 }
kkint32 QueueSize() const
Definition: KKQueue.h:313
const MLClassList & MLClasses() const
Maintains a list of MLClass instances.
Definition: MLClass.h:233
ClassificationBiasMatrix::~ClassificationBiasMatrix ( )

Definition at line 183 of file ClassificationBiasMatrix.cpp.

184 {
185  delete probabilities;
186  probabilities = NULL;
187  delete counts;
188  counts = NULL;
189  delete classes;
190  classes = NULL;
191 }

Member Function Documentation

ClassificationBiasMatrixPtr ClassificationBiasMatrix::BuildFromIstreamXML ( istream &  f,
MLClassList classes,
RunLog log 
)
static

Will construct a ClassificationBiasMatrix instance from a input stream.

Parameters
[in]fInput Stream.
[in]classesList of classes we expect to find in the input stream f.
[in,out]logLogging File.

Definition at line 195 of file ClassificationBiasMatrix.cpp.

References ClassificationBiasMatrix().

199 {
200  ClassificationBiasMatrixPtr cbm = new ClassificationBiasMatrix (classes, log);
201  cbm->ReadXML (f);
202  return cbm;
203 } /* BuildFromIstreamXML */
Assists in adjusting a Classifiers output for bias of a classifier.
ClassificationBiasMatrix(RunLog &_runLog)
Will construct an instance as defined in the Paper.
DateTime KKMLL::ClassificationBiasMatrix::DateTimeFileWritten ( ) const
inline

Definition at line 105 of file ClassificationBiasMatrix.h.

105 {return dateTimeFileWritten;}
void ClassificationBiasMatrix::PerformAdjustmnts ( const VectorDouble classifiedCounts,
VectorDouble adjCounts,
VectorDouble stdErrors 
)

Definition at line 565 of file ClassificationBiasMatrix.cpp.

References KKB::Matrix::Inverse(), KKB::Matrix::Matrix(), KKB::Matrix::operator*(), KKB::Matrix::operator[](), KKB::Row::operator[](), and KKB::Matrix::Transpose().

Referenced by PrintAdjustedResults().

569 {
570  // For description of calc's see the paper:
571  // "Estimating the Taxonomic composition of a sample when individuals are classified with error"
572  // by Andrew Solow, Cabll Davis, Qiao Hu
573  // Woods Hole Oceanographic Institution, Woods Hole Massachusetts
574  // Marine Ecology Progress Series
575  // published 2006-july-06; vol 216:309-311
576 
577  if (classifiedCounts.size () != (kkuint32)numClasses)
578  {
579  KKStr errMsg = "ClassificationBiasMatrix::PerformAdjustmnts ***ERROR*** Disagreement in length of classifiedCounts[" +
580  StrFormatInt ((kkint32)classifiedCounts.size (), "ZZZ0") +
581  "] and Prev Defined ClassList[" + StrFormatInt (numClasses, "ZZZ0") + "].";
582  runLog.Level (-1) << errMsg << endl;
583  valid = false;
584  throw KKException (errMsg);
585  }
586 
587  kkint32 x = 0;
588  kkint32 i, j, k;
589 
590 
591  // We need to deal with the special case when one entry in the probability diagonal is zero.
592  {
593  for (x = 0; x < numClasses; x++)
594  {
595  if ((*probabilities)[x][x] == 0.0)
596  {
597  // This will cause the inversion of the diagonal matrix to fail. To deal
598  // with this situation; I will steal some probability from other buckets on
599  // same row.
600 
601  double totalAmtStolen = 0.0;
602  double percentToSteal = 0.01;
603  for (i = 0; i < numClasses; i++)
604  {
605  if ((*probabilities)[x][i] != 0.0)
606  {
607  double amtToSteal = (*probabilities)[x][i] * percentToSteal;
608  (*probabilities)[x][i] = (*probabilities)[x][i] - amtToSteal;
609  totalAmtStolen += amtToSteal;
610  }
611  }
612 
613  (*probabilities)[x][x] = totalAmtStolen;
614  }
615  }
616  }
617 
618  Matrix m (numClasses, 1);
619  for (x = 0; x < numClasses; x++)
620  m[x][0] = classifiedCounts[x];
621 
622  Matrix transposed = probabilities->Transpose ();
623  Matrix Q = transposed.Inverse ();
624  Matrix n = Q * m;
625 
626  Matrix varM (numClasses, numClasses);
627  for (j = 0; j < numClasses; j++)
628  {
629  double varM_j = 0.0;
630  for (i = 0; i < numClasses; i++)
631  {
632  double p = (*probabilities)[i][j];
633  varM_j += n[i][0] * p * (1.0 - p);
634  }
635  varM[j][j] = varM_j;
636  }
637 
638  for (j = 0; j < numClasses; j++)
639  {
640  for (k = 0; k < numClasses; k++)
641  {
642  if (j != k)
643  {
644  double covM_jk = 0.0;
645  for (i = 0; i < numClasses; i++)
646  covM_jk -= n[i][0] * (*probabilities)[i][j] * (*probabilities)[j][k];
647  varM[j][k] = covM_jk;
648  }
649  }
650  }
651 
652  Matrix varN = Q * varM * Q.Transpose ();
653 
654  adjCounts.clear ();
655  stdErrors.clear ();
656 
657  for (x = 0; x < numClasses; x++)
658  {
659  adjCounts.push_back (n[x][0]);
660  stdErrors.push_back (sqrt (varN[x][x]));
661  }
662 
663  return;
664 } /* PerformAdjustmnts */
Matrix Transpose()
Definition: Matrix.cpp:707
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
Supports two dimensional matrices.
Definition: Matrix.h:46
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
Matrix Inverse()
Definition: Matrix.cpp:731
KKStr StrFormatInt(kkint32 val, const char *mask)
Definition: KKStr.cpp:5004
void ClassificationBiasMatrix::PrintAdjustedResults ( ostream &  sw,
const VectorDouble classifiedCounts 
)

Definition at line 741 of file ClassificationBiasMatrix.cpp.

References KKMLL::MLClassList::ExtractThreeTitleLines(), KKB::KKException::KKException(), and PerformAdjustmnts().

744 {
745  if (classifiedCounts.size () != (kkuint32)numClasses)
746  {
747  KKStr errMsg = "ClassificationBiasMatrix::PrintAdjustedResults ***ERROR*** Number of entries in 'classifiedCounts' not equal the number of classes";
748  cerr << "ClassificationBiasMatrix::PrintAdjustedResults ***ERROR*** " << errMsg << endl;
749  valid = false;
750  throw KKException (errMsg);
751  }
752 
753  try
754  {
755  VectorDouble adjustedReults;
756  VectorDouble stdErrors;
757 
758  PerformAdjustmnts (classifiedCounts, adjustedReults, stdErrors);
759 
760  KKStr tl1, tl2, tl3;
761  classes->ExtractThreeTitleLines (tl1, tl2, tl3);
762  sw << "" << "\t" << "\t" << tl1 << endl;
763  sw << "" << "\t" << "\t" << tl2 << endl;
764  sw << "Description" << "\t" << "\t" << tl3 << endl;
765 
766  kkint32 col = 0;
767 
768  sw << "Classified Results" << "\t";
769  for (col = 0; col < numClasses; col++)
770  sw << "\t" << StrFormatDouble (classifiedCounts[col], "Z,ZZZ,ZZ0.0");
771  sw << endl;
772 
773  sw << "Adjusted Results" << "\t";
774  for (col = 0; col < numClasses; col++)
775  sw << "\t" << StrFormatDouble (adjustedReults[col], "Z,ZZZ,ZZ0.0");
776  sw << endl;
777 
778  sw << "Standard Errors" << "\t";
779  for (col = 0; col < numClasses; col++)
780  sw << "\t" << StrFormatDouble (stdErrors[col], "Z,ZZZ,ZZ0.0");
781  sw << endl;
782  }
783  catch (KKException& e)
784  {
785  KKStr errMsg = "ClassificationBiasMatrix::PrintAdjustedResults ***ERROR*** KKException";
786  runLog.Level (-1) << errMsg << endl << e.ToString () << endl;
787  throw KKException (errMsg, e);
788  }
789  catch (std::exception& e2)
790  {
791  KKStr errMsg = "ClassificationBiasMatrix::PrintAdjustedResults ***ERROR*** std::exception";
792  runLog.Level (-1) << errMsg << endl << e2.what() << endl;
793  throw KKException (errMsg, e2);
794  }
795  catch (...)
796  {
797  KKStr errMsg = "ClassificationBiasMatrix::PrintAdjustedResults ***ERROR*** Exception(...)";
798  runLog.Level (-1) << endl << errMsg << endl;
799  throw KKException (errMsg);
800  }
801 } /* PrintAdjustedResults */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void PerformAdjustmnts(const VectorDouble &classifiedCounts, VectorDouble &adjCounts, VectorDouble &stdErrors)
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
void ExtractThreeTitleLines(KKStr &titleLine1, KKStr &titleLine2, KKStr &titleLine3) const
Using the class names create three title lines where we split names by "_" characters between the thr...
Definition: MLClass.cpp:1068
KKStr StrFormatDouble(double val, const char *mask)
Definition: KKStr.cpp:4819
std::vector< double > VectorDouble
Vector of doubles.
Definition: KKBaseTypes.h:148
virtual const KKStr & ToString() const
Definition: KKException.cpp:98
void ClassificationBiasMatrix::PrintBiasMatrix ( ostream &  sw)

Definition at line 668 of file ClassificationBiasMatrix.cpp.

References KKMLL::MLClassList::ExtractThreeTitleLines(), KKB::KKException::KKException(), KKB::Matrix::operator[](), and KKB::Row::operator[]().

Referenced by TestPaperResults().

669 {
670  if (classes == NULL)
671  {
672  KKStr errMsg = "ClassificationBiasMatrix::PrintBiasMatrix ***ERROR*** 'Classes' not defined; this indicates that this object was not properly initialized.";
673  runLog.Level (-1) << errMsg << endl;
674  valid = false;
675  throw KKException (errMsg);
676  }
677 
678  sw << "BiasMatrix File Name [" << biasFileName << "]" << endl
679  << "Date Bias Matrix was Created [" << dateTimeFileWritten << "]" << endl
680  << "Configuration File Name [" << configFileName << "]" << endl
681  << "ConfigFile Used for Bias Matrix [" << configFileNameFromMatrixBiasFile << "]" << endl
682  << endl
683  << endl;
684 
685  KKStr tl1, tl2, tl3;
686 
687  classes->ExtractThreeTitleLines (tl1, tl2, tl3);
688  {
689  sw << "" << "\t" << "" << "\t" << tl1 << endl;
690  sw << "Class" << "\t" << "" << "\t" << tl2 << endl;
691  sw << "Name" << "\t" << "Count" << "\t" << tl3 << endl;
692  }
693 
694  kkint32 row = 0;
695  kkint32 col = 0;
696 
697  double total = 0.0;
698 
699  VectorDouble colTotals (numClasses, 0.0);
700  VectorDouble rowTotals (numClasses, 0.0);
701 
702  for (row = 0; row < numClasses; row++)
703  {
704  double rowTotal = 0;
705  for (col = 0; col < numClasses; col++)
706  {
707  rowTotal += (*counts)[row][col];
708  colTotals[col] += (*counts)[row][col];
709  }
710  rowTotals[row] = rowTotal;
711 
712  sw << (*classes)[row].Name () << "\t" << StrFormatDouble (rowTotal, "zzz,zz0.00");
713  for (col = 0; col < numClasses; col++)
714  sw << "\t" << StrFormatDouble ((*counts)[row][col], "###,##0.00");
715  sw << endl;
716  total += rowTotal;
717  }
718  sw << "Total" << "\t" << StrFormatDouble (total, "###,##0.00");
719  for (col = 0; col < numClasses; col++)
720  sw << "\t" << StrFormatDouble (colTotals[col], "ZZZ,ZZ0.00");
721  sw << endl;
722 
723  sw << endl;
724 
725  for (row = 0; row < numClasses; row++)
726  {
727  sw << (*classes)[row].Name ();
728  double rowPercent = 100.0 * rowTotals[row] / total;
729  sw << "\t" << StrFormatDouble (rowPercent, "ZZ0.0000") + "%";
730 
731  for (col = 0; col < numClasses; col++)
732  sw << "\t" << StrFormatDouble (100.0 * (*probabilities)[row][col], "ZZZ,ZZ0.00") << "%";
733  sw << endl;
734  }
735  sw << endl;
736 } /* PrintBiasMatrix */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
void ExtractThreeTitleLines(KKStr &titleLine1, KKStr &titleLine2, KKStr &titleLine3) const
Using the class names create three title lines where we split names by "_" characters between the thr...
Definition: MLClass.cpp:1068
KKStr StrFormatDouble(double val, const char *mask)
Definition: KKStr.cpp:4819
std::vector< double > VectorDouble
Vector of doubles.
Definition: KKBaseTypes.h:148
void ClassificationBiasMatrix::TestPaperResults ( ostream &  sw)

Definition at line 264 of file ClassificationBiasMatrix.cpp.

References PrintBiasMatrix().

265 {
266  VectorDouble classCounts (7, 0.0);
267  classCounts[0] = 2891;
268  classCounts[1] = 1965;
269  classCounts[2] = 495;
270  classCounts[3] = 1399;
271  classCounts[4] = 676;
272  classCounts[5] = 1191;
273  classCounts[6] = 1752;
274 
275  VectorDouble adjCounts;
276  VectorDouble stdErrors;
277 
278  PerformAdjustmnts (classCounts, adjCounts, stdErrors);
279 
280  kkint32 x = 0;
281 
282  sw << endl << endl;
283 
284  PrintBiasMatrix (sw);
285 
286  sw << endl << endl;
287 
288  sw << "Desc";
289  for (x = 0; x < 7; x++)
290  sw << "\t" << StrFormatInt (x, "ZZ0");
291  sw << endl;
292 
293  sw << "ClassifiedCounts";
294  for (x = 0; x < 7; x++)
295  sw << "\t" << StrFormatDouble (classCounts[x], "ZZ,ZZ0.0");
296  sw << endl;
297 
298  sw << "adjCounts";
299  for (x = 0; x < 7; x++)
300  sw << "\t" << StrFormatDouble (adjCounts[x], "ZZZ,ZZ0.0");
301  sw << endl;
302 
303  sw << "stdErrors";
304  for (x = 0; x < 7; x++)
305  sw << "\t" << StrFormatDouble (stdErrors[x], "ZZ,ZZ0.0");
306 
307  sw << endl << endl;
308 } /* TestPaperResults*/
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void PerformAdjustmnts(const VectorDouble &classifiedCounts, VectorDouble &adjCounts, VectorDouble &stdErrors)
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStr StrFormatInt(kkint32 val, const char *mask)
Definition: KKStr.cpp:5004
KKStr StrFormatDouble(double val, const char *mask)
Definition: KKStr.cpp:4819
std::vector< double > VectorDouble
Vector of doubles.
Definition: KKBaseTypes.h:148
void ClassificationBiasMatrix::WriteXML ( ostream &  o)

Definition at line 487 of file ClassificationBiasMatrix.cpp.

488 {
489  o << "<ClassificationBiasMatrix>" << std::endl;
490 
491  o << "BiasFileName" << "\t" << biasFileName << std::endl;
492 
493  if ((!classes) || (!counts) || (!probabilities))
494  {
495  runLog.Level (-1) << "ClassificationBiasMatrix::WriteXML ***ERROR*** Not all data is defined." << endl;
496  return;
497  }
498 
499  if ((numClasses != classes->QueueSize ()) ||
500  (numClasses != counts->NumOfRows ()) ||
501  (numClasses != probabilities->NumOfRows ())
502  )
503  {
504  runLog.Level (-1) << "ClassificationBiasMatrix::WriteXML ***ERROR*** Disagreement in variable dimensions." << endl;
505  return;
506  }
507 
508  o << "NumClasses" << "\t" << numClasses << std::endl;
509  o << "Classes" << "\t" << classes->ToCommaDelimitedStr () << std::endl;
510  o << "ConfigFileName" << "\t" << configFileName << std::endl;
511  o << "ConfigDateTime" << "\t" << configDateTime << std::endl;
512  o << "DateTimeFileWritten" << "\t" << dateTimeFileWritten << std::endl;
513 
514  o << "<SimpleConfusionMatrix>" << std::endl;
515  for (kkint32 rowIdx = 0; rowIdx < numClasses; rowIdx++)
516  {
517  o << "DataRow" << "\t"
518  << (*classes)[rowIdx].Name () << "\t";
519 
520  for (kkint32 colIdx = 0; colIdx < numClasses; colIdx++)
521  {
522  if (colIdx > 0)
523  o << ",";
524  o << ((*counts)[rowIdx][colIdx]) << ":" << StrFormatDouble ((*probabilities)[rowIdx][colIdx], "ZZ0.0000");
525  }
526  o << std::endl;
527  }
528 
529  o << "</SimpleConfusionMatrix>" << std::endl;
530 
531  o << "</ClassificationBiasMatrix>" << std::endl;
532 
533 } /* WriteXML */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 NumOfRows() const
Definition: Matrix.h:128
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStr ToCommaDelimitedStr() const
Definition: MLClass.cpp:970
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
KKStr StrFormatDouble(double val, const char *mask)
Definition: KKStr.cpp:4819
kkint32 QueueSize() const
Definition: KKQueue.h:313

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