9#include "neurons_selection.h"
52 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
53 <<
"DataSet* get_training_strategy_pointer() const method.\n"
54 <<
"Training strategy pointer is nullptr.\n";
56 throw logic_error(buffer.str());
151 Index outputs_number;
191 if(new_maximum_neurons <= 0)
193 ostringstream buffer;
195 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
196 <<
"void set_maximum_neurons_number(const Index&) method.\n"
197 <<
"maximum_neurons(" << new_maximum_neurons <<
") must be greater than 0.\n";
199 throw logic_error(buffer.str());
204 ostringstream buffer;
206 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
207 <<
"void set_maximum_neurons_number(const Index&) method.\n"
208 <<
"maximum_neurons(" << new_maximum_neurons <<
") must be equal or greater than minimum_neurons(" <<
minimum_neurons <<
").\n";
210 throw logic_error(buffer.str());
226 if(new_minimum_neurons <= 0)
228 ostringstream buffer;
230 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
231 <<
"void set_minimum_neurons(const Index&) method.\n"
232 <<
"minimum_neurons(" << new_minimum_neurons <<
") must be greater than 0.\n";
234 throw logic_error(buffer.str());
239 ostringstream buffer;
240 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
241 <<
"void set_minimum_neurons(const Index&) method.\n"
242 <<
"minimum_neurons(" << new_minimum_neurons <<
") must be less than maximum_neurons(" <<
maximum_neurons <<
").\n";
244 throw logic_error(buffer.str());
260 if(new_trials_number <= 0)
262 ostringstream buffer;
263 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
264 <<
"void set_trials_number(const Index&) method.\n"
265 <<
"Number of assays must be greater than 0.\n";
267 throw logic_error(buffer.str());
294 if(new_selection_error_goal < 0)
296 ostringstream buffer;
298 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
299 <<
"void set_selection_error_goal(const type&) method.\n"
300 <<
"Selection loss goal must be greater or equal than 0.\n";
302 throw logic_error(buffer.str());
318 if(new_maximum_epochs_number <= 0)
320 ostringstream buffer;
322 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
323 <<
"void set_maximum_epochs_number(const Index&) method.\n"
324 <<
"Maximum epochs number must be greater than 0.\n";
326 throw logic_error(buffer.str());
342 if(new_maximum_time < 0)
344 ostringstream buffer;
346 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
347 <<
"void set_maximum_time(const type&) method.\n"
348 <<
"Maximum time must be greater than 0.\n";
350 throw logic_error(buffer.str());
390 ostringstream buffer;
394 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
395 <<
"void check() const method.\n"
396 <<
"Pointer to training strategy is nullptr.\n";
398 throw logic_error(buffer.str());
405 if(!loss_index_pointer)
407 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
408 <<
"void check() const method.\n"
409 <<
"Pointer to loss index is nullptr.\n";
411 throw logic_error(buffer.str());
418 if(!neural_network_pointer)
420 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
421 <<
"void check() const method.\n"
422 <<
"Pointer to neural network is nullptr.\n";
424 throw logic_error(buffer.str());
427 if(neural_network_pointer->
is_empty())
429 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
430 <<
"void check() const method.\n"
431 <<
"Multilayer Perceptron is empty.\n";
433 throw logic_error(buffer.str());
438 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
439 <<
"void check() const method.\n"
440 <<
"Number of layers in neural network must be greater than 1.\n";
442 throw logic_error(buffer.str());
449 if(!data_set_pointer)
451 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
452 <<
"void check() const method.\n"
453 <<
"Pointer to data set is nullptr.\n";
455 throw logic_error(buffer.str());
460 if(selection_samples_number == 0)
462 buffer <<
"OpenNN Exception: NeuronsSelection class.\n"
463 <<
"void check() const method.\n"
464 <<
"Number of selection samples is zero.\n";
466 throw logic_error(buffer.str());
477 if(time >
static_cast<type
>(3600e5))
479 ostringstream buffer;
481 buffer <<
"OpenNN Exception: OptimizationAlgorithm class.\n"
482 <<
"const string write_time(const type& time) const method.\n"
483 <<
"Time must be lower than 10e5 seconds.\n";
485 throw logic_error(buffer.str());
488 if(time <
static_cast<type
>(0))
490 ostringstream buffer;
492 buffer <<
"OpenNN Exception: OptimizationAlgorithm class.\n"
493 <<
"const string write_time(const type& time) const method.\n"
494 <<
"Time must be greater than 0.\n";
496 throw logic_error(buffer.str());
500 const int hours =
static_cast<int>(time) / 3600;
501 int seconds =
static_cast<int>(time) % 3600;
502 const int minutes = seconds / 60;
503 seconds = seconds % 60;
505 ostringstream elapsed_time;
507 elapsed_time << setfill(
'0') << setw(2) << hours <<
":"
508 << setfill(
'0') << setw(2) << minutes <<
":"
509 << setfill(
'0') << setw(2) << seconds << endl;
511 return elapsed_time.str();
521 case NeuronsSelection::StoppingCondition::MaximumTime:
522 return "MaximumTime";
524 case NeuronsSelection::StoppingCondition::SelectionErrorGoal:
525 return "SelectionErrorGoal";
527 case NeuronsSelection::StoppingCondition::MaximumEpochs:
528 return "MaximumEpochs";
530 case NeuronsSelection::StoppingCondition::MaximumSelectionFailures:
531 return "MaximumSelectionFailures";
533 case NeuronsSelection::StoppingCondition::MaximumNeurons:
534 return "MaximumNeurons";
This class represents the concept of data set for data modelling problems, such as approximation,...
Index get_selection_samples_number() const
Returns the number of samples in the data set which will be used for selection.
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.
Index get_inputs_number() const
Returns the number of inputs to the neural network.
Index get_layers_number() const
Tensor< type, 1 > selection_error_history
Selection loss of all the neural networks trained.
Index minimum_neurons
Minimum number of hidden neurons.
void set_training_strategy_pointer(TrainingStrategy *)
NeuronsSelection()
Default constructor.
const type & get_maximum_time() const
Returns the maximum time in the neurons selection algorithm.
TrainingStrategy * training_strategy_pointer
Pointer to a training strategy object.
const bool & get_display() const
void set_selection_error_goal(const type &)
void set_default()
Sets the members of the neurons selection object to their default values.
Index maximum_neurons
Maximum number of hidden neurons.
void delete_training_error_history()
Delete the history of the loss values.
virtual ~NeuronsSelection()
Destructor.
void check() const
Checks that the different pointers needed for performing the neurons selection are not nullptr.
const Index & get_minimum_neurons() const
Returns the minimum of the hidden perceptrons number used in the neurons selection.
Index trials_number
Number of trials for each neural network.
const Index & get_maximum_epochs_number() const
Returns the maximum number of epochs in the neurons selection algorithm.
bool display
Display messages to screen.
type selection_error_goal
Goal value for the selection error. It is used as a stopping criterion.
void set_maximum_time(const type &)
const string write_time(const type &) const
Writes the time from seconds in format HH:mm:ss.
const Index & get_trials_number() const
Returns the number of trials for each network architecture.
type maximum_time
Maximum selection algorithm time. It is used as a stopping criterion.
void set_maximum_epochs_number(const Index &)
const type & get_selection_error_goal() const
Returns the goal for the selection error in the neurons selection algorithm.
void set_maximum_neurons_number(const Index &)
TrainingStrategy * get_training_strategy_pointer() const
Returns a pointer to the training strategy object.
const Index & get_maximum_neurons() const
Returns the maximum of the hidden perceptrons number used in the neurons selection.
Tensor< type, 1 > training_error_history
Error of all the neural networks trained.
void set_minimum_neurons(const Index &)
Index maximum_epochs_number
Maximum number of epochs to perform neurons selection. It is used as a stopping criterion.
void set_display(const bool &)
string write_stopping_condition(const TrainingResults &) const
bool has_training_strategy() const
Returns true if this neurons selection algorithm has a training strategy associated,...
void set_trials_number(const Index &)
void delete_selection_history()
Delete the history of the selection error values.
This class represents the concept of training strategy for a neural network in OpenNN.
LossIndex * get_loss_index_pointer()
Returns a pointer to the LossIndex class.
NeuralNetwork * get_neural_network_pointer() const
Returns a pointer to the NeuralNetwork class.
NeuronsSelection::StoppingCondition stopping_condition
Stopping condition of the algorithm.
string write_stopping_condition() const
Return a string with the stopping condition of the Results.
This structure contains the optimization algorithm results.
string write_stopping_condition() const
Return a string with the stopping condition of the Results.