9#include "conjugate_gradient.h"
10#include "training_strategy.h"
77 case TrainingDirectionMethod::PR:
80 case TrainingDirectionMethod::FR:
161 if(new_training_direction_method_name ==
"PR")
166 else if(new_training_direction_method_name ==
"FR")
172 ostringstream buffer;
174 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
175 <<
"void set_training_direction_method(const string&) method.\n"
176 <<
"Unknown training direction method: " << new_training_direction_method_name <<
".\n";
178 throw logic_error(buffer.str());
279 if(new_maximum_time <
static_cast<type
>(0.0))
281 ostringstream buffer;
283 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
284 <<
"void set_maximum_time(const type&) method.\n"
285 <<
"Maximum time must be equal or greater than 0.\n";
287 throw logic_error(buffer.str());
306 if(new_save_period <= 0)
308 ostringstream buffer;
310 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
311 <<
"void set_save_period(const type&) method.\n"
312 <<
"Save period must be greater than 0.\n";
314 throw logic_error(buffer.str());
331 ostringstream buffer;
335 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
336 <<
"type calculate_FR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
338 <<
"Loss index pointer is nullptr.\n";
340 throw logic_error(buffer.str());
347 const Index old_gradient_size = old_gradient.size();
349 if(old_gradient_size != parameters_number)
351 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
352 <<
"type calculate_FR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
353 <<
"Size of old gradient(" << old_gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
355 throw logic_error(buffer.str());
358 const Index gradient_size = gradient.size();
360 if(gradient_size != parameters_number)
362 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
363 <<
"type calculate_FR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
364 <<
"Size of gradient(" << gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
366 throw logic_error(buffer.str());
371 type FR_parameter = type(0);
373 Tensor<type, 0> numerator;
374 Tensor<type, 0> denominator;
376 numerator.device(*thread_pool_device) = gradient.contract(gradient, AT_B);
377 denominator.device(*thread_pool_device) = old_gradient.contract(old_gradient, AT_B);
381 if(
abs(denominator(0)) < type(NUMERIC_LIMITS_MIN))
383 FR_parameter = type(0);
387 FR_parameter = numerator(0)/denominator(0);
392 if(FR_parameter <
static_cast<type
>(0.0))
394 FR_parameter = type(0);
396 else if(FR_parameter >
static_cast<type
>(1.0))
398 FR_parameter = type(1);
413 ostringstream buffer;
417 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
418 <<
"type calculate_PR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
419 <<
"Loss index pointer is nullptr.\n";
421 throw logic_error(buffer.str());
428 const Index old_gradient_size = old_gradient.size();
430 if(old_gradient_size != parameters_number)
432 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
433 <<
"type calculate_PR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
434 <<
"Size of old gradient(" << old_gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
436 throw logic_error(buffer.str());
439 const Index gradient_size = gradient.size();
441 if(gradient_size != parameters_number)
443 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
444 <<
"type calculate_PR_parameter(const Tensor<type, 1>&, const Tensor<type, 1>&) const method.\n"
445 <<
"Size of gradient(" << gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
447 throw logic_error(buffer.str());
452 type PR_parameter = type(0);
454 Tensor<type, 0> numerator;
455 Tensor<type, 0> denominator;
457 numerator.device(*thread_pool_device) = (gradient-old_gradient).contract(gradient, AT_B);
458 denominator.device(*thread_pool_device) = old_gradient.contract(old_gradient, AT_B);
462 if(
abs(denominator(0)) < type(NUMERIC_LIMITS_MIN))
464 PR_parameter = type(0);
468 PR_parameter = numerator(0)/denominator(0);
473 if(PR_parameter <
static_cast<type
>(0.0))
475 PR_parameter = type(0);
477 else if(PR_parameter >
static_cast<type
>(1.0))
479 PR_parameter = type(1);
493 const Tensor<type, 1>& gradient,
494 const Tensor<type, 1>& old_training_direction,
495 Tensor<type, 1>& training_direction)
const
499 ostringstream buffer;
503 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
504 <<
"void calculate_PR_training_direction() const method.\n"
505 <<
"Loss index pointer is nullptr.\n";
507 throw logic_error(buffer.str());
514 const Index old_gradient_size = old_gradient.size();
516 if(old_gradient_size != parameters_number)
518 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
519 <<
"void calculate_PR_training_direction() const method.\n"
520 <<
"Size of old gradient(" << old_gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
522 throw logic_error(buffer.str());
525 const Index gradient_size = gradient.size();
527 if(gradient_size != parameters_number)
529 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
530 <<
"void calculate_PR_training_direction() const method.\n"
531 <<
"Size of gradient(" << gradient_size <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
533 throw logic_error(buffer.str());
536 const Index old_training_direction_size = old_training_direction.size();
538 if(old_training_direction_size != parameters_number)
540 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
541 <<
"void calculate_PR_training_direction() const method.\n"
542 <<
"Size of old training direction(" << old_training_direction_size
543 <<
") is not equal to number of parameters(" << parameters_number <<
").\n";
545 throw logic_error(buffer.str());
552 training_direction.device(*thread_pool_device) = -gradient + old_training_direction*PR_parameter;
562 const Tensor<type, 1>& gradient,
563 const Tensor<type, 1>& old_training_direction,
564 Tensor<type, 1>& training_direction)
const
568 ostringstream buffer;
572 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
573 <<
"void calculate_FR_training_direction() const method.\n"
574 <<
"Loss index pointer is nullptr.\n";
576 throw logic_error(buffer.str());
583 const Index old_gradient_size = old_gradient.size();
585 if(old_gradient_size != parameters_number)
587 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
588 <<
"void calculate_FR_training_direction() const method.\n"
589 <<
"Size of old gradient (" << old_gradient_size <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
591 throw logic_error(buffer.str());
594 const Index gradient_size = gradient.size();
596 if(gradient_size != parameters_number)
598 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
599 <<
"void calculate_FR_training_direction() const method.\n"
600 <<
"Size of gradient (" << gradient_size <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
602 throw logic_error(buffer.str());
605 const Index old_training_direction_size = old_training_direction.size();
607 if(old_training_direction_size != parameters_number)
609 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
610 <<
"void calculate_FR_training_direction() const method.\n"
611 <<
"Size of old training direction (" << old_training_direction_size
612 <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
614 throw logic_error(buffer.str());
621 training_direction.device(*thread_pool_device) = -gradient + old_training_direction*FR_parameter;
630void ConjugateGradient::calculate_gradient_descent_training_direction(
const Tensor<type, 1>& gradient,
631 Tensor<type, 1>& training_direction)
const
633 training_direction.device(*thread_pool_device) = -gradient;
642 const Tensor<type, 1>& gradient,
643 const Tensor<type, 1>& old_training_direction,
644 Tensor<type, 1>& training_direction)
const
652 ostringstream buffer;
656 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
657 <<
"void calculate_training_direction() const method.\n"
658 <<
"Loss index pointer is nullptr.\n";
660 throw logic_error(buffer.str());
663 const Index old_gradient_size = old_gradient.size();
665 if(old_gradient_size != parameters_number)
667 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
668 <<
"void calculate_training_direction() const method.\n"
669 <<
"Size of old gradient (" << old_gradient_size <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
671 throw logic_error(buffer.str());
674 const Index gradient_size = gradient.size();
676 if(gradient_size != parameters_number)
678 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
679 <<
"void calculate_training_direction() const method.\n"
680 <<
"Size of gradient (" << gradient_size <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
682 throw logic_error(buffer.str());
685 const Index old_training_direction_size = old_training_direction.size();
687 if(old_training_direction_size != parameters_number)
689 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
690 <<
"void calculate_training_direction() const method.\n"
691 <<
"Size of old training direction (" << old_training_direction_size
692 <<
") is not equal to number of parameters (" << parameters_number <<
").\n";
694 throw logic_error(buffer.str());
701 case TrainingDirectionMethod::FR:
705 case TrainingDirectionMethod::PR:
721 if(
display) cout <<
"Training with conjugate gradient...\n";
727 time_t beginning_time, current_time;
728 time(&beginning_time);
729 type elapsed_time = type(0);
737 const bool has_selection = data_set_pointer->has_selection();
748 const Tensor<Scaler, 1> input_variables_scalers = data_set_pointer->get_input_variables_scalers();
749 const Tensor<Scaler, 1> target_variables_scalers = data_set_pointer->get_target_variables_scalers();
751 const Tensor<Descriptives, 1> input_variables_descriptives = data_set_pointer->
scale_input_variables();
752 Tensor<Descriptives, 1> target_variables_descriptives;
761 scaling_layer_pointer->
set(input_variables_descriptives, input_variables_scalers);
769 unscaling_layer_pointer->
set(target_variables_descriptives, target_variables_scalers);
772 DataSetBatch training_batch(training_samples_number, data_set_pointer);
773 training_batch.fill(training_samples_indices, input_variables_indices, target_variables_indices);
775 DataSetBatch selection_batch(selection_samples_number, data_set_pointer);
776 selection_batch.fill(selection_samples_indices, input_variables_indices, target_variables_indices);
792 type old_loss = type(0);
793 type loss_decrease = numeric_limits<type>::max();
795 bool stop_training =
false;
797 Index selection_failures = 0;
807 optimization_data.epoch = epoch;
811 neural_network_pointer->
forward_propagate(training_batch, training_forward_propagation);
815 loss_index_pointer->back_propagate(training_batch, training_forward_propagation, training_back_propagation);
820 neural_network_pointer->
forward_propagate(selection_batch, selection_forward_propagation);
822 loss_index_pointer->calculate_errors(selection_batch, selection_forward_propagation, selection_back_propagation);
823 loss_index_pointer->calculate_error(selection_batch, selection_forward_propagation, selection_back_propagation);
833 elapsed_time =
static_cast<type
>(difftime(current_time, beginning_time));
837 cout <<
"Training error: " << training_back_propagation.error << endl;
838 if(has_selection) cout <<
"Selection error: " << selection_back_propagation.error << endl;
839 cout <<
"Learning rate: " << optimization_data.learning_rate << endl;
840 cout <<
"Elapsed time: " <<
write_time(elapsed_time) << endl;
847 if(
display) cout <<
"Epoch " << epoch << endl <<
"Loss goal reached: " << training_back_propagation.loss << endl;
849 stop_training =
true;
856 if(
display) cout <<
"Epoch " << epoch << endl <<
"Maximum selection failures reached: " << selection_failures << endl;
858 stop_training =
true;
865 if(
display) cout <<
"Epoch " << epoch << endl <<
"Maximum number of epochs reached: " << epoch << endl;;
867 stop_training =
true;
874 if(
display) cout <<
"Epoch " << epoch << endl <<
"Maximum training time reached: " <<
write_time(elapsed_time) << endl;
876 stop_training =
true;
881 if(epoch != 0) loss_decrease = old_loss - training_back_propagation.loss;
887 stop_training =
true;
892 old_loss = training_back_propagation.loss;
909 update_parameters(training_batch, training_forward_propagation, training_back_propagation, optimization_data);
927 return "CONJUGATE_GRADIENT";
935 Tensor<string, 2> labels_values(8, 2);
939 labels_values(0,0) =
"Training direction method";
944 labels_values(1,0) =
"Learning rate method";
949 labels_values(2,0) =
"Learning rate tolerance";
954 labels_values(3,0) =
"Minimum loss decrease";
959 labels_values(4,0) =
"Loss goal";
964 labels_values(5,0) =
"Maximum selection error increases";
969 labels_values(6,0) =
"Maximum epochs number";
974 labels_values(7,0) =
"Maximum time";
977 return labels_values;
986 ostringstream buffer;
988 file_stream.OpenElement(
"ConjugateGradient");
993 file_stream.OpenElement(
"TrainingDirectionMethod");
1007 file_stream.OpenElement(
"MinimumLossDecrease");
1012 file_stream.
PushText(buffer.str().c_str());
1020 file_stream.OpenElement(
"LossGoal");
1025 file_stream.
PushText(buffer.str().c_str());
1032 file_stream.OpenElement(
"MaximumSelectionErrorIncreases");
1037 file_stream.
PushText(buffer.str().c_str());
1044 file_stream.OpenElement(
"MaximumEpochsNumber");
1049 file_stream.
PushText(buffer.str().c_str());
1057 file_stream.OpenElement(
"MaximumTime");
1062 file_stream.
PushText(buffer.str().c_str());
1069 file_stream.OpenElement(
"HardwareUse");
1074 file_stream.
PushText(buffer.str().c_str());
1092 ostringstream buffer;
1094 buffer <<
"OpenNN Exception: ConjugateGradient class.\n"
1095 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
1096 <<
"Conjugate gradient element is nullptr.\n";
1098 throw logic_error(buffer.str());
1103 const tinyxml2::XMLElement* training_direction_method_element = root_element->FirstChildElement(
"TrainingDirectionMethod");
1105 if(training_direction_method_element)
1107 const string new_training_direction_method = training_direction_method_element->GetText();
1113 catch(
const logic_error& e)
1115 cerr << e.what() << endl;
1122 const tinyxml2::XMLElement* learning_rate_algorithm_element = root_element->FirstChildElement(
"LearningRateAlgorithm");
1124 if(learning_rate_algorithm_element)
1129 element_clone = learning_rate_algorithm_element->DeepClone(&learning_rate_algorithm_document);
1131 learning_rate_algorithm_document.InsertFirstChild(element_clone);
1139 const tinyxml2::XMLElement* minimum_loss_decrease_element = root_element->FirstChildElement(
"MinimumLossDecrease");
1141 if(minimum_loss_decrease_element)
1143 const type new_minimum_loss_decrease =
static_cast<type
>(atof(minimum_loss_decrease_element->GetText()));
1149 catch(
const logic_error& e)
1151 cerr << e.what() << endl;
1160 if(loss_goal_element)
1162 const type new_loss_goal =
static_cast<type
>(atof(loss_goal_element->GetText()));
1168 catch(
const logic_error& e)
1170 cerr << e.what() << endl;
1177 const tinyxml2::XMLElement* maximum_selection_failures_element = root_element->FirstChildElement(
"MaximumSelectionErrorIncreases");
1179 if(maximum_selection_failures_element)
1181 const Index new_maximum_selection_failures =
static_cast<Index
>(atoi(maximum_selection_failures_element->GetText()));
1187 catch(
const logic_error& e)
1189 cerr << e.what() << endl;
1196 const tinyxml2::XMLElement* maximum_iterations_number_element = root_element->FirstChildElement(
"MaximumEpochsNumber");
1198 if(maximum_iterations_number_element)
1200 const Index new_maximum_iterations_number =
static_cast<Index
>(atoi(maximum_iterations_number_element->GetText()));
1206 catch(
const logic_error& e)
1208 cerr << e.what() << endl;
1215 const tinyxml2::XMLElement* maximum_time_element = root_element->FirstChildElement(
"MaximumTime");
1217 if(maximum_time_element)
1219 const type new_maximum_time =
static_cast<type
>(atof(maximum_time_element->GetText()));
1225 catch(
const logic_error& e)
1227 cerr << e.what() << endl;
1234 const tinyxml2::XMLElement* display_period_element = root_element->FirstChildElement(
"DisplayPeriod");
1236 if(display_period_element)
1238 const Index new_display_period =
static_cast<Index
>(atoi(display_period_element->GetText()));
1244 catch(
const logic_error& e)
1246 cerr << e.what() << endl;
1257 const Index new_save_period =
static_cast<Index
>(atoi(element->GetText()));
1263 catch(
const logic_error& e)
1265 cerr << e.what() << endl;
1272 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"NeuralNetworkFileName");
1276 const string new_neural_network_file_name = element->GetText();
1282 catch(
const logic_error& e)
1284 cerr << e.what() << endl;
1295 const string new_display = display_element->GetText();
1301 catch(
const logic_error& e)
1303 cerr << e.what() << endl;
1314 const string new_hardware_use = element->GetText();
1320 catch(
const logic_error& e)
1322 cerr << e.what() << endl;
1341 const Index parameters_number = back_propagation.parameters.dimension(0);
1343 if(optimization_data.epoch == 0 || optimization_data.epoch % parameters_number == 0)
1345 calculate_gradient_descent_training_direction(
1346 back_propagation.gradient,
1347 optimization_data.training_direction);
1352 optimization_data.old_gradient,
1353 back_propagation.gradient,
1354 optimization_data.old_training_direction,
1355 optimization_data.training_direction);
1358 optimization_data.training_slope.device(*thread_pool_device)
1359 = (back_propagation.gradient).contract(optimization_data.training_direction, AT_B);
1361 if(optimization_data.training_slope(0) >= type(0))
1363 calculate_gradient_descent_training_direction(
1364 back_propagation.gradient,
1365 optimization_data.training_direction);
1370 optimization_data.epoch == 0
1371 ? optimization_data.initial_learning_rate = first_learning_rate
1372 : optimization_data.initial_learning_rate = optimization_data.old_learning_rate;
1376 forward_propagation,
1380 optimization_data.learning_rate = directional_point.first;
1381 back_propagation.loss = directional_point.second;
1383 if(
abs(optimization_data.learning_rate) > type(0))
1385 optimization_data.parameters_increment.device(*thread_pool_device)
1386 = optimization_data.training_direction*optimization_data.learning_rate;
1388 back_propagation.parameters.device(*thread_pool_device) += optimization_data.parameters_increment;
1392 const Index parameters_number = back_propagation.parameters.size();
1394 for(Index i = 0; i < parameters_number; i++)
1396 if(
abs(back_propagation.gradient(i)) < type(NUMERIC_LIMITS_MIN))
1398 optimization_data.parameters_increment(i) = type(0);
1400 else if(back_propagation.gradient(i) > type(0))
1402 back_propagation.parameters(i) -= numeric_limits<type>::epsilon();;
1404 optimization_data.parameters_increment(i) = -numeric_limits<type>::epsilon();
1406 else if(back_propagation.gradient(i) < type(0))
1408 back_propagation.parameters(i) += numeric_limits<type>::epsilon();;
1410 optimization_data.parameters_increment(i) = numeric_limits<type>::epsilon();
1414 optimization_data.learning_rate = optimization_data.initial_learning_rate;
1419 optimization_data.old_gradient = back_propagation.gradient;
1421 optimization_data.old_training_direction = optimization_data.training_direction;
1423 optimization_data.old_learning_rate = optimization_data.learning_rate;
1427 forward_propagation.neural_network_pointer->
set_parameters(back_propagation.parameters);
1438 set(new_conjugate_gradient_pointer);
1442ConjugateGradientData::~ConjugateGradientData()
1448void ConjugateGradientData::set(ConjugateGradient* new_conjugate_gradient_pointer)
1450 conjugate_gradient_pointer = new_conjugate_gradient_pointer;
1458 potential_parameters.resize(parameters_number);
1460 parameters_increment.resize(parameters_number);
1462 old_gradient.resize(parameters_number);
1464 training_direction.resize(parameters_number);
1465 old_training_direction.resize(parameters_number);
1469void ConjugateGradientData::print()
const
TrainingResults perform_training()
void set_maximum_selection_failures(const Index &)
void calculate_FR_training_direction(const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const
void set_loss_index_pointer(LossIndex *)
const type & get_maximum_time() const
Returns the maximum training time.
const type & get_loss_goal() const
void from_XML(const tinyxml2::XMLDocument &)
const Index & get_maximum_epochs_number() const
Returns the maximum number of epochs for training.
Tensor< string, 2 > to_string_matrix() const
Writes as matrix of strings the most representative atributes.
type minimum_loss_decrease
Minimum loss improvement between two successive iterations. It is used as a stopping criterion.
LearningRateAlgorithm * get_learning_rate_algorithm_pointer()
Returns a pointer to the learning rate algorithm object inside the conjugate gradient method object.
void calculate_conjugate_gradient_training_direction(const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const
string write_optimization_algorithm_type() const
Write a string with best algorithm type for the model.
const LearningRateAlgorithm & get_learning_rate_algorithm() const
Returns a constant reference to the learning rate algorithm object inside the conjugate gradient meth...
void set_save_period(const Index &)
void set_maximum_time(const type &)
LearningRateAlgorithm learning_rate_algorithm
Learning rate algorithm object for one-dimensional minimization.
void set_loss_goal(const type &)
type calculate_PR_parameter(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const
void set_training_direction_method(const TrainingDirectionMethod &)
type maximum_time
Maximum training time. It is used as a stopping criterion.
void set_maximum_epochs_number(const Index &)
void set_minimum_loss_decrease(const type &)
TrainingDirectionMethod
Enumeration of the available training operators for obtaining the training direction.
virtual ~ConjugateGradient()
Destructor.
type calculate_FR_parameter(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const
type training_loss_goal
Goal value for the loss. It is used as a stopping criterion.
Index maximum_epochs_number
Maximum number of epochs to perform_training. It is used as a stopping criterion.
void write_XML(tinyxml2::XMLPrinter &) const
const Index & get_maximum_selection_failures() const
Returns the maximum number of selection error increases during the training process.
Index maximum_selection_failures
void calculate_PR_training_direction(const Tensor< type, 1 > &, const Tensor< type, 1 > &, const Tensor< type, 1 > &, Tensor< type, 1 > &) const
string write_training_direction_method() const
Returns a string with the name of the training direction.
TrainingDirectionMethod training_direction_method
Applied method for calculating the conjugate gradient direction.
void update_parameters(const DataSetBatch &batch, NeuralNetworkForwardPropagation &forward_propagation, LossIndexBackPropagation &back_propagation, ConjugateGradientData &optimization_data)
ConjugateGradient::update_parameters.
const TrainingDirectionMethod & get_training_direction_method() const
Returns the conjugate gradient training direction method used for training.
const type & get_minimum_loss_decrease() const
Returns the minimum loss improvement during training.
This class represents the concept of data set for data modelling problems, such as approximation,...
Index get_training_samples_number() const
Returns the number of samples in the data set which will be used for training.
Tensor< Descriptives, 1 > scale_target_variables()
Tensor< Index, 1 > get_training_samples_indices() const
Returns the indices of the samples which will be used for training.
Tensor< Index, 1 > get_selection_samples_indices() const
Returns the indices of the samples which will be used for selection.
void unscale_input_variables(const Tensor< Descriptives, 1 > &)
Tensor< Index, 1 > get_target_variables_indices() const
Returns the indices of the target variables.
Index get_selection_samples_number() const
Returns the number of samples in the data set which will be used for selection.
void unscale_target_variables(const Tensor< Descriptives, 1 > &)
Tensor< string, 1 > get_target_variables_names() const
Tensor< Index, 1 > get_input_variables_indices() const
Returns the indices of the input variables.
Tensor< string, 1 > get_input_variables_names() const
Tensor< Descriptives, 1 > scale_input_variables()
A learning rate that is adjusted according to an algorithm during training to minimize training time.
void set_loss_index_pointer(LossIndex *)
void from_XML(const tinyxml2::XMLDocument &)
string write_learning_rate_method() const
Returns a string with the name of the learning rate method to be used.
pair< type, type > calculate_directional_point(const DataSetBatch &, NeuralNetworkForwardPropagation &, LossIndexBackPropagation &, OptimizationAlgorithmData &) const
void write_XML(tinyxml2::XMLPrinter &) const
This abstract class represents the concept of loss index composed of an error term and a regularizati...
NeuralNetwork * get_neural_network_pointer() const
Returns a pointer to the neural network object associated to the error term.
DataSet * get_data_set_pointer() const
Returns a pointer to the data set object associated to the error term.
ScalingLayer * get_scaling_layer_pointer() const
Returns a pointer to the scaling layers object composing this neural network object.
bool has_scaling_layer() const
bool has_unscaling_layer() const
void forward_propagate(const DataSetBatch &, NeuralNetworkForwardPropagation &) const
Calculate forward propagation in neural network.
void save(const string &) const
void set_parameters(Tensor< type, 1 > &)
UnscalingLayer * get_unscaling_layer_pointer() const
Returns a pointer to the unscaling layers object composing this neural network object.
Index get_parameters_number() const
void set_display_period(const Index &)
string neural_network_file_name
Path where the neural network is saved.
void set_hardware_use(const string &)
Set hardware to use. Default: Multi-core.
void set_neural_network_file_name(const string &)
LossIndex * loss_index_pointer
Pointer to a loss index for a neural network object.
virtual void check() const
bool display
Display messages to screen.
const string write_time(const type &) const
Writes the time from seconds in format HH:mm:ss.
Index save_period
Number of iterations between the training saving progress.
string hardware_use
Hardware use.
virtual void set_display(const bool &)
LossIndex * get_loss_index_pointer() const
Index display_period
Number of iterations between the training showing progress.
This class represents a layer of scaling neurons.
void set()
Sets the scaling layer to be empty.
This class represents a layer of unscaling neurons.
void set()
Sets the unscaling layer to be empty.
void PushText(const char *text, bool cdata=false)
Add a text node.
virtual void CloseElement(bool compactMode=false)
If streaming, close the Element.
HALF_CONSTEXPR half abs(half arg)
ConjugateGradientData()
Default constructor.
This structure contains the optimization algorithm results.
Tensor< type, 1 > selection_error_history
History of the selection error over the training iterations.
void resize_training_error_history(const Index &)
Resizes the training error history keeping the values.
OptimizationAlgorithm::StoppingCondition stopping_condition
Stopping condition of the algorithm.
void resize_selection_error_history(const Index &)
Resizes the selection error history keeping the values.
Tensor< type, 1 > training_error_history
History of the loss function loss over the training iterations.
string elapsed_time
Elapsed time of the training process.