OpenNN  2.2
Open Neural Networks Library
Classes | Public Types | Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
OpenNN::Variables Class Reference

#include <variables.h>

Classes

struct  Item
 

Public Types

enum  Use { Input, Target, Unused }
 

Public Member Functions

 Variables (void)
 
 Variables (const size_t &)
 
 Variables (const size_t &, const size_t &)
 
 Variables (const tinyxml2::XMLDocument &)
 
 Variables (const Variables &)
 
virtual ~Variables (void)
 
Variablesoperator= (const Variables &)
 
bool operator== (const Variables &) const
 
const Vector< Item > & get_items (void) const
 
const Itemget_item (const size_t &) const
 
size_t get_variables_number (void) const
 
bool empty (void) const
 
size_t count_used_variables_number (void) const
 
size_t count_unused_variables_number (void) const
 
size_t count_inputs_number (void) const
 
size_t count_targets_number (void) const
 
Vector< size_t > count_uses (void) const
 
Vector< Usearrange_uses (void) const
 
Vector< std::string > write_uses (void) const
 
const Useget_use (const size_t &) const
 
std::string write_use (const size_t &) const
 
bool is_input (const size_t &) const
 
bool is_target (const size_t &) const
 
bool is_unused (const size_t &) const
 
bool is_used (const size_t &) const
 
Vector< size_t > arrange_used_indices (void) const
 
Vector< size_t > arrange_inputs_indices (void) const
 
Vector< size_t > arrange_targets_indices (void) const
 
Vector< size_t > arrange_unused_indices (void) const
 
Vector< int > arrange_inputs_indices_int (void) const
 
Vector< int > arrange_targets_indices_int (void) const
 
Vector< std::string > arrange_names (void) const
 
Vector< std::string > arrange_used_names (void) const
 
Vector< std::string > arrange_used_units (void) const
 
const std::string & get_name (const size_t &) const
 
bool has_names (void) const
 
Vector< std::string > arrange_units (void) const
 
const std::string & get_unit (const size_t &) const
 
Vector< std::string > arrange_descriptions (void) const
 
const std::string & get_description (const size_t &) const
 
const bool & get_display (void) const
 
void set (void)
 
void set (const size_t &)
 
void set (const size_t &, const size_t &)
 
void set (const tinyxml2::XMLDocument &)
 
void set_default (void)
 
void set_variables_number (const size_t &)
 
void set_items (const Vector< Item > &)
 
void set_uses (const Vector< Use > &)
 
void set_uses (const Vector< std::string > &)
 
void set_use (const size_t &, const Use &)
 
void set_use (const size_t &, const std::string &)
 
void set_input (void)
 
void set_target (void)
 
void set_unuse (void)
 
void set_input_indices (const Vector< size_t > &)
 
void set_target_indices (const Vector< size_t > &)
 
void set_unuse_indices (const Vector< size_t > &)
 
void set_input_indices (const Vector< int > &)
 
void set_target_indices (const Vector< int > &)
 
void set_default_uses (void)
 
void set_names (const Vector< std::string > &)
 
void set_name (const size_t &, const std::string &)
 
void set_units (const Vector< std::string > &)
 
void set_units (const size_t &, const std::string &)
 
void set_descriptions (const Vector< std::string > &)
 
void set_description (const size_t &, const std::string &)
 
void set_names (const Vector< std::string > &, const Vector< Vector< std::string > > &)
 
void set_display (const bool &)
 
Matrix< std::string > arrange_information (void) const
 
Vector< std::string > arrange_inputs_units (void) const
 
Vector< std::string > arrange_targets_units (void) const
 
Vector< std::string > arrange_inputs_name (void) const
 
Vector< std::string > arrange_targets_name (void) const
 
Vector< std::string > arrange_inputs_description (void) const
 
Vector< std::string > arrange_targets_description (void) const
 
Matrix< std::string > arrange_inputs_information (void) const
 
Matrix< std::string > arrange_targets_information (void) const
 
void convert_time_series (const size_t &)
 
void convert_association (void)
 
std::string to_string (void) const
 
tinyxml2::XMLDocument * to_XML (void) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
void write_XML (tinyxml2::XMLPrinter &) const
 

Static Private Member Functions

static std::string unsigned_to_string (const size_t &)
 
static std::string prepend (const std::string &, const std::string &)
 

Private Attributes

Vector< Itemitems
 
bool display
 

Detailed Description

This class is used to store information about the variables of a data set. Variables in a data set can be used as inputs and targets. This class also stores information about the name, unit and description of all the variables.

Definition at line 50 of file variables.h.

Constructor & Destructor Documentation

◆ Variables() [1/5]

OpenNN::Variables::Variables ( void  )
explicit

Default constructor. It creates a variables object with zero variables. It also initializes the rest of class members to their default values.

Definition at line 32 of file variables.cpp.

◆ Variables() [2/5]

OpenNN::Variables::Variables ( const size_t &  new_variables_number)
explicit

Variables number constructor. It creates a variables object with a given number of variables. All the variables are set as inputs but the last, which is set as targets. It also initializes the rest of class members to their default values.

Parameters
new_variables_numberNumber of variables.

Definition at line 46 of file variables.cpp.

◆ Variables() [3/5]

OpenNN::Variables::Variables ( const size_t &  new_inputs_number,
const size_t &  new_targets_number 
)
explicit

Variables number constructor. It creates a variables object with a given number of input and target variables. It also initializes the rest of class members to their default values.

Parameters
new_inputs_numberNumber of input variables.
new_targets_numberNumber of target variables.

Definition at line 60 of file variables.cpp.

◆ Variables() [4/5]

OpenNN::Variables::Variables ( const tinyxml2::XMLDocument &  variables_document)
explicit

XML constructor. It creates a variables object and loads its members from a XML document.

Parameters
variables_documentTinyXML document with the member data.

Definition at line 72 of file variables.cpp.

◆ Variables() [5/5]

OpenNN::Variables::Variables ( const Variables other_variables)

Copy constructor. It creates a copy of an existing variables object.

Parameters
other_variablesVariables object to be copied.

Definition at line 84 of file variables.cpp.

Member Function Documentation

◆ arrange_information()

Matrix< std::string > OpenNN::Variables::arrange_information ( void  ) const

Returns all the available information about the variables as a matrix of strings. The number of rows is the number of variables. The number of columns is four. Each row contains the information of a single variable (name, units, description and use).

Definition at line 584 of file variables.cpp.

◆ arrange_inputs_information()

Matrix< std::string > OpenNN::Variables::arrange_inputs_information ( void  ) const

Returns a single matrix with the names, units and descriptions of all the input variables. The number of rows is the number of inputs, and the number of columns is 3.

Definition at line 1140 of file variables.cpp.

◆ arrange_targets_information()

Matrix< std::string > OpenNN::Variables::arrange_targets_information ( void  ) const

Returns a single matrix with the names, units and descriptions of all the target variables. The number of rows is the number of targets, and the number of columns is 3.

Definition at line 1168 of file variables.cpp.

◆ arrange_uses()

Vector< Variables::Use > OpenNN::Variables::arrange_uses ( void  ) const

Returns a vector containing the use of each variable. The size of the vector is equal to the number of variables.

Definition at line 327 of file variables.cpp.

◆ convert_association()

void OpenNN::Variables::convert_association ( void  )

Arranges the variables in a proper format for association. The number of variables is doubled. The first half will be set as inputs, and the second half as targets.

Definition at line 1953 of file variables.cpp.

◆ convert_time_series()

void OpenNN::Variables::convert_time_series ( const size_t &  lags_number)

Converts the variables when the data set is to be used for time series prediction. This method modifies the number of variables. The new number of variables will be variables_number*(1+lags_number).

Definition at line 1911 of file variables.cpp.

◆ count_uses()

Vector< size_t > OpenNN::Variables::count_uses ( void  ) const

Returns a vector containing the numbers of input, target and unused variables, respectively. The size of that vector is three.

Definition at line 296 of file variables.cpp.

◆ from_XML()

void OpenNN::Variables::from_XML ( const tinyxml2::XMLDocument &  document)

Deserializes a TinyXML document into this variables object.

Parameters
documentXML document containing the member data.

Definition at line 2189 of file variables.cpp.

◆ get_description()

const std::string & OpenNN::Variables::get_description ( const size_t &  i) const

Returns the description of a single variable in the data set.

Parameters
iIndex of variable.

Definition at line 1060 of file variables.cpp.

◆ get_display()

const bool & OpenNN::Variables::get_display ( void  ) const

Returns true if messages from this class can be displayed on the screen, or false if messages from this class can't be displayed on the screen.

Definition at line 1196 of file variables.cpp.

◆ get_item()

const Variables::Item & OpenNN::Variables::get_item ( const size_t &  i) const

Returns the information about a single variable.

Parameters
iIndex of variable.

Definition at line 168 of file variables.cpp.

◆ get_name()

const std::string & OpenNN::Variables::get_name ( const size_t &  i) const

Returns the name of a single variable in the data set.

Parameters
iIndex of variable.

Definition at line 841 of file variables.cpp.

◆ get_unit()

const std::string & OpenNN::Variables::get_unit ( const size_t &  i) const

Returns the units of a single variable in the data set.

Parameters
iIndex of variable.

Definition at line 961 of file variables.cpp.

◆ get_use()

const Variables::Use & OpenNN::Variables::get_use ( const size_t &  i) const

Returns the use of a single variable.

Parameters
iVariable index.

Definition at line 389 of file variables.cpp.

◆ is_input()

bool OpenNN::Variables::is_input ( const size_t &  index) const

Returns true if the use of a variable is an input, and false otherwise.

Parameters
indexIndex of variable.

Definition at line 432 of file variables.cpp.

◆ is_target()

bool OpenNN::Variables::is_target ( const size_t &  index) const

Returns true if the use of a variable is a target, and false otherwise.

Parameters
indexIndex of variable.

Definition at line 470 of file variables.cpp.

◆ is_unused()

bool OpenNN::Variables::is_unused ( const size_t &  index) const

Returns true if the use of a variable is neither an input nor a target, and false otherwise.

Parameters
indexIndex of variable.

Definition at line 507 of file variables.cpp.

◆ is_used()

bool OpenNN::Variables::is_used ( const size_t &  index) const

Returns true if the use of a variable is either input or target, and false if it is unused.

Parameters
indexIndex of variable.

Definition at line 544 of file variables.cpp.

◆ operator=()

Variables & OpenNN::Variables::operator= ( const Variables other_variables)

Assignment operator. It assigns to the current object the members of an existing variables object.

Parameters
other_variablesVariables object to be assigned.

Definition at line 111 of file variables.cpp.

◆ operator==()

bool OpenNN::Variables::operator== ( const Variables other_variables) const

Equal to operator. It compares this object with another object of the same class. It returns true if the members of the two objects have the same values, and false otherwise. @ param other_variables Variables object to be compared with.

Definition at line 137 of file variables.cpp.

◆ set() [1/3]

void OpenNN::Variables::set ( const size_t &  new_variables_number)

Sets a new number of variables in the current object. All the variables are set as inputs, but the last one, wich is set as targets.

Parameters
new_variables_numberNumber of variables.

Definition at line 1220 of file variables.cpp.

◆ set() [2/3]

void OpenNN::Variables::set ( const size_t &  inputs_number,
const size_t &  targets_number 
)

Sets new numbers of of inputs and target variables in the current object. The total number of variables is the number of inputs plus the number of targets. The first variables are set as inputs, and last ones are set as targets.

Parameters
inputs_numberNumber of input variables.
targets_numberNumber of target variables.

Definition at line 1236 of file variables.cpp.

◆ set() [3/3]

void OpenNN::Variables::set ( const tinyxml2::XMLDocument &  variables_document)

Sets the variables information members from a XML document.

Parameters
variables_documentPointer to a TinyXML document containing the member data.

Definition at line 1261 of file variables.cpp.

◆ set_default()

void OpenNN::Variables::set_default ( void  )

Sets the default values to the variables object:

  • display: true

Definition at line 1276 of file variables.cpp.

◆ set_default_uses()

void OpenNN::Variables::set_default_uses ( void  )

Sets the default uses for the input and target variables:

  • Input indices: 0, ..., variables number-2.
  • Target indices: variables number-1.

Definition at line 1558 of file variables.cpp.

◆ set_description()

void OpenNN::Variables::set_description ( const size_t &  i,
const std::string &  new_description 
)

This method sets the description of a single variable. If the vector of descriptions is zero the rest of elements are initialized as empty strings.

Parameters
iIndex of variable.
new_descriptionDescription of variable.

Definition at line 1762 of file variables.cpp.

◆ set_descriptions()

void OpenNN::Variables::set_descriptions ( const Vector< std::string > &  new_descriptions)

Sets new descriptions for the variables in the data set from a vector of strings. The size of that vector must be equal to the total number of variables.

Parameters
new_descriptionsDescription of variables.

Definition at line 1725 of file variables.cpp.

◆ set_display()

void OpenNN::Variables::set_display ( const bool &  new_display)

Sets a new display value. If it is set to true messages from this class are to be displayed on the screen; if it is set to false messages from this class are not to be displayed on the screen.

Parameters
new_displayDisplay value.

Definition at line 1899 of file variables.cpp.

◆ set_input_indices() [1/2]

void OpenNN::Variables::set_input_indices ( const Vector< size_t > &  input_indices)

Sets the variables of the given indices as inputs.

Parameters
input_indicesIndices of the variables to set as intputs.

Definition at line 1480 of file variables.cpp.

◆ set_input_indices() [2/2]

void OpenNN::Variables::set_input_indices ( const Vector< int > &  input_indices)

Sets the variables of the given indices as inputs.

Parameters
input_indicesIndices of the variables to set as intputs.

Definition at line 1510 of file variables.cpp.

◆ set_items()

void OpenNN::Variables::set_items ( const Vector< Item > &  new_items)

Sets new variable items in this object.

Parameters
new_itemsVector of item structures to be set.

Definition at line 1287 of file variables.cpp.

◆ set_name()

void OpenNN::Variables::set_name ( const size_t &  i,
const std::string &  new_name 
)

This method set the name of a single variable. If the vector of names is zero the rest of elements are initialized as empty strings.

Parameters
iIndex of variable.
new_nameName of variable.

Definition at line 1622 of file variables.cpp.

◆ set_names() [1/2]

void OpenNN::Variables::set_names ( const Vector< std::string > &  new_names)

Sets new names for the variables in the data set from a vector of strings. The size of that vector must be equal to the total number of variables.

Parameters
new_namesName of variables.

Definition at line 1585 of file variables.cpp.

◆ set_names() [2/2]

void OpenNN::Variables::set_names ( const Vector< std::string > &  columns_name,
const Vector< Vector< std::string > > &  nominal_labels 
)

Sets the names of the variables from a vector of vectors of names. This method is used when loading a data file with nominal values.

Parameters
columns_nameNames of columns in the data file.
nominal_labelsValues of all nominal variables in the data file.

Definition at line 1796 of file variables.cpp.

◆ set_target_indices() [1/2]

void OpenNN::Variables::set_target_indices ( const Vector< size_t > &  target_indices)

Sets the variables of the given indices as inputs.

Parameters
target_indicesIndices of the variables to set as targets.

Definition at line 1495 of file variables.cpp.

◆ set_target_indices() [2/2]

void OpenNN::Variables::set_target_indices ( const Vector< int > &  target_indices)

Sets the variables of the given indices as targets.

Parameters
target_indicesIndices of the variables to set as targets.

Definition at line 1525 of file variables.cpp.

◆ set_units() [1/2]

void OpenNN::Variables::set_units ( const Vector< std::string > &  new_units)

Sets new units for the variables in the data set from a vector of strings. The size of that vector must be equal to the total number of variables.

Parameters
new_unitsUnits of variables.

Definition at line 1655 of file variables.cpp.

◆ set_units() [2/2]

void OpenNN::Variables::set_units ( const size_t &  i,
const std::string &  new_units 
)

This method set the units of a single variable. If the vector of units is zero the rest of elements are initialized as empty strings.

Parameters
iIndex of variable.
new_unitsUnits of variable.

Definition at line 1692 of file variables.cpp.

◆ set_unuse_indices()

void OpenNN::Variables::set_unuse_indices ( const Vector< size_t > &  unused_indices)

Sets the variables of the given indices as unused.

Parameters
unused_indicesIndices of the variables to set as unused.

Definition at line 1540 of file variables.cpp.

◆ set_use() [1/2]

void OpenNN::Variables::set_use ( const size_t &  i,
const Use new_use 
)

Sets the use of a single variable.

Parameters
iIndex of variable.
new_useUse for that variable.

Definition at line 1354 of file variables.cpp.

◆ set_use() [2/2]

void OpenNN::Variables::set_use ( const size_t &  i,
const std::string &  new_use 
)

Sets the use of a single variable from a string. The possible values for that string are "Unused", "Input" and "Target".

Parameters
iIndex of variable.
new_useUse for that variable.

Definition at line 1386 of file variables.cpp.

◆ set_uses() [1/2]

void OpenNN::Variables::set_uses ( const Vector< Use > &  new_uses)

Sets new uses for the all the variables from a single vector. It does not modify the other information on the variables (name, units or description).

Parameters
new_usesVector of use elements.

Definition at line 1299 of file variables.cpp.

◆ set_uses() [2/2]

void OpenNN::Variables::set_uses ( const Vector< std::string > &  new_uses)

Sets new uses for the all the variables from a vector of strings. The possible values for that strings are "Input", "Target" and "Unused".

Parameters
new_usesVector of use strings.

Definition at line 1316 of file variables.cpp.

◆ set_variables_number()

void OpenNN::Variables::set_variables_number ( const size_t &  new_variables_number)

Sets a new number of variables in the variables object. All variables are set as inputs but the last one, which is set as targets.

Parameters
new_variables_numberNumber of variables.

Definition at line 1980 of file variables.cpp.

◆ to_XML()

tinyxml2::XMLDocument * OpenNN::Variables::to_XML ( void  ) const

Serializes the variables object into a XML document of the TinyXML library. See the OpenNN manual for more information about the format of this document.

Definition at line 2028 of file variables.cpp.

◆ write_use()

std::string OpenNN::Variables::write_use ( const size_t &  i) const

Returns a string the use of a variable.

Parameters
iVariable index.

Definition at line 400 of file variables.cpp.

◆ write_uses()

Vector< std::string > OpenNN::Variables::write_uses ( void  ) const

Returns a vector of strings with the use of each variable. The size of the vector is equal to the number of variables. The possible values for the elements are "Unused", "Input" and "Target".

Definition at line 348 of file variables.cpp.

◆ write_XML()

void OpenNN::Variables::write_XML ( tinyxml2::XMLPrinter &  file_stream) const

Serializes the variables object into a XML document of the TinyXML library without keep the DOM tree in memory. See the OpenNN manual for more information about the format of this document.

Definition at line 2117 of file variables.cpp.

Member Data Documentation

◆ items

Vector<Item> OpenNN::Variables::items
private

Vector of variable items. Each item contains the name, units, description and use of a single variable.

Definition at line 268 of file variables.h.


The documentation for this class was generated from the following files: