#include <EarlyStopping.h>
Public Member Functions | |
| EarlyStopping (unsigned) | |
| A new instance of EarlyStopping is created, internal variables are initialized. | |
| double | getGL () |
| Returns the current value of the generalization loss. | |
| double | getTP () |
| Returns the current value of the training progress. | |
| double | getPQ () |
| Returns the current value of the performance quotient. | |
| unsigned | getUP () |
| Returns the current number of generalization loss increases. | |
| bool | GL (double) |
| Checks, whether the generalization loss exceeds a certain value. | |
| bool | GL () |
| Checks, whether the generalization loss exceeds "1". value. | |
| bool | TP (double) |
| Checks, whether the trainings progress falls short of a certain value. | |
| bool | TP () |
| Checks, whether the trainings progress falls short of "0.1". | |
| bool | PQ (double) |
| Checks, whether the performance quotient exceeds a certain value. | |
| bool | PQ () |
| Checks, whether the performance quotient exceeds "0.5". | |
| bool | UP (unsigned) |
| Checks, whether the number of generalization loss increases is equal to or greater than a certain value. | |
| bool | UP () |
| Checks, whether the number of generalization loss increases is equal to or greater than "3". | |
| bool | one_of_all (double, double, double, unsigned) |
| Checks, whether one of the performance characteristics is out of range. | |
| bool | one_of_all () |
| Checks, whether one of the performance characteristics is out of default range. | |
| void | update (double, double) |
| The performance characteristics are evaluated for the current time step. | |
When training neural networks, there is always the danger of overfitting, i.e. the prediction error for a training set is monotonically decreasing with the number of optimization algorithm iterations, but the error for a validation set (i.e. independent data) is first decreasing, followed by an increase. To achieve best generalization performance, the training should then be stopped at an iteration step when the validation set error has its minimum.
This class offers methods, that can be used to monitor the performance of a network related to a couple of performance characteristics, so one can decide when to stop the training.
The given performance characteristics are:
The training progress (TP) given as
, where
is the average training set error evaluated over a period of timesteps (striplength) and
is the minimal error for the training set during this period.
The generalization loss (GL) given as
, where
is the current error of the validation set and
is the minimum error of the validation set, as calculated during the striplength.
The number of generalization loss increases (UP) is given as the number of time steps during the striplength, at which the generalization loss increases compared to the previous time step.
The performance quotient (PQ) given as
.
void main() { // Create net: MyNet net; // Fill net: ... // Create early stopping instance for monitoring 5 time steps: EarlyStopping estop( 5 ); // Training the net: for ( unsigned epoch = 1; epoch < max_epochs; epoch++ ) { // Train net with prefered optimization algorithm: ... // Calculate training and validation error of // current model: ... // Update of monitoring variables: estop.update( error_train, error_validation ); // Overfitting of network? Then stop training: if ( estop.one_of_all( 1.0, 1.0, 1.0, 3) ) break; } // next training epoch }
Definition at line 142 of file EarlyStopping.h.
| EarlyStopping::EarlyStopping | ( | unsigned | sl = 5 |
) |
A new instance of EarlyStopping is created, internal variables are initialized.
A new instance of EarlyStopping is created, internal variables are initialized.
The internal variables of the new instance are initialized and the time interval used for monitoring is set.
| sl | The number of time steps (striplength), for which the performance shall be evaluated. The default values is "5". |
Definition at line 81 of file EarlyStopping.cpp.
| double EarlyStopping::getGL | ( | ) |
Returns the current value of the generalization loss.
Definition at line 175 of file EarlyStopping.cpp.
| double EarlyStopping::getPQ | ( | ) |
Returns the current value of the performance quotient.
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the performance quotient you will get a value without significance otherwise.
Definition at line 231 of file EarlyStopping.cpp.
| double EarlyStopping::getTP | ( | ) |
Returns the current value of the training progress.
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the training progress you will get a value without significance otherwise.
Definition at line 202 of file EarlyStopping.cpp.
| unsigned EarlyStopping::getUP | ( | ) |
Returns the current number of generalization loss increases.
Definition at line 256 of file EarlyStopping.cpp.
| bool EarlyStopping::GL | ( | ) |
Checks, whether the generalization loss exceeds "1". value.
Referenced by one_of_all().
| bool EarlyStopping::GL | ( | double | alpha = 1.0 |
) |
Checks, whether the generalization loss exceeds a certain value.
Checks, whether the generalization loss exceeds a certain value.
| alpha | The value that is compared to the generalization loss. The default value is "1". |
Definition at line 282 of file EarlyStopping.cpp.
| bool EarlyStopping::one_of_all | ( | ) |
Checks, whether one of the performance characteristics is out of default range.
This method will check all performance characteristics:
If at least one of the performance characteristics is out of range the method will return "true".
| bool EarlyStopping::one_of_all | ( | double | alpha1 = 1.0, |
|
| double | alpha2 = 1.0, |
|||
| double | alpha3 = 1.0, |
|||
| unsigned | s = 3 | |||
| ) |
Checks, whether one of the performance characteristics is out of range.
Checks, whether one of the performance characteristics is out of range.
This method will check all performance characteristics against the given parameters:
If at least one of the performance characteristics is out of range the method will return "true".
| alpha1 | The value that is compared to the generalization loss. The default value is "1". | |
| alpha2 | The value that is compared to the trainings progress The default value is "0.1". | |
| alpha3 | The value that is compared to the performance quotient The default value is "0.5". | |
| s | The value that is compared to the number of generalization loss increases. The default value is "3". |
Definition at line 424 of file EarlyStopping.cpp.
| bool EarlyStopping::PQ | ( | ) |
Checks, whether the performance quotient exceeds "0.5".
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the performance quotient you will get a value without significance otherwise.
Referenced by one_of_all().
| bool EarlyStopping::PQ | ( | double | alpha = 0.5 |
) |
Checks, whether the performance quotient exceeds a certain value.
Checks, whether the performance quotient exceeds a certain value.
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the performance quotient you will get a value without significance otherwise.
| alpha | The value that is compared to the performance quotient The default value is "0.5". |
Definition at line 346 of file EarlyStopping.cpp.
| bool EarlyStopping::TP | ( | ) |
Checks, whether the trainings progress falls short of "0.1".
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the trainings progress you will get a value without significance otherwise.
Referenced by one_of_all().
| bool EarlyStopping::TP | ( | double | alpha = 0.1 |
) |
Checks, whether the trainings progress falls short of a certain value.
Checks, whether the trainings progress falls short of a certain value.
Call this method only if the current time step equals or exceeds the predefined striplength. Because of the calculation of the trainings progress you will get a value without significance otherwise.
| alpha | The value that is compared to the trainings progress The default value is "0.1". |
Definition at line 313 of file EarlyStopping.cpp.
| bool EarlyStopping::UP | ( | ) |
Checks, whether the number of generalization loss increases is equal to or greater than "3".
Referenced by one_of_all().
| bool EarlyStopping::UP | ( | unsigned | s = 3 |
) |
Checks, whether the number of generalization loss increases is equal to or greater than a certain value.
Checks, whether the number of generalization loss increases is equal to or greater than a certain value.
| s | The value that is compared to the number of generalization loss increases. The default value is "3". |
Definition at line 375 of file EarlyStopping.cpp.
| void EarlyStopping::update | ( | double | e, | |
| double | e_va | |||
| ) |
The performance characteristics are evaluated for the current time step.
The performance characteristics are evaluated for the current time step.
Given the errors for the training and validation set for the current time step, the performance characteristics Generalization Loss, Trainings Progress and number of generalization loss increases are evaluated. When the current time step (= no. of method calls) is equal to the predefined striplength, the values are reset.
| e | The current training set error. | |
| e_va | The current validation set error. |
Definition at line 117 of file EarlyStopping.cpp.