33#include <pybind11/numpy.h>
34#include <pybind11/pybind11.h>
35#include <pybind11/stl.h>
39namespace py = pybind11;
91 explicit XCS(py::kwargs kwargs)
219 fit(
const py::array_t<double> input,
const int action,
const double reward)
221 py::buffer_info buf = input.request();
223 std::ostringstream
error;
224 error <<
"fit(): x_dim is not equal to: " <<
xcs.
x_dim << std::endl;
225 throw std::invalid_argument(
error.str());
228 std::ostringstream
error;
231 throw std::invalid_argument(
error.str());
233 state = (
double *) buf.ptr;
281 decision(
const py::array_t<double> input,
const bool explore)
283 py::buffer_info buf = input.request();
285 std::ostringstream
error;
287 throw std::invalid_argument(
error.str());
289 state = (
double *) buf.ptr;
302 update(
const double reward,
const bool done)
316 error(
const double reward,
const bool done,
const double max_p)
332 const py::array_t<double> Y)
335 const py::buffer_info buf_x = X.request();
336 const py::buffer_info buf_y = Y.request();
339 const int C_CONTIGUOUS =
340 py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_;
341 if (!(C_CONTIGUOUS == (X.flags() & C_CONTIGUOUS)) ||
342 !(C_CONTIGUOUS == (Y.flags() & C_CONTIGUOUS))) {
343 throw std::invalid_argument(
"X and Y must be C-contiguous");
346 if (buf_x.ndim < 1 || buf_x.ndim > 2) {
347 throw std::invalid_argument(
"X must be 1 or 2-D array");
349 if (buf_y.ndim < 1 || buf_y.ndim > 2) {
350 throw std::invalid_argument(
"Y must be 1 or 2-D array");
352 if (buf_x.shape[0] != buf_y.shape[0]) {
353 throw std::invalid_argument(
"X and Y n_samples are not equal");
355 if (buf_x.ndim > 1 && buf_x.shape[1] !=
xcs.
x_dim) {
356 std::ostringstream
error;
357 error <<
"load_input():";
358 error <<
" received x_dim: (" << buf_x.shape[1] <<
")";
360 error <<
"Perhaps reshape your data.";
361 throw std::invalid_argument(
error.str());
363 if (buf_y.ndim > 1 && buf_y.shape[1] !=
xcs.
y_dim) {
364 std::ostringstream
error;
365 error <<
"load_input():";
366 error <<
" received y_dim: (" << buf_y.shape[1] <<
")";
368 error <<
"Perhaps reshape your data.";
369 throw std::invalid_argument(
error.str());
375 data->
x =
static_cast<double *
>(buf_x.ptr);
376 data->
y =
static_cast<double *
>(buf_y.ptr);
390 std::ostringstream status;
392 status <<
" trials=" << trial;
393 status <<
" train=" << std::fixed << std::setprecision(5) << train;
396 status <<
" val=" << std::fixed << std::setprecision(5) << val;
398 status <<
" pset=" << std::fixed << std::setprecision(1) << psize;
399 status <<
" mset=" << std::fixed << std::setprecision(1) << msize;
400 status <<
" mfrac=" << std::fixed << std::setprecision(2) << mfrac;
401 py::print(status.str());
431 if (kwargs.contains(
"validation_data")) {
432 py::tuple data = kwargs[
"validation_data"].cast<py::tuple>();
434 if (data.size() != 2) {
435 throw std::invalid_argument(
436 "validation_data must be a tuple with two arrays");
438 py::array_t<double> X_val = data[0].cast<py::array_t<double>>();
439 py::array_t<double> y_val = data[1].cast<py::array_t<double>>();
456 bool terminate =
false;
458 for (py::handle item : callbacks) {
459 if (py::isinstance<Callback>(item)) {
460 Callback *cb = py::cast<Callback *>(item);
461 if (cb->
run(&
xcs, metrics)) {
465 throw std::invalid_argument(
"unsupported callback");
478 for (py::handle item : callbacks) {
479 if (py::isinstance<Callback>(item)) {
480 Callback *cb = py::cast<Callback *>(item);
483 throw std::invalid_argument(
"unsupported callback");
501 fit(
const py::array_t<double> X_train,
const py::array_t<double> y_train,
502 const bool shuffle,
const bool warm_start,
const bool verbose,
503 py::object callbacks, py::kwargs kwargs)
513 if (py::isinstance<py::list>(callbacks)) {
514 calls = callbacks.cast<py::list>();
519 for (
int i = 0; i < n; ++i) {
520 const int start = i * n_trials;
523 double val_error = 0;
547 const py::buffer_info buf_c = cover.request();
548 if (buf_c.ndim != 1) {
549 std::ostringstream err;
550 err <<
"cover must be an array of shape (1, " <<
xcs.
y_dim <<
")"
552 throw std::invalid_argument(err.str());
555 std::ostringstream err;
556 err <<
"cover length = " << buf_c.shape[0] <<
" but expected "
558 throw std::invalid_argument(err.str());
560 return reinterpret_cast<double *
>(buf_c.ptr);
570 if (cover.is_none()) {
573 py::array_t<double> cover_arr = cover.cast<py::array_t<double>>();
586 predict(
const py::array_t<double> X,
const py::object &cover)
588 const py::buffer_info buf_x = X.request();
591 const int C_CONTIGUOUS =
592 py::detail::npy_api::constants::NPY_ARRAY_C_CONTIGUOUS_;
593 if (!(C_CONTIGUOUS == (X.flags() & C_CONTIGUOUS))) {
594 throw std::invalid_argument(
"X must be C-contiguous");
596 if (buf_x.ndim < 1 || buf_x.ndim > 2) {
597 throw std::invalid_argument(
"predict(): X must be 1 or 2-D array");
599 if (buf_x.ndim > 1 && buf_x.shape[1] !=
xcs.
x_dim) {
600 std::ostringstream
error;
601 error <<
"predict():";
602 error <<
" received x_dim: (" << buf_x.shape[1] <<
")";
604 error <<
"Perhaps reshape your data.";
605 throw std::invalid_argument(
error.str());
607 const int n_samples = buf_x.shape[0];
608 const double *input =
reinterpret_cast<double *
>(buf_x.ptr);
610 (
double *) malloc(
sizeof(
double) * n_samples *
xcs.
pa_size);
613 return py::array_t<double>(
614 std::vector<ptrdiff_t>{ n_samples,
xcs.
pa_size }, output);
627 score(
const py::array_t<double> X,
const py::array_t<double> Y,
const int N,
628 const py::object &cover)
647 const char *filename =
"_tmp_pickle.bin";
650 std::ifstream file(filename, std::ios::binary);
651 std::string
state((std::istreambuf_iterator<char>(file)),
652 std::istreambuf_iterator<char>());
655 if (std::remove(filename) != 0) {
656 perror(
"Error deleting temporary pickle file");
659 return py::bytes(
state);
671 const char *filename =
"_tmp_pickle.bin";
672 std::ofstream file(filename, std::ios::binary);
673 file.write(
state.cast<std::string>().c_str(),
674 state.cast<std::string>().size());
683 if (std::remove(filename) != 0) {
684 perror(
"Error deleting temporary pickle file");
835 py::module_ json_module = py::module_::import(
"json");
836 py::object parsed_json = json_module.attr(
"loads")(json_str);
837 py::dict pop(parsed_json);
848 py::module_ json_module = py::module_::import(
"json");
849 py::object parsed_json = json_module.attr(
"loads")(json_str);
850 py::dict result(parsed_json);
853 if (
params.contains(
"random_state")) {
854 py::object rs =
params[
"random_state"];
855 if (py::isinstance<py::int_>(rs) && rs.cast<
long long>() < 0) {
856 params[
"random_state"] = py::none();
882 py::dict kwargs_dict(kwargs);
884 for (
const auto &item : kwargs_dict) {
885 params[item.first] = item.second;
888 if (kwargs_dict.contains(
"random_state")) {
889 py::object rs = kwargs[
"random_state"];
891 kwargs_dict[
"random_state"] = -1;
895 py::module_ json_module = py::module_::import(
"json");
896 py::object json_dumps = json_module.attr(
"dumps")(kwargs_dict);
897 std::string json_str = json_dumps.cast<std::string>();
898 const char *json_params = json_str.c_str();
911 py::module_ json_module = py::module_::import(
"json");
924 py::module_ json_module = py::module_::import(
"json");
925 py::object json_dumps = json_module.attr(
"dumps")(classifier);
926 std::string json_str = json_dumps.cast<std::string>();
927 cJSON *json = cJSON_Parse(json_str.c_str());
950 std::ofstream outfile(filename);
961 json_read(
const std::string &filename,
const bool clean)
967 std::ifstream infile(filename);
968 std::stringstream buffer;
969 buffer << infile.rdbuf();
976 m.doc() =
"XCSF learning classifier: rule-based online evolutionary "
977 "machine learning.\nFor details on how to use this module see: "
978 "https://github.com/xcsf-dev/xcsf/wiki/Python-Library-Usage";
980 double (
XCS::*fit1)(
const py::array_t<double>,
const int,
const double) =
982 XCS &(
XCS::*fit2)(
const py::array_t<double>,
const py::array_t<double>,
983 const bool,
const bool,
const bool, py::object,
987 double (
XCS::*error2)(
const double,
const bool,
const double) = &
XCS::error;
989 py::class_<Callback, std::unique_ptr<Callback, py::nodelete>>(m,
993 std::unique_ptr<EarlyStoppingCallback, py::nodelete>>(
994 m,
"EarlyStoppingCallback")
995 .def(py::init<py::str, int, bool, double, int, bool>(),
996 "Creates a callback for terminating the fit function early.",
997 py::arg(
"monitor") =
"train", py::arg(
"patience") = 0,
998 py::arg(
"restore_best") =
false, py::arg(
"min_delta") = 0,
999 py::arg(
"start_from") = 0, py::arg(
"verbose") =
true);
1002 std::unique_ptr<CheckpointCallback, py::nodelete>>(
1003 m,
"CheckpointCallback")
1004 .def(py::init<py::str, std::string, bool, int, bool>(),
1005 "Creates a callback for automatically saving XCSF.",
1006 py::arg(
"monitor") =
"train", py::arg(
"filename") =
"xcsf.bin",
1007 py::arg(
"save_best_only") =
false, py::arg(
"save_freq") = 0,
1008 py::arg(
"verbose") =
true);
1010 py::class_<XCS>(m,
"XCS")
1011 .def(py::init(),
"Creates a new XCSF class with default arguments.")
1012 .def(py::init<py::kwargs>(),
1013 "Creates a new XCSF class with specified arguments.")
1015 "Creates/updates an action set for a given (state, action, "
1016 "reward). state shape must be: (x_dim, ).",
1017 py::arg(
"state"), py::arg(
"action"), py::arg(
"reward"))
1019 "Executes MAX_TRIALS number of XCSF learning iterations using the "
1020 "provided training data. X_train shape must be: (n_samples, "
1021 "x_dim). y_train shape must be: (n_samples, y_dim).",
1022 py::arg(
"X_train"), py::arg(
"y_train"), py::arg(
"shuffle") =
true,
1023 py::arg(
"warm_start") =
false, py::arg(
"verbose") =
true,
1024 py::arg(
"callbacks") = py::none())
1027 "Returns the error using at most N random samples from the "
1028 "provided data. N=0 uses all. X shape must be: (n_samples, x_dim). "
1029 "y shape must be: (n_samples, y_dim). If the match set is empty "
1030 "for a sample, the value of the cover array will be used "
1032 py::arg(
"X"), py::arg(
"y"), py::arg(
"N") = 0,
1033 py::arg(
"cover") = py::none())
1034 .def(
"error", error1,
1035 "Returns a moving average of the system error, updated with step "
1037 .def(
"error", error2,
1038 "Returns the reinforcement learning system prediction error.",
1039 py::arg(
"reward"), py::arg(
"done"), py::arg(
"max_p"))
1041 "Returns the XCSF prediction array for the provided input. X "
1042 "shape must be: (n_samples, x_dim). Returns an array of shape: "
1043 "(n_samples, y_dim). If the match set is empty for a sample, the "
1044 "value of the cover array will be used, otherwise zeros. "
1045 "Cover must be an array of shape: y_dim.",
1046 py::arg(
"X"), py::arg(
"cover") = py::none())
1048 "Saves the current state of XCSF to persistent storage.",
1049 py::arg(
"filename"))
1051 "Loads the current state of XCSF from persistent storage.",
1052 py::arg(
"filename"))
1054 "Stores the current XCSF population in memory for later "
1055 "retrieval, overwriting any previously stored population.")
1057 "Retrieves the previously stored XCSF population from memory.")
1058 .def(
"init_trial", &
XCS::init_trial,
"Initialises a multi-step trial.")
1061 "Initialises a step in a multi-step trial.")
1062 .def(
"end_step", &
XCS::end_step,
"Ends a step in a multi-step trial.")
1064 "Constructs the match set and selects an action to perform for "
1065 "reinforcement learning. state shape must be: (x_dim, )",
1066 py::arg(
"state"), py::arg(
"explore"))
1068 "Creates the action set using the previously selected action.",
1069 py::arg(
"reward"), py::arg(
"done"))
1070 .def(
"time", &
XCS::get_time,
"Returns the current EA time.")
1072 "Returns a dictionary of performance metrics.")
1074 "Returns the number of macro-classifiers in the population.")
1076 "Returns the number of micro-classifiers in the population.")
1078 "Returns the average condition size of classifiers in the "
1081 "Returns the average prediction size of classifiers in the "
1084 "Returns the mean eta for a prediction layer.", py::arg(
"layer"))
1086 "Returns the mean number of neurons for a prediction layer.",
1089 "Returns the mean number of layers in the prediction networks.")
1091 "Returns the mean number of connections for a prediction layer.",
1094 "Returns the mean number of neurons for a condition layer.",
1097 "Returns the mean number of layers in the condition networks.")
1099 "Returns the mean number of connections for a condition layer.",
1102 "Returns the average match set size.")
1104 "Returns the average action set size.")
1106 "Returns the mean fraction of inputs matched by the best rule.")
1107 .def(
"print_pset", &
XCS::print_pset,
"Prints the current population.",
1108 py::arg(
"condition") =
true, py::arg(
"action") =
true,
1109 py::arg(
"prediction") =
true)
1111 "Prints the XCSF parameters and their current values.")
1113 "Inserts a new hidden layer before the output layer within all "
1114 "prediction neural networks in the population.")
1116 "Switches from autoencoding to classification.", py::arg(
"y_dim"),
1119 "Returns a JSON formatted string representing the population set.",
1120 py::arg(
"condition") =
true, py::arg(
"action") =
true,
1121 py::arg(
"prediction") =
true)
1123 "Writes the current population set to a file in JSON.",
1124 py::arg(
"filename"))
1126 "Reads classifiers from a JSON file and adds to the population.",
1127 py::arg(
"filename"), py::arg(
"clean") =
true)
1129 "Returns a dictionary of parameters and their values.")
1133 "Creates a classifier from a dict and inserts into the population.",
1134 py::arg(
"classifier"))
1136 "Creates classifiers from JSON and inserts into the population.",
1137 py::arg(
"json_str"))
1140 "Returns the current population as a dictionary.",
1141 py::arg(
"condition") =
true, py::arg(
"action") =
true,
1142 py::arg(
"prediction") =
true)
virtual void finish(struct XCSF *xcsf)=0
virtual bool run(struct XCSF *xcsf, py::dict metrics)=0
Callback to save XCSF at some frequency.
Callback to stop training when a certain metric has stopped improving.
Python XCSF class data structure.
double get_pset_mean_cond_size(void)
double get_pset_mean_cond_connections(const int layer)
double get_pset_mean_cond_neurons(const int layer)
void store(void)
Stores the current population in memory for later retrieval.
XCS & set_params(py::kwargs kwargs)
Sets parameter values.
double get_mset_size(void)
void end_trial(void)
Frees memory used by a reinforcement learning trial.
size_t load(const char *filename)
Reads the entire current state of XCSF from a file.
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.
void reset(void)
Resets basic constructor variables.
struct XCSF xcs
XCSF data structure.
py::dict internal_params()
Returns a dictionary of the internal parameters.
double get_aset_size(void)
struct Input * test_data
Test data for supervised learning.
double get_pset_mean_pred_eta(const int layer)
py::array_t< double > predict(const py::array_t< double > X, const py::object &cover)
Returns the XCSF prediction array for the provided input.
void json_write(const std::string &filename)
Writes the current population set to a file in JSON.
void callbacks_finish(py::list callbacks)
Executes callback finish.
XCS(py::kwargs kwargs)
Constructor.
double * state
Current input state for RL.
struct Input * train_data
Training data for supervised learning.
double get_pset_mean_cond_layers(void)
double get_pset_mean_pred_connections(const int layer)
double payoff
Current reward for RL.
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.
static XCS deserialize(const py::bytes &state)
Implements pickle file reading.
void print_params(void)
Prints the XCSF parameters and their current values.
size_t save(const char *filename)
Writes the entire current state of XCSF to a file.
std::string json_export(const bool condition, const bool action, const bool prediction)
Returns a JSON formatted string representing the population set.
double get_pset_mean_pred_size(void)
double error(const double reward, const bool done, const double max_p)
Returns the reinforcement learning system prediction error.
XCS()
Default Constructor.
struct Input * val_data
Validation data.
void update_metrics(const double train, const double val, const int n_trials)
Updates performance metrics.
void print_pset(const bool condition, const bool action, const bool prediction)
Prints the current population.
py::dict get_pop(const bool condition, const bool action, const bool prediction)
Returns a Python dictionary containing the population set.
void pred_expand(void)
Inserts a new hidden layer before the output layer within all prediction neural networks in the popul...
void init_step(void)
Initialises a step in a reinforcement learning trial.
void end_step(void)
Ends a step in a reinforcement learning trial.
int action
Current action for RL.
void load_validation_data(py::kwargs kwargs)
Loads validation data if present in kwargs.
void print_status()
Prints the current performance metrics.
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).
py::bytes serialize() const
Implements pickle file writing.
int decision(const py::array_t< double > input, const bool explore)
Selects an action to perform in a reinforcement learning problem.
void set_cover(const py::object &cover)
Sets the XCSF cover array to values given, or zeros.
py::dict get_metrics(void)
void ae_to_classifier(const int y_dim, const int n_del)
Switches from autoencoding to classification.
void json_read(const std::string &filename, const bool clean)
Reads classifiers from a JSON file and adds to the population.
void init_trial(void)
Initialises a reinforcement learning trial.
bool callbacks_run(py::list callbacks)
Executes callbacks and returns whether to terminate.
void update_params()
Updates the Python object's parameter dictionary.
py::dict params
Dictionary of parameters and their values.
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.
double get_pset_mean_pred_neurons(const int layer)
double error(void)
Returns the current system error.
void retrieve(void)
Retrieves the stored population, setting it as current.
double get_pset_mean_pred_layers(void)
py::dict get_params(const bool deep)
Returns a dictionary of parameters.
void json_insert(const std::string &json_str)
Creates classifiers from JSON and inserts into the population.
void update(const double reward, const bool done)
Creates the action set using the previously selected action, updates the classifiers,...
double * get_cover(const py::array_t< double > cover)
Returns the values specified in the cover array.
void insert_cl(const py::dict &classifier)
Creates a classifier from dict and inserts into the population.
double clset_mean_pred_size(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean prediction size of classifiers in the set.
void clset_kill(const struct XCSF *xcsf, struct Set *set)
Frees the set and the classifiers.
char * clset_json_export(const struct XCSF *xcsf, const struct Set *set, const bool return_cond, const bool return_act, const bool return_pred)
Returns a json formatted string representation of a classifier set.
double clset_mean_cond_size(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean condition size of classifiers in the set.
void clset_json_insert(struct XCSF *xcsf, const char *json_str)
Creates classifiers from JSON and inserts into the population.
void clset_init(struct Set *set)
Initialises a new set.
void clset_json_insert_cl(struct XCSF *xcsf, const cJSON *json)
Creates a classifier from cJSON and inserts in the population set.
Functions operating on sets of classifiers.
double clset_mean_cond_neurons(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of condition neurons for a given layer.
double clset_mean_pred_eta(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean prediction layer ETA of classifiers in the set.
double clset_mean_cond_layers(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean number of condition layers in the set.
double clset_mean_pred_connections(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of prediction connections in the set.
double clset_mean_pred_layers(const struct XCSF *xcsf, const struct Set *set)
Calculates the mean number of prediction layers in the set.
double clset_mean_cond_connections(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of condition connections in the set.
double clset_mean_pred_neurons(const struct XCSF *xcsf, const struct Set *set, const int layer)
Calculates the mean number of prediction neurons for a given layer.
Functions operating on sets of neural classifiers.
void param_json_import(struct XCSF *xcsf, const char *json_str)
Sets the parameters from a json formatted string.
void param_print(const struct XCSF *xcsf)
Prints all XCSF parameters.
const char * param_set_explore(struct XCSF *xcsf, const bool a)
char * param_json_export(const struct XCSF *xcsf)
Returns a json formatted string representation of the parameters.
void param_init(struct XCSF *xcsf, const int x_dim, const int y_dim, const int n_actions)
Initialises default XCSF parameters.
Functions for setting and printing parameters.
Checkpoint callback for Python library.
Early stopping callback for Python library.
Utilities for Python library.
std::string get_timestamp()
Returns a formatted string for displaying time.
int size
Number of macro-classifiers.
struct Clist * list
Linked list of classifiers.
int num
The total numerosity of classifiers.
double mset_size
Average match set size.
int x_dim
Number of problem input variables.
int PERF_TRIALS
Number of problem instances to avg performance output.
double aset_size
Average action set size.
int pa_size
Prediction array size.
int n_actions
Number of class labels / actions.
struct Set pset
Population set.
int MAX_TRIALS
Number of problem instances to run in one experiment.
double * cover
Values to return for a prediction instead of covering.
double error
Average system error.
int time
Current number of EA executions.
double mfrac
Generalisation measure.
int y_dim
Number of problem output variables.
void utils_json_parse_check(const cJSON *json)
Checks whether JSON parsed correctly.
Utility functions for random number handling, etc.
double xcs_rl_fit(struct XCSF *xcsf, const double *state, const int action, const double reward)
Creates and updates an action set for a given (state, action, reward).
void xcs_rl_update(struct XCSF *xcsf, const double *state, const int action, const double reward, const bool done)
Provides reinforcement to the sets.
int xcs_rl_decision(struct XCSF *xcsf, const double *state)
Selects an action to perform in a reinforcement learning problem.
void xcs_rl_init_step(struct XCSF *xcsf)
Initialises a step in a reinforcement learning trial.
void xcs_rl_end_trial(struct XCSF *xcsf)
Frees memory used by a reinforcement learning trial.
double xcs_rl_error(struct XCSF *xcsf, const int action, const double reward, const bool done, const double max_p)
Returns the reinforcement learning system prediction error.
void xcs_rl_init_trial(struct XCSF *xcsf)
Initialises a reinforcement learning trial.
void xcs_rl_end_step(struct XCSF *xcsf, const double *state, const int action, const double reward)
Ends a step in a reinforcement learning trial.
Reinforcement learning functions.
double xcs_supervised_fit(struct XCSF *xcsf, const struct Input *train_data, const struct Input *test_data, const bool shuffle, const int start, const int trials)
Executes MAX_TRIALS number of XCSF learning iterations using the training data and test iterations us...
double xcs_supervised_score(struct XCSF *xcsf, const struct Input *data, const double *cover)
Calculates the XCSF error for the input data.
double xcs_supervised_score_n(struct XCSF *xcsf, const struct Input *data, const int N, const double *cover)
Calculates the XCSF error for a subsample of the input data.
void xcs_supervised_predict(struct XCSF *xcsf, const double *x, double *pred, const int n_samples, const double *cover)
Calculates the XCSF predictions for the provided input.
Supervised regression learning functions.
void xcsf_store_pset(struct XCSF *xcsf)
Stores the current population.
size_t xcsf_save(const struct XCSF *xcsf, const char *filename)
Writes the current state of XCSF to a file.
void xcsf_retrieve_pset(struct XCSF *xcsf)
Retrieves the previously stored population.
void xcsf_pred_expand(const struct XCSF *xcsf)
Inserts a new hidden layer before the output layer within all prediction neural networks in the popul...
void xcsf_ae_to_classifier(struct XCSF *xcsf, const int y_dim, const int n_del)
Switches from autoencoding to classification.
size_t xcsf_load(struct XCSF *xcsf, const char *filename)
Reads the state of XCSF from a file.
void xcsf_print_pset(const struct XCSF *xcsf, const bool print_cond, const bool print_act, const bool print_pred)
Prints the current XCSF population.
void xcsf_init(struct XCSF *xcsf)
Initialises XCSF with an empty population.
void xcsf_free(struct XCSF *xcsf)
Frees XCSF population sets.