XCSF  1.4.7
XCSF learning classifier system
EarlyStoppingCallback Class Reference

Callback to stop training when a certain metric has stopped improving. More...

#include <pybind_callback_earlystop.h>

Inheritance diagram for EarlyStoppingCallback:
[legend]
Collaboration diagram for EarlyStoppingCallback:
[legend]

Public Member Functions

 EarlyStoppingCallback (py::str monitor, int patience, bool restore, double min_delta, int start_from, bool verbose)
 Constructs a new early stopping callback. More...
 
void store (struct XCSF *xcsf)
 Stores best XCSF population in memory. More...
 
void retrieve (struct XCSF *xcsf)
 Retrieves best XCSF population in memory. More...
 
bool run (struct XCSF *xcsf, py::dict metrics) override
 Checks whether early stopping criteria has been met. More...
 
void finish (struct XCSF *xcsf) override
 Executes any tasks at the end of fitting. More...
 
- Public Member Functions inherited from Callback
virtual ~Callback ()
 

Private Attributes

py::str monitor
 Name of the metric to monitor. More...
 
int patience
 Stop training after this many trials with no improvement. More...
 
bool restore
 Whether to restore the best population. More...
 
double min_delta
 Minimum change to qualify as an improvement. More...
 
int start_from
 Trials to wait before starting to monitor. More...
 
bool verbose
 Whether to display messages when an action is taken. More...
 
double best_error = std::numeric_limits<double>::max()
 Best error. More...
 
int best_trial = 0
 Trial number the best error was observed. More...
 
bool do_restore = false
 Whether the population needs to be restored. More...
 

Detailed Description

Callback to stop training when a certain metric has stopped improving.

Definition at line 42 of file pybind_callback_earlystop.h.

Constructor & Destructor Documentation

◆ EarlyStoppingCallback()

EarlyStoppingCallback::EarlyStoppingCallback ( py::str  monitor,
int  patience,
bool  restore,
double  min_delta,
int  start_from,
bool  verbose 
)
inline

Constructs a new early stopping callback.

Parameters
[in]monitorName of the metric to monitor: {"train", "val"}.
[in]patienceTrials with no improvement after which training will be stopped.
[in]restoreWhether to restore the best population.
[in]min_deltaMinimum change to qualify as an improvement.
[in]start_fromTrials to wait before starting to monitor improvement.
[in]verboseWhether to display messages when an action is taken.

Definition at line 56 of file pybind_callback_earlystop.h.

References min_delta, monitor, and patience.

Member Function Documentation

◆ finish()

void EarlyStoppingCallback::finish ( struct XCSF xcsf)
inlineoverridevirtual

Executes any tasks at the end of fitting.

Parameters
[in]xcsfThe XCSF data structure.

Implements Callback.

Definition at line 160 of file pybind_callback_earlystop.h.

References do_restore, restore, and retrieve().

Here is the call graph for this function:

◆ retrieve()

void EarlyStoppingCallback::retrieve ( struct XCSF xcsf)
inline

Retrieves best XCSF population in memory.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 104 of file pybind_callback_earlystop.h.

References best_error, best_trial, do_restore, get_timestamp(), verbose, and xcsf_retrieve_pset().

Referenced by finish(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

bool EarlyStoppingCallback::run ( struct XCSF xcsf,
py::dict  metrics 
)
inlineoverridevirtual

Checks whether early stopping criteria has been met.

Parameters
[in]xcsfThe XCSF data structure.
[in]metricsDictionary of performance metrics.
Returns
whether early stopping criteria has been met.

Implements Callback.

Definition at line 125 of file pybind_callback_earlystop.h.

References best_error, best_trial, get_timestamp(), min_delta, monitor, patience, restore, retrieve(), start_from, store(), and verbose.

Here is the call graph for this function:

◆ store()

void EarlyStoppingCallback::store ( struct XCSF xcsf)
inline

Stores best XCSF population in memory.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 86 of file pybind_callback_earlystop.h.

References best_error, best_trial, do_restore, get_timestamp(), verbose, and xcsf_store_pset().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ best_error

double EarlyStoppingCallback::best_error = std::numeric_limits<double>::max()
private

Best error.

Definition at line 175 of file pybind_callback_earlystop.h.

Referenced by retrieve(), run(), and store().

◆ best_trial

int EarlyStoppingCallback::best_trial = 0
private

Trial number the best error was observed.

Definition at line 176 of file pybind_callback_earlystop.h.

Referenced by retrieve(), run(), and store().

◆ do_restore

bool EarlyStoppingCallback::do_restore = false
private

Whether the population needs to be restored.

Definition at line 177 of file pybind_callback_earlystop.h.

Referenced by finish(), retrieve(), and store().

◆ min_delta

double EarlyStoppingCallback::min_delta
private

Minimum change to qualify as an improvement.

Definition at line 171 of file pybind_callback_earlystop.h.

Referenced by EarlyStoppingCallback(), and run().

◆ monitor

py::str EarlyStoppingCallback::monitor
private

Name of the metric to monitor.

Definition at line 168 of file pybind_callback_earlystop.h.

Referenced by EarlyStoppingCallback(), and run().

◆ patience

int EarlyStoppingCallback::patience
private

Stop training after this many trials with no improvement.

Definition at line 169 of file pybind_callback_earlystop.h.

Referenced by EarlyStoppingCallback(), and run().

◆ restore

bool EarlyStoppingCallback::restore
private

Whether to restore the best population.

Definition at line 170 of file pybind_callback_earlystop.h.

Referenced by finish(), and run().

◆ start_from

int EarlyStoppingCallback::start_from
private

Trials to wait before starting to monitor.

Definition at line 172 of file pybind_callback_earlystop.h.

Referenced by run().

◆ verbose

bool EarlyStoppingCallback::verbose
private

Whether to display messages when an action is taken.

Definition at line 173 of file pybind_callback_earlystop.h.

Referenced by retrieve(), run(), and store().


The documentation for this class was generated from the following file: