XCSF
1.4.7
XCSF learning classifier system
|
Functions operating on sets of classifiers. More...
#include "xcsf.h"
Go to the source code of this file.
Functions | |
double | clset_mean_cond_size (const struct XCSF *xcsf, const struct Set *set) |
Calculates the mean condition size of classifiers in the set. More... | |
double | clset_mean_pred_size (const struct XCSF *xcsf, const struct Set *set) |
Calculates the mean prediction size of classifiers in the set. More... | |
double | clset_mean_time (const struct Set *set) |
Calculates the mean time stamp of classifiers in the set. More... | |
double | clset_mfrac (const struct XCSF *xcsf) |
Returns the fraction of inputs matched by the most general rule with error below E0. If no rules below E0, the lowest error rule is used. More... | |
double | clset_total_fit (const struct Set *set) |
Calculates the total fitness of classifiers in the set. More... | |
size_t | clset_pset_load (struct XCSF *xcsf, FILE *fp) |
Reads the population set from a file. More... | |
size_t | clset_pset_save (const struct XCSF *xcsf, FILE *fp) |
Writes the population set to a file. More... | |
void | clset_action (struct XCSF *xcsf, const int action) |
Constructs the action set from the match set. More... | |
void | clset_add (struct Set *set, struct Cl *c) |
Adds a classifier to the set. More... | |
void | clset_free (struct Set *set) |
Frees the set, but not the classifiers. More... | |
void | clset_init (struct Set *set) |
Initialises a new set. More... | |
void | clset_kill (const struct XCSF *xcsf, struct Set *set) |
Frees the set and the classifiers. More... | |
void | clset_match (struct XCSF *xcsf, const double *x, const bool cover) |
Constructs the match set - forward propagates conditions and actions. More... | |
void | clset_pset_enforce_limit (struct XCSF *xcsf) |
Enforces the maximum population size limit. More... | |
void | clset_pset_init (struct XCSF *xcsf) |
Initialises a new population of random classifiers. More... | |
void | clset_print (const struct XCSF *xcsf, const struct Set *set, const bool print_cond, const bool print_act, const bool print_pred) |
Prints the classifiers in the set. More... | |
void | clset_set_times (const struct XCSF *xcsf, const struct Set *set) |
Sets the time stamps for classifiers in the set. More... | |
void | clset_update (struct XCSF *xcsf, struct Set *set, const double *x, const double *y, const bool cur) |
Provides reinforcement to the set and performs set subsumption. More... | |
void | clset_validate (struct Set *set) |
Removes classifiers with 0 numerosity from the set. More... | |
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. More... | |
void | clset_json_insert_cl (struct XCSF *xcsf, const cJSON *json) |
Creates a classifier from cJSON and inserts in the population set. More... | |
void | clset_json_insert (struct XCSF *xcsf, const char *json_str) |
Creates classifiers from JSON and inserts into the population. More... | |
Functions operating on sets of classifiers.
Definition in file clset.h.
void clset_action | ( | struct XCSF * | xcsf, |
const int | action | ||
) |
Constructs the action set from the match set.
[in] | xcsf | The XCSF data structure. |
[in] | action | The action used to build the set. |
Definition at line 404 of file clset.c.
References Cl::action, Clist::cl, clset_add(), and Clist::next.
Referenced by xcs_rl_update().
Adds a classifier to the set.
[in] | set | The set to add the classifier. |
[in] | c | The classifier to add. |
Definition at line 423 of file clset.c.
References Clist::cl, Set::list, Clist::next, Cl::num, Set::num, and Set::size.
Referenced by clset_action(), clset_cover(), clset_json_insert_cl(), clset_match(), clset_pset_del(), clset_pset_init(), clset_pset_load(), clset_subsumption(), ea_add(), ea_subsume(), and xcsf_store_pset().
void clset_free | ( | struct Set * | set | ) |
Frees the set, but not the classifiers.
[in] | set | The set to free. |
Definition at line 572 of file clset.c.
References Set::list, Clist::next, Set::num, and Set::size.
Referenced by xcs_rl_end_step(), xcs_rl_end_trial(), and xcs_supervised_trial().
void clset_init | ( | struct Set * | set | ) |
Initialises a new set.
[in] | set | The set to be initialised. |
Definition at line 328 of file clset.c.
References Set::list, Set::num, and Set::size.
Referenced by clset_json_insert_cl(), clset_pset_load(), xcs_rl_init_step(), xcs_rl_init_trial(), xcs_supervised_trial(), xcsf_init(), xcsf_load(), and xcsf_retrieve_pset().
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.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set 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 754 of file clset.c.
References Clist::cl, cl_json_export(), Set::list, and Clist::next.
Referenced by clset_print(), and XCS::json_export().
void clset_json_insert | ( | struct XCSF * | xcsf, |
const char * | json_str | ||
) |
Creates classifiers from JSON and inserts into the population.
[in,out] | xcsf | The XCSF data structure. |
[in] | json_str | JSON formatted string representing classifiers. |
Definition at line 796 of file clset.c.
References clset_json_insert_cl(), and utils_json_parse_check().
Referenced by clset_load_pop_file(), and XCS::json_insert().
void clset_json_insert_cl | ( | struct XCSF * | xcsf, |
const cJSON * | json | ||
) |
Creates a classifier from cJSON and inserts in the population set.
[in,out] | xcsf | The XCSF data structure. |
[in] | json | cJSON representing a classifier. |
Definition at line 780 of file clset.c.
References cl_json_import(), clset_add(), clset_init(), clset_kill(), and clset_pset_enforce_limit().
Referenced by clset_json_insert(), and XCS::json_insert_cl().
Frees the set and the classifiers.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to free. |
Definition at line 590 of file clset.c.
References Clist::cl, cl_free(), Set::list, Clist::next, Set::num, and Set::size.
Referenced by clset_json_insert_cl(), xcs_rl_end_trial(), xcs_supervised_trial(), xcsf_free(), xcsf_load(), xcsf_retrieve_pset(), and xcsf_store_pset().
void clset_match | ( | struct XCSF * | xcsf, |
const double * | x, | ||
const bool | cover | ||
) |
Constructs the match set - forward propagates conditions and actions.
Processes the matching conditions and actions for each classifier in the population. If a classifier matches, it is added to the match set.
[in] | xcsf | The XCSF data structure. |
[in] | x | The input state. |
[in] | cover | Whether to check action set coverage. |
Definition at line 356 of file clset.c.
References Clist::cl, cl_action(), cl_m(), cl_match(), clset_add(), clset_cover(), clset_mfrac(), and Clist::next.
Referenced by xcs_rl_decision(), xcs_rl_fit(), and xcs_supervised_trial().
Calculates the mean condition size of classifiers in the set.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to calculate the mean condition size. |
Definition at line 673 of file clset.c.
References Clist::cl, cl_cond_size(), Set::list, and Clist::next.
Referenced by XCS::get_pset_mean_cond_size().
Calculates the mean prediction size of classifiers in the set.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to calculate the mean prediction size. |
Definition at line 693 of file clset.c.
References Clist::cl, cl_pred_size(), Set::list, and Clist::next.
Referenced by XCS::get_pset_mean_pred_size().
double clset_mean_time | ( | const struct Set * | set | ) |
Calculates the mean time stamp of classifiers in the set.
[in] | set | The set to calculate the mean time. |
Definition at line 562 of file clset.c.
References clset_total_time(), and Set::num.
Referenced by ea().
double clset_mfrac | ( | const struct XCSF * | xcsf | ) |
Returns the fraction of inputs matched by the most general rule with error below E0. If no rules below E0, the lowest error rule is used.
[in] | xcsf | The XCSF data structure. |
Definition at line 713 of file clset.c.
References Clist::cl, cl_mfrac(), Cl::err, Cl::exp, and Clist::next.
Referenced by clset_match().
void clset_print | ( | const struct XCSF * | xcsf, |
const struct Set * | set, | ||
const bool | print_cond, | ||
const bool | print_act, | ||
const bool | print_pred | ||
) |
Prints the classifiers in the set.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to print. |
[in] | print_cond | Whether to print the conditions. |
[in] | print_act | Whether to print the actions. |
[in] | print_pred | Whether to print the predictions. |
Definition at line 515 of file clset.c.
References clset_json_export().
Referenced by xcsf_print_pset().
void clset_pset_enforce_limit | ( | struct XCSF * | xcsf | ) |
Enforces the maximum population size limit.
[in] | xcsf | The XCSF data structure. |
Definition at line 340 of file clset.c.
References clset_pset_del().
Referenced by clset_cover(), clset_json_insert_cl(), and ea().
void clset_pset_init | ( | struct XCSF * | xcsf | ) |
Initialises a new population of random classifiers.
[in] | xcsf | The XCSF data structure. |
Definition at line 308 of file clset.c.
References cl_init(), cl_rand(), clset_add(), and clset_load_pop_file().
Referenced by xcsf_init().
size_t clset_pset_load | ( | struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Reads the population set from a file.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the file to be read. |
Definition at line 649 of file clset.c.
References cl_load(), clset_add(), clset_init(), and clset_pset_reverse().
Referenced by xcsf_load().
size_t clset_pset_save | ( | const struct XCSF * | xcsf, |
FILE * | fp | ||
) |
Writes the population set to a file.
[in] | xcsf | The XCSF data structure. |
[in] | fp | Pointer to the file to be written. |
Definition at line 610 of file clset.c.
References Clist::cl, cl_save(), and Clist::next.
Referenced by xcsf_save().
double clset_total_fit | ( | const struct Set * | set | ) |
Calculates the total fitness of classifiers in the set.
[in] | set | The set to calculate the total fitness. |
Definition at line 545 of file clset.c.
References Clist::cl, Cl::fit, Set::list, and Clist::next.
Referenced by clset_pset_roulette(), and ea_select().
void clset_update | ( | struct XCSF * | xcsf, |
struct Set * | set, | ||
const double * | x, | ||
const double * | y, | ||
const bool | cur | ||
) |
Provides reinforcement to the set and performs set subsumption.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to provide reinforcement. |
[in] | x | The input state. |
[in] | y | The payoff from the environment. |
[in] | cur | Whether the update is for the current or previous state. |
Definition at line 448 of file clset.c.
References Clist::cl, cl_update(), clset_subsumption(), clset_update_fit(), Set::list, Clist::next, Set::num, and Set::size.
Referenced by xcs_rl_update(), and xcs_supervised_trial().
void clset_validate | ( | struct Set * | set | ) |
Removes classifiers with 0 numerosity from the set.
[in] | set | The set to validate. |
Definition at line 480 of file clset.c.
References Clist::cl, Set::list, Clist::next, Cl::num, Set::num, and Set::size.
Referenced by clset_cover(), clset_subsumption(), and xcs_rl_update().