Class Parameters
Defined in File parameters.h
Class Documentation
-
class Parameters
The Parameters class manages configuration parameters for each program.
This class handles the parsing, validation, and storage of parameters passed via command-line arguments or a JSON configuration file. It supports various data types and provides utility functions to ensure parameters are correctly set and valid.
Public Functions
-
Parameters() = default
-
explicit Parameters(const std::vector<std::string> &args, const std::vector<ParameterCode> &validParams)
Construct a new Parameters object containing all arguments passed by CLI.
- Parameters:
args – Program arguments.
validParams – Valid parameter codes.
-
explicit Parameters(const std::string &jsonfile, const std::vector<ParameterCode> &validParams)
Construct a new Parameters object containing all arguments passed by JSON config file.
- Parameters:
jsonfile – JSON config file name.
validParams – Valid parameter codes.
-
void setInt(ParameterCode id, const std::string &value)
Sets an integer parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the integer parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid integer.
-
void setInt(ParameterCode id, int value)
Sets an integer parameter.
- Parameters:
id – The parameter code to set.
value – The integer value to set.
- Throws:
CommandArgumentException – if the parameter is already set.
-
void setFloat(ParameterCode id, const std::string &value)
Sets a float parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the float parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid float.
-
void setFloat(ParameterCode id, float value)
Sets a float parameter.
- Parameters:
id – The parameter code to set.
value – The float value to set.
- Throws:
CommandArgumentException – if the parameter is already set.
-
void setDouble(ParameterCode id, const std::string &value)
Sets a double parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the double parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid double.
-
void setDouble(ParameterCode id, double value)
Sets a double parameter.
- Parameters:
id – The parameter code to set.
value – The double value to set.
- Throws:
CommandArgumentException – if the parameter is already set.
-
void setBool(ParameterCode id, std::string value)
Sets a boolean parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the boolean parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid boolean.
-
void setBool(ParameterCode id, bool value)
Sets a boolean parameter.
- Parameters:
id – The parameter code to set.
value – The boolean value to set.
- Throws:
CommandArgumentException – if the parameter is already set.
-
void setDoubleVector(ParameterCode id, const std::string &value)
Sets a double vector parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the double vector parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid list of doubles.
-
void setDoubleVector(ParameterCode id, const std::vector<double> &value)
Sets a double vector parameter.
- Parameters:
id – The parameter code to set.
value – The vector of double values to set.
-
void setIntVector(ParameterCode id, const std::string &value)
Sets an integer vector parameter from a string value.
- Parameters:
id – The parameter code to set.
value – The string value to convert and set as the integer vector parameter.
- Throws:
CommandArgumentException – if the parameter is already set or if the value is not a valid list of integers.
-
void setIntVector(ParameterCode id, const std::vector<int> &value)
Sets an integer vector parameter.
- Parameters:
id – The parameter code to set.
value – The vector of integer values to set.
-
void setString(ParameterCode id, const std::string &value)
Sets a string parameter.
- Parameters:
id – The parameter code to set.
value – The string value to set.
- Throws:
CommandArgumentException – if the parameter is already set.
-
void setDefaultInt(ParameterCode id, int value)
Sets a default integer value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultFloat(ParameterCode id, float value)
Sets a default float value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultDouble(ParameterCode id, double value)
Sets a default double value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultBool(ParameterCode id, bool value)
Sets a default boolean value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultDoubleVector(ParameterCode id, const std::string &defaultValue)
Sets a default double vector value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultIntVector(ParameterCode id, const std::string &defaultValue)
Sets a default integer vector value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
-
void setDefaultString(ParameterCode id, const std::string &defaultValue, bool withRoot = false)
Sets a default string value for the given parameter code if not already set.
- Parameters:
id – The parameter code.
defaultValue – The default value to set.
withRoot – Whether to prepend the ROOT_FOLDER to the default value.
-
int getInt(ParameterCode id)
Gets the integer value for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The integer value associated with the parameter code.
-
float getFloat(ParameterCode id)
Gets the float value for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The float value associated with the parameter code.
-
double getDouble(ParameterCode id)
Gets the double value for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The double value associated with the parameter code.
-
bool getBool(ParameterCode id)
Gets the boolean value for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The boolean value associated with the parameter code.
-
std::vector<double> getDoubleVector(ParameterCode id)
Gets the vector of double values for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The vector of double values associated with the parameter code.
-
std::vector<int> getIntVector(ParameterCode id)
Gets the vector of integer values for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The vector of integer values associated with the parameter code.
-
std::string getString(ParameterCode id)
Gets the string value for the given parameter code.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
- Returns:
The string value associated with the parameter code.
-
StringInt getArch()
Gets the architecture of hidden layers.
- Returns:
The architecture of hidden layers.
-
StringInt getArchInd()
Gets the indices of the architecture of hidden layers.
- Returns:
The indices of the architecture of hidden layers.
-
inline std::map<ParameterCode, int> getAllInts() const
Gets all integer parameters.
- Returns:
A map of all integer parameters.
-
inline std::map<ParameterCode, float> getAllFloats() const
Gets all float parameters.
- Returns:
A map of all float parameters.
-
inline std::map<ParameterCode, double> getAllDoubles() const
Gets all double parameters.
- Returns:
A map of all double parameters.
-
inline std::map<ParameterCode, bool> getAllBools() const
Gets all boolean parameters.
- Returns:
A map of all boolean parameters.
-
inline std::map<ParameterCode, std::vector<double>> getAllDoubleVectors() const
Gets all double vector parameters.
- Returns:
A map of all double vector parameters.
-
inline std::map<ParameterCode, std::vector<int>> getAllIntVectors() const
Gets all integer vector parameters.
- Returns:
A map of all integer vector parameters.
-
inline std::map<ParameterCode, std::string> getAllStrings() const
Gets all string parameters.
- Returns:
A map of all string parameters.
-
bool isIntSet(ParameterCode id)
Checks if an integer parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isFloatSet(ParameterCode id)
Checks if a float parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isDoubleSet(ParameterCode id)
Checks if a double parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isBoolSet(ParameterCode id)
Checks if a boolean parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isDoubleVectorSet(ParameterCode id)
Checks if a double vector parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isIntVectorSet(ParameterCode id)
Checks if an integer vector parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
bool isStringSet(ParameterCode id) const
Checks if a string parameter is set.
- Parameters:
id – The parameter code.
- Returns:
True if the parameter is set, false otherwise.
-
void sanitizePath(ParameterCode id, bool shouldFileExist)
Handles every aspect of parameters that represents files.
Checks if a file exists if “shouldFileExist” is set to true.
Appends the ROOT_FOLDER path to every file if ROOT_FOLDER is set.
- Parameters:
id – Parameter code to be processed.
shouldFileExist – Flag indicating whether the file should exist.
-
void writeHiddenLayersFile()
Write the configuration of hidden layers to a file.
-
void readHiddenLayersFile(StringInt &arch, StringInt &archInd)
Reads, checks, and stores the hidden layers configuration file.
Format of the file: The file format should include pairs of strictly positive integers on each line, where the first integer represents the layer’s ID (starting at 1 and incrementing by 1 for each layer) and the second integer represents the number of neurons in that layer. The first layer’s number of neurons must be a multiple of the number of attributes.
-
template<typename T>
inline std::string vectorToString(const std::vector<T> &vec) const Converts a vector of any type to a string representation.
- Template Parameters:
T – The type of elements in the vector.
- Parameters:
vec – The vector to convert.
- Returns:
std::string The string representation of the vector.
-
void assertStringExists(ParameterCode id) const
Asserts that a string parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertIntExists(ParameterCode id)
Asserts that an integer parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertFloatExists(ParameterCode id)
Asserts that a float parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertDoubleExists(ParameterCode id)
Asserts that a double parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertBoolExists(ParameterCode id)
Asserts that a boolean parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertDoubleVectorExists(ParameterCode id)
Asserts that a double vector parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void assertIntVectorExists(ParameterCode id)
Asserts that an integer vector parameter is set.
- Parameters:
id – The parameter code.
- Throws:
CommandArgumentException – if the parameter is not set.
-
void checkAttributeAndClassCounts()
Checks the attribute and class counts for validity.
- Throws:
CommandArgumentException – if the number of attributes or classes is invalid.
-
void checkParametersCommon()
Checks common parameters for validity.
- Throws:
CommandArgumentException – if any common parameter is invalid.
-
void checkParametersFidex()
Checks Fidex-specific parameters for validity.
- Throws:
CommandArgumentException – if any Fidex parameter is invalid.
-
void checkParametersDecisionThreshold()
Checks decision threshold and positive class index parameters for validity.
- Throws:
CommandArgumentException – if any parameter is invalid.
-
void checkParametersDimlpTrn()
Checks Dimlp training specific parameters for validity.
- Throws:
CommandArgumentException – if any Dimlp training parameter is invalid.
-
void checkParametersNormalization()
Checks normalization parameters for validity.
- Throws:
CommandArgumentException – if any normalization parameter is invalid.
-
void setDefaultNbQuantLevels()
Sets the default number of quantization levels.
-
void setDefaultDecisionThreshold()
Sets the default values of decision threshold and positive class index parameters.
Public Static Functions
-
static std::string getParameterName(ParameterCode id)
Gets the name of the parameter associated with the given parameter code.
- Parameters:
id – The parameter code.
- Returns:
The name of the parameter.
-
Parameters() = default