XCSF
1.4.7
XCSF learning classifier system
|
Functions operating on classifiers. More...
#include "cl.h"
#include "action.h"
#include "condition.h"
#include "ea.h"
#include "loss.h"
#include "prediction.h"
#include "utils.h"
Go to the source code of this file.
Functions | |
void | cl_init (const struct XCSF *xcsf, struct Cl *c, const double size, const int time) |
Initialises a new classifier - but not condition, action, prediction. More... | |
void | cl_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src) |
Copies condition, action, and prediction structures. More... | |
void | cl_init_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src) |
Initialises and creates a copy of one classifier from another. More... | |
void | cl_cover (const struct XCSF *xcsf, struct Cl *c, const double *x, const int action) |
Covers the condition and action for a classifier. More... | |
void | cl_rand (const struct XCSF *xcsf, struct Cl *c) |
Initialises random actions, conditions and predictions. More... | |
double | cl_del_vote (const struct XCSF *xcsf, const struct Cl *c, const double avg_fit) |
Returns the deletion vote of a classifier. More... | |
double | cl_acc (const struct XCSF *xcsf, const struct Cl *c) |
Returns the accuracy of a classifier. More... | |
void | cl_update (const struct XCSF *xcsf, struct Cl *c, const double *x, const double *y, const int set_num, const bool cur) |
Updates a classifier's experience, error, and set size. More... | |
void | cl_update_fit (const struct XCSF *xcsf, struct Cl *c, const double acc_sum, const double acc) |
Updates the fitness of a classifier. More... | |
void | cl_free (const struct XCSF *xcsf, struct Cl *c) |
Frees the memory used by a classifier. More... | |
void | cl_print (const struct XCSF *xcsf, const struct Cl *c, const bool print_cond, const bool print_act, const bool print_pred) |
Prints a classifier. More... | |
bool | cl_match (const struct XCSF *xcsf, struct Cl *c, const double *x) |
Calculates whether a classifier matches an input. More... | |
double | cl_mfrac (const struct XCSF *xcsf, const struct Cl *c) |
Returns the fraction of observed inputs matched by a classifier. More... | |
bool | cl_m (const struct XCSF *xcsf, const struct Cl *c) |
Returns whether a classifier matched the most recent input. More... | |
int | cl_action (const struct XCSF *xcsf, struct Cl *c, const double *x) |
Computes the current classifier action using the input. More... | |
const double * | cl_predict (const struct XCSF *xcsf, const struct Cl *c, const double *x) |
Computes the current classifier prediction using the input. More... | |
bool | cl_subsumer (const struct XCSF *xcsf, const struct Cl *c) |
Returns whether a classifier is a potential subsumer. More... | |
bool | cl_general (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2) |
Returns whether classifier c1 is more general than c2. More... | |
bool | cl_mutate (const struct XCSF *xcsf, const struct Cl *c) |
Performs classifier mutation. More... | |
bool | cl_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2) |
Performs classifier crossover. More... | |
double | cl_cond_size (const struct XCSF *xcsf, const struct Cl *c) |
Returns the size of a classifier's condition. More... | |
double | cl_pred_size (const struct XCSF *xcsf, const struct Cl *c) |
Returns the size of a classifier's prediction. More... | |
size_t | cl_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp) |
Writes a classifier to a file. More... | |
size_t | cl_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp) |
Reads a classifier from a file. More... | |
char * | cl_json_export (const struct XCSF *xcsf, const struct Cl *c, const bool return_cond, const bool return_act, const bool return_pred) |
Returns a json formatted string representation of a classifier. More... | |
static void | cl_json_import_properties (struct Cl *c, const cJSON *json) |
Sets a classifier's properties from a cJSON object. More... | |
static void | cl_json_import_current (const struct XCSF *xcsf, struct Cl *c, const cJSON *json) |
Sets a classifier's current properties from a cJSON object. More... | |
void | cl_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json) |
Creates a classifier from a cJSON object. More... | |
Returns the accuracy of a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier. |
Definition at line 162 of file cl.c.
References Cl::err.
Referenced by cl_json_export(), and clset_update_fit().
Computes the current classifier action using the input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier calculating the action. |
[in] | x | The input state. |
Definition at line 304 of file cl.c.
References act_compute(), and Cl::action.
Referenced by clset_match().
Returns the size of a classifier's condition.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose condition size to return. |
Definition at line 399 of file cl.c.
References cond_size().
Referenced by clset_mean_cond_size(), and clset_pset_roulette().
Copies condition, action, and prediction structures.
[in] | xcsf | The XCSF data structure. |
[in] | dest | The destination classifier. |
[in] | src | The source classifier. |
Definition at line 63 of file cl.c.
References act_copy(), Cl::act_vptr, cond_copy(), Cl::cond_vptr, pred_copy(), pred_init(), and Cl::pred_vptr.
Referenced by ea().
Covers the condition and action for a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier being covered. |
[in] | x | The input state to cover. |
[in] | action | The action to cover. |
Definition at line 113 of file cl.c.
References act_cover(), Cl::action, cl_rand(), cond_cover(), and Cl::m.
Referenced by clset_cover().
Performs classifier crossover.
[in] | xcsf | The XCSF data structure. |
[in] | c1 | The first classifier being crossed. |
[in] | c2 | The second classifier being crossed. |
Definition at line 381 of file cl.c.
References act_crossover(), cond_crossover(), and pred_crossover().
Referenced by ea().
Returns the deletion vote of a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to calculate the deletion vote. |
[in] | avg_fit | The population mean fitness. |
Definition at line 147 of file cl.c.
References Cl::exp, Cl::fit, Cl::num, and Cl::size.
Referenced by clset_pset_roulette().
Frees the memory used by a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to free. |
Definition at line 223 of file cl.c.
References act_free(), cond_free(), pred_free(), and Cl::prediction.
Referenced by clset_kill(), ea_add(), and ea_subsume().
Returns whether classifier c1 is more general than c2.
[in] | xcsf | The XCSF data structure. |
[in] | c1 | The classifier tested to be more general. |
[in] | c2 | The classifier tested to be more specific. |
Definition at line 347 of file cl.c.
References act_general(), and cond_general().
Referenced by clset_subsumption(), and ea_subsume().
Initialises a new classifier - but not condition, action, prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier data structure to initialise. |
[in] | size | The initial set size value. |
[in] | time | The current EA time. |
Definition at line 40 of file cl.c.
References Cl::action, Cl::age, Cl::err, Cl::exp, Cl::fit, Cl::m, Cl::mtotal, Cl::num, Cl::prediction, Cl::size, and Cl::time.
Referenced by cl_json_import(), clset_cover(), clset_pset_init(), and ea().
Initialises and creates a copy of one classifier from another.
[in] | xcsf | The XCSF data structure. |
[in] | dest | The destination classifier. |
[in] | src | The source classifier. |
Definition at line 84 of file cl.c.
References act_copy(), Cl::act_vptr, Cl::action, Cl::age, cond_copy(), Cl::cond_vptr, Cl::err, Cl::exp, Cl::fit, Cl::m, Cl::mtotal, Cl::num, pred_copy(), Cl::pred_vptr, Cl::prediction, Cl::size, and Cl::time.
Referenced by xcsf_store_pset().
char* cl_json_export | ( | const struct XCSF * | xcsf, |
const struct Cl * | c, | ||
const bool | return_cond, | ||
const bool | return_act, | ||
const bool | return_pred | ||
) |
Returns a json formatted string representation of a classifier.
[in] | xcsf | XCSF data structure. |
[in] | c | Classifier to be returned. |
[in] | return_cond | Whether to return the condition. |
[in] | return_act | Whether to return the action. |
[in] | return_pred | Whether to return the prediction. |
Definition at line 486 of file cl.c.
References act_json_export(), Cl::action, Cl::age, cl_acc(), cond_json_export(), Cl::err, Cl::exp, Cl::fit, Cl::m, Cl::mtotal, Cl::num, pred_json_export(), Cl::prediction, Cl::size, and Cl::time.
Referenced by cl_print(), and clset_json_export().
Creates a classifier from a cJSON object.
Creates a random classifier and overrides with imported values.
[in] | xcsf | The XCSF data structure. |
[in,out] | c | The classifier to initialise. |
[in] | json | cJSON object. |
Definition at line 608 of file cl.c.
References act_json_import(), cl_init(), cl_json_import_current(), cl_json_import_properties(), cl_rand(), cond_json_import(), and pred_json_import().
Referenced by clset_json_insert_cl().
|
static |
Sets a classifier's current properties from a cJSON object.
[in] | xcsf | The XCSF data structure. |
[in,out] | c | The classifier to initialise. |
[in] | json | cJSON object. |
Definition at line 577 of file cl.c.
References Cl::action, Cl::m, and Cl::prediction.
Referenced by cl_json_import().
|
static |
Sets a classifier's properties from a cJSON object.
[in,out] | c | The classifier to initialise. |
[in] | json | cJSON object. |
Definition at line 534 of file cl.c.
References Cl::age, Cl::err, Cl::exp, Cl::fit, Cl::mtotal, Cl::num, Cl::size, and Cl::time.
Referenced by cl_json_import().
Reads a classifier from a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to load. |
[in] | fp | Pointer to the file to be read. |
Definition at line 452 of file cl.c.
References act_load(), Cl::action, action_set(), Cl::age, cond_load(), condition_set(), Cl::err, Cl::exp, Cl::fit, Cl::m, Cl::mtotal, Cl::num, pred_load(), Cl::prediction, prediction_set(), Cl::size, and Cl::time.
Referenced by clset_pset_load().
Returns whether a classifier matched the most recent input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to test for matching. |
Definition at line 290 of file cl.c.
References Cl::m.
Referenced by clset_match().
Calculates whether a classifier matches an input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to test for matching. |
[in] | x | The input state to be matched. |
Definition at line 257 of file cl.c.
References Cl::age, cond_match(), Cl::m, and Cl::mtotal.
Referenced by clset_match().
Returns the fraction of observed inputs matched by a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier data structure. |
Definition at line 274 of file cl.c.
References Cl::age, and Cl::mtotal.
Referenced by clset_mfrac().
Performs classifier mutation.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier being mutated. |
Definition at line 362 of file cl.c.
References act_mutate(), cond_mutate(), and pred_mutate().
Referenced by ea().
Returns the size of a classifier's prediction.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier whose prediction size to return. |
Definition at line 411 of file cl.c.
References pred_size().
Referenced by clset_mean_pred_size(), and clset_pset_roulette().
Computes the current classifier prediction using the input.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier making the prediction. |
[in] | x | The input state. |
Definition at line 318 of file cl.c.
References pred_compute(), and Cl::prediction.
Referenced by cl_update(), and pa_build().
void cl_print | ( | const struct XCSF * | xcsf, |
const struct Cl * | c, | ||
const bool | print_cond, | ||
const bool | print_act, | ||
const bool | print_pred | ||
) |
Prints a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to print. |
[in] | print_cond | Whether to print the condition. |
[in] | print_act | Whether to print the action. |
[in] | print_pred | Whether to print the prediction. |
Definition at line 241 of file cl.c.
References cl_json_export().
Initialises random actions, conditions and predictions.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier being randomly initialised. |
Definition at line 129 of file cl.c.
References act_init(), action_set(), cond_init(), condition_set(), pred_init(), and prediction_set().
Referenced by cl_cover(), cl_json_import(), and clset_pset_init().
Writes a classifier to a file.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to save. |
[in] | fp | Pointer to the file to be written. |
Definition at line 424 of file cl.c.
References act_save(), Cl::action, Cl::age, cond_save(), Cl::err, Cl::exp, Cl::fit, Cl::m, Cl::mtotal, Cl::num, pred_save(), Cl::prediction, Cl::size, and Cl::time.
Referenced by clset_pset_save().
Returns whether a classifier is a potential subsumer.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to print. |
Definition at line 331 of file cl.c.
References Cl::err, and Cl::exp.
Referenced by clset_subsumption(), and ea_subsume().
void cl_update | ( | const struct XCSF * | xcsf, |
struct Cl * | c, | ||
const double * | x, | ||
const double * | y, | ||
const int | set_num, | ||
const bool | cur | ||
) |
Updates a classifier's experience, error, and set size.
Condition, action, and prediction are updated depending on the knowledge representation.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to update. |
[in] | x | The input state. |
[in] | y | The true (payoff) value. |
[in] | set_num | The number of micro-classifiers in the set. |
[in] | cur | Whether the payoff is for the current or previous state. |
Definition at line 183 of file cl.c.
References act_update(), cl_predict(), cond_update(), Cl::err, Cl::exp, pred_update(), Cl::prediction, and Cl::size.
Referenced by clset_update().
void cl_update_fit | ( | const struct XCSF * | xcsf, |
struct Cl * | c, | ||
const double | acc_sum, | ||
const double | acc | ||
) |
Updates the fitness of a classifier.
[in] | xcsf | The XCSF data structure. |
[in] | c | The classifier to update. |
[in] | acc_sum | The sum of all accuracies in the set. |
[in] | acc | The accuracy of the classifier being updated. |
Definition at line 211 of file cl.c.
References Cl::fit, and Cl::num.
Referenced by clset_update_fit().