OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
neuron_selection.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// N E U R O N S E L E C T I O N C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
18
19#pragma once
20
21namespace opennn
22{
23
25struct TrainingResults;
27
37{
38public:
39
51
58 virtual ~NeuronSelection() = default;
59
62
65
67 bool get_display() const { return display; }
68
75
80 void set_training_strategy(TrainingStrategy* new_training_strategy) { training_strategy = new_training_strategy; }
81
84
89 void set_maximum_neurons(const Index new_maximum_neurons) { maximum_neurons = new_maximum_neurons; }
94 void set_minimum_neurons(const Index new_minimum_neurons) { minimum_neurons = new_minimum_neurons; }
99 void set_trials_number(const Index new_trials_number) { trials_number = new_trials_number; }
100
105 void set_display(bool new_display) { display = new_display; }
106
111 void set_validation_error_goal(const float new_validation_error_goal) { validation_error_goal = new_validation_error_goal; }
116 void set_maximum_epochs(const Index new_maximum_epochs) { maximum_epochs = new_maximum_epochs; }
121 void set_maximum_validation_failures(const Index new_maximum_validation_failures) { maximum_validation_failures = new_maximum_validation_failures; }
126 void set_maximum_time(const float new_maximum_time) { maximum_time = new_maximum_time; }
127
131void check() const;
132
138
140 string get_name() const
141 {
142 return name;
143 }
144
148 virtual void from_JSON(const JsonDocument&) = 0;
149
153 virtual void to_JSON(JsonWriter&) const = 0;
154
160 void save(const filesystem::path&) const;
166 void load(const filesystem::path&);
167
169 virtual void print() const {}
170
171protected:
172
175
178
181
184
187
189 Index trials_number = 1;
190
193
195 Index maximum_epochs = 10;
196
199
201 float maximum_time = 0;
202
204 bool display = true;
205
207 string name;
208};
209
268
269}
270
271// OpenNN: Open Neural Networks Library.
272// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
273// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition json.h:71
Definition json.h:84
void set(TrainingStrategy *)
Re-initializes the selector by setting its training strategy.
virtual NeuronsSelectionResults perform_neurons_selection()=0
Runs the selection algorithm.
Index minimum_neurons
Lower bound on the hidden-layer size.
Definition neuron_selection.h:183
void set_trials_number(const Index new_trials_number)
Sets the number of training trials per candidate (mean is used).
Definition neuron_selection.h:99
void set_maximum_epochs(const Index new_maximum_epochs)
Sets the maximum training epochs per evaluation.
Definition neuron_selection.h:116
void set_minimum_neurons(const Index new_minimum_neurons)
Sets the minimum hidden-layer size considered.
Definition neuron_selection.h:94
void check() const
Validates the bound configuration; throws if anything is missing.
void set_maximum_neurons(const Index new_maximum_neurons)
Sets the maximum hidden-layer size considered.
Definition neuron_selection.h:89
void set_display(bool new_display)
Toggles per-iteration progress printing.
Definition neuron_selection.h:105
float maximum_time
Maximum wall-clock selection time in seconds.
Definition neuron_selection.h:201
void load(const filesystem::path &)
Loads the selector configuration from a file.
void set_default()
Resets all hyperparameters to their default values.
VectorR training_error_history
Per-iteration training error of the best candidate so far.
Definition neuron_selection.h:180
virtual void print() const
Prints a human-readable summary of the selector to stdout.
Definition neuron_selection.h:169
void set_training_strategy(TrainingStrategy *new_training_strategy)
Sets the training strategy directly.
Definition neuron_selection.h:80
virtual void to_JSON(JsonWriter &) const =0
Writes selector hyperparameters to a streaming JSON writer.
void set_validation_error_goal(const float new_validation_error_goal)
Sets the validation error goal.
Definition neuron_selection.h:111
bool display
Whether progress should be printed to stdout during selection.
Definition neuron_selection.h:204
void save(const filesystem::path &) const
Saves the selector configuration to a file.
Index maximum_validation_failures
Maximum consecutive validation-error increases tolerated.
Definition neuron_selection.h:198
StoppingCondition
Reasons that can terminate a neurons-selection run.
Definition neuron_selection.h:44
@ SelectionErrorGoal
Validation error reached the configured goal.
Definition neuron_selection.h:46
@ MaximumSelectionFailures
Validation error increased too many times.
Definition neuron_selection.h:48
@ MaximumEpochs
Configured epoch budget exhausted.
Definition neuron_selection.h:47
@ MaximumTime
Configured time budget exhausted.
Definition neuron_selection.h:45
@ MaximumNeurons
Maximum hidden-layer size reached.
Definition neuron_selection.h:49
Index maximum_neurons
Upper bound on the hidden-layer size.
Definition neuron_selection.h:186
bool get_display() const
Whether progress should be printed to stdout.
Definition neuron_selection.h:67
void set_maximum_validation_failures(const Index new_maximum_validation_failures)
Sets the maximum number of consecutive validation-error increases tolerated.
Definition neuron_selection.h:121
bool has_training_strategy() const
Whether a training strategy has been bound.
Definition neuron_selection.h:64
virtual void from_JSON(const JsonDocument &)=0
Loads selector hyperparameters from a parsed JSON document.
Index maximum_epochs
Maximum training epochs per evaluation.
Definition neuron_selection.h:195
virtual ~NeuronSelection()=default
Virtual destructor.
TrainingStrategy * training_strategy
Training strategy used to evaluate candidates; not owned.
Definition neuron_selection.h:174
NeuronSelection(TrainingStrategy *training_strategy=nullptr)
Constructs the selector.
string get_name() const
Canonical name of the selector (set by subclasses).
Definition neuron_selection.h:140
string name
Canonical name of the selector (set by subclasses).
Definition neuron_selection.h:207
const TrainingStrategy * get_training_strategy() const
Read-only access to the bound training strategy.
Definition neuron_selection.h:61
Index trials_number
Number of independent training runs averaged per candidate.
Definition neuron_selection.h:189
float validation_error_goal
Validation error goal; selection stops when reached.
Definition neuron_selection.h:192
void set_maximum_time(const float new_maximum_time)
Sets the maximum wall-clock selection time.
Definition neuron_selection.h:126
VectorR validation_error_history
Per-iteration validation error of the best candidate so far.
Definition neuron_selection.h:177
Coordinates the training of a NeuralNetwork on a Dataset.
Definition training_strategy.h:45
Definition adaptive_moment_estimation.h:19
Matrix< Index, Dynamic, 1 > VectorI
Definition neural_network.h:157
Matrix< float, Dynamic, 1 > VectorR
Definition neural_network.h:156
Outcome of a NeuronSelection run.
Definition neuron_selection.h:219
VectorR validation_error_history
Per-iteration validation error of the best candidate.
Definition neuron_selection.h:254
Index optimal_neurons_number
Hidden-layer size at the optimal architecture.
Definition neuron_selection.h:245
void resize_history(const Index new_size)
Resizes the error history vectors.
void print() const
Prints a human-readable summary of the result to stdout.
float optimum_training_error
Training error at the optimal architecture.
Definition neuron_selection.h:257
VectorI neurons_number_history
Per-iteration hidden-layer size considered.
Definition neuron_selection.h:242
NeuronsSelectionResults(const Index maximum_epochs=0)
Constructs the result pre-sized for an expected iteration count.
float optimum_validation_error
Validation error at the optimal architecture.
Definition neuron_selection.h:260
string elapsed_time
Total elapsed wall-clock time, formatted as "hh:mm:ss".
Definition neuron_selection.h:266
NeuronSelection::StoppingCondition stopping_condition
Stopping condition that ended the selection run.
Definition neuron_selection.h:263
VectorR training_error_history
Per-iteration training error of the best candidate.
Definition neuron_selection.h:251
string write_stopping_condition() const
Returns the canonical string name of the stopping condition.
VectorR optimal_parameters
Network parameters at the optimal architecture.
Definition neuron_selection.h:248
Per-epoch error history and final summary produced by Optimizer::train().
Definition optimizer.h:374