XCSF  1.4.7
XCSF learning classifier system
cond_ellipsoid.c File Reference

Hyperellipsoid condition functions. More...

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

Go to the source code of this file.

Macros

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

Functions

static double cond_ellipsoid_dist (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Returns the relative distance to a hyperellipsoid. More...
 
void cond_ellipsoid_init (const struct XCSF *xcsf, struct Cl *c)
 Creates and initialises a hyperellipsoid condition. More...
 
void cond_ellipsoid_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by a hyperellipsoid condition. More...
 
void cond_ellipsoid_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies a hyperellipsoid condition from one classifier to another. More...
 
void cond_ellipsoid_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Generates a hyperellipsoid that matches the current input. More...
 
void cond_ellipsoid_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Updates a hyperellipsoid, sliding the centers towards the mean input. More...
 
bool cond_ellipsoid_match (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Calculates whether a hyperellipsoid condition matches an input. More...
 
bool cond_ellipsoid_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs uniform crossover with two hyperellipsoid conditions. More...
 
bool cond_ellipsoid_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Mutates a hyperellipsoid condition with the self-adaptive rate. More...
 
bool cond_ellipsoid_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_ellipsoid_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints a hyperellipsoid condition. More...
 
double cond_ellipsoid_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of a hyperellipsoid condition. More...
 
size_t cond_ellipsoid_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a hyperellipsoid condition to a file. More...
 
size_t cond_ellipsoid_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a hyperellipsoid condition from a file. More...
 
char * cond_ellipsoid_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a hyperellipsoid. More...
 
void cond_ellipsoid_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a hyperellipsoid from a cJSON object. More...
 

Variables

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

Detailed Description

Hyperellipsoid condition functions.

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

Definition in file cond_ellipsoid.c.

Macro Definition Documentation

◆ N_MU

#define N_MU   (1)

Number of hyperellipsoid mutation rates.

Definition at line 29 of file cond_ellipsoid.c.

Function Documentation

◆ cond_ellipsoid_copy()

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

Copies a hyperellipsoid condition from one classifier to another.

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

Definition at line 103 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, CondEllipsoid::mu, N_MU, and CondEllipsoid::spread.

◆ cond_ellipsoid_cover()

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

Generates a hyperellipsoid 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 124 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, rand_uniform(), and CondEllipsoid::spread.

Here is the call graph for this function:

◆ cond_ellipsoid_crossover()

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

Performs uniform crossover with two hyperellipsoid 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 177 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, rand_uniform(), and CondEllipsoid::spread.

Here is the call graph for this function:

◆ cond_ellipsoid_dist()

static double cond_ellipsoid_dist ( const struct XCSF xcsf,
const struct Cl c,
const double *  x 
)
static

Returns the relative distance to a hyperellipsoid.

Distance is zero at the center; one on the border; and greater than one outside of the hyperellipsoid.

Parameters
[in]xcsfXCSF data structure.
[in]cClassifier whose hyperellipsoid distance is to be computed.
[in]xInput to compute the relative distance.
Returns
The relative distance of an input to the hyperellipsoid.

Definition at line 46 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, and CondEllipsoid::spread.

Referenced by cond_ellipsoid_general(), and cond_ellipsoid_match().

Here is the caller graph for this function:

◆ cond_ellipsoid_free()

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

Frees the memory used by a hyperellipsoid condition.

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

Definition at line 86 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, CondEllipsoid::mu, and CondEllipsoid::spread.

◆ cond_ellipsoid_general()

bool cond_ellipsoid_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 hyperellipsoid condition of c1 is more general than c2.

Definition at line 241 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, cond_ellipsoid_dist(), and CondEllipsoid::spread.

Here is the call graph for this function:

◆ cond_ellipsoid_init()

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

Creates and initialises a hyperellipsoid condition.

Uses the center-spread representation.

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

Definition at line 65 of file cond_ellipsoid.c.

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

Here is the call graph for this function:

◆ cond_ellipsoid_json_export()

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

Returns a json formatted string representation of a hyperellipsoid.

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

Definition at line 341 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, CondEllipsoid::mu, N_MU, and CondEllipsoid::spread.

Referenced by cond_ellipsoid_print().

Here is the caller graph for this function:

◆ cond_ellipsoid_json_import()

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

Creates a hyperellipsoid from a cJSON object.

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

Definition at line 364 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, CondEllipsoid::mu, N_MU, sam_json_import(), and CondEllipsoid::spread.

Here is the call graph for this function:

◆ cond_ellipsoid_load()

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

Reads a hyperellipsoid 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 320 of file cond_ellipsoid.c.

References Cl::cond, and N_MU.

◆ cond_ellipsoid_match()

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

Calculates whether a hyperellipsoid condition matches an input.

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

Definition at line 163 of file cond_ellipsoid.c.

References cond_ellipsoid_dist().

Here is the call graph for this function:

◆ cond_ellipsoid_mutate()

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

Mutates a hyperellipsoid 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 209 of file cond_ellipsoid.c.

References CondEllipsoid::center, clamp(), Cl::cond, CondEllipsoid::mu, MU_TYPE, N_MU, rand_normal(), sam_adapt(), and CondEllipsoid::spread.

Here is the call graph for this function:

◆ cond_ellipsoid_print()

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

Prints a hyperellipsoid condition.

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

Definition at line 274 of file cond_ellipsoid.c.

References cond_ellipsoid_json_export().

Here is the call graph for this function:

◆ cond_ellipsoid_save()

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

Writes a hyperellipsoid 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 302 of file cond_ellipsoid.c.

References CondEllipsoid::center, Cl::cond, CondEllipsoid::mu, N_MU, and CondEllipsoid::spread.

◆ cond_ellipsoid_size()

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

Returns the size of a hyperellipsoid condition.

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

Definition at line 288 of file cond_ellipsoid.c.

◆ cond_ellipsoid_update()

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

Updates a hyperellipsoid, 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 143 of file cond_ellipsoid.c.

References CondEllipsoid::center, and Cl::cond.

Variable Documentation

◆ MU_TYPE

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

Self-adaptation method for mutating hyperellipsoids.

Definition at line 34 of file cond_ellipsoid.c.

Referenced by cond_ellipsoid_init(), and cond_ellipsoid_mutate().