CVB++ 15.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
19namespace Cvb
20{
21 CVB_BEGIN_INLINE_NS
22
24 namespace Polimago
25 {
27 namespace Testing
28 {
29
31
33 class HoldoutTestResultFactory : public TestResultFactory
34 {
35 public:
37
41 : TestResultFactory()
42 {
43 }
44
45 public:
46#if 0
48
57 {
58 return Internal::DoResCallObjectOut<ClassificationTestResult>([&](void* & res)
59 {
60 return CVB_CALL_CAPI(PMLeaveOutTestOnSil (mts.Handle (), ..., holdoutSize, usage, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
61 });
62 }
63
65
73 {
74 return Internal::DoResCallObjectOut<RegressionTestResult>([&](void* & res)
75 {
76 return CVB_CALL_CAPI(PMLeaveOutTestOnSil (mts.Handle (), ..., holdoutSize, CExports::CU_Regression, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
77 });
78 }
79
81
89 std::unique_ptr<ClassificationTestResult> RunTest (int holdoutSize, ClassificationType usage, const Minos::TrainingSet & database)
90 {
91 return Internal::DoResCallObjectOut<ClassificationTestResult>([&](void* & res)
92 {
93 return CVB_CALL_CAPI(PMLeaveOutTestOnMts (mts.Handle (), ..., holdoutSize, usage, preproCode_, featureResolution_, lambda_, iterpolation_ == InterpolationType::Linear, res));
94 });
95 }
96#endif
97
99
104 {
105 return interpolation_;
106 }
107
110
114 void SetInterpolation(InterpolationType interpolation) noexcept
115 {
116 interpolation_ = interpolation;
117 }
118
120
124 double Lambda() const noexcept
125 {
126 return lambda_;
127 }
128
131
135 void SetLambda(double lambda)
136 {
139 {
140 throw std::out_of_range("lambda value out of range");
141 }
142
143 lambda_ = lambda;
144 }
145
147
152 {
153 return preproCode_;
154 }
155
157
161 void SetPreprocessing(const String &code)
162 {
164 {
165 throw std::invalid_argument("Preprocessing codes must not be longer than 15 characters");
166 }
167 std::string asciiCode(Internal::CastToAscii(code));
168 std::transform(asciiCode.begin(), asciiCode.end(), asciiCode.begin(),
169 [](char ch) { return static_cast<char>(std::tolower(ch)); });
170 if (asciiCode.find_first_not_of(Training::PredictorFactoryBase::PreprocessingValidCharacters().data())
171 != std::string::npos)
172 {
173 throw std::invalid_argument("Preprocessing code contains invalid characters");
174 }
175
176 preproCode_.assign(asciiCode.begin(), asciiCode.end());
177 }
178
180
184 int FeatureResolution() const noexcept
185 {
186 return featureResolution_;
187 }
188
190
194 void SetFeatureResolution(int featureResolution)
195 {
198 {
199 throw std::out_of_range("feature resolution value out of range");
200 }
201
202 featureResolution_ = featureResolution;
203 }
204
205 private:
207 String preproCode_;
210 };
211
214
215 } /* namespace Testing */
216
219
220 } /* namespace Polimago */
221 CVB_END_INLINE_NS
222} /* namespace Cvb */
HoldoutTestResultFactory()
Constructor.
Definition holdout_test_result_factory.hpp:40
Factory object for holdout tests.
Definition holdout_test_result_factory.hpp:34
String Preprocessing() const
Get preprocessing code with which the object is to be generated.
Definition holdout_test_result_factory.hpp:151
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:114
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:135
HoldoutTestResultFactory()
Constructor.
Definition holdout_test_result_factory.hpp:40
double Lambda() const noexcept
Gets the regularization value to be used for generating the object.
Definition holdout_test_result_factory.hpp:124
int FeatureResolution() const noexcept
Gets the feature resolution (determines the size of the classification retina.
Definition holdout_test_result_factory.hpp:184
void SetPreprocessing(const String &code)
Set preprocessing code with which the object is to be generated.
Definition holdout_test_result_factory.hpp:161
void SetFeatureResolution(int featureResolution)
Sets the feature resolution (determines the size of the classification retina).
Definition holdout_test_result_factory.hpp:194
InterpolationType Interpolation() const noexcept
Gets the interpolation setting to be used for generating this object.
Definition holdout_test_result_factory.hpp:103
static constexpr InterpolationType InterpolationDefault
Default value for interpolation.
Definition predictor_factory_base.hpp:209
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:50
static ValueRange< int > FeatureResolutionRange()
Valid range of feature resolution value.
Definition predictor_factory_base.hpp:59
static constexpr double LambdaDefault
Default value for lambda.
Definition predictor_factory_base.hpp:47
static constexpr int FeatureResolutionDefault
Default value for feature resolution.
Definition predictor_factory_base.hpp:56
static constexpr int PreprocessingMaxLength
Maximum length of a preprocessing code (excluding the terminating zero).
Definition predictor_factory_base.hpp:65
Classifier type that operates on images.
Definition decl_regression_sil.hpp:190
Namespace for the Polimago package testing functionality.
Definition classification_test_result.hpp:21
std::shared_ptr< HoldoutTestResultFactory > HoldoutTestResultFactoryPtr
Convenience shared pointer for HoldoutTestResultFactory.
Definition holdout_test_result_factory.hpp:213
Namespace for the Polimago package.
Definition classification_predictor.hpp:38
ClassificationType
Determine the classification type to be carried out.
Definition classification_predictor.hpp:42
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.
Definition predictor_base.hpp:37
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
Angle Max(Angle a, Angle b) noexcept
Returns the bigger of two angles.
Definition angle.hpp:495
Angle Min(Angle a, Angle b) noexcept
Returns the smaller of two angles.
Definition angle.hpp:512
T transform(T... args)