XCSF
1.4.7
XCSF learning classifier system
|
An implementation of GP trees based upon TinyGP. More...
#include "xcsf.h"
Go to the source code of this file.
Data Structures | |
struct | ArgsGPTree |
Parameters for initialising GP trees. More... | |
struct | GPTree |
GP tree data structure. More... | |
Functions | |
void | tree_free (const struct GPTree *gp) |
Frees a GP tree. More... | |
void | tree_rand (struct GPTree *gp, const struct ArgsGPTree *args) |
Creates a random GP tree. More... | |
void | tree_copy (struct GPTree *dest, const struct GPTree *src) |
Copies a GP tree. More... | |
void | tree_print (const struct GPTree *gp, const struct ArgsGPTree *args) |
Prints a GP tree. More... | |
char * | tree_json_export (const struct GPTree *gp, const struct ArgsGPTree *args) |
Returns a json formatted string representation of a GP tree. More... | |
void | tree_json_import (struct GPTree *gp, const struct ArgsGPTree *args, const cJSON *json) |
Creates a GP tree from a cJSON object. More... | |
double | tree_eval (struct GPTree *gp, const struct ArgsGPTree *args, const double *x) |
Evaluates a GP tree. More... | |
void | tree_crossover (struct GPTree *p1, struct GPTree *p2) |
Performs sub-tree crossover. More... | |
bool | tree_mutate (struct GPTree *gp, const struct ArgsGPTree *args) |
Performs point mutation on a GP tree. More... | |
size_t | tree_save (const struct GPTree *gp, FILE *fp) |
Writes the GP tree to a file. More... | |
size_t | tree_load (struct GPTree *gp, FILE *fp) |
Reads a GP tree from a file. More... | |
void | tree_args_init (struct ArgsGPTree *args) |
Sets tree GP parameters to default values. More... | |
void | tree_args_free (struct ArgsGPTree *args) |
Frees memory used by GP tree parameters. More... | |
char * | tree_args_json_import (struct ArgsGPTree *args, cJSON *json) |
Sets the GP tree parameters from a cJSON object. More... | |
char * | tree_args_json_export (const struct ArgsGPTree *args) |
Returns a json formatted string of the GP tree parameters. More... | |
size_t | tree_args_save (const struct ArgsGPTree *args, FILE *fp) |
Saves Tree GP parameters. More... | |
size_t | tree_args_load (struct ArgsGPTree *args, FILE *fp) |
Loads Tree GP parameters. More... | |
void | tree_args_init_constants (struct ArgsGPTree *args) |
Builds global constants used by GP trees. More... | |
void | tree_param_set_max (struct ArgsGPTree *args, const double a) |
void | tree_param_set_min (struct ArgsGPTree *args, const double a) |
void | tree_param_set_n_inputs (struct ArgsGPTree *args, const int a) |
void | tree_param_set_n_constants (struct ArgsGPTree *args, const int a) |
void | tree_param_set_init_depth (struct ArgsGPTree *args, const int a) |
void | tree_param_set_max_len (struct ArgsGPTree *args, const int a) |
An implementation of GP trees based upon TinyGP.
Definition in file gp.h.
void tree_args_free | ( | struct ArgsGPTree * | args | ) |
Frees memory used by GP tree parameters.
[in] | args | Parameters for initialising and operating GP trees. |
Definition at line 438 of file gp.c.
References ArgsGPTree::constants.
Referenced by cond_param_free().
void tree_args_init | ( | struct ArgsGPTree * | args | ) |
Sets tree GP parameters to default values.
[in] | args | Parameters for initialising and operating GP trees. |
Definition at line 422 of file gp.c.
References ArgsGPTree::constants, ArgsGPTree::init_depth, ArgsGPTree::max, ArgsGPTree::max_len, ArgsGPTree::min, ArgsGPTree::n_constants, and ArgsGPTree::n_inputs.
Referenced by cond_gp_param_defaults().
void tree_args_init_constants | ( | struct ArgsGPTree * | args | ) |
Builds global constants used by GP trees.
[in] | args | Parameters for initialising and operating GP trees. |
Definition at line 539 of file gp.c.
References ArgsGPTree::constants, ArgsGPTree::max, ArgsGPTree::min, ArgsGPTree::n_constants, and rand_uniform().
Referenced by cond_gp_param_defaults(), and cond_gp_param_json_import().
char* tree_args_json_export | ( | const struct ArgsGPTree * | args | ) |
Returns a json formatted string of the GP tree parameters.
[in] | args | Parameters for initialising and operating GP trees. |
Definition at line 449 of file gp.c.
References ArgsGPTree::init_depth, ArgsGPTree::max, ArgsGPTree::max_len, ArgsGPTree::min, and ArgsGPTree::n_constants.
Referenced by cond_gp_param_json_export().
char* tree_args_json_import | ( | struct ArgsGPTree * | args, |
cJSON * | json | ||
) |
Sets the GP tree parameters from a cJSON object.
[in,out] | args | GP tree parameter data structure. |
[in] | json | cJSON object. |
Definition at line 469 of file gp.c.
References tree_param_set_init_depth(), tree_param_set_max(), tree_param_set_max_len(), tree_param_set_min(), and tree_param_set_n_constants().
Referenced by cond_gp_param_json_import().
size_t tree_args_load | ( | struct ArgsGPTree * | args, |
FILE * | fp | ||
) |
Loads Tree GP parameters.
[in] | args | Parameters for initialising and operating GP trees. |
[in] | fp | Pointer to the output file. |
Definition at line 521 of file gp.c.
References ArgsGPTree::constants, ArgsGPTree::init_depth, ArgsGPTree::max, ArgsGPTree::max_len, ArgsGPTree::min, ArgsGPTree::n_constants, and ArgsGPTree::n_inputs.
Referenced by cond_param_load().
size_t tree_args_save | ( | const struct ArgsGPTree * | args, |
FILE * | fp | ||
) |
Saves Tree GP parameters.
[in] | args | Parameters for initialising and operating GP trees. |
[in] | fp | Pointer to the output file. |
Definition at line 501 of file gp.c.
References ArgsGPTree::constants, ArgsGPTree::init_depth, ArgsGPTree::max, ArgsGPTree::max_len, ArgsGPTree::min, ArgsGPTree::n_constants, and ArgsGPTree::n_inputs.
Referenced by cond_param_save().
Copies a GP tree.
[in] | dest | The destination GP tree. |
[in] | src | The source GP tree. |
Definition at line 302 of file gp.c.
References GPTree::len, GPTree::mu, N_MU, GPTree::pos, and GPTree::tree.
Referenced by cond_gp_copy().
Performs sub-tree crossover.
[in] | p1 | The first GP tree to perform crossover. |
[in] | p2 | The second GP tree to perform crossover. |
Definition at line 318 of file gp.c.
References GPTree::len, rand_uniform_int(), GPTree::tree, and tree_traverse().
Referenced by cond_gp_crossover().
double tree_eval | ( | struct GPTree * | gp, |
const struct ArgsGPTree * | args, | ||
const double * | x | ||
) |
Evaluates a GP tree.
[in] | gp | The GP tree to evaluate. |
[in] | args | Tree GP parameters. |
[in] | x | The input state. |
Definition at line 133 of file gp.c.
References ADD, clamp(), ArgsGPTree::constants, DIV, GP_NUM_FUNC, MUL, ArgsGPTree::n_constants, GPTree::pos, RET_MAX, RET_MIN, SUB, and GPTree::tree.
Referenced by cond_gp_match().
void tree_free | ( | const struct GPTree * | gp | ) |
Frees a GP tree.
[in] | gp | The GP tree to free. |
Definition at line 119 of file gp.c.
References GPTree::mu, and GPTree::tree.
Referenced by cond_gp_cover(), and cond_gp_free().
char* tree_json_export | ( | const struct GPTree * | gp, |
const struct ArgsGPTree * | args | ||
) |
Returns a json formatted string representation of a GP tree.
[in] | gp | The GP tree to return. |
[in] | args | Tree GP parameters. |
Definition at line 253 of file gp.c.
References GPTree::mu, N_MU, and tree_string().
Referenced by cond_gp_json_export(), and tree_print().
void tree_json_import | ( | struct GPTree * | gp, |
const struct ArgsGPTree * | args, | ||
const cJSON * | json | ||
) |
Creates a GP tree from a cJSON object.
[in,out] | gp | The GP tree to initialise. |
[in] | args | Parameters for initialising a GP tree. |
[in] | json | cJSON object. |
Definition at line 273 of file gp.c.
Referenced by cond_gp_json_import().
size_t tree_load | ( | struct GPTree * | gp, |
FILE * | fp | ||
) |
Reads a GP tree from a file.
[in] | gp | The GP tree to load. |
[in] | fp | Pointer to the file to be read. |
Definition at line 400 of file gp.c.
References GPTree::len, GPTree::mu, N_MU, GPTree::pos, and GPTree::tree.
Referenced by cond_gp_load().
bool tree_mutate | ( | struct GPTree * | gp, |
const struct ArgsGPTree * | args | ||
) |
Performs point mutation on a GP tree.
Terminals are randomly replaced with other terminals and functions are randomly replaced with other functions.
[in] | gp | The GP tree to be mutated. |
[in] | args | Tree GP parameters. |
Definition at line 355 of file gp.c.
References GP_NUM_FUNC, GPTree::len, GPTree::mu, MU_TYPE, ArgsGPTree::n_constants, ArgsGPTree::n_inputs, N_MU, rand_uniform(), rand_uniform_int(), sam_adapt(), and GPTree::tree.
Referenced by cond_gp_mutate().
void tree_param_set_init_depth | ( | struct ArgsGPTree * | args, |
const int | a | ||
) |
Definition at line 587 of file gp.c.
References ArgsGPTree::init_depth.
Referenced by cond_gp_param_defaults(), and tree_args_json_import().
void tree_param_set_max | ( | struct ArgsGPTree * | args, |
const double | a | ||
) |
Definition at line 553 of file gp.c.
References ArgsGPTree::max.
Referenced by cond_gp_param_defaults(), and tree_args_json_import().
void tree_param_set_max_len | ( | struct ArgsGPTree * | args, |
const int | a | ||
) |
Definition at line 598 of file gp.c.
References ArgsGPTree::max_len.
Referenced by cond_gp_param_defaults(), and tree_args_json_import().
void tree_param_set_min | ( | struct ArgsGPTree * | args, |
const double | a | ||
) |
Definition at line 559 of file gp.c.
References ArgsGPTree::min.
Referenced by cond_gp_param_defaults(), and tree_args_json_import().
void tree_param_set_n_constants | ( | struct ArgsGPTree * | args, |
const int | a | ||
) |
Definition at line 576 of file gp.c.
References ArgsGPTree::n_constants.
Referenced by cond_gp_param_defaults(), and tree_args_json_import().
void tree_param_set_n_inputs | ( | struct ArgsGPTree * | args, |
const int | a | ||
) |
Definition at line 565 of file gp.c.
References ArgsGPTree::n_inputs.
Referenced by cond_gp_param_defaults().
void tree_print | ( | const struct GPTree * | gp, |
const struct ArgsGPTree * | args | ||
) |
Prints a GP tree.
[in] | gp | The GP tree to print. |
[in] | args | Tree GP parameters. |
Definition at line 289 of file gp.c.
References tree_json_export().
void tree_rand | ( | struct GPTree * | gp, |
const struct ArgsGPTree * | args | ||
) |
Creates a random GP tree.
[in] | gp | The GP tree being randomised. |
[in] | args | Tree GP parameters. |
Definition at line 102 of file gp.c.
References ArgsGPTree::init_depth, GPTree::len, ArgsGPTree::max_len, GPTree::mu, MU_TYPE, N_MU, sam_init(), GPTree::tree, and tree_grow().
Referenced by cond_gp_cover(), and cond_gp_init().
size_t tree_save | ( | const struct GPTree * | gp, |
FILE * | fp | ||
) |
Writes the GP tree to a file.
[in] | gp | The GP tree to save. |
[in] | fp | Pointer to the file to be written. |
Definition at line 383 of file gp.c.
References GPTree::len, GPTree::mu, N_MU, GPTree::pos, and GPTree::tree.
Referenced by cond_gp_save().