16 #include "model_selection.h"
26 : training_strategy_pointer(NULL)
38 : training_strategy_pointer(new_training_strategy_pointer)
50 : training_strategy_pointer(NULL)
62 : training_strategy_pointer(NULL)
89 std::ostringstream buffer;
91 buffer <<
"OpenNN Exception: ModelSelection class.\n"
92 <<
"DataSet* get_training_strategy_pointer(void) const method.\n"
93 <<
"Training strategy pointer is NULL.\n";
95 throw std::logic_error(buffer.str());
276 std::ostringstream buffer;
278 buffer <<
"OpenNN Exception: ModelSelection class.\n"
279 <<
"void set_assays_numbers(const size_t&, const size_t&) method.\n"
280 <<
"Pointer to training strategy is NULL.\n";
282 throw std::logic_error(buffer.str());
287 std::ostringstream buffer;
289 buffer <<
"OpenNN Exception: ModelSelection class.\n"
290 <<
"void set_assays_numbers(const size_t&, const size_t&) method.\n"
291 <<
"Pointer to performance functional is NULL.\n";
293 throw std::logic_error(buffer.str());
298 std::ostringstream buffer;
300 buffer <<
"OpenNN Exception: ModelSelection class.\n"
301 <<
"void set_assays_numbers(const size_t&, const size_t&) method.\n"
302 <<
"Pointer to multilayer perceptron is NULL.\n";
304 throw std::logic_error(buffer.str());
318 const size_t minimum_hidden_layer_size = 1;
319 const size_t maximum_hidden_layer_size = 12;
321 size_t hidden_layer_size_increment = (maximum_hidden_layer_size-minimum_hidden_layer_size)/new_complexity_assays_number;
323 if(hidden_layer_size_increment < 1)
325 hidden_layer_size_increment = 1;
328 for(
size_t i = 0; i < new_complexity_assays_number; i++)
446 std::ostringstream buffer;
450 buffer <<
"OpenNN Exception: ModelSelection class.\n"
451 <<
"void check(void) const method.\n"
452 <<
"Pointer to training strategy is NULL.\n";
454 throw std::logic_error(buffer.str());
461 if(!performance_functional_pointer)
463 buffer <<
"OpenNN Exception: ModelSelection class.\n"
464 <<
"void check(void) const method.\n"
465 <<
"Pointer to performance functional is NULL.\n";
467 throw std::logic_error(buffer.str());
474 if(!neural_network_pointer)
476 buffer <<
"OpenNN Exception: ModelSelection class.\n"
477 <<
"void check(void) const method.\n"
478 <<
"Pointer to neural network is NULL.\n";
480 throw std::logic_error(buffer.str());
485 if(!multilayer_perceptron_pointer)
487 buffer <<
"OpenNN Exception: ModelSelection class.\n"
488 <<
"void check(void) const method.\n"
489 <<
"Pointer to multilayer perceptron is NULL.\n";
491 throw std::logic_error(buffer.str());
498 if(!data_set_pointer)
500 buffer <<
"OpenNN Exception: ModelSelection class.\n"
501 <<
"void check(void) const method.\n"
502 <<
"Pointer to data set is NULL.\n";
504 throw std::logic_error(buffer.str());
511 if(generalization_instances_number == 0)
513 buffer <<
"OpenNN Exception: ModelSelection class.\n"
514 <<
"void check(void) const method.\n"
515 <<
"Number of generalization instances is zero.\n";
517 throw std::logic_error(buffer.str());
548 Matrix<double> linear_correlations(inputs_number, targets_number);
556 for(
size_t i = 0; i < inputs_number; i++)
558 input = data_set_pointer->
get_variable(input_indices[i]);
560 for(
size_t j = 0; j < inputs_number; j++)
562 target = data_set_pointer->
get_variable(target_indices[j]);
568 return(linear_correlations);
608 std::cout <<
"Calculating logistic correlations...\n";
613 for(
size_t i = 0; i < inputs_number; i++)
617 for(
size_t j = 0; j < targets_number; j++)
621 std::cout <<
"\n#Input " << i+1 <<
", target " << j+1 <<
".\n\n";
649 training_strategy.
set_main_type(TrainingStrategy::LEVENBERG_MARQUARDT_ALGORITHM);
659 return(correlations);
693 std::ostringstream buffer;
695 buffer <<
"OpenNN Exception: ModelSelection class.\n"
696 <<
"ModelSelectionResults perform_inputs_selection(void) const method.\n"
697 <<
"This method is under development.\n";
699 throw std::logic_error(buffer.str());
819 case MaximumLinearCorrelation:
825 case MaximumLogisticCorrelation:
839 std::ostringstream buffer;
841 buffer <<
"OpenNN Exception: ModelSelection class.\n"
842 <<
"void perform_inputs_selection(void) const method.\n"
843 <<
"Unknown inputs selection method.\n";
845 throw std::logic_error(buffer.str());
858 std::ostringstream buffer;
860 buffer <<
"OpenNN Exception: ModelSelection class.\n"
861 <<
"ModelSelectionResults perform_order_selection(void) method.\n"
862 <<
"This method is under development.\n";
864 throw std::logic_error(buffer.str());
1051 std::ostringstream buffer;
1053 buffer <<
"OpenNN Exception: ModelSelection class.\n"
1054 <<
"ModelSelectionResults perform_model_selection(void) method.\n"
1055 <<
"This method is under development.\n";
1057 throw std::logic_error(buffer.str());
1072 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
1074 std::ostringstream buffer;
1078 tinyxml2::XMLElement* model_selection_element = document->NewElement(
"ModelSelection");
1080 document->InsertFirstChild(model_selection_element);
1084 tinyxml2::XMLElement* hidden_perceptrons_numbers_element = document->NewElement(
"HiddenLayerSizes");
1085 model_selection_element->LinkEndChild(hidden_perceptrons_numbers_element);
1090 tinyxml2::XMLText* hidden_perceptrons_numbers_text = document->NewText(buffer.str().c_str());
1091 hidden_perceptrons_numbers_element->LinkEndChild(hidden_perceptrons_numbers_text);
1095 tinyxml2::XMLElement* parameters_assays_number_element = document->NewElement(
"ParametersAssaysNumber");
1096 model_selection_element->LinkEndChild(parameters_assays_number_element);
1101 tinyxml2::XMLText* parameters_assays_number_text = document->NewText(buffer.str().c_str());
1102 parameters_assays_number_element->LinkEndChild(parameters_assays_number_text);
1134 tinyxml2::XMLDocument* document =
to_XML();
1136 document->SaveFile(file_name.c_str());
1149 std::ostringstream buffer;
1151 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
1153 if(document->LoadFile(file_name.c_str()))
1155 buffer <<
"OpenNN Exception: ModelSelection class.\n"
1156 <<
"void load(const std::string&) method.\n"
1157 <<
"Cannot load XML file " << file_name <<
".\n";
1159 throw std::logic_error(buffer.str());
1164 tinyxml2::XMLElement* model_selection_element = document->FirstChildElement(
"ModelSelection");
1166 if(!model_selection_element)
1168 buffer <<
"OpenNN Exception: ModelSelection class.\n"
1169 <<
"void load(const std::string&) method.\n"
1170 <<
"Invalid model order selection XML root element.\n";
1172 throw std::logic_error(buffer.str());
1177 tinyxml2::XMLElement* hidden_perceptrons_numbers_element = model_selection_element->FirstChildElement(
"HiddenLayerSizes");
1179 if(hidden_perceptrons_numbers_element)
1182 new_hidden_perceptrons_numbers.
parse(hidden_perceptrons_numbers_element->GetText());
1188 catch(
const std::logic_error& e)
1190 std::cout << e.what() << std::endl;
1196 tinyxml2::XMLElement* parameters_assays_number_element = model_selection_element->FirstChildElement(
"ParametersAssaysNumber");
1198 if(parameters_assays_number_element)
void parse(const std::string &)
const bool & get_reserve_performance_data(void) const
Returns true if the performance functional performances are to be reserved, and false otherwise...
void from_XML(const tinyxml2::XMLDocument &)
const Vector< size_t > & get_hidden_perceptrons_numbers(void) const
Returns the complexities of the neural networks given by the numbers of hidden perceptrons.
PerformanceFunctional * get_performance_functional_pointer(void) const
Returns a pointer to the performance functional object to which the training strategy is associated...
InputsSelectionMethod
Enumeration of available methods for inputs selection.
const InputsSelectionMethod & get_inputs_selection_method(void) const
Returns the method for selecting those inputs which have more impact on the targets.
void perform_maximum_linear_correlation_inputs_selection(void) const
const Variables & get_variables(void) const
Returns a constant reference to the variables object composing this data set object.
void set_assays_numbers(const size_t &, const size_t &)
ModelSelectionResults perform_model_selection(void) const
bool reserve_generalization_performance_data
True if the generalization performance of all neural networks are to be reserved. ...
const bool & get_reserve_performance_data_statistics(void) const
Returns true if the statistics of the performance data are to be inclued in the model selection resul...
void perform_maximum_logistic_correlation_inputs_selection(void) const
TrainingStrategy * get_training_strategy_pointer(void) const
Returns a pointer to the training strategy object.
bool reserve_minimal_parameters
True if the vector parameters of the neural network presenting minimum generalization performance is ...
size_t parameters_assays_number
Number of trials for each neural network.
void set_reserve_generalization_performance_data_statistics(const bool &)
void set(void)
Sets the size of a vector to zero.
const bool & get_reserve_model_order_selection_plot(void) const
Returns true if the necessary data for plotting the model selection results is to be included in the ...
const size_t & get_parameters_assays_number(void) const
Returns the number of trials for each network architecture.
const bool & get_reserve_generalization_performance_data(void) const
Returns true if the performance functional generalization performances are to be reserved, and false otherwise.
bool display
Display messages to screen.
void set_reserve_model_order_selection_plot(const bool &)
Matrix< size_t > calculate_greater_than_indices(const T &) const
void load(const std::string &)
void set_training(void)
Sets all the instances in the data set for training.
const bool & get_reserve_parameters_data(void) const
Returns true if the neural network parameters are to be reserved, and false otherwise.
bool reserve_parameters_data
True if the parameters of all neural networks are to be reserved.
void set_inputs_selection_method(const InputsSelectionMethod &)
void check(void) const
Checks that the different pointers needed for performing the model selection are not NULL...
Vector< size_t > arrange_targets_indices(void) const
Returns the indices of the target variables.
Vector< Statistics< double > > scale_inputs(const std::string &)
size_t count_generalization_instances_number(void) const
Returns the number of instances in the data set which will be used for generalization.
void set_reserve_performance_data(const bool &)
void set_reserve_parameters_data(const bool &)
void set_reserve_performance_data_statistics(const bool &)
void perform_inputs_selection(void) const
void perform_exhaustive_inputs_selection(void) const
MultilayerPerceptron * get_multilayer_perceptron_pointer(void) const
Returns a pointer to the multilayer perceptron composing this neural network.
double correlation_goal
Goal value for a single input-target correlation.
bool reserve_performance_data
True if the performance of all neural networks are to be reserved.
const bool & get_reserve_generalization_performance_data_statistics(void) const
Returns true if the statistics of the generalization performance data are to be inclued in the model ...
Instances * get_instances_pointer(void)
Returns a pointer to the variables object composing this data set object.
bool reserve_performance_data_statistics
True if the statistics of the different performances are to be reserved.
Matrix< double > calculate_output_data(const Matrix< double > &) const
void set_column(const size_t &, const Vector< T > &)
bool reserve_model_order_selection_plot
True if the data needed to plot the results from the model selection plot is to be reserved...
Results perform_training(void)
void set_training_strategy_pointer(TrainingStrategy *)
ModelSelection(void)
Default constructor.
ModelSelectionResults perform_order_selection(void) const
tinyxml2::XMLDocument * to_XML(void) const
void set_main_type(const MainType &)
TrainingStrategy * training_strategy_pointer
Pointer to a training strategy object.
virtual ~ModelSelection(void)
Destructor.
Matrix< double > calculate_linear_correlations(void) const
void save(const std::string &) const
Vector< double > get_variable(const size_t &) const
T calculate_linear_correlation(const Vector< T > &) const
size_t count_inputs_number(void) const
Returns the number of input variables of the data set.
void set_parameters_assays_number(const size_t &)
Matrix< double > calculate_logistic_correlations(void) const
size_t count_targets_number(void) const
Returns the number of target variables of the data set.
Matrix< T > to_column_matrix(void) const
const bool & get_display(void) const
void set_reserve_minimal_parameters(const bool &)
void print(void) const
Prints to the screen the XML representation of this model selection object.
void set_layer_activation_function(const size_t &, const Perceptron::ActivationFunction &)
void set_display(const bool &)
void set_reserve_generalization_performance_data(const bool &)
InputsSelectionMethod inputs_selection_method
Inputs selection method variable.
bool reserve_generalization_performance_data_statistics
True if the statistics of the different generalization performances are to be reserved.
const bool & get_reserve_minimal_parameters(void) const
Returns true if the parameters vector of the neural network with minimum performance functional perfo...
Vector< size_t > hidden_perceptrons_numbers
Complexities for selecting the network architecture.
void set_hidden_perceptrons_numbers(const Vector< size_t > &)
Vector< size_t > arrange_inputs_indices(void) const
Returns the indices of the input variables.
const Instances & get_instances(void) const
Returns a constant reference to the instances object composing this data set object.