XCSF
1.4.7
XCSF learning classifier system
|
An implementation of dynamical GP graphs with fuzzy activations. More...
Go to the source code of this file.
Macros | |
#define | FUZZY_NOT (0) |
Fuzzy NOT function. More... | |
#define | FUZZY_CFMQVS_AND (1) |
Fuzzy AND (CFMQVS) function. More... | |
#define | FUZZY_CFMQVS_OR (2) |
Fuzzy OR (CFMQVS) function. More... | |
#define | NUM_FUNC (3) |
Number of selectable node functions. More... | |
#define | N_MU (3) |
Number of DGP graph mutation rates. More... | |
#define | STRING_FUZZY_NOT ("Fuzzy NOT\0") |
Fuzzy NOT. More... | |
#define | STRING_FUZZY_CFMQVS_AND ("Fuzzy AND\0") |
Fuzzy AND. More... | |
#define | STRING_FUZZY_CFMQVS_OR ("Fuzzy OR\0") |
Fuzzy OR. More... | |
Functions | |
static int | random_connection (const int n_nodes, const int n_inputs) |
Returns a random connection. More... | |
static bool | graph_mutate_functions (struct Graph *dgp) |
Mutates the node functions within a DGP graph. More... | |
static bool | graph_mutate_connectivity (struct Graph *dgp) |
Mutates the connectivity of a DGP graph. More... | |
static bool | graph_mutate_cycles (struct Graph *dgp) |
Mutates the number of update cycles performed by a DGP graph. More... | |
static double | node_activate (int function, const double *inputs, const int K) |
Returns the result from applying a specified activation function. More... | |
static const char * | function_string (const int function) |
Returns the name of a specified node function. More... | |
static int | function_int (const char *function) |
Returns the integer value of a specified node function. More... | |
static void | synchronous_update (const struct Graph *dgp, const double *inputs) |
Performs a synchronous update. More... | |
void | graph_init (struct Graph *dgp, const struct ArgsDGP *args) |
Initialises a new DGP graph. More... | |
void | graph_copy (struct Graph *dest, const struct Graph *src) |
Copies a DGP graph. More... | |
double | graph_output (const struct Graph *dgp, const int IDX) |
Returns the current state of a specified node in the graph. More... | |
void | graph_reset (const struct Graph *dgp) |
Resets the states to their initial state. More... | |
void | graph_rand (struct Graph *dgp) |
Randomises a specified DGP graph. More... | |
void | graph_update (const struct Graph *dgp, const double *inputs, const bool reset) |
Updates a DGP graph T cycles. More... | |
void | graph_print (const struct Graph *dgp) |
Prints a DGP graph. More... | |
char * | graph_json_export (const struct Graph *dgp) |
Returns a json formatted string representation of a DGP graph. More... | |
static void | graph_json_import_current_state (struct Graph *dgp, const cJSON *json) |
Sets DGP current states from a cJSON object. More... | |
static void | graph_json_import_initial_state (struct Graph *dgp, const cJSON *json) |
Sets DGP initial states from a cJSON object. More... | |
static void | graph_json_import_functions (struct Graph *dgp, const cJSON *json) |
Sets DGP functions from a cJSON object. More... | |
static void | graph_json_import_connectivity (struct Graph *dgp, const cJSON *json) |
Sets DGP mutation rates from a cJSON object. More... | |
void | graph_json_import (struct Graph *dgp, const struct ArgsDGP *args, const cJSON *json) |
Creates a DGP graph from a cJSON object. More... | |
void | graph_free (const struct Graph *dgp) |
Frees a DGP graph. More... | |
bool | graph_mutate (struct Graph *dgp) |
Mutates a specified DGP graph. More... | |
size_t | graph_save (const struct Graph *dgp, FILE *fp) |
Writes DGP graph to a file. More... | |
size_t | graph_load (struct Graph *dgp, FILE *fp) |
Reads DGP graph from a file. More... | |
void | graph_args_init (struct ArgsDGP *args) |
Sets DGP parameters to default values. More... | |
char * | graph_args_json_export (const struct ArgsDGP *args) |
Returns a json formatted string of the DGP parameters. More... | |
char * | graph_args_json_import (struct ArgsDGP *args, cJSON *json) |
Sets the DGP graph parameters from a cJSON object. More... | |
size_t | graph_args_save (const struct ArgsDGP *args, FILE *fp) |
Saves DGP parameters. More... | |
size_t | graph_args_load (struct ArgsDGP *args, FILE *fp) |
Loads DGP parameters. More... | |
void | graph_param_set_max_k (struct ArgsDGP *args, const int a) |
void | graph_param_set_max_t (struct ArgsDGP *args, const int a) |
void | graph_param_set_n (struct ArgsDGP *args, const int a) |
void | graph_param_set_n_inputs (struct ArgsDGP *args, const int a) |
void | graph_param_set_evolve_cycles (struct ArgsDGP *args, const bool a) |
Variables | |
static const int | MU_TYPE [(3)] |
Self-adaptation method for mutating DGP graphs. More... | |
An implementation of dynamical GP graphs with fuzzy activations.
Definition in file dgp.c.
|
static |
Returns the integer value of a specified node function.
[in] | function | The node function. |
Definition at line 184 of file dgp.c.
References FUZZY_CFMQVS_AND, FUZZY_CFMQVS_OR, FUZZY_NOT, STRING_FUZZY_CFMQVS_AND, STRING_FUZZY_CFMQVS_OR, and STRING_FUZZY_NOT.
Referenced by graph_json_import_functions().
|
static |
Returns the name of a specified node function.
[in] | function | The node function. |
Definition at line 162 of file dgp.c.
References FUZZY_CFMQVS_AND, FUZZY_CFMQVS_OR, FUZZY_NOT, STRING_FUZZY_CFMQVS_AND, STRING_FUZZY_CFMQVS_OR, and STRING_FUZZY_NOT.
Referenced by graph_json_export().
void graph_args_init | ( | struct ArgsDGP * | args | ) |
Sets DGP parameters to default values.
[in] | args | Parameters for initialising and operating DGP graphs. |
Definition at line 624 of file dgp.c.
References ArgsDGP::evolve_cycles, ArgsDGP::max_k, ArgsDGP::max_t, ArgsDGP::n, and ArgsDGP::n_inputs.
Referenced by cond_dgp_param_defaults().
char* graph_args_json_export | ( | const struct ArgsDGP * | args | ) |
Returns a json formatted string of the DGP parameters.
[in] | args | Parameters for initialising and operating DGP graphs. |
Definition at line 639 of file dgp.c.
References ArgsDGP::evolve_cycles, ArgsDGP::max_k, ArgsDGP::max_t, and ArgsDGP::n.
Referenced by cond_dgp_param_json_export().
char* graph_args_json_import | ( | struct ArgsDGP * | args, |
cJSON * | json | ||
) |
Sets the DGP graph parameters from a cJSON object.
[in,out] | args | DGP parameter data structure. |
[in] | json | cJSON object. |
Definition at line 658 of file dgp.c.
References graph_param_set_evolve_cycles(), graph_param_set_max_k(), graph_param_set_max_t(), and graph_param_set_n().
Referenced by cond_dgp_param_json_import().
size_t graph_args_load | ( | struct ArgsDGP * | args, |
FILE * | fp | ||
) |
Loads DGP parameters.
[in] | args | Parameters for initialising and operating DGP graphs. |
[in] | fp | Pointer to the output file. |
Definition at line 705 of file dgp.c.
References ArgsDGP::evolve_cycles, ArgsDGP::max_k, ArgsDGP::max_t, ArgsDGP::n, and ArgsDGP::n_inputs.
Referenced by cond_param_load().
size_t graph_args_save | ( | const struct ArgsDGP * | args, |
FILE * | fp | ||
) |
Saves DGP parameters.
[in] | args | Parameters for initialising and operating DGP graphs. |
[in] | fp | Pointer to the output file. |
Definition at line 687 of file dgp.c.
References ArgsDGP::evolve_cycles, ArgsDGP::max_k, ArgsDGP::max_t, ArgsDGP::n, and ArgsDGP::n_inputs.
Referenced by cond_param_save().
Copies a DGP graph.
[in] | dest | The destination DGP graph. |
[in] | src | The source DGP graph. |
Definition at line 251 of file dgp.c.
References Graph::connectivity, Graph::evolve_cycles, Graph::function, Graph::initial_state, Graph::klen, Graph::max_k, Graph::max_t, Graph::mu, Graph::n, Graph::n_inputs, N_MU, Graph::state, and Graph::t.
Referenced by cond_dgp_copy(), and rule_dgp_cond_copy().
void graph_free | ( | const struct Graph * | dgp | ) |
Frees a DGP graph.
[in] | dgp | The DGP graph to be freed. |
Definition at line 523 of file dgp.c.
References Graph::connectivity, Graph::function, Graph::initial_state, Graph::mu, Graph::state, Graph::tmp_input, and Graph::tmp_state.
Referenced by cond_dgp_free(), cond_dgp_json_import(), rule_dgp_cond_free(), and rule_dgp_cond_json_import().
Initialises a new DGP graph.
[in] | dgp | The DGP graph to initialise. |
[in] | args | Parameters for initialising a DGP graph. |
Definition at line 226 of file dgp.c.
References Graph::connectivity, ArgsDGP::evolve_cycles, Graph::evolve_cycles, Graph::function, Graph::initial_state, Graph::klen, ArgsDGP::max_k, Graph::max_k, ArgsDGP::max_t, Graph::max_t, Graph::mu, MU_TYPE, ArgsDGP::n, Graph::n, ArgsDGP::n_inputs, Graph::n_inputs, N_MU, sam_init(), Graph::state, Graph::t, Graph::tmp_input, and Graph::tmp_state.
Referenced by cond_dgp_copy(), cond_dgp_init(), rule_dgp_cond_copy(), and rule_dgp_cond_init().
char* graph_json_export | ( | const struct Graph * | dgp | ) |
Returns a json formatted string representation of a DGP graph.
[in] | dgp | The DGP graph to return. |
Definition at line 346 of file dgp.c.
References Graph::connectivity, Graph::function, function_string(), Graph::initial_state, Graph::klen, Graph::mu, Graph::n, Graph::n_inputs, N_MU, Graph::state, and Graph::t.
Referenced by cond_dgp_json_export(), graph_print(), and rule_dgp_cond_json_export().
Creates a DGP graph from a cJSON object.
[in,out] | dgp | The DGP to initialise. |
[in] | args | Parameters for initialising a DGP graph. |
[in] | json | cJSON object. |
Definition at line 477 of file dgp.c.
References Graph::connectivity, ArgsDGP::evolve_cycles, Graph::evolve_cycles, Graph::function, graph_json_import_connectivity(), graph_json_import_current_state(), graph_json_import_functions(), graph_json_import_initial_state(), graph_rand(), Graph::initial_state, Graph::klen, ArgsDGP::max_k, Graph::max_k, ArgsDGP::max_t, Graph::max_t, Graph::mu, ArgsDGP::n, Graph::n, ArgsDGP::n_inputs, Graph::n_inputs, N_MU, sam_json_import(), Graph::state, Graph::t, Graph::tmp_input, and Graph::tmp_state.
Referenced by cond_dgp_json_import(), and rule_dgp_cond_json_import().
|
static |
Sets DGP mutation rates from a cJSON object.
[in,out] | dgp | The DGP to initialise. |
[in] | json | cJSON object. |
Definition at line 450 of file dgp.c.
References Graph::connectivity, Graph::klen, Graph::n, and Graph::n_inputs.
Referenced by graph_json_import().
|
static |
Sets DGP current states from a cJSON object.
[in,out] | dgp | The DGP to initialise. |
[in] | json | cJSON object. |
Definition at line 377 of file dgp.c.
References Graph::n, and Graph::state.
Referenced by graph_json_import().
|
static |
Sets DGP functions from a cJSON object.
[in,out] | dgp | The DGP to initialise. |
[in] | json | cJSON object. |
Definition at line 427 of file dgp.c.
References Graph::function, function_int(), and Graph::n.
Referenced by graph_json_import().
|
static |
Sets DGP initial states from a cJSON object.
[in,out] | dgp | The DGP to initialise. |
[in] | json | cJSON object. |
Definition at line 402 of file dgp.c.
References Graph::initial_state, and Graph::n.
Referenced by graph_json_import().
size_t graph_load | ( | struct Graph * | dgp, |
FILE * | fp | ||
) |
Reads DGP graph from a file.
[in] | dgp | The DGP graph to load. |
[in] | fp | Pointer to the file to be written. |
Definition at line 588 of file dgp.c.
References Graph::connectivity, Graph::evolve_cycles, Graph::function, Graph::initial_state, Graph::klen, Graph::max_k, Graph::max_t, Graph::mu, Graph::n, Graph::n_inputs, N_MU, Graph::state, Graph::t, Graph::tmp_input, and Graph::tmp_state.
Referenced by cond_dgp_load(), and rule_dgp_cond_load().
bool graph_mutate | ( | struct Graph * | dgp | ) |
Mutates a specified DGP graph.
[in] | dgp | The DGP graph to be mutated. |
Definition at line 540 of file dgp.c.
References Graph::evolve_cycles, graph_mutate_connectivity(), graph_mutate_cycles(), graph_mutate_functions(), Graph::mu, MU_TYPE, N_MU, and sam_adapt().
Referenced by cond_dgp_mutate(), and rule_dgp_cond_mutate().
|
static |
Mutates the connectivity of a DGP graph.
[in] | dgp | The DGP graph to be mutated. |
Definition at line 90 of file dgp.c.
References Graph::connectivity, Graph::klen, Graph::mu, Graph::n, Graph::n_inputs, rand_uniform(), and random_connection().
Referenced by graph_mutate().
|
static |
Mutates the number of update cycles performed by a DGP graph.
[in] | dgp | The DGP graph to be mutated. |
Definition at line 111 of file dgp.c.
References Graph::max_t, Graph::mu, and Graph::t.
Referenced by graph_mutate().
|
static |
Mutates the node functions within a DGP graph.
[in] | dgp | The DGP graph to be mutated. |
Definition at line 69 of file dgp.c.
References Graph::function, Graph::mu, Graph::n, NUM_FUNC, rand_uniform(), and rand_uniform_int().
Referenced by graph_mutate().
double graph_output | ( | const struct Graph * | dgp, |
const int | IDX | ||
) |
Returns the current state of a specified node in the graph.
[in] | dgp | The DGP graph to output. |
[in] | IDX | Which node within the graph to output. |
Definition at line 274 of file dgp.c.
References Graph::state.
Referenced by cond_dgp_match(), rule_dgp_act_compute(), and rule_dgp_cond_match().
void graph_param_set_evolve_cycles | ( | struct ArgsDGP * | args, |
const bool | a | ||
) |
Definition at line 763 of file dgp.c.
References ArgsDGP::evolve_cycles.
Referenced by cond_dgp_param_defaults(), and graph_args_json_import().
void graph_param_set_max_k | ( | struct ArgsDGP * | args, |
const int | a | ||
) |
Definition at line 719 of file dgp.c.
References ArgsDGP::max_k.
Referenced by cond_dgp_param_defaults(), and graph_args_json_import().
void graph_param_set_max_t | ( | struct ArgsDGP * | args, |
const int | a | ||
) |
Definition at line 730 of file dgp.c.
References ArgsDGP::max_t.
Referenced by cond_dgp_param_defaults(), and graph_args_json_import().
void graph_param_set_n | ( | struct ArgsDGP * | args, |
const int | a | ||
) |
Definition at line 741 of file dgp.c.
References ArgsDGP::n.
Referenced by cond_dgp_param_defaults(), and graph_args_json_import().
void graph_param_set_n_inputs | ( | struct ArgsDGP * | args, |
const int | a | ||
) |
Definition at line 752 of file dgp.c.
References ArgsDGP::n_inputs.
Referenced by cond_dgp_param_defaults().
void graph_print | ( | const struct Graph * | dgp | ) |
Prints a DGP graph.
[in] | dgp | The DGP graph to print. |
Definition at line 333 of file dgp.c.
References graph_json_export().
void graph_rand | ( | struct Graph * | dgp | ) |
Randomises a specified DGP graph.
[in] | dgp | The DGP graph to randomise. |
Definition at line 296 of file dgp.c.
References Graph::connectivity, Graph::evolve_cycles, Graph::function, Graph::initial_state, Graph::klen, Graph::max_t, Graph::n, Graph::n_inputs, NUM_FUNC, rand_uniform(), rand_uniform_int(), random_connection(), Graph::state, and Graph::t.
Referenced by cond_dgp_cover(), cond_dgp_init(), graph_json_import(), rule_dgp_act_cover(), and rule_dgp_cond_init().
void graph_reset | ( | const struct Graph * | dgp | ) |
Resets the states to their initial state.
[in] | dgp | The DGP graph to reset. |
Definition at line 284 of file dgp.c.
References Graph::initial_state, Graph::n, and Graph::state.
Referenced by graph_update().
size_t graph_save | ( | const struct Graph * | dgp, |
FILE * | fp | ||
) |
Writes DGP graph to a file.
[in] | dgp | The DGP graph to save. |
[in] | fp | Pointer to the file to be written. |
Definition at line 563 of file dgp.c.
References Graph::connectivity, Graph::evolve_cycles, Graph::function, Graph::initial_state, Graph::klen, Graph::max_k, Graph::max_t, Graph::mu, Graph::n, Graph::n_inputs, N_MU, Graph::state, and Graph::t.
Referenced by cond_dgp_save(), and rule_dgp_cond_save().
void graph_update | ( | const struct Graph * | dgp, |
const double * | inputs, | ||
const bool | reset | ||
) |
Updates a DGP graph T cycles.
[in] | dgp | The DGP graph to update. |
[in] | inputs | The inputs to the graph. |
[in] | reset | Whether to reset states to initial values. |
Definition at line 318 of file dgp.c.
References graph_reset(), synchronous_update(), and Graph::t.
Referenced by cond_dgp_match(), and rule_dgp_cond_match().
|
static |
Returns the result from applying a specified activation function.
[in] | function | The activation function to apply. |
[in] | inputs | The input to the activation function. |
[in] | K | The number of inputs to the activation function. |
Definition at line 129 of file dgp.c.
References clamp(), FUZZY_CFMQVS_AND, FUZZY_CFMQVS_OR, and FUZZY_NOT.
Referenced by synchronous_update().
|
static |
Returns a random connection.
[in] | n_nodes | The number of nodes in the graph. |
[in] | n_inputs | The number of external inputs to the graph. |
Definition at line 53 of file dgp.c.
References rand_uniform(), and rand_uniform_int().
Referenced by graph_mutate_connectivity(), and graph_rand().
|
static |
Performs a synchronous update.
[in] | dgp | The DGP graph to update. |
[in] | inputs | The inputs to the graph. |
Definition at line 203 of file dgp.c.
References Graph::connectivity, Graph::function, Graph::max_k, Graph::n, Graph::n_inputs, node_activate(), Graph::state, Graph::tmp_input, and Graph::tmp_state.
Referenced by graph_update().
|
static |
Self-adaptation method for mutating DGP graphs.
Definition at line 41 of file dgp.c.
Referenced by graph_init(), and graph_mutate().