XCSF  1.4.7
XCSF learning classifier system
cond_ternary.c File Reference

Ternary condition functions. More...

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

Go to the source code of this file.

Macros

#define DONT_CARE   ('#')
 Don't care symbol. More...
 
#define N_MU   (1)
 Number of ternary mutation rates. More...
 

Functions

static void cond_ternary_rand (const struct XCSF *xcsf, const struct Cl *c)
 Randomises a ternary condition. More...
 
void cond_ternary_init (const struct XCSF *xcsf, struct Cl *c)
 Creates and initialises a ternary bitstring condition. More...
 
void cond_ternary_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by a ternary condition. More...
 
void cond_ternary_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies a ternary condition from one classifier to another. More...
 
void cond_ternary_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Generates a ternary condition that matches the current input. More...
 
void cond_ternary_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Dummy update function. More...
 
bool cond_ternary_match (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Calculates whether a ternary condition matches an input. More...
 
bool cond_ternary_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs uniform crossover with two ternary conditions. More...
 
bool cond_ternary_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Mutates a ternary condition. More...
 
bool cond_ternary_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_ternary_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints a ternary condition. More...
 
double cond_ternary_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of a ternary condition. More...
 
size_t cond_ternary_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a ternary condition to a file. More...
 
size_t cond_ternary_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a ternary condition from a file. More...
 
char * cond_ternary_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a ternary condition. More...
 
void cond_ternary_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a ternary condition from a cJSON object. More...
 
char * cond_ternary_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string of the ternary parameters. More...
 
char * cond_ternary_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the ternary parameters from a cJSON object. More...
 
void cond_ternary_param_defaults (struct XCSF *xcsf)
 Initialises default ternary condition parameters. More...
 

Variables

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

Detailed Description

Ternary condition functions.

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

Binarises inputs.

Definition in file cond_ternary.c.

Macro Definition Documentation

◆ DONT_CARE

#define DONT_CARE   ('#')

Don't care symbol.

Definition at line 30 of file cond_ternary.c.

◆ N_MU

#define N_MU   (1)

Number of ternary mutation rates.

Definition at line 31 of file cond_ternary.c.

Function Documentation

◆ cond_ternary_copy()

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

Copies a ternary condition from one classifier to another.

Parameters
[in]xcsfThe XCSF data structure.
[in]destThe destination classifier.
[in]srcThe source classifier.

Definition at line 99 of file cond_ternary.c.

References Cl::cond, CondTernary::length, CondTernary::mu, N_MU, and CondTernary::string.

◆ cond_ternary_cover()

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

Generates a ternary condition that matches the current input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition is being covered.
[in]xThe input state to cover.

Definition at line 120 of file cond_ternary.c.

References Cl::cond, DONT_CARE, float_to_binary(), rand_uniform(), CondTernary::string, and CondTernary::tmp_input.

Here is the call graph for this function:

◆ cond_ternary_crossover()

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

Performs uniform crossover with two ternary conditions.

Parameters
[in]xcsfThe XCSF data structure.
[in]c1The first classifier whose condition is being crossed.
[in]c2The second classifier whose condition is being crossed.
Returns
Whether any alterations were made.

Definition at line 185 of file cond_ternary.c.

References Cl::cond, CondTernary::length, rand_uniform(), and CondTernary::string.

Here is the call graph for this function:

◆ cond_ternary_free()

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

Frees the memory used by a ternary condition.

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

Definition at line 82 of file cond_ternary.c.

References Cl::cond, CondTernary::mu, CondTernary::string, and CondTernary::tmp_input.

◆ cond_ternary_general()

bool cond_ternary_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]xcsfThe XCSF data structure.
[in]c1The classifier whose condition is tested to be more general.
[in]c2The classifier whose condition is tested to be more specific.
Returns
Whether the condition of c1 is more general than c2.

Definition at line 238 of file cond_ternary.c.

References Cl::cond, DONT_CARE, CondTernary::length, and CondTernary::string.

◆ cond_ternary_init()

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

Creates and initialises a ternary bitstring condition.

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

Definition at line 64 of file cond_ternary.c.

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

Here is the call graph for this function:

◆ cond_ternary_json_export()

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

Returns a json formatted string representation of a ternary condition.

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

Definition at line 338 of file cond_ternary.c.

References Cl::cond, CondTernary::length, CondTernary::mu, N_MU, and CondTernary::string.

Referenced by cond_ternary_print().

Here is the caller graph for this function:

◆ cond_ternary_json_import()

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

Creates a ternary condition from a cJSON object.

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

Definition at line 362 of file cond_ternary.c.

References Cl::cond, CondTernary::length, CondTernary::mu, N_MU, sam_json_import(), and CondTernary::string.

Here is the call graph for this function:

◆ cond_ternary_load()

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

Reads a ternary condition from a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition is to be read.
[in]fpPointer to the file to be read.
Returns
The number of elements read.

Definition at line 311 of file cond_ternary.c.

References Cl::cond, and N_MU.

◆ cond_ternary_match()

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

Calculates whether a ternary condition matches an input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition to match.
[in]xThe input state.
Returns
Whether the condition matches the input.

Definition at line 161 of file cond_ternary.c.

References Cl::cond, DONT_CARE, float_to_binary(), CondTernary::string, and CondTernary::tmp_input.

Here is the call graph for this function:

◆ cond_ternary_mutate()

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

Mutates a ternary condition.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition is being mutated.
Returns
Whether any alterations were made.

Definition at line 211 of file cond_ternary.c.

References Cl::cond, DONT_CARE, CondTernary::length, CondTernary::mu, MU_TYPE, N_MU, rand_uniform(), sam_adapt(), and CondTernary::string.

Here is the call graph for this function:

◆ cond_ternary_param_defaults()

void cond_ternary_param_defaults ( struct XCSF xcsf)

Initialises default ternary condition parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 426 of file cond_ternary.c.

References cond_param_set_bits(), and cond_param_set_p_dontcare().

Referenced by cond_param_defaults().

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

◆ cond_ternary_param_json_export()

char* cond_ternary_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string of the ternary parameters.

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

Definition at line 387 of file cond_ternary.c.

References ArgsCond::bits, and ArgsCond::p_dontcare.

Referenced by cond_param_json_export().

Here is the caller graph for this function:

◆ cond_ternary_param_json_import()

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

Sets the ternary 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 405 of file cond_ternary.c.

References cond_param_set_bits(), and cond_param_set_p_dontcare().

Referenced by cond_param_json_import().

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

◆ cond_ternary_print()

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

Prints a ternary condition.

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

Definition at line 263 of file cond_ternary.c.

References cond_ternary_json_export().

Here is the call graph for this function:

◆ cond_ternary_rand()

static void cond_ternary_rand ( const struct XCSF xcsf,
const struct Cl c 
)
static

Randomises a ternary condition.

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

Definition at line 44 of file cond_ternary.c.

References Cl::cond, DONT_CARE, CondTernary::length, rand_uniform(), and CondTernary::string.

Referenced by cond_ternary_init().

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

◆ cond_ternary_save()

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

Writes a ternary condition to a file.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition is to be written.
[in]fpPointer to the file to be written.
Returns
The number of elements written.

Definition at line 292 of file cond_ternary.c.

References Cl::cond, CondTernary::length, CondTernary::mu, N_MU, and CondTernary::string.

◆ cond_ternary_size()

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

Returns the size of a ternary condition.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose condition size to return.
Returns
The size of the condition.

Definition at line 277 of file cond_ternary.c.

References Cl::cond, and CondTernary::length.

◆ cond_ternary_update()

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

Dummy update function.

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

Definition at line 144 of file cond_ternary.c.

Variable Documentation

◆ MU_TYPE

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

Self-adaptation method for mutating ternary conditions.

Definition at line 36 of file cond_ternary.c.

Referenced by cond_ternary_init(), and cond_ternary_mutate().