XCSF
1.4.7
XCSF learning classifier system
|
Functions operating on sets of classifiers. More...
Go to the source code of this file.
Macros | |
#define | MAX_COVER (1000000) |
Maximum number of covering attempts. More... | |
Functions | |
static void | clset_pset_never_match (const struct XCSF *xcsf, struct Clist **del, struct Clist **delprev) |
Finds a rule in the population that never matches an input. More... | |
static void | clset_pset_roulette (const struct XCSF *xcsf, struct Clist **del, struct Clist **delprev) |
Selects a classifier from the population for deletion via roulette. More... | |
static void | clset_pset_del (struct XCSF *xcsf) |
Deletes a single classifier from the population set. More... | |
static bool | clset_action_coverage (const struct XCSF *xcsf, bool *act_covered) |
Checks whether each action is covered by the match set. More... | |
static void | clset_cover (struct XCSF *xcsf, const double *x) |
Ensures all possible actions are covered by the match set. More... | |
static void | clset_update_fit (const struct XCSF *xcsf, const struct Set *set) |
Updates the fitness of classifiers in the set. More... | |
static void | clset_subsumption (struct XCSF *xcsf, struct Set *set) |
Performs set subsumption. More... | |
static double | clset_total_time (const struct Set *set) |
Calculates the total time stamps of classifiers in the set. More... | |
static void | clset_load_pop_file (struct XCSF *xcsf) |
void | clset_pset_init (struct XCSF *xcsf) |
Initialises a new population of random classifiers. More... | |
void | clset_init (struct Set *set) |
Initialises a new set. More... | |
void | clset_pset_enforce_limit (struct XCSF *xcsf) |
Enforces the maximum population size limit. 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_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_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... | |
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... | |
double | clset_total_fit (const struct Set *set) |
Calculates the total fitness 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... | |
void | clset_free (struct Set *set) |
Frees the set, but not the classifiers. More... | |
void | clset_kill (const struct XCSF *xcsf, struct Set *set) |
Frees the set and the classifiers. More... | |
size_t | clset_pset_save (const struct XCSF *xcsf, FILE *fp) |
Writes the population set to a file. More... | |
static void | clset_pset_reverse (struct XCSF *xcsf) |
Reverses the order of the population classifier list. More... | |
size_t | clset_pset_load (struct XCSF *xcsf, FILE *fp) |
Reads the population set from a file. More... | |
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_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... | |
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.c.
#define MAX_COVER (1000000) |
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().
|
static |
Checks whether each action is covered by the match set.
[in] | xcsf | The XCSF data structure. |
[out] | act_covered | Vector specifying whether each action is covered. |
Definition at line 137 of file clset.c.
References Cl::action, Clist::cl, and Clist::next.
Referenced by clset_cover().
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().
|
static |
Ensures all possible actions are covered by the match set.
[in] | xcsf | The XCSF data structure. |
[in] | x | The input state. |
Definition at line 159 of file clset.c.
References cl_cover(), cl_init(), clset_action_coverage(), clset_add(), clset_pset_enforce_limit(), clset_validate(), and MAX_COVER.
Referenced by clset_match().
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().
|
static |
Definition at line 281 of file clset.c.
References clset_json_insert().
Referenced by clset_pset_init().
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().
|
static |
Deletes a single classifier from the population set.
[in] | xcsf | The XCSF data structure. |
Definition at line 104 of file clset.c.
References Clist::cl, clset_add(), clset_pset_never_match(), clset_pset_roulette(), Clist::next, and Cl::num.
Referenced by clset_pset_enforce_limit().
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().
|
static |
Finds a rule in the population that never matches an input.
[in] | xcsf | The XCSF data structure. |
[out] | del | A pointer to the classifier to be deleted, if one is found. |
[out] | delprev | A pointer to the rule previous to the one being deleted. |
Definition at line 37 of file clset.c.
References Cl::age, Clist::cl, Cl::mtotal, and Clist::next.
Referenced by clset_pset_del().
|
static |
Reverses the order of the population classifier list.
[in] | xcsf | The XCSF data structure. |
Definition at line 628 of file clset.c.
References Clist::next.
Referenced by clset_pset_load().
|
static |
Selects a classifier from the population for deletion via roulette.
If compaction is enabled and the average system error is below E0, two classifiers are selected using roulette wheel selection with the deletion vote and the rule with the largest condition + prediction size is chosen. For fixed-length representations, the effect is the same as one roulette spin.
[in] | xcsf | The XCSF data structure. |
[out] | del | A pointer to the rule to be deleted. |
[out] | delprev | A pointer to the rule previous to the one being deleted. |
Definition at line 65 of file clset.c.
References Clist::cl, cl_cond_size(), cl_del_vote(), cl_pred_size(), clset_total_fit(), Clist::next, and rand_uniform().
Referenced by clset_pset_del().
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().
Performs set subsumption.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to perform subsumption. |
Definition at line 230 of file clset.c.
References Clist::cl, cl_general(), cl_subsumer(), clset_add(), clset_validate(), Set::list, Clist::next, and Cl::num.
Referenced by clset_update().
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().
|
static |
Calculates the total time stamps of classifiers in the set.
[in] | set | The set to calculate the total time. |
Definition at line 269 of file clset.c.
References Clist::cl, Set::list, Clist::next, Cl::num, and Cl::time.
Referenced by clset_mean_time().
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().
Updates the fitness of classifiers in the set.
[in] | xcsf | The XCSF data structure. |
[in] | set | The set to update. |
Definition at line 205 of file clset.c.
References Clist::cl, cl_acc(), cl_update_fit(), Set::list, Clist::next, Cl::num, and Set::size.
Referenced by clset_update().
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().