CVB++ 14.0
test_result_base.hpp
1#pragma once
2
3#include "../_cexports/c_polimago.h"
4
5#include "../global.hpp"
6#include "../string.hpp"
7#include "predictor_base.hpp"
8
9#include <vector>
10
11namespace Cvb
12{
13CVB_BEGIN_INLINE_NS
14
16namespace Polimago
17{
19namespace Testing
20{
21
23
26{
27protected:
28 TestResultBase (ReleaseObjectGuard&& guard)
29 : PolimagoFactoryCreatedObject (std::move (guard)),
30 exampleMeanSquareErrors_()
31 {
32 CVB_CALL_CAPI(PMGetTestResultTrainParams(Handle(), trainingParameters_));
33
34 auto num_examples = NumExamples ();
35 for (decltype(num_examples) i = 0; i < num_examples; ++i)
36 {
37 exampleMeanSquareErrors_.push_back (CVB_CALL_CAPI (PMGetTestResultExampleMeanSquareError(Handle(), i)));
38 }
39 }
40
41 TestResultBase (TestResultBase&&) noexcept = default;
42
43 TestResultBase& operator=(TestResultBase&&) noexcept = default;
44
45 virtual ~TestResultBase () = default;
46
47 // Helper to load a saved predictor from file
48 static CExports::TTESTRESULT LoadInternal (const String & fileName)
49 {
50 CExports::TTESTRESULT testResult = nullptr;
51
52 CVB_CALL_CAPI_CHECKED (PMOpenTestResultTyped(fileName.c_str(), testResult));
53 return testResult;
54 }
55
56 void SaveFunction (const String &fileName) const override
57 {
58 CVB_CALL_CAPI_CHECKED (PMSaveTestResultTyped(fileName.c_str(), Handle()));
59 }
60
61public:
63
67 int NumExamples() const
68 {
69 return static_cast<int>(CVB_CALL_CAPI (PMGetTestResultNumExamples(Handle())));
70 }
71
73
77 double TotalMeanSquareError() const
78 {
79 return static_cast<int>(CVB_CALL_CAPI (PMGetTestResultTotalMeanSquareError(Handle())));
80 }
81
83
88 {
89 return exampleMeanSquareErrors_;
90 }
91
93
97 int FeatureResolution() const noexcept
98 {
99 return trainingParameters_.FeatureMap.FeatureResolution;
100 }
101
102private:
103 std::vector<double> exampleMeanSquareErrors_;
104};
105
108
109
110} /* namespace Testing */
111
114
115} /* namespace Polimago */
116CVB_END_INLINE_NS
117} /* namespace Cvb */
Base class for Polimago objects created by one of the factory classes.
Definition: predictor_base.hpp:44
void * Handle() const noexcept
Classic API Polimago handle.
Definition: predictor_base.hpp:66
Base class for all Polimago Test Results.
Definition: test_result_base.hpp:26
int FeatureResolution() const noexcept
Feature resolution value with which the classifier was trained.
Definition: test_result_base.hpp:97
std::vector< double > ExampleMeanSquareError() const
Mean square error for each individual example (the index runs over all the examples that contributed ...
Definition: test_result_base.hpp:87
int NumExamples() const
Number of examples that contributed to this test result.
Definition: test_result_base.hpp:67
double TotalMeanSquareError() const
Total mean square error of the predictor over all examples and all coordinates.
Definition: test_result_base.hpp:77
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24