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

#include <instances.h>

Classes

struct  Item
 

Public Types

enum  Use { Training, Selection, Testing, Unused }
 
enum  SplittingMethod { Sequential, Random }
 

Public Member Functions

 Instances (void)
 
 Instances (const size_t &)
 
 Instances (const tinyxml2::XMLDocument &)
 
 Instances (const Instances &)
 
virtual ~Instances (void)
 
Instancesoperator= (const Instances &)
 
bool operator== (const Instances &) const
 
size_t get_instances_number (void) const
 
bool empty (void) const
 
Vector< Usearrange_uses (void) const
 
Vector< std::string > write_uses (void) const
 
Vector< std::string > write_abbreviated_uses (void) const
 
const Useget_use (const size_t &) const
 
std::string write_use (const size_t &) const
 
bool is_used (const size_t &) const
 
bool is_unused (const size_t &) const
 
size_t count_training_instances_number (void) const
 
size_t count_selection_instances_number (void) const
 
size_t count_testing_instances_number (void) const
 
size_t count_unused_instances_number (void) const
 
size_t count_used_instances_number (void) const
 
Vector< size_t > count_uses (void) const
 
Vector< size_t > arrange_used_indices (void) const
 
Vector< size_t > arrange_unused_indices (void) const
 
Vector< size_t > arrange_training_indices (void) const
 
Vector< size_t > arrange_selection_indices (void) const
 
Vector< size_t > arrange_testing_indices (void) const
 
Vector< int > arrange_training_indices_int (void) const
 
Vector< int > arrange_selection_indices_int (void) const
 
const bool & get_display (void) const
 
void set (void)
 
void set (const size_t &)
 
void set (const tinyxml2::XMLDocument &)
 
void set_default (void)
 
void set_instances_number (const size_t &)
 
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_unused (const Vector< size_t > &)
 
void set_training (void)
 
void set_selection (void)
 
void set_testing (void)
 
void set_display (const bool &)
 
void split_sequential_indices (const double &training_ratio=0.6, const double &selection_ratio=0.2, const double &testing_ratio=0.2)
 
void split_random_indices (const double &training_ratio=0.6, const double &selection_ratio=0.2, const double &testing_ratio=0.2)
 
void split_instances (const SplittingMethod &splitting_method=Random, const double &training_ratio=0.6, const double &selection_ratio=0.2, const double &testing_ratio=0.2)
 
Vector< double > calculate_uses_percentage (void) const
 
void convert_time_series (const size_t &)
 
std::string to_string (void) const
 
void print (void) const
 
tinyxml2::XMLDocument * to_XML (void) const
 
void from_XML (const tinyxml2::XMLDocument &)
 
void write_XML (tinyxml2::XMLPrinter &) const
 

Static Public Member Functions

static SplittingMethod get_splitting_method (const std::string &)
 

Private Attributes

Vector< Itemitems
 
bool display
 

Detailed Description

This class is used to store information about the instances of a data set. Instances in a data set can be used for training, selection and testing.

Definition at line 46 of file instances.h.

Member Enumeration Documentation

◆ SplittingMethod

This is an enumeration of the available methods for dividing the instances into training, selection and testing subsets.

Definition at line 91 of file instances.h.

◆ Use

This enumeration represents the possible uses of an instance (no use, training, selection or testing).

Definition at line 86 of file instances.h.

Constructor & Destructor Documentation

◆ Instances() [1/4]

OpenNN::Instances::Instances ( void  )
explicit

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

Definition at line 28 of file instances.cpp.

◆ Instances() [2/4]

OpenNN::Instances::Instances ( const size_t &  new_instances_number)
explicit

Instances number constructor. It creates a data set object with a given number of instances. It also initializes the rest of class members to their default values.

Parameters
new_instances_numberNumber of instances in the data set.

Definition at line 41 of file instances.cpp.

◆ Instances() [3/4]

OpenNN::Instances::Instances ( const tinyxml2::XMLDocument &  instances_document)
explicit

XML constructor. It creates a instances object by loading the object members from a TinyXML document.

Parameters
instances_documentXML document from the TinyXML library.

Definition at line 53 of file instances.cpp.

◆ Instances() [4/4]

OpenNN::Instances::Instances ( const Instances other_instances)

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

Parameters
other_instancesInstances object to be copied.

Definition at line 65 of file instances.cpp.

Member Function Documentation

◆ calculate_uses_percentage()

Vector< double > OpenNN::Instances::calculate_uses_percentage ( void  ) const

Returns the percentages of unused, training, selection and testing instances, respectively.

Definition at line 1551 of file instances.cpp.

◆ convert_time_series()

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

Converts the instances when the data set is to be used for time series prediction. This method modifies the number of instances. The new number of instances will be instances_number - lags_number.

Definition at line 1574 of file instances.cpp.

◆ count_unused_instances_number()

size_t OpenNN::Instances::count_unused_instances_number ( void  ) const

Returns the number of instances in the data set which will neither be used for training, selection or testing.

Definition at line 367 of file instances.cpp.

◆ count_used_instances_number()

size_t OpenNN::Instances::count_used_instances_number ( void  ) const

Returns the total number of training, selection and testing instances, i.e. those which are not "Unused".

Definition at line 390 of file instances.cpp.

◆ count_uses()

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

Returns a vector with the number of training, selection, testing and unused instances. The size of that vector is therefore four.

Definition at line 471 of file instances.cpp.

◆ from_XML()

void OpenNN::Instances::from_XML ( const tinyxml2::XMLDocument &  instances_document)

Deserializes a TinyXML document into this instances object.

Parameters
instances_documentXML document containing the member data.

Definition at line 1143 of file instances.cpp.

◆ get_display()

const bool & OpenNN::Instances::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 705 of file instances.cpp.

◆ get_splitting_method()

Instances::SplittingMethod OpenNN::Instances::get_splitting_method ( const std::string &  splitting_method)
static

Returns a value of the splitting method enumeration from a string with that method.

Parameters
splitting_methodString with the method for splitting the instances.

Definition at line 130 of file instances.cpp.

◆ get_use()

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

Returns the use of a single instance.

Parameters
iInstance index.

Definition at line 286 of file instances.cpp.

◆ is_used()

bool OpenNN::Instances::is_used ( const size_t &  i) const

Returns true if a given instance is to be used for training, selection or testing, and false if it is to be unused.

Definition at line 333 of file instances.cpp.

◆ operator=()

Instances & OpenNN::Instances::operator= ( const Instances other_instances)

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

Parameters
other_instancesInstances object to be assigned.

Definition at line 88 of file instances.cpp.

◆ operator==()

bool OpenNN::Instances::operator== ( const Instances other_instances) 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_instances Instances object to be compared with.

Definition at line 109 of file instances.cpp.

◆ set() [1/2]

void OpenNN::Instances::set ( const size_t &  new_instances_number)

Sets a new number of instances in the instances object. All the instances are set for training.

Parameters
new_instances_numberNumber of instances.

Definition at line 729 of file instances.cpp.

◆ set() [2/2]

void OpenNN::Instances::set ( const tinyxml2::XMLDocument &  instances_document)

Sets the instances information members from a XML document.

Parameters
instances_documentPointer to a TinyXML document containing the member data.

Definition at line 742 of file instances.cpp.

◆ set_default()

void OpenNN::Instances::set_default ( void  )

Sets the default values to this instances object:

  • display: true

Definition at line 757 of file instances.cpp.

◆ set_display()

void OpenNN::Instances::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 981 of file instances.cpp.

◆ set_instances_number()

void OpenNN::Instances::set_instances_number ( const size_t &  new_instances_number)

Sets a new number of instances in the data set. All instances are also set for training.

Parameters
new_instances_numberNumber of instances.

Definition at line 993 of file instances.cpp.

◆ set_use() [1/2]

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

Sets the use of a single instance.

Parameters
iIndex of instance.
new_useUse for that instance.

Definition at line 867 of file instances.cpp.

◆ set_use() [2/2]

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

Sets the use of a single instance from a string.

Parameters
iIndex of instance.
new_useString with the use name ("Training", "Selection", "Testing" or "Unused")

Definition at line 879 of file instances.cpp.

◆ set_uses() [1/2]

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

Sets new uses to all the instances from a single vector.

Parameters
new_usesVector of use structures. The size must be equal to the number of instances.

Definition at line 769 of file instances.cpp.

◆ set_uses() [2/2]

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

Sets new uses to all the instances from a single vector of strings.

Parameters
new_usesVector of use strings. Possible values for the elements are "Training", "Selection", "Testing" and "Unused". The size must be equal to the number of instances.

Definition at line 806 of file instances.cpp.

◆ split_instances()

void OpenNN::Instances::split_instances ( const SplittingMethod splitting_method = Random,
const double &  training_ratio = 0.6,
const double &  selection_ratio = 0.2,
const double &  testing_ratio = 0.2 
)

Divides the instances into training, selection and testing subsets.

Parameters
splitting_methodInstances splitting method (Sequential or Random, Random by default).
training_ratioRatio of training instances (0.6 by default).
selection_ratioRatio of selection instances (0.2 by default).
testing_ratioRatio of testing instances (0.2 by default).

Definition at line 1471 of file instances.cpp.

◆ split_random_indices()

void OpenNN::Instances::split_random_indices ( const double &  training_instances_ratio = 0.6,
const double &  selection_instances_ratio = 0.2,
const double &  testing_instances_ratio = 0.2 
)

Creates new training, selection and testing indices at random.

Parameters
training_instances_ratioRatio of training instances in the data set.
selection_instances_ratioRatio of selection instances in the data set.
testing_instances_ratioRatio of testing instances in the data set.

Definition at line 1286 of file instances.cpp.

◆ split_sequential_indices()

void OpenNN::Instances::split_sequential_indices ( const double &  training_instances_ratio = 0.6,
const double &  selection_instances_ratio = 0.2,
const double &  testing_instances_ratio = 0.2 
)

Creates new training, selection and testing indices with sequential indices.

Parameters
training_instances_ratioRatio of training instances in the data set.
selection_instances_ratioRatio of selection instances in the data set.
testing_instances_ratioRatio of testing instances in the data set.

Definition at line 1384 of file instances.cpp.

◆ to_XML()

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

Serializes the instances 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 1006 of file instances.cpp.

◆ write_use()

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

Returns a string the use name of a single instance.

Parameters
iInstance index.

Definition at line 297 of file instances.cpp.

◆ write_XML()

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

Serializes the instances 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 1092 of file instances.cpp.


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