XCSF  1.4.7
XCSF learning classifier system
prediction.h File Reference

Interface for classifier predictions. More...

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

Go to the source code of this file.

Data Structures

struct  ArgsPred
 Parameters for initialising and operating predictions. More...
 
struct  PredVtbl
 Prediction interface data structure. More...
 

Macros

#define PRED_TYPE_INVALID   (-1)
 Error code for invalid prediction. More...
 
#define PRED_TYPE_CONSTANT   (0)
 Prediction type constant. More...
 
#define PRED_TYPE_NLMS_LINEAR   (1)
 Prediction type linear nlms. More...
 
#define PRED_TYPE_NLMS_QUADRATIC   (2)
 Prediction type quadratic nlms. More...
 
#define PRED_TYPE_RLS_LINEAR   (3)
 Prediction type linear rls. More...
 
#define PRED_TYPE_RLS_QUADRATIC   (4)
 Prediction type quadratic rls. More...
 
#define PRED_TYPE_NEURAL   (5)
 Prediction type neural. More...
 
#define PRED_STRING_CONSTANT   ("constant\0")
 Constant. More...
 
#define PRED_STRING_NLMS_LINEAR   ("nlms_linear\0")
 Linear nlms. More...
 
#define PRED_STRING_NLMS_QUADRATIC   ("nlms_quadratic\0")
 Quadratic nlms. More...
 
#define PRED_STRING_RLS_LINEAR   ("rls_linear\0")
 Linear rls. More...
 
#define PRED_STRING_RLS_QUADRATIC   ("rls_quadratic\0")
 Quadratic rls. More...
 
#define PRED_STRING_NEURAL   ("neural\0")
 Neural. More...
 
#define PRED_TYPE_OPTIONS
 

Functions

const char * prediction_type_as_string (const int type)
 Returns a string representation of a prediction type from the integer. More...
 
int prediction_type_as_int (const char *type)
 Returns the integer representation of a prediction type given a name. More...
 
size_t pred_param_load (struct XCSF *xcsf, FILE *fp)
 Loads prediction parameters. More...
 
size_t pred_param_save (const struct XCSF *xcsf, FILE *fp)
 Saves prediction parameters. More...
 
void pred_param_defaults (struct XCSF *xcsf)
 Initialises default prediction parameters. More...
 
void pred_param_free (struct XCSF *xcsf)
 Frees prediction parameters. More...
 
char * pred_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the prediction parameters from a cJSON object. More...
 
char * pred_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string of the prediction parameters. More...
 
void pred_transform_input (const struct XCSF *xcsf, const double *x, const double X0, double *tmp_input)
 Prepares the input state for least squares computation. More...
 
void prediction_set (const struct XCSF *xcsf, struct Cl *c)
 Sets a classifier's prediction functions to the implementations. More...
 
static size_t pred_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes the prediction to a file. More...
 
static size_t pred_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads the prediction from a file. More...
 
static double pred_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of the classifier prediction. More...
 
static bool pred_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Performs classifier prediction crossover. More...
 
static bool pred_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Performs classifier prediction mutation. More...
 
static void pred_compute (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Computes the current classifier prediction using the input. More...
 
static void pred_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies the prediction from one classifier to another. More...
 
static void pred_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by the classifier prediction. More...
 
static void pred_init (const struct XCSF *xcsf, struct Cl *c)
 Initialises a classifier's prediction. More...
 
static void pred_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints the classifier prediction. More...
 
static void pred_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Updates the classifier's prediction. More...
 
static char * pred_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a prediction. More...
 
static void pred_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a prediction from a cJSON object. More...
 
void pred_param_set_eta (struct XCSF *xcsf, const double a)
 
void pred_param_set_eta_min (struct XCSF *xcsf, const double a)
 
void pred_param_set_lambda (struct XCSF *xcsf, const double a)
 
void pred_param_set_scale_factor (struct XCSF *xcsf, const double a)
 
void pred_param_set_x0 (struct XCSF *xcsf, const double a)
 
void pred_param_set_evolve_eta (struct XCSF *xcsf, const bool a)
 
void pred_param_set_type (struct XCSF *xcsf, const int a)
 
int pred_param_set_type_string (struct XCSF *xcsf, const char *a)
 

Detailed Description

Interface for classifier predictions.

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

Definition in file prediction.h.

Macro Definition Documentation

◆ PRED_STRING_CONSTANT

#define PRED_STRING_CONSTANT   ("constant\0")

Constant.

Definition at line 36 of file prediction.h.

◆ PRED_STRING_NEURAL

#define PRED_STRING_NEURAL   ("neural\0")

Neural.

Definition at line 41 of file prediction.h.

◆ PRED_STRING_NLMS_LINEAR

#define PRED_STRING_NLMS_LINEAR   ("nlms_linear\0")

Linear nlms.

Definition at line 37 of file prediction.h.

◆ PRED_STRING_NLMS_QUADRATIC

#define PRED_STRING_NLMS_QUADRATIC   ("nlms_quadratic\0")

Quadratic nlms.

Definition at line 38 of file prediction.h.

◆ PRED_STRING_RLS_LINEAR

#define PRED_STRING_RLS_LINEAR   ("rls_linear\0")

Linear rls.

Definition at line 39 of file prediction.h.

◆ PRED_STRING_RLS_QUADRATIC

#define PRED_STRING_RLS_QUADRATIC   ("rls_quadratic\0")

Quadratic rls.

Definition at line 40 of file prediction.h.

◆ PRED_TYPE_CONSTANT

#define PRED_TYPE_CONSTANT   (0)

Prediction type constant.

Definition at line 29 of file prediction.h.

◆ PRED_TYPE_INVALID

#define PRED_TYPE_INVALID   (-1)

Error code for invalid prediction.

Definition at line 28 of file prediction.h.

◆ PRED_TYPE_NEURAL

#define PRED_TYPE_NEURAL   (5)

Prediction type neural.

Definition at line 34 of file prediction.h.

◆ PRED_TYPE_NLMS_LINEAR

#define PRED_TYPE_NLMS_LINEAR   (1)

Prediction type linear nlms.

Definition at line 30 of file prediction.h.

◆ PRED_TYPE_NLMS_QUADRATIC

#define PRED_TYPE_NLMS_QUADRATIC   (2)

Prediction type quadratic nlms.

Definition at line 31 of file prediction.h.

◆ PRED_TYPE_OPTIONS

#define PRED_TYPE_OPTIONS
Value:
"constant, nlms_linear, nlms_quadratic, rls_linear, rls_quadratic, " \
"neural"

Definition at line 43 of file prediction.h.

◆ PRED_TYPE_RLS_LINEAR

#define PRED_TYPE_RLS_LINEAR   (3)

Prediction type linear rls.

Definition at line 32 of file prediction.h.

◆ PRED_TYPE_RLS_QUADRATIC

#define PRED_TYPE_RLS_QUADRATIC   (4)

Prediction type quadratic rls.

Definition at line 33 of file prediction.h.

Function Documentation

◆ pred_compute()

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

Computes the current classifier prediction using the input.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier calculating the prediction.
[in]xThe input state.

Definition at line 189 of file prediction.h.

References PredVtbl::pred_impl_compute, and Cl::pred_vptr.

Referenced by cl_predict().

Here is the caller graph for this function:

◆ pred_copy()

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

Copies the prediction from one classifier to another.

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

Definition at line 201 of file prediction.h.

References PredVtbl::pred_impl_copy, and Cl::pred_vptr.

Referenced by cl_copy(), and cl_init_copy().

Here is the caller graph for this function:

◆ pred_crossover()

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

Performs classifier prediction crossover.

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

Definition at line 164 of file prediction.h.

References PredVtbl::pred_impl_crossover, and Cl::pred_vptr.

Referenced by cl_crossover().

Here is the caller graph for this function:

◆ pred_free()

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

Frees the memory used by the classifier prediction.

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

Definition at line 212 of file prediction.h.

References PredVtbl::pred_impl_free, and Cl::pred_vptr.

Referenced by cl_free().

Here is the caller graph for this function:

◆ pred_init()

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

Initialises a classifier's prediction.

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

Definition at line 223 of file prediction.h.

References PredVtbl::pred_impl_init, and Cl::pred_vptr.

Referenced by cl_copy(), and cl_rand().

Here is the caller graph for this function:

◆ pred_json_export()

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

Returns a json formatted string representation of a prediction.

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

Definition at line 261 of file prediction.h.

References PredVtbl::pred_impl_json_export, and Cl::pred_vptr.

Referenced by cl_json_export().

Here is the caller graph for this function:

◆ pred_json_import()

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

Creates a prediction from a cJSON object.

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

Definition at line 273 of file prediction.h.

References PredVtbl::pred_impl_json_import, Cl::pred_vptr, prediction_type_as_int(), and prediction_type_as_string().

Referenced by cl_json_import().

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

◆ pred_load()

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

Reads the prediction from a file.

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

Definition at line 139 of file prediction.h.

References PredVtbl::pred_impl_load, and Cl::pred_vptr.

Referenced by cl_load().

Here is the caller graph for this function:

◆ pred_mutate()

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

Performs classifier prediction mutation.

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

Definition at line 177 of file prediction.h.

References PredVtbl::pred_impl_mutate, and Cl::pred_vptr.

Referenced by cl_mutate().

Here is the caller graph for this function:

◆ pred_param_defaults()

void pred_param_defaults ( struct XCSF xcsf)

Initialises default prediction parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 120 of file prediction.c.

References pred_neural_param_defaults(), pred_param_set_eta(), pred_param_set_eta_min(), pred_param_set_evolve_eta(), pred_param_set_lambda(), pred_param_set_scale_factor(), pred_param_set_type(), pred_param_set_x0(), and PRED_TYPE_NLMS_LINEAR.

Referenced by param_init().

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

◆ pred_param_free()

void pred_param_free ( struct XCSF xcsf)

Frees prediction parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 252 of file prediction.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:

◆ pred_param_json_export()

char* pred_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string of the prediction parameters.

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

Definition at line 138 of file prediction.c.

References layer_args_json_export(), pred_nlms_param_json_export(), pred_rls_param_json_export(), PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, PRED_TYPE_RLS_QUADRATIC, prediction_type_as_string(), and ArgsPred::type.

Referenced by param_json_export().

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

◆ pred_param_json_import()

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

Sets the prediction 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 179 of file prediction.c.

References pred_neural_param_json_import(), pred_nlms_param_json_import(), pred_rls_param_json_import(), PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.

Referenced by param_json_import_prediction().

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

◆ pred_param_load()

size_t pred_param_load ( struct XCSF xcsf,
FILE *  fp 
)

Loads prediction parameters.

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

Definition at line 232 of file prediction.c.

References ArgsPred::eta, ArgsPred::eta_min, ArgsPred::evolve_eta, ArgsPred::lambda, ArgsPred::largs, layer_args_load(), ArgsPred::scale_factor, ArgsPred::type, and ArgsPred::x0.

Referenced by param_load().

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

◆ pred_param_save()

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

Saves prediction parameters.

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

Definition at line 210 of file prediction.c.

References ArgsPred::eta, ArgsPred::eta_min, ArgsPred::evolve_eta, ArgsPred::lambda, ArgsPred::largs, layer_args_save(), ArgsPred::scale_factor, ArgsPred::type, and ArgsPred::x0.

Referenced by param_save().

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

◆ pred_param_set_eta()

void pred_param_set_eta ( struct XCSF xcsf,
const double  a 
)

Definition at line 291 of file prediction.c.

Referenced by pred_nlms_param_json_import(), and pred_param_defaults().

Here is the caller graph for this function:

◆ pred_param_set_eta_min()

void pred_param_set_eta_min ( struct XCSF xcsf,
const double  a 
)

Definition at line 305 of file prediction.c.

Referenced by pred_nlms_param_json_import(), and pred_param_defaults().

Here is the caller graph for this function:

◆ pred_param_set_evolve_eta()

void pred_param_set_evolve_eta ( struct XCSF xcsf,
const bool  a 
)

Definition at line 337 of file prediction.c.

Referenced by pred_nlms_param_json_import(), and pred_param_defaults().

Here is the caller graph for this function:

◆ pred_param_set_lambda()

void pred_param_set_lambda ( struct XCSF xcsf,
const double  a 
)

Definition at line 319 of file prediction.c.

Referenced by pred_param_defaults(), and pred_rls_param_json_import().

Here is the caller graph for this function:

◆ pred_param_set_scale_factor()

void pred_param_set_scale_factor ( struct XCSF xcsf,
const double  a 
)

Definition at line 325 of file prediction.c.

Referenced by pred_param_defaults(), and pred_rls_param_json_import().

Here is the caller graph for this function:

◆ pred_param_set_type()

void pred_param_set_type ( struct XCSF xcsf,
const int  a 
)

Definition at line 343 of file prediction.c.

Referenced by pred_param_defaults().

Here is the caller graph for this function:

◆ pred_param_set_type_string()

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

Definition at line 354 of file prediction.c.

References PRED_TYPE_INVALID, prediction_type_as_int(), and ArgsPred::type.

Referenced by param_json_import_prediction().

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

◆ pred_param_set_x0()

void pred_param_set_x0 ( struct XCSF xcsf,
const double  a 
)

Definition at line 331 of file prediction.c.

Referenced by pred_nlms_param_json_import(), pred_param_defaults(), and pred_rls_param_json_import().

Here is the caller graph for this function:

◆ pred_print()

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

Prints the classifier prediction.

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

Definition at line 234 of file prediction.h.

References PredVtbl::pred_impl_print, and Cl::pred_vptr.

◆ pred_save()

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

Writes the prediction to a file.

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

Definition at line 126 of file prediction.h.

References PredVtbl::pred_impl_save, and Cl::pred_vptr.

Referenced by cl_save().

Here is the caller graph for this function:

◆ pred_size()

static double pred_size ( const struct XCSF xcsf,
const struct Cl c 
)
static

Returns the size of the classifier prediction.

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

Definition at line 151 of file prediction.h.

References PredVtbl::pred_impl_size, and Cl::pred_vptr.

Referenced by cl_pred_size().

Here is the caller graph for this function:

◆ pred_transform_input()

void pred_transform_input ( const struct XCSF xcsf,
const double *  x,
const double  X0,
double *  tmp_input 
)

Prepares the input state for least squares computation.

Parameters
[in]xcsfThe XCSF data structure.
[in]xThe input state.
[in]X0Bias term.
[out]tmp_inputThe transformed input.

Definition at line 265 of file prediction.c.

References PRED_TYPE_NLMS_QUADRATIC, and PRED_TYPE_RLS_QUADRATIC.

Referenced by pred_nlms_compute(), and pred_rls_compute().

Here is the caller graph for this function:

◆ pred_update()

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

Updates the classifier's prediction.

Precondition
The prediction has been computed for the current state.
Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier whose prediction is to be updated.
[in]xInput state.
[in]yTruth/payoff value.

Definition at line 248 of file prediction.h.

References PredVtbl::pred_impl_update, and Cl::pred_vptr.

Referenced by cl_update().

Here is the caller graph for this function:

◆ prediction_set()

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

Sets a classifier's prediction functions to the implementations.

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

Definition at line 36 of file prediction.c.

References pred_constant_vtbl, pred_neural_vtbl, pred_nlms_vtbl, pred_rls_vtbl, PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, PRED_TYPE_RLS_QUADRATIC, and Cl::pred_vptr.

Referenced by cl_load(), and cl_rand().

Here is the caller graph for this function:

◆ prediction_type_as_int()

int prediction_type_as_int ( const char *  type)

Returns the integer representation of a prediction type given a name.

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

Definition at line 92 of file prediction.c.

References PRED_STRING_CONSTANT, PRED_STRING_NEURAL, PRED_STRING_NLMS_LINEAR, PRED_STRING_NLMS_QUADRATIC, PRED_STRING_RLS_LINEAR, PRED_STRING_RLS_QUADRATIC, PRED_TYPE_CONSTANT, PRED_TYPE_INVALID, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.

Referenced by pred_json_import(), and pred_param_set_type_string().

Here is the caller graph for this function:

◆ prediction_type_as_string()

const char* prediction_type_as_string ( const int  type)

Returns a string representation of a prediction type from the integer.

Parameters
[in]typeInteger representation of a prediction type.
Returns
String representing the name of the prediction type.

Definition at line 65 of file prediction.c.

References PRED_STRING_CONSTANT, PRED_STRING_NEURAL, PRED_STRING_NLMS_LINEAR, PRED_STRING_NLMS_QUADRATIC, PRED_STRING_RLS_LINEAR, PRED_STRING_RLS_QUADRATIC, PRED_TYPE_CONSTANT, PRED_TYPE_NEURAL, PRED_TYPE_NLMS_LINEAR, PRED_TYPE_NLMS_QUADRATIC, PRED_TYPE_RLS_LINEAR, and PRED_TYPE_RLS_QUADRATIC.

Referenced by pred_json_import(), and pred_param_json_export().

Here is the caller graph for this function: