CVB++ 15.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{
13 CVB_BEGIN_INLINE_NS
14
16 namespace Polimago
17 {
19 namespace Testing
20 {
21
23
25 class TestResultBase : public PolimagoFactoryCreatedObject
26 {
27 protected:
28 explicit 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 // Helper to load a saved predictor from file
42 static CExports::TTESTRESULT LoadInternal(const String &fileName)
43 {
44 CExports::TTESTRESULT testResult = nullptr;
45
46 CVB_CALL_CAPI_CHECKED(PMOpenTestResultTyped(fileName.c_str(), testResult));
47 return testResult;
48 }
49
50 void SaveFunction(const String &fileName) const override
51 {
52 CVB_CALL_CAPI_CHECKED(PMSaveTestResultTyped(fileName.c_str(), Handle()));
53 }
54
55 public:
57
61 int NumExamples() const
62 {
63 return static_cast<int>(CVB_CALL_CAPI(PMGetTestResultNumExamples(Handle())));
64 }
65
67
71 double TotalMeanSquareError() const
72 {
73 return static_cast<int>(CVB_CALL_CAPI(PMGetTestResultTotalMeanSquareError(Handle())));
74 }
75
78
83 {
84 return exampleMeanSquareErrors_;
85 }
86
88
92 int FeatureResolution() const noexcept
93 {
94 return TrainingParameters().FeatureMap.FeatureResolution;
95 }
96
97 private:
98 std::vector<double> exampleMeanSquareErrors_;
99 };
100
103
104 } /* namespace Testing */
105
108
109 } /* namespace Polimago */
110 CVB_END_INLINE_NS
111} /* namespace Cvb */
void * Handle() const noexcept
Classic API Polimago handle.
Definition predictor_base.hpp:68
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:92
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:82
int NumExamples() const
Number of examples that contributed to this test result.
Definition test_result_base.hpp:61
double TotalMeanSquareError() const
Total mean square error of the predictor over all examples and all coordinates.
Definition test_result_base.hpp:71
T move(T... args)
Namespace for the Polimago package testing functionality.
Definition classification_test_result.hpp:21
std::shared_ptr< TestResultBase > TestResultBasePtr
Convenience shared pointer for TestResultBase.
Definition test_result_base.hpp:102
Namespace for the Polimago package.
Definition classification_predictor.hpp:38
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49