Parses the command line for parameters and holds user-specified parameters. More...
Static Public Member Functions | |
static void | AddBindingName (const std::string &bindingName, const std::string &name) |
Add a user-friendly name for a binding. More... | |
static void | AddExample (const std::string &bindingName, const std::function< std::string()> &example) |
Add an example for a binding. More... | |
static void | AddFunction (const std::string &type, const std::string &name, void(*func)(util::ParamData &, const void *, void *)) |
Add a function to the function map. More... | |
static void | AddLongDescription (const std::string &bindingName, const std::function< std::string()> &longDescription) |
Add a long description for a binding. More... | |
static void | AddParameter (const std::string &bindingName, util::ParamData &&d) |
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. More... | |
static void | AddSeeAlso (const std::string &bindingName, const std::string &description, const std::string &link) |
Add a SeeAlso for a binding. More... | |
static void | AddShortDescription (const std::string &bindingName, const std::string &shortDescription) |
Add a short description for a binding. More... | |
static IO & | GetSingleton () |
Retrieve the singleton. More... | |
static util::Timers & | GetTimers () |
Retrieve the global Timers object. More... | |
static util::Params | Parameters (const std::string &bindingName) |
Return a new Params object initialized with all the parameters of the binding bindingName . More... | |
Parses the command line for parameters and holds user-specified parameters.
The IO class is a subsystem by which parameters for machine learning methods can be specified and accessed. In conjunction with the macros PARAM_DOUBLE, PARAM_INT, PARAM_STRING, PARAM_FLAG, and others, this class aims to make user configurability of mlpack methods very easy. There are only three methods in IO that a user should need: IO::ParseCommandLine(), IO::GetParam(), and IO::HasParam() (in addition to the PARAM_*() macros).
A parameter is specified by using one of the following macros (this is not a complete list; see core/io/io.hpp):
ID | Name of the parameter. |
DESC | Short description of the parameter (one/two sentences). |
ALIAS | An alias for the parameter. |
DEF | Default value of the parameter. |
The flag (boolean) type automatically defaults to false; it is specified merely as a flag on the command line (no '=true' is required).
Here is an example of a few parameters being defined; this is for the KNN binding (methods/neighbor_search/knn_main.cpp):
More documentation is available on the PARAM_*() macros in the documentation for core/io/io.hpp.
In addition to allowing documentation for each individual parameter and module, the BINDING_NAME() macro provides support for documenting the programName, BINDING_SHORT_DESC() macro provides support for documenting the shortDescription, BINDING_LONG_DESC() macro provides support for documenting the longDescription, the BINDING_EXAMPLE() macro provides support for documenting the example and the BINDING_SEE_ALSO() macro provides support for documenting the seeAlso. There should only be one instance of the BINDING_NAME(), BINDING_SHORT_DESC() and BINDING_LONG_DESC() macros and there can be multiple instance of BINDING_EXAMPLE() and BINDING_SEE_ALSO() macro. Below is an example:
This description should be verbose, and explain to a non-expert user what the program does and how to use it. If relevant, paper citations should be included.
To have IO parse the command line at the beginning of code execution, only a call to ParseCommandLine() is necessary:
IO provides –help and –info options which give nicely formatted documentation of each option; the documentation is generated from the DESC arguments in the PARAM_*() macros.
When the parameters have been defined, the next important thing is how to access them. For this, the HasParam() and GetParam() methods are used. For instance, to see if the user passed the flag (boolean) "naive":
To get the value of a parameter, such as a string, use GetParam:
main()
(that is, main bindings). If options are defined elsewhere, they may be spuriously included into other bindings and confuse users. Similarly, if your binding has options which you did not define, it is probably because the option is defined somewhere else and included in your binding.
|
static |
Add a user-friendly name for a binding.
bindingName | Name of the binding to add the user-friendly name for. |
name | User-friendly name. |
|
static |
Add an example for a binding.
bindingName | Name of the binding to add the example for. |
example | Function that returns the example. |
|
static |
Add a function to the function map.
type | Type that this function should be called for. |
name | Name of the function. |
func | Function to call. |
Referenced by CLIOption< N >::CLIOption(), GoOption< T >::GoOption(), JuliaOption< T >::JuliaOption(), MDOption< T >::MDOption(), PyOption< T >::PyOption(), and ROption< T >::ROption().
|
static |
Add a long description for a binding.
bindingName | Name of the binding to add the description for. |
longDescription | Function that returns the long description. |
|
static |
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e.
PARAM_INT()).
bindingName | Name of the binding that this parameter is associated with. |
d | Utility structure holding parameter data. |
Referenced by CLIOption< N >::CLIOption(), GoOption< T >::GoOption(), JuliaOption< T >::JuliaOption(), MDOption< T >::MDOption(), PyOption< T >::PyOption(), ROption< T >::ROption(), and TestOption< N >::TestOption().
|
static |
Add a SeeAlso for a binding.
bindingName | Name of the binding to add the example for. |
description | Description of the SeeAlso. |
link | Link of the SeeAlso. |
|
static |
Add a short description for a binding.
bindingName | Name of the binding to add the description for. |
shortDescription | Description to use. |
|
static |
Retrieve the singleton.
As an end user, if you are just using the IO object, you should not need to use this function—the other static functions should be sufficient.
In this case, the singleton is used to store data for the static methods, as there is no point in defining static methods only to have users call private instance methods.
|
static |
Retrieve the global Timers object.
|
static |
Return a new Params object initialized with all the parameters of the binding bindingName
.
This is intended to be called at the beginning of the run of a binding.
Referenced by MDOption< T >::MDOption(), and mlpack::bindings::cli::ParseCommandLine().