XCSF  1.4.7
XCSF learning classifier system
ea.c File Reference

Evolutionary algorithm functions. More...

#include "ea.h"
#include "cl.h"
#include "clset.h"
#include "utils.h"
Include dependency graph for ea.c:

Go to the source code of this file.

Functions

static void ea_init_offspring (const struct XCSF *xcsf, const struct Cl *c1p, const struct Cl *c2p, struct Cl *c1, struct Cl *c2, const bool cmod)
 Initialises offspring error and fitness. More...
 
static void ea_subsume (struct XCSF *xcsf, struct Cl *c, struct Cl *c1p, struct Cl *c2p, const struct Set *set)
 Performs evolutionary algorithm subsumption. More...
 
static void ea_add (struct XCSF *xcsf, const struct Set *set, struct Cl *c1p, struct Cl *c2p, struct Cl *c1, const bool cmod, const bool mmod)
 Adds offspring to the population. More...
 
static struct Clea_select_rw (const struct XCSF *xcsf, const struct Set *set, const double fit_sum)
 Selects a classifier from the set via roulette wheel. More...
 
static struct Clea_select_tournament (const struct XCSF *xcsf, const struct Set *set)
 Selects a classifier from the set via tournament. More...
 
static void ea_select (const struct XCSF *xcsf, const struct Set *set, struct Cl **c1p, struct Cl **c2p)
 Selects two parents. More...
 
void ea (struct XCSF *xcsf, const struct Set *set)
 Executes the evolutionary algorithm (EA). More...
 
void ea_param_defaults (struct XCSF *xcsf)
 Initialises default evolutionary algorithm parameters. More...
 
char * ea_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string representation of the EA parameters. More...
 
void ea_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the EA parameters from a cJSON object. More...
 
size_t ea_param_save (const struct XCSF *xcsf, FILE *fp)
 Saves evolutionary algorithm parameters. More...
 
size_t ea_param_load (struct XCSF *xcsf, FILE *fp)
 Loads evolutionary algorithm parameters. More...
 
const char * ea_type_as_string (const int type)
 Returns a string representation of an EA select type from an integer. More...
 
int ea_type_as_int (const char *type)
 Returns the integer representation of an EA selection type. More...
 
const char * ea_param_set_select_size (struct XCSF *xcsf, const double a)
 
const char * ea_param_set_theta (struct XCSF *xcsf, const double a)
 
const char * ea_param_set_p_crossover (struct XCSF *xcsf, const double a)
 
const char * ea_param_set_lambda (struct XCSF *xcsf, const int a)
 
const char * ea_param_set_err_reduc (struct XCSF *xcsf, const double a)
 
const char * ea_param_set_fit_reduc (struct XCSF *xcsf, const double a)
 
const char * ea_param_set_subsumption (struct XCSF *xcsf, const bool a)
 
const char * ea_param_set_pred_reset (struct XCSF *xcsf, const bool a)
 
int ea_param_set_select_type (struct XCSF *xcsf, const int a)
 
int ea_param_set_type_string (struct XCSF *xcsf, const char *a)
 

Detailed Description

Evolutionary algorithm functions.

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

Definition in file ea.c.

Function Documentation

◆ ea()

void ea ( struct XCSF xcsf,
const struct Set set 
)

Executes the evolutionary algorithm (EA).

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set in which to run the EA.

Definition at line 199 of file ea.c.

References cl_copy(), cl_crossover(), cl_init(), cl_mutate(), clset_mean_time(), clset_pset_enforce_limit(), clset_set_times(), ea_add(), ea_init_offspring(), ea_select(), Cl::size, Set::size, and Cl::time.

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:

◆ ea_add()

static void ea_add ( struct XCSF xcsf,
const struct Set set,
struct Cl c1p,
struct Cl c2p,
struct Cl c1,
const bool  cmod,
const bool  mmod 
)
static

Adds offspring to the population.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set in which the EA is being run.
[in]c1pFirst parent classifier.
[in]c2pSecond parent classifier.
[in]c1The offspring classifier to add.
[in]cmodWhether crossover modified the offspring.
[in]mmodWhether mutation modified the offspring.

Definition at line 113 of file ea.c.

References cl_free(), clset_add(), ea_subsume(), and Cl::num.

Referenced by ea().

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

◆ ea_init_offspring()

static void ea_init_offspring ( const struct XCSF xcsf,
const struct Cl c1p,
const struct Cl c2p,
struct Cl c1,
struct Cl c2,
const bool  cmod 
)
static

Initialises offspring error and fitness.

Parameters
[in]xcsfThe XCSF data structure.
[in]c1pFirst parent classifier.
[in]c2pSecond parent classifier.
[in]c1The first offspring classifier to initialise.
[in]c2The second offspring classifier to initialise.
[in]cmodWhether crossover modified the offspring.

Definition at line 39 of file ea.c.

References Cl::err, Cl::fit, and Cl::num.

Referenced by ea().

Here is the caller graph for this function:

◆ ea_param_defaults()

void ea_param_defaults ( struct XCSF xcsf)

Initialises default evolutionary algorithm parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 237 of file ea.c.

References ea_param_set_err_reduc(), ea_param_set_fit_reduc(), ea_param_set_lambda(), ea_param_set_p_crossover(), ea_param_set_pred_reset(), ea_param_set_select_size(), ea_param_set_select_type(), ea_param_set_subsumption(), ea_param_set_theta(), and EA_SELECT_ROULETTE.

Referenced by param_init().

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

◆ ea_param_json_export()

char* ea_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string representation of the EA parameters.

Parameters
[in]xcsfXCSF data structure.
Returns
String encoded in json format.

Definition at line 256 of file ea.c.

References EA_SELECT_TOURNAMENT, and ea_type_as_string().

Referenced by param_json_export().

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

◆ ea_param_json_import()

void ea_param_json_import ( struct XCSF xcsf,
cJSON *  json 
)

Sets the EA parameters from a cJSON object.

Parameters
[in,out]xcsfThe XCSF data structure.
[in]jsoncJSON object.

Definition at line 282 of file ea.c.

References catch_error(), ea_param_set_err_reduc(), ea_param_set_fit_reduc(), ea_param_set_lambda(), ea_param_set_p_crossover(), ea_param_set_pred_reset(), ea_param_set_select_size(), ea_param_set_subsumption(), ea_param_set_theta(), ea_param_set_type_string(), EA_SELECT_INVALID, and EA_SELECT_OPTIONS.

Referenced by param_json_import().

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

◆ ea_param_load()

size_t ea_param_load ( struct XCSF xcsf,
FILE *  fp 
)

Loads evolutionary algorithm parameters.

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

Definition at line 355 of file ea.c.

Referenced by param_load().

Here is the caller graph for this function:

◆ ea_param_save()

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

Saves evolutionary algorithm parameters.

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

Definition at line 333 of file ea.c.

Referenced by param_save().

Here is the caller graph for this function:

◆ ea_param_set_err_reduc()

const char* ea_param_set_err_reduc ( struct XCSF xcsf,
const double  a 
)

Definition at line 448 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_fit_reduc()

const char* ea_param_set_fit_reduc ( struct XCSF xcsf,
const double  a 
)

Definition at line 458 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_lambda()

const char* ea_param_set_lambda ( struct XCSF xcsf,
const int  a 
)

Definition at line 438 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_p_crossover()

const char* ea_param_set_p_crossover ( struct XCSF xcsf,
const double  a 
)

Definition at line 428 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_pred_reset()

const char* ea_param_set_pred_reset ( struct XCSF xcsf,
const bool  a 
)

Definition at line 475 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_select_size()

const char* ea_param_set_select_size ( struct XCSF xcsf,
const double  a 
)

Definition at line 408 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_select_type()

int ea_param_set_select_type ( struct XCSF xcsf,
const int  a 
)

Definition at line 482 of file ea.c.

References EA_SELECT_INVALID, EA_SELECT_ROULETTE, and EA_SELECT_TOURNAMENT.

Referenced by ea_param_defaults().

Here is the caller graph for this function:

◆ ea_param_set_subsumption()

const char* ea_param_set_subsumption ( struct XCSF xcsf,
const bool  a 
)

Definition at line 468 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_theta()

const char* ea_param_set_theta ( struct XCSF xcsf,
const double  a 
)

Definition at line 418 of file ea.c.

Referenced by ea_param_defaults(), and ea_param_json_import().

Here is the caller graph for this function:

◆ ea_param_set_type_string()

int ea_param_set_type_string ( struct XCSF xcsf,
const char *  a 
)

Definition at line 492 of file ea.c.

References EA_SELECT_INVALID, and ea_type_as_int().

Referenced by ea_param_json_import().

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

◆ ea_select()

static void ea_select ( const struct XCSF xcsf,
const struct Set set,
struct Cl **  c1p,
struct Cl **  c2p 
)
static

Selects two parents.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set in which the EA is being run.
[out]c1pFirst selected parent classifier.
[out]c2pSecond selected parent classifier.

Definition at line 180 of file ea.c.

References clset_total_fit(), EA_SELECT_ROULETTE, ea_select_rw(), and ea_select_tournament().

Referenced by ea().

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

◆ ea_select_rw()

static struct Cl* ea_select_rw ( const struct XCSF xcsf,
const struct Set set,
const double  fit_sum 
)
static

Selects a classifier from the set via roulette wheel.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to select from.
[in]fit_sumThe sum of all the fitnesses in the set.
Returns
A pointer to the selected classifier.

Definition at line 135 of file ea.c.

References Clist::cl, Cl::fit, Set::list, Clist::next, and rand_uniform().

Referenced by ea_select().

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

◆ ea_select_tournament()

static struct Cl* ea_select_tournament ( const struct XCSF xcsf,
const struct Set set 
)
static

Selects a classifier from the set via tournament.

Parameters
[in]xcsfThe XCSF data structure.
[in]setThe set to select from.
Returns
A pointer to the selected classifier.

Definition at line 156 of file ea.c.

References Clist::cl, Cl::fit, Set::list, Clist::next, and rand_uniform().

Referenced by ea_select().

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

◆ ea_subsume()

static void ea_subsume ( struct XCSF xcsf,
struct Cl c,
struct Cl c1p,
struct Cl c2p,
const struct Set set 
)
static

Performs evolutionary algorithm subsumption.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe offspring classifier to attempt to subsume.
[in]c1pFirst parent classifier.
[in]c2pSecond parent classifier.
[in]setThe set in which the EA is being run.

Definition at line 67 of file ea.c.

References Clist::cl, cl_free(), cl_general(), cl_subsumer(), clset_add(), Set::list, Clist::next, Cl::num, rand_uniform_int(), and Set::size.

Referenced by ea_add().

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

◆ ea_type_as_int()

int ea_type_as_int ( const char *  type)

Returns the integer representation of an EA selection type.

Parameters
[in]typeString representation of an EA type.
Returns
Integer representing the EA type.

Definition at line 394 of file ea.c.

References EA_SELECT_INVALID, EA_SELECT_ROULETTE, EA_SELECT_TOURNAMENT, EA_STRING_ROULETTE, and EA_STRING_TOURNAMENT.

Referenced by ea_param_set_type_string().

Here is the caller graph for this function:

◆ ea_type_as_string()

const char* ea_type_as_string ( const int  type)

Returns a string representation of an EA select type from an integer.

Parameters
[in]typeInteger representation of an EA select type.
Returns
String representing the name of the EA select type.

Definition at line 376 of file ea.c.

References EA_SELECT_ROULETTE, EA_SELECT_TOURNAMENT, EA_STRING_ROULETTE, and EA_STRING_TOURNAMENT.

Referenced by ea_param_json_export().

Here is the caller graph for this function: