XCSF
1.4.7
XCSF learning classifier system
|
Interface for classifier conditions. More...
#include "xcsf.h"
Go to the source code of this file.
Data Structures | |
struct | ArgsCond |
Parameters for initialising and operating conditions. More... | |
struct | CondVtbl |
Condition interface data structure. More... | |
Macros | |
#define | COND_TYPE_INVALID (-1) |
Error code for invalid condition. More... | |
#define | COND_TYPE_DUMMY (0) |
Condition type dummy. More... | |
#define | COND_TYPE_HYPERRECTANGLE_CSR (1) |
Condition type CSR hyperrectangle. More... | |
#define | COND_TYPE_HYPERRECTANGLE_UBR (2) |
Condition type UBR hyperrectangle. More... | |
#define | COND_TYPE_HYPERELLIPSOID (3) |
Condition type hyperellipsoid. More... | |
#define | COND_TYPE_NEURAL (4) |
Condition type neural network. More... | |
#define | COND_TYPE_GP (5) |
Condition type tree GP. More... | |
#define | COND_TYPE_DGP (6) |
Condition type DGP. More... | |
#define | COND_TYPE_TERNARY (7) |
Condition type ternary. More... | |
#define | RULE_TYPE_DGP (11) |
Condition type and action type DGP. More... | |
#define | RULE_TYPE_NEURAL (12) |
Condition type and action type neural. More... | |
#define | RULE_TYPE_NETWORK (13) |
Condition type and prediction type neural. More... | |
#define | COND_STRING_DUMMY ("dummy\0") |
Dummy. More... | |
#define | COND_STRING_HYPERRECTANGLE_CSR ("hyperrectangle_csr\0") |
CSR. More... | |
#define | COND_STRING_HYPERRECTANGLE_UBR ("hyperrectangle_ubr\0") |
UBR. More... | |
#define | COND_STRING_HYPERELLIPSOID ("hyperellipsoid\0") |
Hyperellipsoid. More... | |
#define | COND_STRING_NEURAL ("neural\0") |
Neural. More... | |
#define | COND_STRING_GP ("tree_gp\0") |
Tree GP. More... | |
#define | COND_STRING_DGP ("dgp\0") |
DGP. More... | |
#define | COND_STRING_TERNARY ("ternary\0") |
Ternary. More... | |
#define | COND_STRING_RULE_DGP ("rule_dgp\0") |
Rule DGP. More... | |
#define | COND_STRING_RULE_NEURAL ("rule_neural\0") |
Rule neural. More... | |
#define | COND_STRING_RULE_NETWORK ("rule_network\0") |
Rule network. More... | |
#define | COND_TYPE_OPTIONS |
Functions | |
void | condition_set (const struct XCSF *xcsf, struct Cl *c) |
Sets a classifier's condition functions to the implementations. More... | |
const char * | condition_type_as_string (const int type) |
Returns a string representation of a condition type from an integer. More... | |
int | condition_type_as_int (const char *type) |
Returns the integer representation of a condition type given a name. More... | |
void | cond_param_defaults (struct XCSF *xcsf) |
Initialises default condition parameters. More... | |
void | cond_param_free (struct XCSF *xcsf) |
Frees condition parameters. More... | |
char * | cond_param_json_import (struct XCSF *xcsf, cJSON *json) |
Sets the condition parameters from a cJSON object. More... | |
char * | cond_param_json_export (const struct XCSF *xcsf) |
Returns a json formatted string of the condition parameters. More... | |
size_t | cond_param_save (const struct XCSF *xcsf, FILE *fp) |
Saves condition parameters. More... | |
size_t | cond_param_load (struct XCSF *xcsf, FILE *fp) |
Loads condition parameters. More... | |
static size_t | cond_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp) |
Writes the condition to a file. More... | |
static size_t | cond_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp) |
Reads the condition from a file. More... | |
static double | cond_size (const struct XCSF *xcsf, const struct Cl *c) |
Returns the size of the classifier condition. More... | |
static void | cond_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y) |
Updates the classifier's condition. More... | |
static bool | cond_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2) |
Performs classifier condition crossover. More... | |
static bool | cond_general (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2) |
Returns whether classifier c1 has a condition more general than c2. More... | |
static bool | cond_match (const struct XCSF *xcsf, const struct Cl *c, const double *x) |
Calculates whether the condition matches the input. More... | |
static bool | cond_mutate (const struct XCSF *xcsf, const struct Cl *c) |
Performs classifier condition mutation. More... | |
static void | cond_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src) |
Copies the condition from one classifier to another. More... | |
static void | cond_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x) |
Generates a condition that matches the current input. More... | |
static void | cond_free (const struct XCSF *xcsf, const struct Cl *c) |
Frees the memory used by the classifier condition. More... | |
static void | cond_init (const struct XCSF *xcsf, struct Cl *c) |
Initialises a classifier's condition. More... | |
static void | cond_print (const struct XCSF *xcsf, const struct Cl *c) |
Prints the classifier condition. More... | |
static char * | cond_json_export (const struct XCSF *xcsf, const struct Cl *c) |
Returns a json formatted string representation of a condition. More... | |
static void | cond_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json) |
Creates a condition from a cJSON object. More... | |
void | cond_param_set_eta (struct XCSF *xcsf, const double a) |
void | cond_param_set_min (struct XCSF *xcsf, const double a) |
void | cond_param_set_max (struct XCSF *xcsf, const double a) |
void | cond_param_set_p_dontcare (struct XCSF *xcsf, const double a) |
void | cond_param_set_spread_min (struct XCSF *xcsf, const double a) |
void | cond_param_set_bits (struct XCSF *xcsf, const int a) |
int | cond_param_set_type_string (struct XCSF *xcsf, const char *a) |
void | cond_param_set_type (struct XCSF *xcsf, const int a) |
Interface for classifier conditions.
Definition in file condition.h.
#define COND_STRING_DGP ("dgp\0") |
DGP.
Definition at line 47 of file condition.h.
#define COND_STRING_DUMMY ("dummy\0") |
Dummy.
Definition at line 41 of file condition.h.
#define COND_STRING_GP ("tree_gp\0") |
Tree GP.
Definition at line 46 of file condition.h.
#define COND_STRING_HYPERELLIPSOID ("hyperellipsoid\0") |
Hyperellipsoid.
Definition at line 44 of file condition.h.
#define COND_STRING_HYPERRECTANGLE_CSR ("hyperrectangle_csr\0") |
CSR.
Definition at line 42 of file condition.h.
#define COND_STRING_HYPERRECTANGLE_UBR ("hyperrectangle_ubr\0") |
UBR.
Definition at line 43 of file condition.h.
#define COND_STRING_NEURAL ("neural\0") |
Neural.
Definition at line 45 of file condition.h.
#define COND_STRING_RULE_DGP ("rule_dgp\0") |
Rule DGP.
Definition at line 49 of file condition.h.
#define COND_STRING_RULE_NETWORK ("rule_network\0") |
Rule network.
Definition at line 51 of file condition.h.
#define COND_STRING_RULE_NEURAL ("rule_neural\0") |
Rule neural.
Definition at line 50 of file condition.h.
#define COND_STRING_TERNARY ("ternary\0") |
Ternary.
Definition at line 48 of file condition.h.
#define COND_TYPE_DGP (6) |
Condition type DGP.
Definition at line 35 of file condition.h.
#define COND_TYPE_DUMMY (0) |
Condition type dummy.
Definition at line 29 of file condition.h.
#define COND_TYPE_GP (5) |
Condition type tree GP.
Definition at line 34 of file condition.h.
#define COND_TYPE_HYPERELLIPSOID (3) |
Condition type hyperellipsoid.
Definition at line 32 of file condition.h.
#define COND_TYPE_HYPERRECTANGLE_CSR (1) |
Condition type CSR hyperrectangle.
Definition at line 30 of file condition.h.
#define COND_TYPE_HYPERRECTANGLE_UBR (2) |
Condition type UBR hyperrectangle.
Definition at line 31 of file condition.h.
#define COND_TYPE_INVALID (-1) |
Error code for invalid condition.
Definition at line 28 of file condition.h.
#define COND_TYPE_NEURAL (4) |
Condition type neural network.
Definition at line 33 of file condition.h.
#define COND_TYPE_OPTIONS |
Definition at line 53 of file condition.h.
#define COND_TYPE_TERNARY (7) |
Condition type ternary.
Definition at line 36 of file condition.h.
#define RULE_TYPE_DGP (11) |
Condition type and action type DGP.
Definition at line 37 of file condition.h.
#define RULE_TYPE_NETWORK (13) |
Condition type and prediction type neural.
Definition at line 39 of file condition.h.
#define RULE_TYPE_NEURAL (12) |
Condition type and action type neural.
Definition at line 38 of file condition.h.
Copies the condition from one classifier to another.
[in] | xcsf | The XCSF data structure. |
[in] | dest | The destination classifier. |
[in] | src | The source classifier. |
Definition at line 241 of file condition.h.
References CondVtbl::cond_impl_copy, and Cl::cond_vptr.
Referenced by cl_copy(), and cl_init_copy().
Generates a condition that matches the current input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is being covered. |
[in] | x | The input state to cover. |
Definition at line 253 of file condition.h.
References CondVtbl::cond_impl_cover, and Cl::cond_vptr.
Referenced by cl_cover().
|
static |
Performs classifier condition crossover.
[in] | xcsf | The XCSF data structure. |
[in] | c1 | The first classifier whose condition is being crossed. |
[in] | c2 | The second classifier whose condition is being crossed. |
Definition at line 190 of file condition.h.
References CondVtbl::cond_impl_crossover, and Cl::cond_vptr.
Referenced by cl_crossover().
Frees the memory used by the classifier condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is to be freed. |
Definition at line 264 of file condition.h.
References CondVtbl::cond_impl_free, and Cl::cond_vptr.
Referenced by cl_free().
|
static |
Returns whether classifier c1 has a condition more general than c2.
[in] | xcsf | The XCSF data structure. |
[in] | c1 | The classifier whose condition is tested to be more general. |
[in] | c2 | The classifier whose condition is tested to be more specific. |
Definition at line 204 of file condition.h.
References CondVtbl::cond_impl_general, and Cl::cond_vptr.
Referenced by cl_general().
Initialises a classifier's condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is to be initialised. |
Definition at line 275 of file condition.h.
References CondVtbl::cond_impl_init, and Cl::cond_vptr.
Referenced by cl_rand().
Returns a json formatted string representation of a condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | Classifier whose condition is to be returned. |
Definition at line 298 of file condition.h.
References CondVtbl::cond_impl_json_export, and Cl::cond_vptr.
Referenced by cl_json_export().
Creates a condition from a cJSON object.
[in] | xcsf | The XCSF data structure. |
[in,out] | c | The classifier whose condition is to be initialised. |
[in] | json | cJSON object. |
Definition at line 310 of file condition.h.
References CondVtbl::cond_impl_json_import, Cl::cond_vptr, condition_type_as_int(), and condition_type_as_string().
Referenced by cl_json_import().
Reads the condition from a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is to be read. |
[in] | fp | Pointer to the file to be read. |
Definition at line 151 of file condition.h.
References CondVtbl::cond_impl_load, and Cl::cond_vptr.
Referenced by cl_load().
Calculates whether the condition matches the input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition to match. |
[in] | x | The input state. |
Definition at line 217 of file condition.h.
References CondVtbl::cond_impl_match, and Cl::cond_vptr.
Referenced by cl_match().
Performs classifier condition mutation.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is being mutated. |
Definition at line 229 of file condition.h.
References CondVtbl::cond_impl_mutate, and Cl::cond_vptr.
Referenced by cl_mutate().
void cond_param_defaults | ( | struct XCSF * | xcsf | ) |
Initialises default condition parameters.
[in] | xcsf | The XCSF data structure. |
Definition at line 166 of file condition.c.
References cond_dgp_param_defaults(), cond_gp_param_defaults(), cond_neural_param_defaults(), cond_param_set_eta(), cond_param_set_max(), cond_param_set_min(), cond_param_set_spread_min(), cond_param_set_type(), cond_ternary_param_defaults(), and COND_TYPE_HYPERRECTANGLE_CSR.
Referenced by param_init().
void cond_param_free | ( | struct XCSF * | xcsf | ) |
Frees condition parameters.
[in] | xcsf | The XCSF data structure. |
Definition at line 365 of file condition.c.
References layer_args_free(), and tree_args_free().
Referenced by param_free().
char* cond_param_json_export | ( | const struct XCSF * | xcsf | ) |
Returns a json formatted string of the condition parameters.
[in] | xcsf | XCSF data structure. |
Definition at line 232 of file condition.c.
References cond_dgp_param_json_export(), cond_gp_param_json_export(), cond_param_json_export_csr(), cond_ternary_param_json_export(), COND_TYPE_DGP, COND_TYPE_GP, COND_TYPE_HYPERELLIPSOID, COND_TYPE_HYPERRECTANGLE_CSR, COND_TYPE_HYPERRECTANGLE_UBR, COND_TYPE_NEURAL, COND_TYPE_TERNARY, condition_type_as_string(), layer_args_json_export(), RULE_TYPE_DGP, RULE_TYPE_NETWORK, RULE_TYPE_NEURAL, and ArgsCond::type.
Referenced by param_json_export().
char* cond_param_json_import | ( | struct XCSF * | xcsf, |
cJSON * | json | ||
) |
Sets the condition parameters from a cJSON object.
[in,out] | xcsf | The XCSF data structure. |
[in] | json | cJSON object. |
Definition at line 281 of file condition.c.
References cond_dgp_param_json_import(), cond_gp_param_json_import(), cond_neural_param_json_import(), cond_param_json_import_csr(), cond_ternary_param_json_import(), COND_TYPE_DGP, COND_TYPE_GP, COND_TYPE_HYPERELLIPSOID, COND_TYPE_HYPERRECTANGLE_CSR, COND_TYPE_HYPERRECTANGLE_UBR, COND_TYPE_NEURAL, COND_TYPE_TERNARY, RULE_TYPE_DGP, RULE_TYPE_NETWORK, and RULE_TYPE_NEURAL.
Referenced by param_json_import_condition().
size_t cond_param_load | ( | struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Loads condition parameters.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the output file. |
Definition at line 343 of file condition.c.
References ArgsCond::bits, ArgsCond::dargs, ArgsCond::eta, graph_args_load(), ArgsCond::largs, layer_args_load(), ArgsCond::max, ArgsCond::min, ArgsCond::p_dontcare, ArgsCond::spread_min, ArgsCond::targs, tree_args_load(), and ArgsCond::type.
Referenced by param_load().
size_t cond_param_save | ( | const struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Saves condition parameters.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the output file. |
Definition at line 319 of file condition.c.
References ArgsCond::bits, ArgsCond::dargs, ArgsCond::eta, graph_args_save(), ArgsCond::largs, layer_args_save(), ArgsCond::max, ArgsCond::min, ArgsCond::p_dontcare, ArgsCond::spread_min, ArgsCond::targs, tree_args_save(), and ArgsCond::type.
Referenced by param_save().
void cond_param_set_bits | ( | struct XCSF * | xcsf, |
const int | a | ||
) |
Definition at line 429 of file condition.c.
Referenced by cond_ternary_param_defaults(), and cond_ternary_param_json_import().
void cond_param_set_eta | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 378 of file condition.c.
Referenced by cond_param_defaults(), and cond_param_json_import_csr().
void cond_param_set_max | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 398 of file condition.c.
Referenced by cond_param_defaults(), and cond_param_json_import_csr().
void cond_param_set_min | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 392 of file condition.c.
Referenced by cond_param_defaults(), and cond_param_json_import_csr().
void cond_param_set_p_dontcare | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 404 of file condition.c.
Referenced by cond_ternary_param_defaults(), and cond_ternary_param_json_import().
void cond_param_set_spread_min | ( | struct XCSF * | xcsf, |
const double | a | ||
) |
Definition at line 418 of file condition.c.
Referenced by cond_param_defaults(), and cond_param_json_import_csr().
void cond_param_set_type | ( | struct XCSF * | xcsf, |
const int | a | ||
) |
Definition at line 450 of file condition.c.
Referenced by cond_param_defaults().
int cond_param_set_type_string | ( | struct XCSF * | xcsf, |
const char * | a | ||
) |
Definition at line 440 of file condition.c.
References COND_TYPE_INVALID, condition_type_as_int(), and ArgsCond::type.
Referenced by param_json_import_condition().
Prints the classifier condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is to be printed. |
Definition at line 286 of file condition.h.
References CondVtbl::cond_impl_print, and Cl::cond_vptr.
Writes the condition to a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition is to be written. |
[in] | fp | Pointer to the file to be written. |
Definition at line 138 of file condition.h.
References CondVtbl::cond_impl_save, and Cl::cond_vptr.
Referenced by cl_save().
Returns the size of the classifier condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition size to return. |
Definition at line 163 of file condition.h.
References CondVtbl::cond_impl_size, and Cl::cond_vptr.
Referenced by cl_cond_size().
|
static |
Updates the classifier's condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | Classifier whose condition is to be updated. |
[in] | x | Input state. |
[in] | y | Truth/payoff value. |
Definition at line 176 of file condition.h.
References CondVtbl::cond_impl_update, and Cl::cond_vptr.
Referenced by cl_update().
Sets a classifier's condition functions to the implementations.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to set. |
Definition at line 41 of file condition.c.
References Cl::act_vptr, cond_dgp_vtbl, cond_dummy_vtbl, cond_ellipsoid_vtbl, cond_gp_vtbl, cond_neural_vtbl, cond_rectangle_vtbl, cond_ternary_vtbl, COND_TYPE_DGP, COND_TYPE_DUMMY, COND_TYPE_GP, COND_TYPE_HYPERELLIPSOID, COND_TYPE_HYPERRECTANGLE_CSR, COND_TYPE_HYPERRECTANGLE_UBR, COND_TYPE_NEURAL, COND_TYPE_TERNARY, Cl::cond_vptr, rule_dgp_act_vtbl, rule_dgp_cond_vtbl, rule_neural_act_vtbl, rule_neural_cond_vtbl, RULE_TYPE_DGP, and RULE_TYPE_NEURAL.
Referenced by cl_load(), and cl_rand().
int condition_type_as_int | ( | const char * | type | ) |
Returns the integer representation of a condition type given a name.
[in] | type | String representation of a condition type. |
Definition at line 123 of file condition.c.
References COND_STRING_DGP, COND_STRING_DUMMY, COND_STRING_GP, COND_STRING_HYPERELLIPSOID, COND_STRING_HYPERRECTANGLE_CSR, COND_STRING_HYPERRECTANGLE_UBR, COND_STRING_NEURAL, COND_STRING_RULE_DGP, COND_STRING_RULE_NETWORK, COND_STRING_RULE_NEURAL, COND_STRING_TERNARY, COND_TYPE_DGP, COND_TYPE_DUMMY, COND_TYPE_GP, COND_TYPE_HYPERELLIPSOID, COND_TYPE_HYPERRECTANGLE_CSR, COND_TYPE_HYPERRECTANGLE_UBR, COND_TYPE_INVALID, COND_TYPE_NEURAL, COND_TYPE_TERNARY, RULE_TYPE_DGP, RULE_TYPE_NETWORK, and RULE_TYPE_NEURAL.
Referenced by cond_json_import(), and cond_param_set_type_string().
const char* condition_type_as_string | ( | const int | type | ) |
Returns a string representation of a condition type from an integer.
[in] | type | Integer representation of a condition type. |
Definition at line 86 of file condition.c.
References COND_STRING_DGP, COND_STRING_DUMMY, COND_STRING_GP, COND_STRING_HYPERELLIPSOID, COND_STRING_HYPERRECTANGLE_CSR, COND_STRING_HYPERRECTANGLE_UBR, COND_STRING_NEURAL, COND_STRING_RULE_DGP, COND_STRING_RULE_NETWORK, COND_STRING_RULE_NEURAL, COND_STRING_TERNARY, COND_TYPE_DGP, COND_TYPE_DUMMY, COND_TYPE_GP, COND_TYPE_HYPERELLIPSOID, COND_TYPE_HYPERRECTANGLE_CSR, COND_TYPE_HYPERRECTANGLE_UBR, COND_TYPE_NEURAL, COND_TYPE_TERNARY, RULE_TYPE_DGP, RULE_TYPE_NETWORK, and RULE_TYPE_NEURAL.
Referenced by cond_json_import(), and cond_param_json_export().