XCSF
1.4.7
XCSF learning classifier system
|
Python XCSF class data structure. More...
Public Member Functions | |
XCS () | |
Default Constructor. More... | |
XCS (py::kwargs kwargs) | |
Constructor. More... | |
void | reset (void) |
Resets basic constructor variables. More... | |
size_t | save (const char *filename) |
Writes the entire current state of XCSF to a file. More... | |
size_t | load (const char *filename) |
Reads the entire current state of XCSF from a file. More... | |
void | store (void) |
Stores the current population in memory for later retrieval. More... | |
void | retrieve (void) |
Retrieves the stored population, setting it as current. More... | |
void | print_params (void) |
Prints the XCSF parameters and their current values. More... | |
void | pred_expand (void) |
Inserts a new hidden layer before the output layer within all prediction neural networks in the population. More... | |
void | ae_to_classifier (const int y_dim, const int n_del) |
Switches from autoencoding to classification. More... | |
void | print_pset (const bool condition, const bool action, const bool prediction) |
Prints the current population. More... | |
double | fit (const py::array_t< double > input, const int action, const double reward) |
Creates/updates an action set for a given (state, action, reward). More... | |
void | init_trial (void) |
Initialises a reinforcement learning trial. More... | |
void | end_trial (void) |
Frees memory used by a reinforcement learning trial. More... | |
void | init_step (void) |
Initialises a step in a reinforcement learning trial. More... | |
void | end_step (void) |
Ends a step in a reinforcement learning trial. More... | |
int | decision (const py::array_t< double > input, const bool explore) |
Selects an action to perform in a reinforcement learning problem. More... | |
void | update (const double reward, const bool done) |
Creates the action set using the previously selected action, updates the classifiers, and runs the EA on explore steps. More... | |
double | error (const double reward, const bool done, const double max_p) |
Returns the reinforcement learning system prediction error. More... | |
void | load_input (struct Input *data, const py::array_t< double > X, const py::array_t< double > Y) |
Loads an input data structure for fitting. More... | |
void | print_status () |
Prints the current performance metrics. More... | |
void | update_metrics (const double train, const double val, const int n_trials) |
Updates performance metrics. More... | |
void | load_validation_data (py::kwargs kwargs) |
Loads validation data if present in kwargs. More... | |
bool | callbacks_run (py::list callbacks) |
Executes callbacks and returns whether to terminate. More... | |
void | callbacks_finish (py::list callbacks) |
Executes callback finish. More... | |
XCS & | fit (const py::array_t< double > X_train, const py::array_t< double > y_train, const bool shuffle, const bool warm_start, const bool verbose, py::object callbacks, py::kwargs kwargs) |
Executes MAX_TRIALS number of XCSF learning iterations using the provided training data. More... | |
double * | get_cover (const py::array_t< double > cover) |
Returns the values specified in the cover array. More... | |
void | set_cover (const py::object &cover) |
Sets the XCSF cover array to values given, or zeros. More... | |
py::array_t< double > | predict (const py::array_t< double > X, const py::object &cover) |
Returns the XCSF prediction array for the provided input. More... | |
double | score (const py::array_t< double > X, const py::array_t< double > Y, const int N, const py::object &cover) |
Returns the error using N random samples from the provided data. More... | |
py::bytes | serialize () const |
Implements pickle file writing. More... | |
double | error (void) |
Returns the current system error. More... | |
py::dict | get_metrics (void) |
int | get_pset_size (void) |
int | get_pset_num (void) |
int | get_time (void) |
double | get_pset_mean_cond_size (void) |
double | get_pset_mean_pred_size (void) |
double | get_pset_mean_pred_eta (const int layer) |
double | get_pset_mean_pred_neurons (const int layer) |
double | get_pset_mean_pred_connections (const int layer) |
double | get_pset_mean_pred_layers (void) |
double | get_pset_mean_cond_connections (const int layer) |
double | get_pset_mean_cond_neurons (const int layer) |
double | get_pset_mean_cond_layers (void) |
double | get_mset_size (void) |
double | get_aset_size (void) |
double | get_mfrac (void) |
const char * | json_export (const bool condition, const bool action, const bool prediction) |
Returns a JSON formatted string representing the population set. More... | |
void | update_params () |
Updates the Python object's parameter dictionary. More... | |
py::dict | get_params (const bool deep) |
Returns a dictionary of parameters. More... | |
XCS & | set_params (py::kwargs kwargs) |
Sets parameter values. More... | |
py::dict | internal_params () |
Returns a dictionary of the internal parameters. More... | |
void | json_insert_cl (const std::string &json_str) |
Creates a classifier from JSON and inserts into the population. More... | |
void | json_insert (const std::string &json_str) |
Creates classifiers from JSON and inserts into the population. More... | |
void | json_write (const std::string &filename) |
Writes the current population set to a file in JSON. More... | |
void | json_read (const std::string &filename) |
Reads classifiers from a JSON file and adds to the population. More... | |
Static Public Member Functions | |
static XCS | deserialize (const py::bytes &state) |
Implements pickle file reading. More... | |
Private Attributes | |
struct XCSF | xcs |
XCSF data structure. More... | |
double * | state |
Current input state for RL. More... | |
int | action |
Current action for RL. More... | |
double | payoff |
Current reward for RL. More... | |
struct Input * | train_data |
Training data for supervised learning. More... | |
struct Input * | test_data |
Test data for supervised learning. More... | |
struct Input * | val_data |
Validation data. More... | |
py::dict | params |
Dictionary of parameters and their values. More... | |
py::list | metric_train |
py::list | metric_val |
py::list | metric_trial |
py::list | metric_psize |
py::list | metric_msize |
py::list | metric_mfrac |
int | metric_counter |
Python XCSF class data structure.
Definition at line 64 of file pybind_wrapper.cpp.
|
inline |
Default Constructor.
Definition at line 87 of file pybind_wrapper.cpp.
References reset(), xcs, and xcsf_init().
Referenced by deserialize().
|
inlineexplicit |
Constructor.
[in] | kwargs | Parameters and their values. |
Definition at line 97 of file pybind_wrapper.cpp.
References reset(), set_params(), xcs, and xcsf_init().
|
inline |
Switches from autoencoding to classification.
[in] | y_dim | The output dimension (i.e., the number of classes). |
[in] | n_del | The number of hidden layers to remove. |
Definition at line 198 of file pybind_wrapper.cpp.
References xcs, xcsf_ae_to_classifier(), and Input::y_dim.
|
inline |
Executes callback finish.
[in] | callbacks | The callbacks to perform. |
Definition at line 474 of file pybind_wrapper.cpp.
References Callback::finish(), and xcs.
Referenced by fit().
|
inline |
Executes callbacks and returns whether to terminate.
[in] | callbacks | The callbacks to perform. |
Definition at line 452 of file pybind_wrapper.cpp.
References get_metrics(), Callback::run(), and xcs.
Referenced by fit().
|
inline |
Selects an action to perform in a reinforcement learning problem.
Constructs the match set and selects an action to perform.
[in] | input | The input state. |
[in] | explore | Whether this is an exploration step. |
Definition at line 287 of file pybind_wrapper.cpp.
References action, error(), param_set_explore(), state, XCSF::x_dim, xcs, and xcs_rl_decision().
|
inlinestatic |
Implements pickle file reading.
Uses a temporary binary file.
state | The pickled state of a saved XCSF. |
Definition at line 659 of file pybind_wrapper.cpp.
References state, XCS(), xcs, and xcsf_load().
|
inline |
Ends a step in a reinforcement learning trial.
Definition at line 274 of file pybind_wrapper.cpp.
References action, payoff, state, xcs, and xcs_rl_end_step().
|
inline |
Frees memory used by a reinforcement learning trial.
Definition at line 256 of file pybind_wrapper.cpp.
References xcs, and xcs_rl_end_trial().
|
inline |
Returns the reinforcement learning system prediction error.
[in] | reward | The current reward. |
[in] | done | Whether the environment is in a terminal state. |
[in] | max_p | The maximum payoff in the environment. |
Definition at line 322 of file pybind_wrapper.cpp.
References action, payoff, xcs, and xcs_rl_error().
|
inline |
Returns the current system error.
Definition at line 688 of file pybind_wrapper.cpp.
References XCSF::error, and xcs.
Referenced by decision(), fit(), load_input(), and predict().
|
inline |
Creates/updates an action set for a given (state, action, reward).
[in] | input | The input state to match. |
[in] | action | The selected action. |
[in] | reward | The reward for having performed the action. |
Definition at line 225 of file pybind_wrapper.cpp.
References action, error(), XCSF::n_actions, state, XCSF::x_dim, xcs, and xcs_rl_fit().
|
inline |
Executes MAX_TRIALS number of XCSF learning iterations using the provided training data.
[in] | X_train | The input values to use for training. |
[in] | y_train | The true output values to use for training. |
[in] | shuffle | Whether to randomise the instances during training. |
[in] | warm_start | Whether to continue with existing population. |
[in] | verbose | Whether to print learning metrics. |
[in] | callbacks | List of Callback objects or None. |
[in] | kwargs | Keyword arguments. |
Definition at line 499 of file pybind_wrapper.cpp.
References callbacks_finish(), callbacks_run(), XCSF::cover, load_input(), load_validation_data(), XCSF::MAX_TRIALS, XCSF::PERF_TRIALS, print_status(), train_data, update_metrics(), val_data, xcs, xcs_supervised_fit(), xcs_supervised_score(), xcsf_free(), and xcsf_init().
|
inline |
Definition at line 785 of file pybind_wrapper.cpp.
References XCSF::aset_size, and xcs.
|
inline |
Returns the values specified in the cover array.
[in] | cover | The values to return for covering. |
Definition at line 543 of file pybind_wrapper.cpp.
References xcs, and XCSF::y_dim.
Referenced by set_cover().
|
inline |
Definition at line 694 of file pybind_wrapper.cpp.
References metric_mfrac, metric_msize, metric_psize, metric_train, metric_trial, and metric_val.
Referenced by callbacks_run().
|
inline |
Definition at line 791 of file pybind_wrapper.cpp.
References XCSF::mfrac, and xcs.
|
inline |
Definition at line 779 of file pybind_wrapper.cpp.
References XCSF::mset_size, and xcs.
|
inline |
Returns a dictionary of parameters.
deep | For sklearn compatibility. |
Definition at line 842 of file pybind_wrapper.cpp.
References params.
|
inline |
Definition at line 761 of file pybind_wrapper.cpp.
References clset_mean_cond_connections(), XCSF::pset, and xcs.
|
inline |
Definition at line 773 of file pybind_wrapper.cpp.
References clset_mean_cond_layers(), XCSF::pset, and xcs.
|
inline |
Definition at line 767 of file pybind_wrapper.cpp.
References clset_mean_cond_neurons(), XCSF::pset, and xcs.
|
inline |
Definition at line 725 of file pybind_wrapper.cpp.
References clset_mean_cond_size(), XCSF::pset, and xcs.
|
inline |
Definition at line 749 of file pybind_wrapper.cpp.
References clset_mean_pred_connections(), XCSF::pset, and xcs.
|
inline |
Definition at line 737 of file pybind_wrapper.cpp.
References clset_mean_pred_eta(), XCSF::pset, and xcs.
|
inline |
Definition at line 755 of file pybind_wrapper.cpp.
References clset_mean_pred_layers(), XCSF::pset, and xcs.
|
inline |
Definition at line 743 of file pybind_wrapper.cpp.
References clset_mean_pred_neurons(), XCSF::pset, and xcs.
|
inline |
Definition at line 731 of file pybind_wrapper.cpp.
References clset_mean_pred_size(), XCSF::pset, and xcs.
|
inline |
Definition at line 713 of file pybind_wrapper.cpp.
References Set::num, XCSF::pset, and xcs.
|
inline |
Definition at line 707 of file pybind_wrapper.cpp.
References XCSF::pset, Set::size, and xcs.
|
inline |
Definition at line 719 of file pybind_wrapper.cpp.
References XCSF::time, and xcs.
|
inline |
Initialises a step in a reinforcement learning trial.
Definition at line 265 of file pybind_wrapper.cpp.
References xcs, and xcs_rl_init_step().
|
inline |
Initialises a reinforcement learning trial.
Definition at line 247 of file pybind_wrapper.cpp.
References xcs, and xcs_rl_init_trial().
|
inline |
Returns a dictionary of the internal parameters.
Definition at line 882 of file pybind_wrapper.cpp.
References param_json_export(), and xcs.
|
inline |
Returns a JSON formatted string representing the population set.
[in] | condition | Whether to return the condition. |
[in] | action | Whether to return the action. |
[in] | prediction | Whether to return the prediction. |
Definition at line 806 of file pybind_wrapper.cpp.
References action, clset_json_export(), Set::list, XCSF::pset, and xcs.
Referenced by json_write().
|
inline |
Creates classifiers from JSON and inserts into the population.
[in] | json_str | JSON formatted string representing a classifier. |
Definition at line 909 of file pybind_wrapper.cpp.
References clset_json_insert(), and xcs.
Referenced by json_read().
|
inline |
Creates a classifier from JSON and inserts into the population.
[in] | json_str | JSON formatted string representing a classifier. |
Definition at line 896 of file pybind_wrapper.cpp.
References clset_json_insert_cl(), utils_json_parse_check(), and xcs.
|
inline |
Reads classifiers from a JSON file and adds to the population.
[in] | filename | Name of the input file. |
Definition at line 931 of file pybind_wrapper.cpp.
References json_insert().
|
inline |
Writes the current population set to a file in JSON.
[in] | filename | Name of the output file. |
Definition at line 919 of file pybind_wrapper.cpp.
References json_export().
|
inline |
Reads the entire current state of XCSF from a file.
[in] | filename | String containing the name of the input file. |
Definition at line 148 of file pybind_wrapper.cpp.
References update_params(), xcs, and xcsf_load().
|
inline |
Loads an input data structure for fitting.
[in,out] | data | Input data structure used to point to the data. |
[in] | X | Vector of features with shape (n_samples, x_dim). |
[in] | Y | Vector of truth values with shape (n_samples, y_dim). |
Definition at line 337 of file pybind_wrapper.cpp.
References error(), Input::n_samples, Input::x, XCSF::x_dim, Input::x_dim, xcs, Input::y, XCSF::y_dim, and Input::y_dim.
Referenced by fit(), load_validation_data(), and score().
|
inline |
Loads validation data if present in kwargs.
[in] | kwargs | Parameters and their values. |
Definition at line 426 of file pybind_wrapper.cpp.
References XCSF::cover, load_input(), XCSF::pa_size, test_data, val_data, and xcs.
Referenced by fit().
|
inline |
Inserts a new hidden layer before the output layer within all prediction neural networks in the population.
Definition at line 187 of file pybind_wrapper.cpp.
References xcs, and xcsf_pred_expand().
|
inline |
Returns the XCSF prediction array for the provided input.
[in] | X | The input variables. |
[in] | cover | If the match set is empty, the prediction array will be set to this value instead of covering. |
Definition at line 584 of file pybind_wrapper.cpp.
References XCSF::cover, error(), Input::n_samples, XCSF::pa_size, set_cover(), XCSF::x_dim, xcs, and xcs_supervised_predict().
|
inline |
Prints the XCSF parameters and their current values.
Definition at line 177 of file pybind_wrapper.cpp.
References param_print(), and xcs.
|
inline |
Prints the current population.
[in] | condition | Whether to print the condition. |
[in] | action | Whether to print the action. |
[in] | prediction | Whether to print the prediction. |
Definition at line 210 of file pybind_wrapper.cpp.
References action, xcs, and xcsf_print_pset().
|
inline |
Prints the current performance metrics.
Definition at line 381 of file pybind_wrapper.cpp.
References get_timestamp(), metric_mfrac, metric_msize, metric_psize, metric_train, metric_trial, metric_val, and val_data.
Referenced by fit().
|
inline |
Resets basic constructor variables.
Definition at line 108 of file pybind_wrapper.cpp.
References action, metric_counter, Input::n_samples, param_init(), payoff, state, test_data, train_data, update_params(), val_data, Input::x, Input::x_dim, xcs, Input::y, and Input::y_dim.
Referenced by XCS().
|
inline |
Retrieves the stored population, setting it as current.
Definition at line 168 of file pybind_wrapper.cpp.
References xcs, and xcsf_retrieve_pset().
|
inline |
Writes the entire current state of XCSF to a file.
[in] | filename | String containing the name of the output file. |
Definition at line 137 of file pybind_wrapper.cpp.
References xcs, and xcsf_save().
|
inline |
Returns the error using N random samples from the provided data.
[in] | X | The input values to use for scoring. |
[in] | Y | The true output values to use for scoring. |
[in] | N | The maximum number of samples to draw randomly for scoring. |
[in] | cover | If the match set is empty, the prediction array will be set to this value, otherwise it is set to zeros. |
Definition at line 618 of file pybind_wrapper.cpp.
References XCSF::cover, load_input(), set_cover(), test_data, xcs, xcs_supervised_score(), and xcs_supervised_score_n().
|
inline |
Implements pickle file writing.
Uses a temporary binary file.
Definition at line 635 of file pybind_wrapper.cpp.
References state, xcs, and xcsf_save().
|
inline |
Sets the XCSF cover array to values given, or zeros.
[in] | cover | The values to use instead of covering. |
Definition at line 566 of file pybind_wrapper.cpp.
References XCSF::cover, get_cover(), XCSF::pa_size, and xcs.
Referenced by predict(), and score().
|
inline |
Sets parameter values.
kwargs | Parameters and their values. |
Definition at line 854 of file pybind_wrapper.cpp.
References param_json_import(), params, and xcs.
Referenced by XCS().
|
inline |
Stores the current population in memory for later retrieval.
Definition at line 159 of file pybind_wrapper.cpp.
References xcs, and xcsf_store_pset().
|
inline |
Creates the action set using the previously selected action, updates the classifiers, and runs the EA on explore steps.
[in] | reward | The reward from performing the action. |
[in] | done | Whether the environment is in a terminal state. |
Definition at line 308 of file pybind_wrapper.cpp.
References action, payoff, state, xcs, and xcs_rl_update().
|
inline |
Updates performance metrics.
[in] | train | The current training error. |
[in] | val | The current validation error. |
[in] | n_trials | Number of trials run. |
Definition at line 409 of file pybind_wrapper.cpp.
References metric_counter, metric_mfrac, metric_msize, metric_psize, metric_train, metric_trial, metric_val, XCSF::mfrac, XCSF::mset_size, XCSF::pset, Set::size, and xcs.
Referenced by fit().
|
inline |
Updates the Python object's parameter dictionary.
Definition at line 819 of file pybind_wrapper.cpp.
References param_json_export(), params, and xcs.
Referenced by load(), and reset().
|
private |
Current action for RL.
Definition at line 69 of file pybind_wrapper.cpp.
Referenced by decision(), end_step(), error(), fit(), json_export(), print_pset(), reset(), and update().
|
private |
Definition at line 81 of file pybind_wrapper.cpp.
Referenced by reset(), and update_metrics().
|
private |
Definition at line 80 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Definition at line 79 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Definition at line 78 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Definition at line 75 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Definition at line 77 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Definition at line 76 of file pybind_wrapper.cpp.
Referenced by get_metrics(), print_status(), and update_metrics().
|
private |
Dictionary of parameters and their values.
Definition at line 74 of file pybind_wrapper.cpp.
Referenced by get_params(), set_params(), and update_params().
|
private |
Current reward for RL.
Definition at line 70 of file pybind_wrapper.cpp.
Referenced by end_step(), error(), reset(), and update().
|
private |
Current input state for RL.
Definition at line 68 of file pybind_wrapper.cpp.
Referenced by decision(), deserialize(), end_step(), fit(), reset(), serialize(), and update().
|
private |
Test data for supervised learning.
Definition at line 72 of file pybind_wrapper.cpp.
Referenced by load_validation_data(), reset(), and score().
|
private |
Training data for supervised learning.
Definition at line 71 of file pybind_wrapper.cpp.
|
private |
Validation data.
Definition at line 73 of file pybind_wrapper.cpp.
Referenced by fit(), load_validation_data(), print_status(), and reset().
|
private |
XCSF data structure.
Definition at line 940 of file pybind_wrapper.cpp.
Referenced by ae_to_classifier(), callbacks_finish(), callbacks_run(), decision(), deserialize(), end_step(), end_trial(), error(), fit(), get_aset_size(), get_cover(), get_mfrac(), get_mset_size(), get_pset_mean_cond_connections(), get_pset_mean_cond_layers(), get_pset_mean_cond_neurons(), get_pset_mean_cond_size(), get_pset_mean_pred_connections(), get_pset_mean_pred_eta(), get_pset_mean_pred_layers(), get_pset_mean_pred_neurons(), get_pset_mean_pred_size(), get_pset_num(), get_pset_size(), get_time(), init_step(), init_trial(), internal_params(), json_export(), json_insert(), json_insert_cl(), load(), load_input(), load_validation_data(), pred_expand(), predict(), print_params(), print_pset(), reset(), retrieve(), save(), score(), serialize(), set_cover(), set_params(), store(), update(), update_metrics(), update_params(), and XCS().