XCSF  1.4.7
XCSF learning classifier system
action.h File Reference

Interface for classifier actions. More...

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

Go to the source code of this file.

Data Structures

struct  ArgsAct
 Parameters for initialising and operating actions. More...
 
struct  ActVtbl
 Action interface data structure. More...
 

Macros

#define ACT_TYPE_INVALID   (-1)
 Error code for invalid actions. More...
 
#define ACT_TYPE_INTEGER   (0)
 Action type integer. More...
 
#define ACT_TYPE_NEURAL   (1)
 Action type neural network. More...
 
#define ACT_STRING_INTEGER   ("integer\0")
 Integer. More...
 
#define ACT_STRING_NEURAL   ("neural\0")
 Neural. More...
 
#define ACT_TYPE_OPTIONS   "integer, neural"
 

Functions

void action_set (const struct XCSF *xcsf, struct Cl *c)
 Sets a classifier's action functions to the implementations. More...
 
const char * action_type_as_string (const int type)
 Returns a string representation of an action type from an integer. More...
 
int action_type_as_int (const char *type)
 Returns the integer representation of an action type given a name. More...
 
void action_param_defaults (struct XCSF *xcsf)
 Initialises default action parameters. More...
 
void action_param_free (struct XCSF *xcsf)
 Frees action parameters. More...
 
char * action_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the action parameters from a cJSON object. More...
 
char * action_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string of the action parameters. More...
 
size_t action_param_save (const struct XCSF *xcsf, FILE *fp)
 Saves action parameters. More...
 
size_t action_param_load (struct XCSF *xcsf, FILE *fp)
 Loads action parameters. More...
 
static size_t act_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes the action to a file. More...
 
static size_t act_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads the action from a file. More...
 
static bool act_general (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Returns whether the action of classifier c1 is more general than c2. More...
 
static bool act_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs classifier action crossover. More...
 
static bool act_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Performs classifier action mutation. More...
 
static int act_compute (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Computes the current classifier action using the input. More...
 
static void act_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies the action from one classifier to another. More...
 
static void act_cover (const struct XCSF *xcsf, const struct Cl *c, const double *x, const int action)
 Generates an action that matches the specified value. More...
 
static void act_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by the classifier action. More...
 
static void act_init (const struct XCSF *xcsf, struct Cl *c)
 Initialises a classifier's action. More...
 
static void act_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints the classifier action. More...
 
static void act_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Updates the classifier's action. More...
 
static char * act_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of an action . More...
 
static void act_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates an action from a cJSON object. More...
 
int action_param_set_type_string (struct XCSF *xcsf, const char *a)
 
void action_param_set_type (struct XCSF *xcsf, const int a)
 

Detailed Description

Interface for classifier actions.

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

Definition in file action.h.

Macro Definition Documentation

◆ ACT_STRING_INTEGER

#define ACT_STRING_INTEGER   ("integer\0")

Integer.

Definition at line 32 of file action.h.

◆ ACT_STRING_NEURAL

#define ACT_STRING_NEURAL   ("neural\0")

Neural.

Definition at line 33 of file action.h.

◆ ACT_TYPE_INTEGER

#define ACT_TYPE_INTEGER   (0)

Action type integer.

Definition at line 29 of file action.h.

◆ ACT_TYPE_INVALID

#define ACT_TYPE_INVALID   (-1)

Error code for invalid actions.

Definition at line 28 of file action.h.

◆ ACT_TYPE_NEURAL

#define ACT_TYPE_NEURAL   (1)

Action type neural network.

Definition at line 30 of file action.h.

◆ ACT_TYPE_OPTIONS

#define ACT_TYPE_OPTIONS   "integer, neural"

Definition at line 35 of file action.h.

Function Documentation

◆ act_compute()

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

Computes the current classifier action using the input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier calculating the action.
[in]xThe input state.
Returns
The classifier's action.

Definition at line 173 of file action.h.

References ActVtbl::act_impl_compute, and Cl::act_vptr.

Referenced by cl_action().

Here is the caller graph for this function:

◆ act_copy()

static void act_copy ( const struct XCSF xcsf,
struct Cl dest,
const struct Cl src 
)
static

Copies the action from one classifier to another.

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

Definition at line 185 of file action.h.

References ActVtbl::act_impl_copy, and Cl::act_vptr.

Referenced by cl_copy(), and cl_init_copy().

Here is the caller graph for this function:

◆ act_cover()

static void act_cover ( const struct XCSF xcsf,
const struct Cl c,
const double *  x,
const int  action 
)
static

Generates an action that matches the specified value.

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

Definition at line 198 of file action.h.

References ActVtbl::act_impl_cover, Cl::act_vptr, and Cl::action.

Referenced by cl_cover().

Here is the caller graph for this function:

◆ act_crossover()

static bool act_crossover ( const struct XCSF xcsf,
const struct Cl c1,
const struct Cl c2 
)
static

Performs classifier action crossover.

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

Definition at line 148 of file action.h.

References ActVtbl::act_impl_crossover, and Cl::act_vptr.

Referenced by cl_crossover().

Here is the caller graph for this function:

◆ act_free()

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

Frees the memory used by the classifier action.

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

Definition at line 210 of file action.h.

References ActVtbl::act_impl_free, and Cl::act_vptr.

Referenced by cl_free().

Here is the caller graph for this function:

◆ act_general()

static bool act_general ( const struct XCSF xcsf,
const struct Cl c1,
const struct Cl c2 
)
static

Returns whether the action of classifier c1 is more general than c2.

Parameters
[in]xcsfThe XCSF data structure.
[in]c1The classifier whose action is tested to be more general.
[in]c2The classifier whose action is tested to be more specific.
Returns
Whether the action of c1 is more general than c2.

Definition at line 135 of file action.h.

References ActVtbl::act_impl_general, and Cl::act_vptr.

Referenced by cl_general().

Here is the caller graph for this function:

◆ act_init()

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

Initialises a classifier's action.

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

Definition at line 221 of file action.h.

References ActVtbl::act_impl_init, and Cl::act_vptr.

Referenced by cl_rand().

Here is the caller graph for this function:

◆ act_json_export()

static char* act_json_export ( const struct XCSF xcsf,
const struct Cl c 
)
static

Returns a json formatted string representation of an action .

Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier whose action is to be returned.
Returns
String encoded in json format.

Definition at line 258 of file action.h.

References ActVtbl::act_impl_json_export, and Cl::act_vptr.

Referenced by cl_json_export().

Here is the caller graph for this function:

◆ act_json_import()

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

Creates an action from a cJSON object.

Parameters
[in]xcsfThe XCSF data structure.
[in,out]cThe classifier whose action is to be initialised.
[in]jsoncJSON object.

Definition at line 270 of file action.h.

References ActVtbl::act_impl_json_import, Cl::act_vptr, action_type_as_int(), and action_type_as_string().

Referenced by cl_json_import().

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

◆ act_load()

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

Reads the action from a file.

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

Definition at line 122 of file action.h.

References ActVtbl::act_impl_load, and Cl::act_vptr.

Referenced by cl_load().

Here is the caller graph for this function:

◆ act_mutate()

static bool act_mutate ( const struct XCSF xcsf,
const struct Cl c 
)
static

Performs classifier action mutation.

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

Definition at line 160 of file action.h.

References ActVtbl::act_impl_mutate, and Cl::act_vptr.

Referenced by cl_mutate().

Here is the caller graph for this function:

◆ act_print()

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

Prints the classifier action.

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

Definition at line 232 of file action.h.

References ActVtbl::act_impl_print, and Cl::act_vptr.

◆ act_save()

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

Writes the action to a file.

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

Definition at line 109 of file action.h.

References ActVtbl::act_impl_save, and Cl::act_vptr.

Referenced by cl_save().

Here is the caller graph for this function:

◆ act_update()

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

Updates the classifier's action.

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

Definition at line 245 of file action.h.

References ActVtbl::act_impl_update, and Cl::act_vptr.

Referenced by cl_update().

Here is the caller graph for this function:

◆ action_param_defaults()

void action_param_defaults ( struct XCSF xcsf)

Initialises default action parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 91 of file action.c.

References act_neural_param_defaults(), ACT_TYPE_INTEGER, and action_param_set_type().

Referenced by param_init().

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

◆ action_param_free()

void action_param_free ( struct XCSF xcsf)

Frees action parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 184 of file action.c.

References layer_args_free().

Referenced by param_free().

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

◆ action_param_json_export()

char* action_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string of the action parameters.

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

Definition at line 103 of file action.c.

References ACT_TYPE_NEURAL, action_type_as_string(), layer_args_json_export(), and ArgsAct::type.

Referenced by param_json_export().

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

◆ action_param_json_import()

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

Sets the action parameters from a cJSON object.

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

Definition at line 131 of file action.c.

References act_neural_param_json_import(), ACT_TYPE_INTEGER, and ACT_TYPE_NEURAL.

Referenced by param_json_import_action().

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

◆ action_param_load()

size_t action_param_load ( struct XCSF xcsf,
FILE *  fp 
)

Loads action parameters.

Parameters
[in]xcsfThe XCSF data structure.
[in]fpPointer to the output file.
Returns
The total number of elements written.

Definition at line 170 of file action.c.

References ArgsAct::largs, layer_args_load(), and ArgsAct::type.

Referenced by param_load().

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

◆ action_param_save()

size_t action_param_save ( const struct XCSF xcsf,
FILE *  fp 
)

Saves action parameters.

Parameters
[in]xcsfThe XCSF data structure.
[in]fpPointer to the output file.
Returns
The total number of elements written.

Definition at line 154 of file action.c.

References ArgsAct::largs, layer_args_save(), and ArgsAct::type.

Referenced by param_save().

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

◆ action_param_set_type()

void action_param_set_type ( struct XCSF xcsf,
const int  a 
)

Definition at line 202 of file action.c.

Referenced by action_param_defaults().

Here is the caller graph for this function:

◆ action_param_set_type_string()

int action_param_set_type_string ( struct XCSF xcsf,
const char *  a 
)

Definition at line 192 of file action.c.

References ACT_TYPE_INVALID, action_type_as_int(), and ArgsAct::type.

Referenced by param_json_import_action().

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

◆ action_set()

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

Sets a classifier's action functions to the implementations.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to set.

Definition at line 35 of file action.c.

References act_integer_vtbl, act_neural_vtbl, ACT_TYPE_INTEGER, ACT_TYPE_NEURAL, and Cl::act_vptr.

Referenced by cl_load(), and cl_rand().

Here is the caller graph for this function:

◆ action_type_as_int()

int action_type_as_int ( const char *  type)

Returns the integer representation of an action type given a name.

Parameters
[in]typeString representation of a condition type.
Returns
Integer representing the action type.

Definition at line 75 of file action.c.

References ACT_STRING_INTEGER, ACT_STRING_NEURAL, ACT_TYPE_INTEGER, ACT_TYPE_INVALID, and ACT_TYPE_NEURAL.

Referenced by act_json_import(), and action_param_set_type_string().

Here is the caller graph for this function:

◆ action_type_as_string()

const char* action_type_as_string ( const int  type)

Returns a string representation of an action type from an integer.

Parameters
[in]typeInteger representation of an action type.
Returns
String representing the name of the action type.

Definition at line 56 of file action.c.

References ACT_STRING_INTEGER, ACT_STRING_NEURAL, ACT_TYPE_INTEGER, and ACT_TYPE_NEURAL.

Referenced by act_json_import(), and action_param_json_export().

Here is the caller graph for this function: