Turi Create  4.0
option_info.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_OPTION_HANDLING_OPTION_INFO_H_
7 #define TURI_OPTION_HANDLING_OPTION_INFO_H_
8 
9 #include <string>
10 #include <vector>
11 #include <core/data/flexible_type/flexible_type.hpp>
12 
13 namespace turi { namespace option_handling {
14 
15 /**
16  * \ingroup toolkit_util
17  * The primary structure for information regarding the possible
18  * parameters of the algorithm. The values passed into the model are
19  * checked against this information.
20  */
21 struct option_info {
22  /// The name of the parameter.
23  std::string name;
24 
25  /// A short description of the parameter.
26  std::string description;
27 
28  /// The default value
30 
31  /** The type of the parameter. If REAL or CATEGORICAL, allowed
32  * values are specified in the parameters below. Integer behaves
33  * like REAL, but a warning is issued if the given value is not an
34  * integer. If BOOL, the specified value must translate to either 0
35  * or 1. If COLUMN, then it must be a valid column in the data.
36  */
37  enum {REAL, INTEGER, BOOL, CATEGORICAL, STRING, FLEXIBLE_TYPE} parameter_type;
38 
39  /// If real, these specify the allowed range of the model.
40  flexible_type lower_bound, upper_bound;
41 
42  /// If categorical, this specifies the allowed values.
43  std::vector<flexible_type> allowed_values;
44 
45  /// Export to dictionary
47 
48  /** Interpret a value according to the current options.
49  */
50  flexible_type interpret_value(const flexible_type& value) const;
51 
52  /** Validate a given option. If the option doesn't match up with
53  * what is specified, a string error is raised detailing what's wrong.
54  */
55  void check_value(const flexible_type& value) const;
56 
57  /// Serialization -- save
58  void save(turi::oarchive& oarc) const;
59 
60  /// Serialization -- load
61  void load(turi::iarchive& iarc);
62 
63 };
64 
65 }}
66 
67 #endif /* TURI_OPTION_HANDLING_OPTION_INFO_H_*/
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
Definition: iarchive.hpp:60
void check_value(const flexible_type &value) const
flexible_type to_dictionary() const
Export to dictionary.
flexible_type lower_bound
If real, these specify the allowed range of the model.
Definition: option_info.hpp:40
std::string name
The name of the parameter.
Definition: option_info.hpp:23
enum turi::option_handling::option_info::@9 parameter_type
void load(turi::iarchive &iarc)
Serialization – load.
flexible_type interpret_value(const flexible_type &value) const
void save(turi::oarchive &oarc) const
Serialization – save.
flexible_type default_value
The default value.
Definition: option_info.hpp:29
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
Definition: oarchive.hpp:80
std::vector< flexible_type > allowed_values
If categorical, this specifies the allowed values.
Definition: option_info.hpp:43
std::string description
A short description of the parameter.
Definition: option_info.hpp:26