XCSF
1.4.7
XCSF learning classifier system
|
Interface for classifier predictions. More...
#include "xcsf.h"
Go to the source code of this file.
Data Structures | |
struct | ArgsPred |
Parameters for initialising and operating predictions. More... | |
struct | PredVtbl |
Prediction interface data structure. More... | |
Macros | |
#define | PRED_TYPE_INVALID (-1) |
Error code for invalid prediction. More... | |
#define | PRED_TYPE_CONSTANT (0) |
Prediction type constant. More... | |
#define | PRED_TYPE_NLMS_LINEAR (1) |
Prediction type linear nlms. More... | |
#define | PRED_TYPE_NLMS_QUADRATIC (2) |
Prediction type quadratic nlms. More... | |
#define | PRED_TYPE_RLS_LINEAR (3) |
Prediction type linear rls. More... | |
#define | PRED_TYPE_RLS_QUADRATIC (4) |
Prediction type quadratic rls. More... | |
#define | PRED_TYPE_NEURAL (5) |
Prediction type neural. More... | |
#define | PRED_STRING_CONSTANT ("constant\0") |
Constant. More... | |
#define | PRED_STRING_NLMS_LINEAR ("nlms_linear\0") |
Linear nlms. More... | |
#define | PRED_STRING_NLMS_QUADRATIC ("nlms_quadratic\0") |
Quadratic nlms. More... | |
#define | PRED_STRING_RLS_LINEAR ("rls_linear\0") |
Linear rls. More... | |
#define | PRED_STRING_RLS_QUADRATIC ("rls_quadratic\0") |
Quadratic rls. More... | |
#define | PRED_STRING_NEURAL ("neural\0") |
Neural. More... | |
#define | PRED_TYPE_OPTIONS |
Functions | |
const char * | prediction_type_as_string (const int type) |
Returns a string representation of a prediction type from the integer. More... | |
int | prediction_type_as_int (const char *type) |
Returns the integer representation of a prediction type given a name. More... | |
size_t | pred_param_load (struct XCSF *xcsf, FILE *fp) |
Loads prediction parameters. More... | |
size_t | pred_param_save (const struct XCSF *xcsf, FILE *fp) |
Saves prediction parameters. More... | |
void | pred_param_defaults (struct XCSF *xcsf) |
Initialises default prediction parameters. More... | |
void | pred_param_free (struct XCSF *xcsf) |
Frees prediction parameters. More... | |
char * | pred_param_json_import (struct XCSF *xcsf, cJSON *json) |
Sets the prediction parameters from a cJSON object. More... | |
char * | pred_param_json_export (const struct XCSF *xcsf) |
Returns a json formatted string of the prediction parameters. More... | |
void | pred_transform_input (const struct XCSF *xcsf, const double *x, const double X0, double *tmp_input) |
Prepares the input state for least squares computation. More... | |
void | prediction_set (const struct XCSF *xcsf, struct Cl *c) |
Sets a classifier's prediction functions to the implementations. More... | |
static size_t | pred_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp) |
Writes the prediction to a file. More... | |
static size_t | pred_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp) |
Reads the prediction from a file. More... | |
static double | pred_size (const struct XCSF *xcsf, const struct Cl *c) |
Returns the size of the classifier prediction. More... | |
static bool | pred_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2) |
Performs classifier prediction crossover. More... | |
static bool | pred_mutate (const struct XCSF *xcsf, const struct Cl *c) |
Performs classifier prediction mutation. More... | |
static void | pred_compute (const struct XCSF *xcsf, const struct Cl *c, const double *x) |
Computes the current classifier prediction using the input. More... | |
static void | pred_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src) |
Copies the prediction from one classifier to another. More... | |
static void | pred_free (const struct XCSF *xcsf, const struct Cl *c) |
Frees the memory used by the classifier prediction. More... | |
static void | pred_init (const struct XCSF *xcsf, struct Cl *c) |
Initialises a classifier's prediction. More... | |
static void | pred_print (const struct XCSF *xcsf, const struct Cl *c) |
Prints the classifier prediction. More... | |
static void | pred_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y) |
Updates the classifier's prediction. More... | |
static char * | pred_json_export (const struct XCSF *xcsf, const struct Cl *c) |
Returns a json formatted string representation of a prediction. More... | |
static void | pred_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json) |
Creates a prediction from a cJSON object. More... | |
void | pred_param_set_eta (struct XCSF *xcsf, const double a) |
void | pred_param_set_eta_min (struct XCSF *xcsf, const double a) |
void | pred_param_set_lambda (struct XCSF *xcsf, const double a) |
void | pred_param_set_scale_factor (struct XCSF *xcsf, const double a) |
void | pred_param_set_x0 (struct XCSF *xcsf, const double a) |
void | pred_param_set_evolve_eta (struct XCSF *xcsf, const bool a) |
void | pred_param_set_type (struct XCSF *xcsf, const int a) |
int | pred_param_set_type_string (struct XCSF *xcsf, const char *a) |
Interface for classifier predictions.
Definition in file prediction.h.
#define PRED_STRING_CONSTANT ("constant\0") |
Constant.
Definition at line 36 of file prediction.h.
#define PRED_STRING_NEURAL ("neural\0") |
Neural.
Definition at line 41 of file prediction.h.
#define PRED_STRING_NLMS_LINEAR ("nlms_linear\0") |
Linear nlms.
Definition at line 37 of file prediction.h.
#define PRED_STRING_NLMS_QUADRATIC ("nlms_quadratic\0") |
Quadratic nlms.
Definition at line 38 of file prediction.h.
#define PRED_STRING_RLS_LINEAR ("rls_linear\0") |
Linear rls.
Definition at line 39 of file prediction.h.
#define PRED_STRING_RLS_QUADRATIC ("rls_quadratic\0") |
Quadratic rls.
Definition at line 40 of file prediction.h.
#define PRED_TYPE_CONSTANT (0) |
Prediction type constant.
Definition at line 29 of file prediction.h.
#define PRED_TYPE_INVALID (-1) |
Error code for invalid prediction.
Definition at line 28 of file prediction.h.
#define PRED_TYPE_NEURAL (5) |
Prediction type neural.
Definition at line 34 of file prediction.h.
#define PRED_TYPE_NLMS_LINEAR (1) |
Prediction type linear nlms.
Definition at line 30 of file prediction.h.
#define PRED_TYPE_NLMS_QUADRATIC (2) |
Prediction type quadratic nlms.
Definition at line 31 of file prediction.h.
#define PRED_TYPE_OPTIONS |
Definition at line 43 of file prediction.h.
#define PRED_TYPE_RLS_LINEAR (3) |
Prediction type linear rls.
Definition at line 32 of file prediction.h.
#define PRED_TYPE_RLS_QUADRATIC (4) |
Prediction type quadratic rls.
Definition at line 33 of file prediction.h.
Computes the current classifier prediction using the input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier calculating the prediction. |
[in] | x | The input state. |
Definition at line 189 of file prediction.h.
References PredVtbl::pred_impl_compute, and Cl::pred_vptr.
Referenced by cl_predict().
Copies the prediction from one classifier to another.
[in] | xcsf | The XCSF data structure. |
[in] | dest | The destination classifier. |
[in] | src | The source classifier. |
Definition at line 201 of file prediction.h.
References PredVtbl::pred_impl_copy, and Cl::pred_vptr.
Referenced by cl_copy(), and cl_init_copy().
|
static |
Performs classifier prediction crossover.
[in] | xcsf | The XCSF data structure. |
[in] | c1 | The first classifier whose prediction is being crossed. |
[in] | c2 | The second classifier whose prediction is being crossed. |
Definition at line 164 of file prediction.h.
References PredVtbl::pred_impl_crossover, and Cl::pred_vptr.
Referenced by cl_crossover().
Frees the memory used by the classifier prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is to be freed. |
Definition at line 212 of file prediction.h.
References PredVtbl::pred_impl_free, and Cl::pred_vptr.
Referenced by cl_free().
Initialises a classifier's prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is to be initialised. |
Definition at line 223 of file prediction.h.
References PredVtbl::pred_impl_init, and Cl::pred_vptr.
Referenced by cl_copy(), and cl_rand().
Returns a json formatted string representation of a prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | Classifier whose prediction is to be returned. |
Definition at line 261 of file prediction.h.
References PredVtbl::pred_impl_json_export, and Cl::pred_vptr.
Referenced by cl_json_export().
Creates a prediction from a cJSON object.
[in] | xcsf | The XCSF data structure. |
[in,out] | c | The classifier whose prediction is to be initialised. |
[in] | json | cJSON object. |
Definition at line 273 of file prediction.h.
References PredVtbl::pred_impl_json_import, Cl::pred_vptr, prediction_type_as_int(), and prediction_type_as_string().
Referenced by cl_json_import().
Reads the prediction from a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is to be read. |
[in] | fp | Pointer to the file to be read. |
Definition at line 139 of file prediction.h.
References PredVtbl::pred_impl_load, and Cl::pred_vptr.
Referenced by cl_load().
Performs classifier prediction mutation.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is being mutated. |
Definition at line 177 of file prediction.h.
References PredVtbl::pred_impl_mutate, and Cl::pred_vptr.
Referenced by cl_mutate().
void pred_param_defaults | ( | struct XCSF * | xcsf | ) |
Initialises default prediction parameters.
[in] | xcsf | The XCSF data structure. |
Definition at line 120 of file prediction.c.
References pred_neural_param_defaults(), pred_param_set_eta(), pred_param_set_eta_min(), pred_param_set_evolve_eta(), pred_param_set_lambda(), pred_param_set_scale_factor(), pred_param_set_type(), pred_param_set_x0(), and PRED_TYPE_NLMS_LINEAR.
Referenced by param_init().
void pred_param_free | ( | struct XCSF * | xcsf | ) |
Frees prediction parameters.
[in] | xcsf | The XCSF data structure. |
Definition at line 252 of file prediction.c.
References layer_args_free().
Referenced by param_free().
char* pred_param_json_export | ( | const struct XCSF * | xcsf | ) |
Returns a json formatted string of the prediction parameters.
[in] | xcsf | XCSF data structure. |
Definition at line 138 of file prediction.c.
References layer_args_json_export(), pred_nlms_param_json_export(), pred_rls_param_json_export(), PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, PRED_TYPE_RLS_QUADRATIC, prediction_type_as_string(), and ArgsPred::type.
Referenced by param_json_export().
char* pred_param_json_import | ( | struct XCSF * | xcsf, |
cJSON * | json | ||
) |
Sets the prediction parameters from a cJSON object.
[in,out] | xcsf | XCSF data structure. |
[in] | json | cJSON object. |
Definition at line 179 of file prediction.c.
References pred_neural_param_json_import(), pred_nlms_param_json_import(), pred_rls_param_json_import(), PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.
Referenced by param_json_import_prediction().
size_t pred_param_load | ( | struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Loads prediction parameters.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the output file. |
Definition at line 232 of file prediction.c.
References ArgsPred::eta, ArgsPred::eta_min, ArgsPred::evolve_eta, ArgsPred::lambda, ArgsPred::largs, layer_args_load(), ArgsPred::scale_factor, ArgsPred::type, and ArgsPred::x0.
Referenced by param_load().
size_t pred_param_save | ( | const struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Saves prediction parameters.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the output file. |
Definition at line 210 of file prediction.c.
References ArgsPred::eta, ArgsPred::eta_min, ArgsPred::evolve_eta, ArgsPred::lambda, ArgsPred::largs, layer_args_save(), ArgsPred::scale_factor, ArgsPred::type, and ArgsPred::x0.
Referenced by param_save().
void pred_param_set_eta | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 291 of file prediction.c.
Referenced by pred_nlms_param_json_import(), and pred_param_defaults().
void pred_param_set_eta_min | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 305 of file prediction.c.
Referenced by pred_nlms_param_json_import(), and pred_param_defaults().
void pred_param_set_evolve_eta | ( | struct XCSF * | xcsf, |
const bool | a | ||
) |
Definition at line 337 of file prediction.c.
Referenced by pred_nlms_param_json_import(), and pred_param_defaults().
void pred_param_set_lambda | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 319 of file prediction.c.
Referenced by pred_param_defaults(), and pred_rls_param_json_import().
void pred_param_set_scale_factor | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 325 of file prediction.c.
Referenced by pred_param_defaults(), and pred_rls_param_json_import().
void pred_param_set_type | ( | struct XCSF * | xcsf, |
const int | a | ||
) |
Definition at line 343 of file prediction.c.
Referenced by pred_param_defaults().
int pred_param_set_type_string | ( | struct XCSF * | xcsf, |
const char * | a | ||
) |
Definition at line 354 of file prediction.c.
References PRED_TYPE_INVALID, prediction_type_as_int(), and ArgsPred::type.
Referenced by param_json_import_prediction().
void pred_param_set_x0 | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 331 of file prediction.c.
Referenced by pred_nlms_param_json_import(), pred_param_defaults(), and pred_rls_param_json_import().
Prints the classifier prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is to be printed. |
Definition at line 234 of file prediction.h.
References PredVtbl::pred_impl_print, and Cl::pred_vptr.
Writes the prediction to a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction is to be written. |
[in] | fp | Pointer to the file to be written. |
Definition at line 126 of file prediction.h.
References PredVtbl::pred_impl_save, and Cl::pred_vptr.
Referenced by cl_save().
Returns the size of the classifier prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction size to return. |
Definition at line 151 of file prediction.h.
References PredVtbl::pred_impl_size, and Cl::pred_vptr.
Referenced by cl_pred_size().
void pred_transform_input | ( | const struct XCSF * | xcsf, |
const double * | x, | ||
const double | X0, | ||
double * | tmp_input | ||
) |
Prepares the input state for least squares computation.
[in] | xcsf | The XCSF data structure. |
[in] | x | The input state. |
[in] | X0 | Bias term. |
[out] | tmp_input | The transformed input. |
Definition at line 265 of file prediction.c.
References PRED_TYPE_NLMS_QUADRATIC, and PRED_TYPE_RLS_QUADRATIC.
Referenced by pred_nlms_compute(), and pred_rls_compute().
|
static |
Updates the classifier's prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | Classifier whose prediction is to be updated. |
[in] | x | Input state. |
[in] | y | Truth/payoff value. |
Definition at line 248 of file prediction.h.
References PredVtbl::pred_impl_update, and Cl::pred_vptr.
Referenced by cl_update().
Sets a classifier's prediction functions to the implementations.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to set. |
Definition at line 36 of file prediction.c.
References pred_constant_vtbl, pred_neural_vtbl, pred_nlms_vtbl, pred_rls_vtbl, PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, PRED_TYPE_RLS_QUADRATIC, and Cl::pred_vptr.
Referenced by cl_load(), and cl_rand().
int prediction_type_as_int | ( | const char * | type | ) |
Returns the integer representation of a prediction type given a name.
[in] | type | String representation of a prediction type. |
Definition at line 92 of file prediction.c.
References PRED_STRING_CONSTANT, PRED_STRING_NEURAL, PRED_STRING_NLMS_LINEAR, PRED_STRING_NLMS_QUADRATIC, PRED_STRING_RLS_LINEAR, PRED_STRING_RLS_QUADRATIC, PRED_TYPE_CONSTANT, PRED_TYPE_INVALID, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.
Referenced by pred_json_import(), and pred_param_set_type_string().
const char* prediction_type_as_string | ( | const int | type | ) |
Returns a string representation of a prediction type from the integer.
[in] | type | Integer representation of a prediction type. |
Definition at line 65 of file prediction.c.
References PRED_STRING_CONSTANT, PRED_STRING_NEURAL, PRED_STRING_NLMS_LINEAR, PRED_STRING_NLMS_QUADRATIC, PRED_STRING_RLS_LINEAR, PRED_STRING_RLS_QUADRATIC, PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.
Referenced by pred_json_import(), and pred_param_json_export().