XCSF  1.4.7
XCSF learning classifier system
cl.h File Reference

Functions operating on classifiers. More...

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

Go to the source code of this file.

Functions

bool cl_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs classifier crossover. 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_m (const struct XCSF *xcsf, const struct Cl *c)
 Returns whether a classifier matched the most recent input. More...
 
bool cl_match (const struct XCSF *xcsf, struct Cl *c, const double *x)
 Calculates whether a classifier matches an input. More...
 
bool cl_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Performs classifier mutation. More...
 
bool cl_subsumer (const struct XCSF *xcsf, const struct Cl *c)
 Returns whether a classifier is a potential subsumer. 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...
 
double cl_acc (const struct XCSF *xcsf, const struct Cl *c)
 Returns the accuracy of a classifier. 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_mfrac (const struct XCSF *xcsf, const struct Cl *c)
 Returns the fraction of observed inputs matched by a classifier. More...
 
int cl_action (const struct XCSF *xcsf, struct Cl *c, const double *x)
 Computes the current classifier action using the input. 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_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a classifier from a file. More...
 
size_t cl_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a classifier to a file. More...
 
void cl_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies condition, action, and prediction structures. 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_free (const struct XCSF *xcsf, struct Cl *c)
 Frees the memory used by a classifier. More...
 
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_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_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...
 
void cl_rand (const struct XCSF *xcsf, struct Cl *c)
 Initialises random actions, conditions and predictions. 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...
 
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...
 
void cl_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a classifier from a cJSON object. More...
 

Detailed Description

Functions operating on classifiers.

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

Definition in file cl.h.

Function Documentation

◆ cl_acc()

double cl_acc ( const struct XCSF xcsf,
const struct Cl c 
)

Returns the accuracy of a classifier.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier.
Returns
The classifier's accuracy.

Definition at line 162 of file cl.c.

References Cl::err.

Referenced by cl_json_export(), and clset_update_fit().

Here is the caller graph for this function:

◆ cl_action()

int cl_action ( const struct XCSF xcsf,
struct Cl c,
const double *  x 
)

Computes the current classifier action using the input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier calculating the action.
[in]xThe input state.
Returns
The classifier's action.

Definition at line 304 of file cl.c.

References act_compute(), and Cl::action.

Referenced by clset_match().

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

◆ cl_cond_size()

double cl_cond_size ( const struct XCSF xcsf,
const struct Cl c 
)

Returns the size of a classifier's condition.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition size to return.
Returns
The size of the condition.

Definition at line 399 of file cl.c.

References cond_size().

Referenced by clset_mean_cond_size(), and clset_pset_roulette().

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

◆ cl_copy()

void cl_copy ( const struct XCSF xcsf,
struct Cl dest,
const struct Cl src 
)

Copies condition, action, and prediction structures.

Parameters
[in]xcsfThe XCSF data structure.
[in]destThe destination classifier.
[in]srcThe 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().

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

◆ cl_cover()

void cl_cover ( const struct XCSF xcsf,
struct Cl c,
const double *  x,
const int  action 
)

Covers the condition and action for a classifier.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier being covered.
[in]xThe input state to cover.
[in]actionThe 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().

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

◆ cl_crossover()

bool cl_crossover ( const struct XCSF xcsf,
const struct Cl c1,
const struct Cl c2 
)

Performs classifier crossover.

Parameters
[in]xcsfThe XCSF data structure.
[in]c1The first classifier being crossed.
[in]c2The second classifier being crossed.
Returns
Whether any alterations were made.

Definition at line 381 of file cl.c.

References act_crossover(), cond_crossover(), and pred_crossover().

Referenced by ea().

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

◆ cl_del_vote()

double cl_del_vote ( const struct XCSF xcsf,
const struct Cl c,
const double  avg_fit 
)

Returns the deletion vote of a classifier.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to calculate the deletion vote.
[in]avg_fitThe population mean fitness.
Returns
The classifier's deletion vote.

Definition at line 147 of file cl.c.

References Cl::exp, Cl::fit, Cl::num, and Cl::size.

Referenced by clset_pset_roulette().

Here is the caller graph for this function:

◆ cl_free()

void cl_free ( const struct XCSF xcsf,
struct Cl c 
)

Frees the memory used by a classifier.

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

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

◆ cl_general()

bool cl_general ( const struct XCSF xcsf,
const struct Cl c1,
const struct Cl c2 
)

Returns whether classifier c1 is more general than c2.

Parameters
[in]xcsfThe XCSF data structure.
[in]c1The classifier tested to be more general.
[in]c2The classifier tested to be more specific.
Returns
Whether classifier c1 is more general than c2.

Definition at line 347 of file cl.c.

References act_general(), and cond_general().

Referenced by clset_subsumption(), and ea_subsume().

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

◆ cl_init()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier data structure to initialise.
[in]sizeThe initial set size value.
[in]timeThe 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().

Here is the caller graph for this function:

◆ cl_init_copy()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]destThe destination classifier.
[in]srcThe 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().

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

◆ cl_json_export()

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.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier 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 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().

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

◆ cl_json_import()

void cl_json_import ( const struct XCSF xcsf,
struct Cl c,
const cJSON *  json 
)

Creates a classifier from a cJSON object.

Creates a random classifier and overrides with imported values.

Parameters
[in]xcsfThe XCSF data structure.
[in,out]cThe classifier to initialise.
[in]jsoncJSON 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().

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

◆ cl_load()

size_t cl_load ( const struct XCSF xcsf,
struct Cl c,
FILE *  fp 
)

Reads a classifier from a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to load.
[in]fpPointer to the file to be read.
Returns
The number of elements 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().

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

◆ cl_m()

bool cl_m ( const struct XCSF xcsf,
const struct Cl c 
)

Returns whether a classifier matched the most recent input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to test for matching.
Returns
Whether the classifier matched the most recent input.

Definition at line 290 of file cl.c.

References Cl::m.

Referenced by clset_match().

Here is the caller graph for this function:

◆ cl_match()

bool cl_match ( const struct XCSF xcsf,
struct Cl c,
const double *  x 
)

Calculates whether a classifier matches an input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to test for matching.
[in]xThe input state to be matched.
Returns
Whether the classifier matches the input.

Definition at line 257 of file cl.c.

References Cl::age, cond_match(), Cl::m, and Cl::mtotal.

Referenced by clset_match().

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

◆ cl_mfrac()

double cl_mfrac ( const struct XCSF xcsf,
const struct Cl c 
)

Returns the fraction of observed inputs matched by a classifier.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier data structure.
Returns
The fraction of matching inputs.

Definition at line 274 of file cl.c.

References Cl::age, and Cl::mtotal.

Referenced by clset_mfrac().

Here is the caller graph for this function:

◆ cl_mutate()

bool cl_mutate ( const struct XCSF xcsf,
const struct Cl c 
)

Performs classifier mutation.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier being mutated.
Returns
Whether any alterations were made.

Definition at line 362 of file cl.c.

References act_mutate(), cond_mutate(), and pred_mutate().

Referenced by ea().

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

◆ cl_pred_size()

double cl_pred_size ( const struct XCSF xcsf,
const struct Cl c 
)

Returns the size of a classifier's prediction.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose prediction size to return.
Returns
The size of the prediction.

Definition at line 411 of file cl.c.

References pred_size().

Referenced by clset_mean_pred_size(), and clset_pset_roulette().

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

◆ cl_predict()

const double* cl_predict ( const struct XCSF xcsf,
const struct Cl c,
const double *  x 
)

Computes the current classifier prediction using the input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier making the prediction.
[in]xThe input state.
Returns
The classifier's (payoff) predictions.

Definition at line 318 of file cl.c.

References pred_compute(), and Cl::prediction.

Referenced by cl_update(), and pa_build().

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

◆ cl_print()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to print.
[in]print_condWhether to print the condition.
[in]print_actWhether to print the action.
[in]print_predWhether to print the prediction.

Definition at line 241 of file cl.c.

References cl_json_export().

Here is the call graph for this function:

◆ cl_rand()

void cl_rand ( const struct XCSF xcsf,
struct Cl c 
)

Initialises random actions, conditions and predictions.

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

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

◆ cl_save()

size_t cl_save ( const struct XCSF xcsf,
const struct Cl c,
FILE *  fp 
)

Writes a classifier to a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to save.
[in]fpPointer to the file to be written.
Returns
The number of elements 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().

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

◆ cl_subsumer()

bool cl_subsumer ( const struct XCSF xcsf,
const struct Cl c 
)

Returns whether a classifier is a potential subsumer.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to print.
Returns
Whether the classifier is an eligible subsumer.

Definition at line 331 of file cl.c.

References Cl::err, and Cl::exp.

Referenced by clset_subsumption(), and ea_subsume().

Here is the caller graph for this function:

◆ cl_update()

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.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to update.
[in]xThe input state.
[in]yThe true (payoff) value.
[in]set_numThe number of micro-classifiers in the set.
[in]curWhether 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().

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

◆ cl_update_fit()

void cl_update_fit ( const struct XCSF xcsf,
struct Cl c,
const double  acc_sum,
const double  acc 
)

Updates the fitness of a classifier.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to update.
[in]acc_sumThe sum of all accuracies in the set.
[in]accThe 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().

Here is the caller graph for this function: