XCSF 1.5.1
XCSF learning classifier system
Loading...
Searching...
No Matches
clset.h File Reference

Functions operating on sets of classifiers. More...

#include "xcsf.h"
Include dependency graph for clset.h:
This graph shows which files directly or indirectly include this file:

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.
 
double clset_mean_pred_size (const struct XCSF *xcsf, const struct Set *set)
 Calculates the mean prediction size of classifiers in the set.
 
double clset_mean_time (const struct Set *set)
 Calculates the mean time stamp of classifiers in the set.
 
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.
 
double clset_total_fit (const struct Set *set)
 Calculates the total fitness of classifiers in the set.
 
size_t clset_pset_load (struct XCSF *xcsf, FILE *fp)
 Reads the population set from a file.
 
size_t clset_pset_save (const struct XCSF *xcsf, FILE *fp)
 Writes the population set to a file.
 
void clset_action (struct XCSF *xcsf, const int action)
 Constructs the action set from the match set.
 
void clset_add (struct Set *set, struct Cl *c)
 Adds a classifier to the set.
 
void clset_free (struct Set *set)
 Frees the set, but not the classifiers.
 
void clset_init (struct Set *set)
 Initialises a new set.
 
void clset_kill (const struct XCSF *xcsf, struct Set *set)
 Frees the set and the classifiers.
 
void clset_match (struct XCSF *xcsf, const double *x, const bool cover)
 Constructs the match set - forward propagates conditions and actions.
 
void clset_pset_enforce_limit (struct XCSF *xcsf)
 Enforces the maximum population size limit.
 
void clset_pset_init (struct XCSF *xcsf)
 Initialises a new population of random classifiers.
 
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.
 
void clset_set_times (const struct XCSF *xcsf, const struct Set *set)
 Sets the time stamps for classifiers in the set.
 
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.
 
void clset_validate (struct Set *set)
 Removes classifiers with 0 numerosity from the set.
 
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.
 
void clset_json_insert_cl (struct XCSF *xcsf, const cJSON *json)
 Creates a classifier from cJSON and inserts in the population set.
 
void clset_json_insert (struct XCSF *xcsf, const char *json_str)
 Creates classifiers from JSON and inserts into the population.
 

Detailed Description

Functions operating on sets of classifiers.

Author
Richard Preen rpree.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om
Date
2015–2023.

Definition in file clset.h.

Function Documentation

◆ clset_action()

void clset_action ( struct XCSF *  xcsf,
const int  action 
)

Constructs the action set from the match set.

Parameters
[in]xcsfThe XCSF data structure.
[in]actionThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_add()

void clset_add ( struct Set *  set,
struct Cl *  c 
)

Adds a classifier to the set.

Parameters
[in]setThe set to add the classifier.
[in]cThe 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().

Here is the caller graph for this function:

◆ clset_free()

void clset_free ( struct Set *  set)

Frees the set, but not the classifiers.

Parameters
[in]setThe 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().

Here is the caller graph for this function:

◆ clset_init()

void clset_init ( struct Set *  set)

Initialises a new set.

Parameters
[in]setThe 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::json_read(), xcs_rl_init_step(), xcs_rl_init_trial(), xcs_supervised_trial(), xcsf_init(), xcsf_load(), and xcsf_retrieve_pset().

Here is the caller graph for this function:

◆ clset_json_export()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to be returned.
[in]return_condWhether to return the condition.
[in]return_actWhether to return the action.
[in]return_predWhether to return the prediction.
Returns
String encoded in json format.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_json_insert()

void clset_json_insert ( struct XCSF *  xcsf,
const char *  json_str 
)

Creates classifiers from JSON and inserts into the population.

Parameters
[in,out]xcsfThe XCSF data structure.
[in]json_strJSON 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_json_insert_cl()

void clset_json_insert_cl ( struct XCSF *  xcsf,
const cJSON *  json 
)

Creates a classifier from cJSON and inserts in the population set.

Parameters
[in,out]xcsfThe XCSF data structure.
[in]jsoncJSON 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::insert_cl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_kill()

void clset_kill ( const struct XCSF *  xcsf,
struct Set *  set 
)

Frees the set and the classifiers.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe 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::json_read(), xcs_rl_end_trial(), xcs_supervised_trial(), xcsf_free(), xcsf_load(), xcsf_retrieve_pset(), and xcsf_store_pset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_match()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]xThe input state.
[in]coverWhether 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_mean_cond_size()

double clset_mean_cond_size ( const struct XCSF *  xcsf,
const struct Set *  set 
)

Calculates the mean condition size of classifiers in the set.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to calculate the mean condition size.
Returns
The mean condition size of classifiers in the set.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_mean_pred_size()

double clset_mean_pred_size ( const struct XCSF *  xcsf,
const struct Set *  set 
)

Calculates the mean prediction size of classifiers in the set.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to calculate the mean prediction size.
Returns
The mean prediction size of classifiers in the set.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_mean_time()

double clset_mean_time ( const struct Set *  set)

Calculates the mean time stamp of classifiers in the set.

Parameters
[in]setThe set to calculate the mean time.
Returns
The mean time of classifiers in the set.

Definition at line 562 of file clset.c.

References clset_total_time(), and Set::num.

Referenced by ea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_mfrac()

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.

Parameters
[in]xcsfThe XCSF data structure.
Returns
The fraction of inputs matched.

Definition at line 713 of file clset.c.

References Clist::cl, cl_mfrac(), Cl::err, Cl::exp, and Clist::next.

Referenced by clset_match().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_print()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to print.
[in]print_condWhether to print the conditions.
[in]print_actWhether to print the actions.
[in]print_predWhether to print the predictions.

Definition at line 515 of file clset.c.

References clset_json_export().

Referenced by xcsf_print_pset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_pset_enforce_limit()

void clset_pset_enforce_limit ( struct XCSF *  xcsf)

Enforces the maximum population size limit.

Parameters
[in]xcsfThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_pset_init()

void clset_pset_init ( struct XCSF *  xcsf)

Initialises a new population of random classifiers.

Parameters
[in]xcsfThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_pset_load()

size_t clset_pset_load ( struct XCSF *  xcsf,
FILE *  fp 
)

Reads the population set from a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]fpPointer to the file to be read.
Returns
The number of elements read.

Definition at line 649 of file clset.c.

References cl_load(), clset_add(), clset_init(), and clset_pset_reverse().

Referenced by xcsf_load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_pset_save()

size_t clset_pset_save ( const struct XCSF *  xcsf,
FILE *  fp 
)

Writes the population set to a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]fpPointer to the file to be written.
Returns
The number of elements written.

Definition at line 610 of file clset.c.

References Clist::cl, cl_save(), and Clist::next.

Referenced by xcsf_save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_set_times()

void clset_set_times ( const struct XCSF *  xcsf,
const struct Set *  set 
)

Sets the time stamps for classifiers in the set.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to update the time stamps.

Definition at line 530 of file clset.c.

References Clist::cl, Set::list, Clist::next, and Cl::time.

Referenced by ea().

Here is the caller graph for this function:

◆ clset_total_fit()

double clset_total_fit ( const struct Set *  set)

Calculates the total fitness of classifiers in the set.

Parameters
[in]setThe set to calculate the total fitness.
Returns
The total fitness of classifiers in the set.

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().

Here is the caller graph for this function:

◆ clset_update()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to provide reinforcement.
[in]xThe input state.
[in]yThe payoff from the environment.
[in]curWhether 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clset_validate()

void clset_validate ( struct Set *  set)

Removes classifiers with 0 numerosity from the set.

Parameters
[in]setThe 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().

Here is the caller graph for this function: