XCSF  1.4.7
XCSF learning classifier system
pred_rls.c File Reference

Recursive least mean squares prediction functions. More...

#include "pred_rls.h"
#include "blas.h"
#include "utils.h"
Include dependency graph for pred_rls.c:

Go to the source code of this file.

Functions

void pred_rls_init (const struct XCSF *xcsf, struct Cl *c)
 Initialises an RLS prediction. More...
 
void pred_rls_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies an RLS prediction from one classifier to another. More...
 
void pred_rls_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by an RLS prediction. More...
 
void pred_rls_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Updates an RLS prediction for a given input and truth sample. More...
 
void pred_rls_compute (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Computes the current RLS prediction for a provided input. More...
 
void pred_rls_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints an RLS prediction. More...
 
bool pred_rls_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Dummy function since RLS predictions do not perform crossover. More...
 
bool pred_rls_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Dummy function since RLS predictions do not perform mutation. More...
 
double pred_rls_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of an RLS prediction. More...
 
size_t pred_rls_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes an RLS prediction to a file. More...
 
size_t pred_rls_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads an RLS prediction from a file. More...
 
char * pred_rls_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of an RLS prediction. More...
 
void pred_rls_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates an RLS prediction from a cJSON object. More...
 
char * pred_rls_param_json_export (const struct XCSF *xcsf)
 Returns a json formatted string of the RLS parameters. More...
 
char * pred_rls_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the RLS parameters from a cJSON object. More...
 

Detailed Description

Recursive least mean squares prediction functions.

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

Definition in file pred_rls.c.

Function Documentation

◆ pred_rls_compute()

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

Computes the current RLS prediction for a provided input.

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

Definition at line 158 of file pred_rls.c.

References blas_dot(), PredRLS::n, Cl::pred, pred_transform_input(), Cl::prediction, PredRLS::tmp_input, and PredRLS::weights.

Here is the call graph for this function:

◆ pred_rls_copy()

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

Copies an RLS prediction from one classifier to another.

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

Definition at line 69 of file pred_rls.c.

References PredRLS::n_weights, Cl::pred, pred_rls_init(), and PredRLS::weights.

Here is the call graph for this function:

◆ pred_rls_crossover()

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

Dummy function since RLS predictions do not perform 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
False.

Definition at line 190 of file pred_rls.c.

◆ pred_rls_free()

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

Frees the memory used by an RLS prediction.

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

Definition at line 84 of file pred_rls.c.

References PredRLS::matrix, Cl::pred, PredRLS::tmp_input, PredRLS::tmp_matrix1, PredRLS::tmp_matrix2, PredRLS::tmp_vec, and PredRLS::weights.

◆ pred_rls_init()

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

Initialises an RLS prediction.

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

Definition at line 34 of file pred_rls.c.

References blas_fill(), PredRLS::matrix, PredRLS::n, PredRLS::n_weights, Cl::pred, PRED_TYPE_RLS_QUADRATIC, PredRLS::tmp_input, PredRLS::tmp_matrix1, PredRLS::tmp_matrix2, PredRLS::tmp_vec, and PredRLS::weights.

Referenced by pred_rls_copy(), and pred_rls_load().

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

◆ pred_rls_json_export()

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

Returns a json formatted string representation of an RLS prediction.

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

Definition at line 276 of file pred_rls.c.

References PredRLS::n_weights, Cl::pred, PRED_TYPE_RLS_QUADRATIC, and PredRLS::weights.

Referenced by pred_rls_print().

Here is the caller graph for this function:

◆ pred_rls_json_import()

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

Creates an RLS prediction from a cJSON object.

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

Definition at line 299 of file pred_rls.c.

References PredRLS::n_weights, Cl::pred, and PredRLS::weights.

◆ pred_rls_load()

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

Reads an RLS 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 256 of file pred_rls.c.

References PredRLS::matrix, PredRLS::n, PredRLS::n_weights, Cl::pred, pred_rls_init(), and PredRLS::weights.

Here is the call graph for this function:

◆ pred_rls_mutate()

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

Dummy function since RLS predictions do not perform mutation.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose prediction is being mutated.
Returns
False.

Definition at line 206 of file pred_rls.c.

◆ pred_rls_param_json_export()

char* pred_rls_param_json_export ( const struct XCSF xcsf)

Returns a json formatted string of the RLS parameters.

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

Definition at line 323 of file pred_rls.c.

References ArgsPred::lambda, ArgsPred::scale_factor, and ArgsPred::x0.

Referenced by pred_param_json_export().

Here is the caller graph for this function:

◆ pred_rls_param_json_import()

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

Sets the RLS 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 342 of file pred_rls.c.

References pred_param_set_lambda(), pred_param_set_scale_factor(), and pred_param_set_x0().

Referenced by pred_param_json_import().

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

◆ pred_rls_print()

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

Prints an RLS prediction.

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

Definition at line 175 of file pred_rls.c.

References pred_rls_json_export().

Here is the call graph for this function:

◆ pred_rls_save()

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

Writes an RLS 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 235 of file pred_rls.c.

References PredRLS::matrix, PredRLS::n, PredRLS::n_weights, Cl::pred, and PredRLS::weights.

◆ pred_rls_size()

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

Returns the size of an RLS prediction.

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

Definition at line 220 of file pred_rls.c.

References PredRLS::n_weights, and Cl::pred.

◆ pred_rls_update()

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

Updates an RLS prediction for a given input and truth sample.

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 106 of file pred_rls.c.

References blas_axpy(), blas_dot(), blas_gemm(), blas_scal(), PredRLS::matrix, PredRLS::n, Cl::pred, Cl::prediction, PredRLS::tmp_input, PredRLS::tmp_matrix1, PredRLS::tmp_matrix2, PredRLS::tmp_vec, and PredRLS::weights.

Here is the call graph for this function: