XCSF  1.4.7
XCSF learning classifier system
cond_rectangle.c File Reference

Hyperrectangle condition functions. More...

#include "cond_rectangle.h"
#include "ea.h"
#include "sam.h"
#include "utils.h"
Include dependency graph for cond_rectangle.c:

Go to the source code of this file.

Macros

#define N_MU   (1)
 Number of hyperrectangle mutation rates. More...
 

Functions

void cond_rectangle_init (const struct XCSF *xcsf, struct Cl *c)
 Creates and initialises a hyperrectangle condition. More...
 
void cond_rectangle_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by a hyperrectangle condition. More...
 
void cond_rectangle_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies a hyperrectangle condition from one classifier to another. More...
 
void cond_rectangle_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Generates a hyperrectangle that matches the current input. More...
 
void cond_rectangle_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Updates a hyperrectangle, sliding the centers towards the mean input. More...
 
bool cond_rectangle_match (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Calculates whether a hyperrectangle condition matches an input. More...
 
bool cond_rectangle_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs uniform crossover with two hyperrectangle conditions. More...
 
bool cond_rectangle_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Mutates a hyperrectangle condition with the self-adaptive rate. More...
 
bool cond_rectangle_general (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Returns whether classifier c1 has a condition more general than c2. More...
 
void cond_rectangle_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints a hyperrectangle condition. More...
 
double cond_rectangle_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of a hyperrectangle condition. More...
 
size_t cond_rectangle_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a hyperrectangle condition to a file. More...
 
size_t cond_rectangle_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a hyperrectangle condition from a file. More...
 
char * cond_rectangle_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a hyperrectangle. More...
 
void cond_rectangle_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a hyperrectangle from a cJSON object. More...
 

Variables

static const int MU_TYPE [(1)] = { (0) }
 Self-adaptation method for mutating hyperrectangles. More...
 

Detailed Description

Hyperrectangle condition functions.

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

Definition in file cond_rectangle.c.

Macro Definition Documentation

◆ N_MU

#define N_MU   (1)

Number of hyperrectangle mutation rates.

Definition at line 29 of file cond_rectangle.c.

Function Documentation

◆ cond_rectangle_copy()

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

Copies a hyperrectangle condition from one classifier to another.

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

Definition at line 86 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, CondRectangle::mu, and N_MU.

◆ cond_rectangle_cover()

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

Generates a hyperrectangle 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 107 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, COND_TYPE_HYPERRECTANGLE_CSR, and rand_uniform().

Here is the call graph for this function:

◆ cond_rectangle_crossover()

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

Performs uniform crossover with two hyperrectangle 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 188 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, and rand_uniform().

Here is the call graph for this function:

◆ cond_rectangle_free()

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

Frees the memory used by a hyperrectangle condition.

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

Definition at line 69 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, and CondRectangle::mu.

◆ cond_rectangle_general()

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

Returns whether classifier c1 has a condition more general than c2.

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
Whether the hyperrectangle condition of c1 is more general than c2.

Definition at line 256 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, and COND_TYPE_HYPERRECTANGLE_CSR.

◆ cond_rectangle_init()

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

Creates and initialises a hyperrectangle condition.

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

Definition at line 42 of file cond_rectangle.c.

References Cl::cond, COND_TYPE_HYPERRECTANGLE_CSR, MU_TYPE, N_MU, rand_uniform(), and sam_init().

Here is the call graph for this function:

◆ cond_rectangle_json_export()

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

Returns a json formatted string representation of a hyperrectangle.

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

Definition at line 358 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, COND_TYPE_HYPERRECTANGLE_CSR, CondRectangle::mu, and N_MU.

Referenced by cond_rectangle_print().

Here is the caller graph for this function:

◆ cond_rectangle_json_import()

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

Creates a hyperrectangle from a cJSON object.

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

Definition at line 387 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, COND_TYPE_HYPERRECTANGLE_CSR, CondRectangle::mu, N_MU, and sam_json_import().

Here is the call graph for this function:

◆ cond_rectangle_load()

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

Reads a hyperrectangle 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 337 of file cond_rectangle.c.

References Cl::cond, and N_MU.

◆ cond_rectangle_match()

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

Calculates whether a hyperrectangle 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 156 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, and COND_TYPE_HYPERRECTANGLE_CSR.

◆ cond_rectangle_mutate()

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

Mutates a hyperrectangle 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 220 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, clamp(), Cl::cond, COND_TYPE_HYPERRECTANGLE_CSR, CondRectangle::mu, MU_TYPE, N_MU, rand_normal(), and sam_adapt().

Here is the call graph for this function:

◆ cond_rectangle_print()

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

Prints a hyperrectangle condition.

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

Definition at line 291 of file cond_rectangle.c.

References cond_rectangle_json_export().

Here is the call graph for this function:

◆ cond_rectangle_save()

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

Writes a hyperrectangle 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 319 of file cond_rectangle.c.

References CondRectangle::b1, CondRectangle::b2, Cl::cond, CondRectangle::mu, and N_MU.

◆ cond_rectangle_size()

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

Returns the size of a hyperrectangle condition.

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

Definition at line 305 of file cond_rectangle.c.

◆ cond_rectangle_update()

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

Updates a hyperrectangle, sliding the centers towards the mean input.

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

Definition at line 135 of file cond_rectangle.c.

References CondRectangle::b1, Cl::cond, and COND_TYPE_HYPERRECTANGLE_CSR.

Variable Documentation

◆ MU_TYPE

const int MU_TYPE[(1)] = { (0) }
static

Self-adaptation method for mutating hyperrectangles.

Definition at line 34 of file cond_rectangle.c.

Referenced by cond_rectangle_init(), and cond_rectangle_mutate().