XCSF  1.4.7
XCSF learning classifier system
cond_gp.h File Reference

Tree GP condition functions. More...

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

Go to the source code of this file.

Data Structures

struct  CondGP
 Tree GP condition data structure. More...
 

Functions

void cond_gp_param_defaults (struct XCSF *xcsf)
 Initialises default tree GP condition parameters. More...
 
char * cond_gp_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string of the tree GP parameters. More...
 
char * cond_gp_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the tree GP parameters from a cJSON object. More...
 
bool cond_gp_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs sub-tree crossover with two tree-GP conditions. More...
 
bool cond_gp_general (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Dummy general function. More...
 
bool cond_gp_match (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Calculates whether a GP tree condition matches an input. More...
 
bool cond_gp_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Mutates a tree-GP condition with the self-adaptive rate. More...
 
void cond_gp_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies a tree-GP condition from one classifier to another. More...
 
void cond_gp_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Generates a GP tree that matches the current input. More...
 
void cond_gp_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by a tree-GP condition. More...
 
void cond_gp_init (const struct XCSF *xcsf, struct Cl *c)
 Creates and initialises a tree-GP condition. More...
 
void cond_gp_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints a tree-GP condition. More...
 
void cond_gp_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Dummy update function. More...
 
double cond_gp_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of a tree-GP condition. More...
 
size_t cond_gp_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a tree-GP condition to a file. More...
 
size_t cond_gp_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a tree-GP condition from a file. More...
 
char * cond_gp_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a tree-GP condition. More...
 
void cond_gp_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a tree GP condition from a cJSON object. More...
 

Variables

static struct CondVtbl const cond_gp_vtbl
 Tree GP condition implemented functions. More...
 

Detailed Description

Tree GP condition functions.

Author
Richard Preen rpree.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om
Date
2016–2022.

Definition in file cond_gp.h.

Function Documentation

◆ cond_gp_copy()

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

Copies a tree-GP condition from one classifier to another.

Parameters
[in]xcsfXCSF data structure.
[in]destDestination classifier.
[in]srcSource classifier.

Definition at line 63 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_copy().

Here is the call graph for this function:

◆ cond_gp_cover()

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

Generates a GP tree that matches the current input.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is being covered.
[in]xInput state to cover.

Definition at line 79 of file cond_gp.c.

References Cl::cond, cond_gp_match(), CondGP::gp, tree_free(), and tree_rand().

Here is the call graph for this function:

◆ cond_gp_crossover()

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

Performs sub-tree crossover with two tree-GP conditions.

Parameters
[in]xcsfXCSF data structure.
[in]c1First classifier whose condition is being crossed.
[in]c2Second classifier whose condition is being crossed.
Returns
Whether any alterations were made.

Definition at line 145 of file cond_gp.c.

References Cl::cond, CondGP::gp, rand_uniform(), and tree_crossover().

Here is the call graph for this function:

◆ cond_gp_free()

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

Frees the memory used by a tree-GP condition.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be freed.

Definition at line 48 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_free().

Here is the call graph for this function:

◆ cond_gp_general()

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

Dummy general function.

Parameters
[in]xcsfXCSF data structure.
[in]c1Classifier whose condition is tested to be more general.
[in]c2Classifier whose condition is tested to be more specific.
Returns
False

Definition at line 166 of file cond_gp.c.

◆ cond_gp_init()

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

Creates and initialises a tree-GP condition.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition is to be initialised.

Definition at line 35 of file cond_gp.c.

References Cl::cond, and tree_rand().

Here is the call graph for this function:

◆ cond_gp_json_export()

char* cond_gp_json_export ( const struct XCSF xcsf,
const struct Cl c 
)

Returns a json formatted string representation of a tree-GP condition.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be returned.
Returns
String encoded in json format.

Definition at line 242 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_json_export().

Referenced by cond_gp_print().

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

◆ cond_gp_json_import()

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

Creates a tree GP condition from a cJSON object.

Parameters
[in]xcsfThe XCSF data structure.
[in,out]cThe classifier to initialise.
[in]jsoncJSON object.

Definition at line 307 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_json_import().

Here is the call graph for this function:

◆ cond_gp_load()

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

Reads a tree-GP condition from a file.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be read.
[in]fpPointer to the file to be read.
Returns
The number of elements read.

Definition at line 226 of file cond_gp.c.

References Cl::cond, and tree_load().

Here is the call graph for this function:

◆ cond_gp_match()

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

Calculates whether a GP tree condition matches an input.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition to match.
[in]xInput state.
Returns
Whether the hyperrectangle condition matches the input.

Definition at line 113 of file cond_gp.c.

References Cl::cond, CondGP::gp, GPTree::pos, and tree_eval().

Referenced by cond_gp_cover().

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

◆ cond_gp_mutate()

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

Mutates a tree-GP condition with the self-adaptive rate.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is being mutated.
Returns
Whether any alterations were made.

Definition at line 130 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_mutate().

Here is the call graph for this function:

◆ cond_gp_param_defaults()

void cond_gp_param_defaults ( struct XCSF xcsf)

Initialises default tree GP condition parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 286 of file cond_gp.c.

References tree_args_init(), tree_args_init_constants(), tree_param_set_init_depth(), tree_param_set_max(), tree_param_set_max_len(), tree_param_set_min(), tree_param_set_n_constants(), and tree_param_set_n_inputs().

Referenced by cond_param_defaults().

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

◆ cond_gp_param_json_export()

char* cond_gp_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string of the tree GP parameters.

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

Definition at line 262 of file cond_gp.c.

References tree_args_json_export().

Referenced by cond_param_json_export().

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

◆ cond_gp_param_json_import()

char* cond_gp_param_json_import ( struct XCSF xcsf,
cJSON *  json 
)

Sets the tree GP parameters from a cJSON object.

Parameters
[in,out]xcsfThe XCSF data structure.
[in]jsoncJSON object.
Returns
NULL if successful; or the name of parameter if not found.

Definition at line 274 of file cond_gp.c.

References tree_args_init_constants(), and tree_args_json_import().

Referenced by cond_param_json_import().

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

◆ cond_gp_print()

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

Prints a tree-GP condition.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be printed.

Definition at line 181 of file cond_gp.c.

References cond_gp_json_export().

Here is the call graph for this function:

◆ cond_gp_save()

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

Writes a tree-GP condition to a file.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be written.
[in]fpPointer to the file to be written.
Returns
The number of elements written.

Definition at line 210 of file cond_gp.c.

References Cl::cond, CondGP::gp, and tree_save().

Here is the call graph for this function:

◆ cond_gp_size()

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

Returns the size of a tree-GP condition.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition size to return.
Returns
The length of the tree.

Definition at line 195 of file cond_gp.c.

References Cl::cond, CondGP::gp, and GPTree::len.

◆ cond_gp_update()

void cond_gp_update ( const struct XCSF xcsf,
const struct Cl c,
const double *  x,
const double *  y 
)

Dummy update function.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose condition is to be updated.
[in]xInput state.
[in]yTruth/payoff value.

Definition at line 96 of file cond_gp.c.

Variable Documentation

◆ cond_gp_vtbl

struct CondVtbl const cond_gp_vtbl
static
Initial value:
= {
}
void cond_gp_print(const struct XCSF *xcsf, const struct Cl *c)
Prints a tree-GP condition.
Definition: cond_gp.c:181
void cond_gp_cover(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Generates a GP tree that matches the current input.
Definition: cond_gp.c:79
void cond_gp_copy(const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
Copies a tree-GP condition from one classifier to another.
Definition: cond_gp.c:63
size_t cond_gp_save(const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
Writes a tree-GP condition to a file.
Definition: cond_gp.c:210
bool cond_gp_general(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Dummy general function.
Definition: cond_gp.c:166
char * cond_gp_json_export(const struct XCSF *xcsf, const struct Cl *c)
Returns a json formatted string representation of a tree-GP condition.
Definition: cond_gp.c:242
bool cond_gp_crossover(const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
Performs sub-tree crossover with two tree-GP conditions.
Definition: cond_gp.c:145
size_t cond_gp_load(const struct XCSF *xcsf, struct Cl *c, FILE *fp)
Reads a tree-GP condition from a file.
Definition: cond_gp.c:226
bool cond_gp_mutate(const struct XCSF *xcsf, const struct Cl *c)
Mutates a tree-GP condition with the self-adaptive rate.
Definition: cond_gp.c:130
void cond_gp_free(const struct XCSF *xcsf, const struct Cl *c)
Frees the memory used by a tree-GP condition.
Definition: cond_gp.c:48
bool cond_gp_match(const struct XCSF *xcsf, const struct Cl *c, const double *x)
Calculates whether a GP tree condition matches an input.
Definition: cond_gp.c:113
double cond_gp_size(const struct XCSF *xcsf, const struct Cl *c)
Returns the size of a tree-GP condition.
Definition: cond_gp.c:195
void cond_gp_json_import(const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
Creates a tree GP condition from a cJSON object.
Definition: cond_gp.c:307
void cond_gp_init(const struct XCSF *xcsf, struct Cl *c)
Creates and initialises a tree-GP condition.
Definition: cond_gp.c:35
void cond_gp_update(const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
Dummy update function.
Definition: cond_gp.c:96

Tree GP condition implemented functions.

Definition at line 92 of file cond_gp.h.

Referenced by condition_set().