3#include "../_cexports/c_polimago.h"
5#include "../global.hpp"
6#include "classification_test_result.hpp"
24 class PredictionResult
27 PredictionResult(
const PredictionResult &other) =
default;
28 PredictionResult &operator=(
const PredictionResult &other) =
default;
29 PredictionResult(PredictionResult &&other) =
default;
30 PredictionResult &operator=(PredictionResult &&other) =
default;
31 ~PredictionResult() =
default;
35 : exampleIndex_(exampleIndex)
40 friend class ConfusionMatrix;
71 return confidenceDistribution_;
24 class PredictionResult {
…};
96 BuildConfusionMatrix(res);
97 UpdateVisibleMatrix();
110 if (classIndex >= numClasses)
116 for (
decltype(numClasses) c = 0; c < numClasses; ++c)
118 sum +=
static_cast<int>(indexArray_[classIndex][c].size());
132 for (
decltype(numClasses) i = 0; i < numClasses; ++i)
148 if (classIndex >= numClasses)
152 return static_cast<int>(
At(classIndex, classIndex).size());
164 for (
decltype(numClasses) i = 0; i < numClasses; ++i)
180 if (classIndex >= numClasses)
186 for (
decltype(numClasses) c = 0; c < numClasses; ++c)
188 sum +=
static_cast<int>(indexArray_[classIndex][c].size());
191 sum +=
static_cast<int>(
At(classIndex, c).size());
206 for (
decltype(numClasses) i = 0; i < numClasses; ++i)
222 for (
auto &&r : rejects_)
224 retval +=
static_cast<int>(r.size());
237 if (classIndex >= rejects_.size())
242 return rejects_[classIndex];
252 return static_cast<int>(indexArray_.size());
282 return visibleArray_[trueClass][predictedClass];
292 return confidenceThreshold_;
305 if ((threshold < 0.0) || (threshold > 1.5))
309 confidenceThreshold_ = threshold;
310 UpdateVisibleMatrix();
318 rejects_.resize(numClasses);
320 indexArray_.resize(numClasses);
321 for (
auto &&indexRow : indexArray_)
323 indexRow.resize(numClasses);
326 for (
decltype(numExamples) i = 0; i < numExamples; ++i)
334 void UpdateVisibleMatrix()
336 for (
auto &&r : rejects_)
343 visibleArray_ = indexArray_;
347 visibleArray_.resize(indexArray_.size());
348 for (
auto &&visibleRow : visibleArray_)
350 visibleRow.resize(indexArray_[0].size());
352 for (
size_t x = 0; x < visibleArray_.size(); ++x)
354 visibleArray_[x].resize(indexArray_[x].size());
355 for (
size_t y = 0; y < visibleArray_[x].size(); ++y)
357 for (
auto &&e : indexArray_[x][y])
361 visibleArray_[x][y].push_back(e);
365 rejects_[x].push_back(e);
373 std::vector<std::vector<std::vector<PredictionResult>>> indexArray_;
374 std::vector<std::vector<std::vector<PredictionResult>>> visibleArray_;
375 std::vector<std::vector<PredictionResult>> rejects_;
376 double confidenceThreshold_ = 0.0;
ConfusionMatrix(const ClassificationTestResult &res)
Constructor.
Definition confusion_matrix.hpp:94
Classification test result object.
Definition classification_test_result.hpp:27
int NumClasses() const
Number of classes in the sample database on which the test result was calculated.
Definition classification_test_result.hpp:124
std::vector< double > ExampleConfidences() const
Confidences in the classification decision for each sample.
Definition classification_test_result.hpp:176
std::vector< std::vector< double > > ExampleConfidenceDistributions() const
Confidence distributions for each example.
Definition classification_test_result.hpp:186
std::vector< int > TrueClassIndices() const
The real class index for each example.
Definition classification_test_result.hpp:196
std::vector< int > PredictedClassIndices() const
Prediction results for all indices.
Definition classification_test_result.hpp:206
Representation of a confusion matrix.
Definition confusion_matrix.hpp:87
int TotalCorrect() const
Overall number of correctly classified samples.
Definition confusion_matrix.hpp:160
void SetConfidenceThreshold(double threshold)
Set the threshold to be taken into account when determining the confusion matrix.
Definition confusion_matrix.hpp:303
std::vector< PredictionResult > At(int trueClass, int predictedClass) const
Access the results stored in the confusion matrix.
Definition confusion_matrix.hpp:275
std::vector< PredictionResult > Rejects(int classIndex) const
Get the rejects for a given class.
Definition confusion_matrix.hpp:235
int NumClasses() const noexcept
Number of classes in this matrix.
Definition confusion_matrix.hpp:250
int TotalErrors(int classIndex) const
Determine the total number of errors made for a given class.
Definition confusion_matrix.hpp:177
int TotalSamples(int classIndex) const
Determine the total number of samples available for a given class.
Definition confusion_matrix.hpp:107
int TotalRejects() const
Total number of rejected items (i.e. items that have a confidence of less than the currently set thre...
Definition confusion_matrix.hpp:219
double ConfidenceThreshold() const noexcept
Get threshold to be taken into account when determining the confusion matrix.
Definition confusion_matrix.hpp:290
int TotalSamples() const
Return the total sample count.
Definition confusion_matrix.hpp:128
int TotalErrors() const
Determine the total error count.
Definition confusion_matrix.hpp:202
int TotalCorrect(int classIndex) const
Number of correctly classified samples in a given class.
Definition confusion_matrix.hpp:145
ConfusionMatrix(const ClassificationTestResult &res)
Constructor.
Definition confusion_matrix.hpp:94
The information contained in each cell of the confusion matrix.
Definition confusion_matrix.hpp:25
double Confidence() const noexcept
Confidence value of the (best) classification result.
Definition confusion_matrix.hpp:59
int ExampleIndex() const noexcept
The index of the example (with refers to the index in the sample image list from which the test resul...
Definition confusion_matrix.hpp:49
std::vector< double > ConfidenceDistribution() const
Distribution of confidences among the other known classes.
Definition confusion_matrix.hpp:69
int NumExamples() const
Number of examples that contributed to this test result.
Definition test_result_base.hpp:61
Namespace for the Polimago package testing functionality.
Definition classification_test_result.hpp:21
Namespace for the Polimago package.
Definition classification_predictor.hpp:29
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17