XCSF  1.4.7
XCSF learning classifier system
pred_neural.c File Reference

Multi-layer perceptron neural network prediction functions. More...

Include dependency graph for pred_neural.c:

Go to the source code of this file.

Functions

void pred_neural_init (const struct XCSF *xcsf, struct Cl *c)
 Creates and initialises a neural network prediction. More...
 
void pred_neural_free (const struct XCSF *xcsf, const struct Cl *c)
 Frees the memory used by a neural network prediction. More...
 
void pred_neural_copy (const struct XCSF *xcsf, struct Cl *dest, const struct Cl *src)
 Copies a neural network prediction from one classifier to another. More...
 
void pred_neural_update (const struct XCSF *xcsf, const struct Cl *c, const double *x, const double *y)
 Backward propagates and updates a neural network prediction. More...
 
void pred_neural_compute (const struct XCSF *xcsf, const struct Cl *c, const double *x)
 Forward propagates a neural network prediction with a provided input. More...
 
void pred_neural_print (const struct XCSF *xcsf, const struct Cl *c)
 Prints a neural network prediction. More...
 
bool pred_neural_crossover (const struct XCSF *xcsf, const struct Cl *c1, const struct Cl *c2)
 Dummy function since neural predictions do not perform crossover. More...
 
bool pred_neural_mutate (const struct XCSF *xcsf, const struct Cl *c)
 Mutates a neural network prediction. More...
 
double pred_neural_size (const struct XCSF *xcsf, const struct Cl *c)
 Returns the size of a neural network prediction. More...
 
size_t pred_neural_save (const struct XCSF *xcsf, const struct Cl *c, FILE *fp)
 Writes a neural network prediction to a file. More...
 
size_t pred_neural_load (const struct XCSF *xcsf, struct Cl *c, FILE *fp)
 Reads a neural network prediction from a file. More...
 
double pred_neural_eta (const struct XCSF *xcsf, const struct Cl *c, const int layer)
 Returns the gradient descent rate of a neural prediction layer. More...
 
int pred_neural_neurons (const struct XCSF *xcsf, const struct Cl *c, const int layer)
 Returns the number of neurons in a neural prediction layer. More...
 
int pred_neural_connections (const struct XCSF *xcsf, const struct Cl *c, const int layer)
 Returns the number of active connections in a neural prediction layer. More...
 
int pred_neural_layers (const struct XCSF *xcsf, const struct Cl *c)
 Returns the number of layers within a neural network prediction. More...
 
void pred_neural_expand (const struct XCSF *xcsf, const struct Cl *c)
 Creates and inserts a hidden layer before the prediction output layer. More...
 
void pred_neural_ae_to_classifier (const struct XCSF *xcsf, const struct Cl *c, const int n_del)
 Removes prediction (decoder) layers and inserts softmax output layer. More...
 
char * pred_neural_json_export (const struct XCSF *xcsf, const struct Cl *c)
 Returns a json formatted string representation of a neural prediction. More...
 
void pred_neural_json_import (const struct XCSF *xcsf, struct Cl *c, const cJSON *json)
 Creates a neural prediction from a cJSON object. More...
 
void pred_neural_param_defaults (struct XCSF *xcsf)
 Initialises default neural prediction parameters. More...
 
char * pred_neural_param_json_import (struct XCSF *xcsf, cJSON *json)
 Sets the neural network parameters from a cJSON object. More...
 

Detailed Description

Multi-layer perceptron neural network prediction functions.

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

Definition in file pred_neural.c.

Function Documentation

◆ pred_neural_ae_to_classifier()

void pred_neural_ae_to_classifier ( const struct XCSF xcsf,
const struct Cl c,
const int  n_del 
)

Removes prediction (decoder) layers and inserts softmax output layer.

Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier to convert from autoencoding to classification.
[in]n_delNumber of (decoder) layers to remove from the network.

Definition at line 349 of file pred_neural.c.

References CONNECTED, ArgsLayer::decay, ArgsLayer::eta, ArgsLayer::eta_min, ArgsLayer::evolve_connect, ArgsLayer::evolve_eta, ArgsLayer::evolve_weights, Layer::i, layer_args_init(), layer_init(), LINEAR, ArgsLayer::momentum, Net::n_layers, Net::n_outputs, PredNeural::net, neural_pop(), neural_push(), Cl::pred, ArgsLayer::sgd_weights, and SOFTMAX.

Referenced by xcsf_ae_to_classifier().

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

◆ pred_neural_compute()

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

Forward propagates a neural network prediction with a provided input.

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

Definition at line 106 of file pred_neural.c.

References PredNeural::net, neural_output(), neural_propagate(), Cl::pred, and Cl::prediction.

Here is the call graph for this function:

◆ pred_neural_connections()

int pred_neural_connections ( const struct XCSF xcsf,
const struct Cl c,
const int  layer 
)

Returns the number of active connections in a neural prediction layer.

Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier maintaining a neural network prediction.
[in]layerPosition of a layer in the network.
Returns
The current number of active (non-zero) connections in a layer.

Definition at line 268 of file pred_neural.c.

References Llist::layer, Layer::n_active, PredNeural::net, Cl::pred, Llist::prev, and Net::tail.

Referenced by clset_mean_pred_connections().

Here is the caller graph for this function:

◆ pred_neural_copy()

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

Copies a neural network prediction from one classifier to another.

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

Definition at line 73 of file pred_neural.c.

References PredNeural::net, neural_copy(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_crossover()

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

Dummy function since neural 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 137 of file pred_neural.c.

◆ pred_neural_eta()

double pred_neural_eta ( const struct XCSF xcsf,
const struct Cl c,
const int  layer 
)

Returns the gradient descent rate of a neural prediction layer.

Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier maintaining a neural network prediction.
[in]layerPosition of a layer in the network.
Returns
The current gradient descent rate of a layer.

Definition at line 216 of file pred_neural.c.

References Layer::eta, Llist::layer, PredNeural::net, Cl::pred, Llist::prev, and Net::tail.

Referenced by clset_mean_pred_eta().

Here is the caller graph for this function:

◆ pred_neural_expand()

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

Creates and inserts a hidden layer before the prediction output layer.

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

Definition at line 306 of file pred_neural.c.

References CONNECTED, ArgsLayer::decay, ArgsLayer::eta, ArgsLayer::eta_min, ArgsLayer::evolve_connect, ArgsLayer::evolve_eta, ArgsLayer::evolve_functions, ArgsLayer::evolve_weights, ArgsLayer::function, Layer::h, Net::head, Llist::layer, layer_args_init(), layer_init(), Layer::max_outputs, ArgsLayer::momentum, Layer::n_inputs, ArgsLayer::n_inputs, Net::n_layers, Layer::n_outputs, PredNeural::net, neural_insert(), neural_resize(), Llist::next, Cl::pred, and ArgsLayer::sgd_weights.

Referenced by xcsf_pred_expand().

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

◆ pred_neural_free()

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

Frees the memory used by a neural network prediction.

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

Definition at line 58 of file pred_neural.c.

References PredNeural::net, neural_free(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_init()

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

Creates and initialises a neural network prediction.

Uses fully-connected layers.

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

Definition at line 45 of file pred_neural.c.

References neural_create(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_json_export()

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

Returns a json formatted string representation of a neural prediction.

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

Definition at line 392 of file pred_neural.c.

References PredNeural::net, neural_json_export(), and Cl::pred.

Referenced by pred_neural_print().

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

◆ pred_neural_json_import()

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

Creates a neural prediction from a cJSON object.

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

Definition at line 414 of file pred_neural.c.

References PredNeural::net, neural_json_import(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_layers()

int pred_neural_layers ( const struct XCSF xcsf,
const struct Cl c 
)

Returns the number of layers within a neural network prediction.

Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier maintaining a neural network prediction.
Returns
The number of layers.

Definition at line 292 of file pred_neural.c.

References Net::n_layers, PredNeural::net, and Cl::pred.

Referenced by clset_mean_pred_layers().

Here is the caller graph for this function:

◆ pred_neural_load()

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

Reads a neural network 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 199 of file pred_neural.c.

References neural_load(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_mutate()

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

Mutates a neural network prediction.

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

Definition at line 153 of file pred_neural.c.

References PredNeural::net, neural_mutate(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_neurons()

int pred_neural_neurons ( const struct XCSF xcsf,
const struct Cl c,
const int  layer 
)

Returns the number of neurons in a neural prediction layer.

Parameters
[in]xcsfThe XCSF data structure.
[in]cClassifier maintaining a neural network prediction.
[in]layerPosition of a layer in the network.
Returns
The current number of neurons in a layer.

Definition at line 240 of file pred_neural.c.

References CONVOLUTIONAL, Llist::layer, Layer::n_filters, Layer::n_outputs, PredNeural::net, Cl::pred, Llist::prev, Net::tail, and Layer::type.

Referenced by clset_mean_pred_neurons().

Here is the caller graph for this function:

◆ pred_neural_param_defaults()

void pred_neural_param_defaults ( struct XCSF xcsf)

Initialises default neural prediction parameters.

Parameters
[in]xcsfThe XCSF data structure.

Definition at line 431 of file pred_neural.c.

References CONNECTED, ArgsLayer::eta, ArgsLayer::evolve_connect, ArgsLayer::evolve_eta, ArgsLayer::evolve_neurons, ArgsLayer::evolve_weights, ArgsLayer::function, layer_args_copy(), layer_args_init(), LOGISTIC, ArgsLayer::max_neuron_grow, ArgsLayer::momentum, ArgsLayer::n_init, ArgsLayer::n_inputs, ArgsLayer::n_max, ArgsLayer::next, ArgsLayer::sgd_weights, and ArgsLayer::type.

Referenced by pred_param_defaults().

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

◆ pred_neural_param_json_import()

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

Sets the neural network 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 465 of file pred_neural.c.

References layer_args_free(), layer_args_init(), layer_args_json_import(), layer_args_validate(), ArgsLayer::n_inputs, and ArgsLayer::next.

Referenced by pred_param_json_import().

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

◆ pred_neural_print()

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

Prints a neural network prediction.

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

Definition at line 122 of file pred_neural.c.

References pred_neural_json_export().

Here is the call graph for this function:

◆ pred_neural_save()

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

Writes a neural network 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 183 of file pred_neural.c.

References PredNeural::net, neural_save(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_size()

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

Returns the size of a neural network prediction.

See also
neural_size()
Parameters
[in]xcsfThe XCSF data structure.
[in]cThe classifier whose prediction size to return.
Returns
The network size.

Definition at line 168 of file pred_neural.c.

References PredNeural::net, neural_size(), and Cl::pred.

Here is the call graph for this function:

◆ pred_neural_update()

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

Backward propagates and updates a neural network prediction.

Precondition
The prediction has been forward propagated 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 91 of file pred_neural.c.

References PredNeural::net, neural_learn(), and Cl::pred.

Here is the call graph for this function: