mlpack  git-master
static_checks.hpp
Go to the documentation of this file.
1 
15 #ifndef MLPACK_CORE_OPTIMIZERS_STATIC_CHECKS_HPP
16 #define MLPACK_CORE_OPTIMIZERS_STATIC_CHECKS_HPP
17 
18 #include <mlpack/core.hpp>
20 
21 namespace mlpack {
22 namespace optimization {
23 namespace traits {
24 
30 template<typename FunctionType>
32 {
33  const static bool value =
34  HasEvaluate<FunctionType, EvaluateForm>::value ||
35  HasEvaluate<FunctionType, EvaluateConstForm>::value ||
36  HasEvaluate<FunctionType, EvaluateStaticForm>::value;
37 };
38 
44 template <typename FunctionType>
46 {
47  const static bool value =
48  HasGradient<FunctionType, GradientForm>::value ||
49  HasGradient<FunctionType, GradientConstForm>::value ||
50  HasGradient<FunctionType, GradientStaticForm>::value;
51 };
52 
58 template<typename FunctionType>
60 {
61  const static bool value =
62  HasNumFunctions<FunctionType, NumFunctionsForm>::value ||
63  HasNumFunctions<FunctionType, NumFunctionsConstForm>::value ||
64  HasNumFunctions<FunctionType, NumFunctionsStaticForm>::value;
65 };
66 
72 template<typename FunctionType>
74 {
75  const static bool value =
76  HasShuffle<FunctionType, ShuffleForm>::value ||
77  HasShuffle<FunctionType, ShuffleConstForm>::value ||
78  HasShuffle<FunctionType, ShuffleStaticForm>::value;
79 };
80 
86 template<typename FunctionType>
88 {
89  const static bool value =
90  HasEvaluate<FunctionType, DecomposableEvaluateForm>::value ||
91  HasEvaluate<FunctionType, DecomposableEvaluateConstForm>::value ||
92  HasEvaluate<FunctionType, DecomposableEvaluateStaticForm>::value;
93 };
94 
100 template <typename FunctionType>
102 {
103  const static bool value =
104  HasGradient<FunctionType, DecomposableGradientForm>::value ||
105  HasGradient<FunctionType, DecomposableGradientConstForm>::value ||
106  HasGradient<FunctionType, DecomposableGradientStaticForm>::value;
107 };
108 
114 template<typename FunctionType>
116 {
117  const static bool value =
118  HasNumConstraints<FunctionType, NumConstraintsForm>::value ||
119  HasNumConstraints<FunctionType, NumConstraintsConstForm>::value ||
120  HasNumConstraints<FunctionType, NumConstraintsStaticForm>::value;
121 };
122 
128 template<typename FunctionType>
130 {
131  const static bool value =
132  HasEvaluateConstraint<FunctionType, EvaluateConstraintForm>::value ||
133  HasEvaluateConstraint<FunctionType, EvaluateConstraintConstForm>::value ||
134  HasEvaluateConstraint<FunctionType, EvaluateConstraintStaticForm>::value;
135 };
136 
142 template <typename FunctionType>
144 {
145  const static bool value =
146  HasGradientConstraint<FunctionType, GradientConstraintForm>::value ||
147  HasGradientConstraint<FunctionType, GradientConstraintConstForm>::value ||
148  HasGradientConstraint<FunctionType, GradientConstraintStaticForm>::value;
149 };
150 
157 template <typename FunctionType>
159 {
160  const static bool value =
161  HasGradient<FunctionType, SparseGradientForm>::value ||
162  HasGradient<FunctionType, SparseGradientConstForm>::value ||
163  HasGradient<FunctionType, SparseGradientStaticForm>::value;
164 };
165 
171 template<typename FunctionType>
173 {
174  const static bool value =
175  HasNumFeatures<FunctionType, NumFeaturesForm>::value ||
176  HasNumFeatures<FunctionType, NumFeaturesConstForm>::value ||
177  HasNumFeatures<FunctionType, NumFeaturesStaticForm>::value;
178 };
179 
185 template <typename FunctionType>
187 {
188  const static bool value =
189  HasPartialGradient<FunctionType, PartialGradientForm>::value ||
190  HasPartialGradient<FunctionType, PartialGradientConstForm>::value ||
191  HasPartialGradient<FunctionType, PartialGradientStaticForm>::value;
192 };
193 
199 template<typename FunctionType>
201 {
202  const static bool value =
203  HasEvaluateWithGradient<FunctionType, EvaluateWithGradientForm>::value ||
204  HasEvaluateWithGradient<FunctionType,
206  HasEvaluateWithGradient<FunctionType,
208 };
209 
216 template<typename FunctionType>
218 {
219  const static bool value =
220  HasEvaluateWithGradient<FunctionType,
222  HasEvaluateWithGradient<FunctionType,
224  HasEvaluateWithGradient<FunctionType,
226 };
227 
231 template<typename FunctionType>
232 inline void CheckFunctionTypeAPI()
233 {
235  "The FunctionType does not have a correct definition of Evaluate(). "
236  "Please check that the FunctionType fully satisfies the requirements of "
237  "the FunctionType API; see the optimizer tutorial for details.");
238 
240  "The FunctionType does not have a correct definition of Gradient(). "
241  "Please check that the FunctionType fully satisfies the requirements of "
242  "the FunctionType API; see the optimizer tutorial for details.");
243 
245  "The FunctionType does not have a correct definition of "
246  "EvaluateWithGradient(). Please check that the FunctionType fully "
247  "satisfies the requirements of the FunctionType API; see the optimizer "
248  "tutorial for more details.");
249 }
250 
254 template<typename FunctionType>
256 {
258  "The FunctionType does not have a correct definition of a decomposable "
259  "Evaluate() method. Please check that the FunctionType fully satisfies"
260  " the requirements of the DecomposableFunctionType API; see the optimizer"
261  " tutorial for more details.");
262 
264  "The FunctionType does not have a correct definition of a decomposable "
265  "Gradient() method. Please check that the FunctionType fully satisfies"
266  " the requirements of the DecomposableFunctionType API; see the optimizer"
267  " tutorial for more details.");
268 
270  "The FunctionType does not have a correct definition of a decomposable "
271  "EvaluateWithGradient() method. Please check that the FunctionType "
272  "fully satisfies the requirements of the DecomposableFunctionType API; "
273  "see the optimizer tutorial for more details.");
274 
276  "The FunctionType does not have a correct definition of NumFunctions(). "
277  "Please check that the FunctionType fully satisfies the requirements of "
278  "the DecomposableFunctionType API; see the optimizer tutorial for more "
279  "details.");
280 
281  static_assert(CheckShuffle<FunctionType>::value,
282  "The FunctionType does not have a correct definition of Shuffle(). "
283  "Please check that the FunctionType fully satisfies the requirements of "
284  "the DecomposableFunctionType API; see the optimizer tutorial for more "
285  "details.");
286 }
287 
291 template<typename FunctionType>
293 {
295  "The FunctionType does not have a correct definition of NumFunctions(). "
296  "Please check that the FunctionType fully satisfies the requirements of "
297  "the SparseFunctionType API; see the optimizer tutorial for more "
298  "details.");
299 
301  "The FunctionType does not have a correct definition of Evaluate(). "
302  "Please check that the FunctionType fully satisfies the requirements of "
303  "the SparseFunctionType API; see the optimizer tutorial for more "
304  "details.");
305 
307  "The FunctionType does not have a correct definition of a sparse "
308  "Gradient() method. Please check that the FunctionType fully satisfies "
309  "the requirements of the SparseFunctionType API; see the optimizer "
310  "tutorial for more details.");
311 }
312 
316 template<typename FunctionType>
318 {
320  "The FunctionType does not have a correct definition of Evaluate(). "
321  "Please check that the FunctionType fully satisfies the requirements of "
322  "the NonDifferentiableFunctionType API; see the optimizer tutorial for "
323  "more details.");
324 }
325 
329 template<typename FunctionType>
331 {
333  "The FunctionType does not have a correct definition of NumFeatures(). "
334  "Please check that the FunctionType fully satisfies the requirements of "
335  "the ResolvableFunctionType API; see the optimizer tutorial for more "
336  "details.");
337 
339  "The FunctionType does not have a correct definition of Evaluate(). "
340  "Please check that the FunctionType fully satisfies the requirements of "
341  "the ResolvableFunctionType API; see the optimizer tutorial for more "
342  "details.");
343 
345  "The FunctionType does not have a correct definition of a partial "
346  "Gradient() function. Please check that the FunctionType fully satisfies "
347  "the requirements of the ResolvableFunctionType API; see the optimizer "
348  "tutorial for more details.");
349 }
350 
354 template<typename FunctionType>
356 {
358  "The FunctionType does not have a correct definition of Evaluate(). "
359  "Please check that the FunctionType fully satisfies the requirements of "
360  "the ConstrainedFunctionType API; see the optimizer tutorial for more "
361  "details.");
362 
364  "The FunctionType does not have a correct definition of Gradient(). "
365  "Please check that the FunctionType fully satisfies the requirements of "
366  "the ConstrainedFunctionType API; see the optimizer tutorial for more "
367  "details.");
368 
370  "The FunctionType does not have a correct definition of NumConstraints()."
371  " Please check that the FunctionType fully satisfies the requirements of "
372  "the ConstrainedFunctionType API; see the optimizer tutorial for more "
373  "details.");
374 
376  "The FunctionType does not have a correct definition of "
377  "EvaluateConstraint(). Please check that the FunctionType fully satisfies"
378  " the ConstrainedFunctionType API; see the optimizer tutorial for more "
379  "details.");
380 
382  "The FunctionType does not have a correct definition of "
383  "GradientConstraint(). Please check that the FunctionType fully satisfies"
384  " the ConstrainedFunctionType API; see the optimizer tutorial for more "
385  "details.");
386 }
387 
392 template<typename FunctionType>
394 {
396  "The FunctionType does not have a correct definition of Evaluate(). "
397  "Please check that the FunctionType fully satisfies the requirements of "
398  "the NonDifferentiableDecomposableFunctionType API; see the optimizer "
399  "tutorial for more details.");
400 }
401 
402 } // namespace traits
403 } // namespace optimization
404 } // namespace mlpack
405 
406 #endif
Check if a suitable overload of Shuffle() is available.
double(*)(const arma::mat &, arma::mat &) EvaluateWithGradientStaticForm
This is the form of a static EvaluateWithGradient() method.
Definition: traits.hpp:83
Check if a suitable overload of PartialGradient() is available.
Check if a suitable overload of Gradient() that supports sparse gradients is available.
.hpp
Definition: add_to_po.hpp:21
double(FunctionType::*)(const arma::mat &, arma::mat &) const EvaluateWithGradientConstForm
This is the form of a const EvaluateWithGradient() method.
Definition: traits.hpp:78
Check if a suitable overload of NumFunctions() is available.
Check if a suitable overload of EvaluateConstraint() is available.
void CheckResolvableFunctionTypeAPI()
Perform checks for the ResolvableFunctionType API.
double(*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientStaticForm
This is the form of a decomposable static EvaluateWithGradient() method.
Definition: traits.hpp:152
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) const DecomposableEvaluateWithGradientConstForm
This is the form of a decomposable const EvaluateWithGradient() method.
Definition: traits.hpp:147
Check if a suitable decomposable overload of Gradient() is available.
void CheckNonDifferentiableFunctionTypeAPI()
Perform checks for the NonDifferentiableFunctionType API.
Check if a suitable overload of Gradient() is available.
Check if a suitable overload of EvaluateWithGradient() is available.
Check if a suitable overload of NumFeatures() is available.
Check if a suitable overload of GradientConstraint() is available.
Check if a suitable decomposable overload of EvaluateWithGradient() is available. ...
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
Check if a suitable overload of NumConstraints() is available.
void CheckDecomposableFunctionTypeAPI()
Perform checks for the DecomposableFunctionType API.
Check if a suitable overload of Evaluate() is available.
void CheckSparseFunctionTypeAPI()
Perform checks for the SparseFunctionType API.
void CheckNonDifferentiableDecomposableFunctionTypeAPI()
Perform checks for the NonDifferentiableDecomposableFunctionType API.
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientForm
This is the form of a decomposable non-const EvaluateWithGradient() method.
Definition: traits.hpp:142
void CheckFunctionTypeAPI()
Perform checks for the regular FunctionType API.
Check if a suitable decomposable overload of Evaluate() is available.
void CheckConstrainedFunctionTypeAPI()
Perform checks for the ConstrainedFunctionType API.