CVB++ 14.0
holdout_test_result_factory.hpp
1#pragma once
2
3#include "../_cexports/c_polimago.h"
4
5#include "../global.hpp"
6#include "../string.hpp"
7#include "test_result_factory.hpp"
8#include "predictor_base.hpp"
9#include "predictor_factory_base.hpp"
10#include "classification_predictor.hpp"
11#include "../minos/training_set.hpp"
12#include "../sample_database/sample_classification_image_list.hpp"
13#include "../sample_database/sample_regression_image_list.hpp"
14
15#include <memory>
16#include <algorithm>
17#include <iterator>
18
19
20namespace Cvb
21{
22CVB_BEGIN_INLINE_NS
23
25namespace Polimago
26{
28namespace Testing
29{
30
32
35{
36public:
38
43 { }
44
46
47 HoldoutTestResultFactory& operator=(const HoldoutTestResultFactory&) = default;
48
49 virtual ~HoldoutTestResultFactory () {};
50
51public:
52#if 0
54
63 {
64 return Internal::DoResCallObjectOut<ClassificationTestResult>([&](void* & res)
65 {
66 return CVB_CALL_CAPI(PMLeaveOutTestOnSil (mts.Handle (), ..., holdoutSize, usage, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
67 });
68 }
69
71
78 std::unique_ptr<RegressionTestResult> RunTest (int holdoutSize, const SampleDatabase::SampleRegressionImageList & database)
79 {
80 return Internal::DoResCallObjectOut<RegressionTestResult>([&](void* & res)
81 {
82 return CVB_CALL_CAPI(PMLeaveOutTestOnSil (mts.Handle (), ..., holdoutSize, CExports::CU_Regression, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
83 });
84 }
85
87
95 std::unique_ptr<ClassificationTestResult> RunTest (int holdoutSize, ClassificationType usage, const Minos::TrainingSet & database)
96 {
97 return Internal::DoResCallObjectOut<ClassificationTestResult>([&](void* & res)
98 {
99 return CVB_CALL_CAPI(PMLeaveOutTestOnMts (mts.Handle (), ..., holdoutSize, usage, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
100 });
101 }
102#endif
103
105
110 {
111 return interpolation_;
112 }
113
115
119 void SetInterpolation(InterpolationType interpolation) noexcept
120 {
121 interpolation_ = interpolation;
122 }
123
125
129 double Lambda() const noexcept
130 {
131 return lambda_;
132 }
133
135
139 void SetLambda(double lambda)
140 {
142 {
143 throw std::out_of_range ("lambda value out of range");
144 }
145
146 lambda_ = lambda;
147 }
148
150
155 {
156 return preproCode_;
157 }
158
160
164 void SetPreprocessing(const String &code)
165 {
167 {
168 throw std::invalid_argument ("Preprocessing codes must not be longer than 15 characters");
169 }
170 std::string asciiCode (Internal::CastToAscii(code));
171 std::transform(asciiCode.begin(), asciiCode.end(), asciiCode.begin(), [](char ch)
172 {
173 return static_cast<char>(std::tolower(ch));
174 });
175 if (asciiCode.find_first_not_of (Training::PredictorFactoryBase::PreprocessingValidCharacters().data()) != std::string::npos)
176 {
177 throw std::invalid_argument ("Preprocessing code contains invalid characters");
178 }
179
180 preproCode_.assign (asciiCode.begin(), asciiCode.end());
181 }
182
184
188 int FeatureResolution() const noexcept
189 {
190 return featureResolution_;
191 }
192
194
198 void SetFeatureResolution(int featureResolution)
199 {
201 {
202 throw std::out_of_range ("feature resolution value out of range");
203 }
204
205 featureResolution_ = featureResolution;
206 }
207
208private:
210 String preproCode_;
213};
214
217
218} /* namespace Testing */
219
222
223} /* namespace Polimago */
224CVB_END_INLINE_NS
225} /* namespace Cvb */
Factory object for holdout tests.
Definition: holdout_test_result_factory.hpp:35
String Preprocessing() const
Get preprocessing code with which the object is to be generated.
Definition: holdout_test_result_factory.hpp:154
void SetInterpolation(InterpolationType interpolation) noexcept
Sets the interpolation setting to be used for generating this object. Using interpolation will genera...
Definition: holdout_test_result_factory.hpp:119
void SetLambda(double lambda)
Sets the regularization value to be used for generating the object. Possible values range from 0 to 1...
Definition: holdout_test_result_factory.hpp:139
HoldoutTestResultFactory()
Constructor.
Definition: holdout_test_result_factory.hpp:41
double Lambda() const noexcept
Gets the regularization value to be used for generating the object.
Definition: holdout_test_result_factory.hpp:129
int FeatureResolution() const noexcept
Gets the feature resolution (determines the size of the classification retina.
Definition: holdout_test_result_factory.hpp:188
void SetPreprocessing(const String &code)
Set preprocessing code with which the object is to be generated.
Definition: holdout_test_result_factory.hpp:164
void SetFeatureResolution(int featureResolution)
Sets the feature resolution (determines the size of the classification retina).
Definition: holdout_test_result_factory.hpp:198
InterpolationType Interpolation() const noexcept
Gets the interpolation setting to be used for generating this object.
Definition: holdout_test_result_factory.hpp:109
Base class for test factory classes.
Definition: test_result_factory.hpp:24
static constexpr InterpolationType InterpolationDefault
Default value for interpolation.
Definition: predictor_factory_base.hpp:193
static constexpr std::array< char, 4 > PreprocessingValidCharacters()
Characters that a preprocessing string may contain.
Definition: predictor_factory_base.hpp:68
static ValueRange< double > LambdaRange()
Acceptable scale factor range for search classifier training.
Definition: predictor_factory_base.hpp:47
static ValueRange< int > FeatureResolutionRange()
Valid range of feature resolution value.
Definition: predictor_factory_base.hpp:56
static constexpr double LambdaDefault
Default value for lambda.
Definition: predictor_factory_base.hpp:44
static constexpr int FeatureResolutionDefault
Default value for feature resolution.
Definition: predictor_factory_base.hpp:53
static constexpr int PreprocessingMaxLength
Maximum length of a preprocessing code (excluding the terminating zero).
Definition: predictor_factory_base.hpp:62
Classifier type that operates on images.
Definition: decl_regression_sil.hpp:182
ClassificationType
Determine the classification type to be carried out.
Definition: classification_predictor.hpp:32
InterpolationType
Interpolation to be used when extracting image data for classifier generation.
Definition: predictor_base.hpp:33
@ Linear
Image data is (if necessary) extracted with linear interpolation.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Angle Max(Angle a, Angle b) noexcept
Returns the bigger of two angles.
Definition: angle.hpp:504
Angle Min(Angle a, Angle b) noexcept
Returns the smaller of two angles.
Definition: angle.hpp:521