XCSF
1.4.7
XCSF learning classifier system
|
An implementation of a long short-term memory layer. More...
#include "neural_layer_lstm.h"
#include "blas.h"
#include "neural_activations.h"
#include "neural_layer_connected.h"
#include "sam.h"
#include "utils.h"
Go to the source code of this file.
Macros | |
#define | N_MU (6) |
Number of mutation rates applied to an LSTM layer. More... | |
Functions | |
static void | set_layer_n_weights (struct Layer *l) |
Sets the total number of weights in an LSTM layer. More... | |
static void | set_layer_n_biases (struct Layer *l) |
Sets the total number of biases in an LSTM layer. More... | |
static void | set_layer_n_active (struct Layer *l) |
Sets the number of active (non-zero) weights in an LSTM layer. More... | |
static void | malloc_layer_arrays (struct Layer *l) |
Allocate memory used by an LSTM layer. More... | |
static void | malloc_layers (struct Layer *l) |
Allocate memory for the sub-layers. More... | |
static void | free_layer_arrays (const struct Layer *l) |
Free memory used by an LSTM layer. More... | |
static void | set_eta (struct Layer *l) |
Sets the gradient descent rate used to update an LSTM layer. More... | |
static void | reset_layer_deltas (const struct Layer *l) |
Zeros the deltas used to update an LSTM layer. More... | |
static bool | mutate_eta (struct Layer *l) |
Mutates the gradient descent rate used to update an LSTM layer. More... | |
static bool | mutate_neurons (struct Layer *l) |
Mutates the number of neurons in an LSTM layer. More... | |
static bool | mutate_connectivity (struct Layer *l) |
Mutates the number of active weights in an LSTM layer. More... | |
static bool | mutate_weights (struct Layer *l) |
Mutates the magnitude of weights and biases in an LSTM layer. More... | |
void | neural_layer_lstm_init (struct Layer *l, const struct ArgsLayer *args) |
Initialises a long short-term memory layer. More... | |
struct Layer * | neural_layer_lstm_copy (const struct Layer *src) |
Initialises and creates a copy of one LSTM layer from another. More... | |
void | neural_layer_lstm_free (const struct Layer *l) |
Free memory used by an LSTM layer. More... | |
void | neural_layer_lstm_rand (struct Layer *l) |
Randomises an LSTM layer weights. More... | |
void | neural_layer_lstm_forward (const struct Layer *l, const struct Net *net, const double *input) |
Forward propagates an LSTM layer. More... | |
void | neural_layer_lstm_backward (const struct Layer *l, const struct Net *net, const double *input, double *delta) |
Backward propagates an LSTM layer. More... | |
void | neural_layer_lstm_update (const struct Layer *l) |
Updates the weights and biases of an LSTM layer. More... | |
void | neural_layer_lstm_resize (struct Layer *l, const struct Layer *prev) |
Resizes an LSTM layer if the previous layer has changed size. More... | |
double * | neural_layer_lstm_output (const struct Layer *l) |
Returns the output from an LSTM layer. More... | |
bool | neural_layer_lstm_mutate (struct Layer *l) |
Mutates an LSTM layer. More... | |
void | neural_layer_lstm_print (const struct Layer *l, const bool print_weights) |
Prints an LSTM layer. More... | |
char * | neural_layer_lstm_json_export (const struct Layer *l, const bool return_weights) |
Returns a json formatted string representation of an LSTM layer. More... | |
size_t | neural_layer_lstm_save (const struct Layer *l, FILE *fp) |
Writes an LSTM layer to a file. More... | |
size_t | neural_layer_lstm_load (struct Layer *l, FILE *fp) |
Reads an LSTM layer from a file. More... | |
Variables | |
static const int | MU_TYPE [(6)] |
Self-adaptation method for mutating an LSTM layer. More... | |
An implementation of a long short-term memory layer.
Stateful, and with a step of 1. Typically the output activation is TANH and recurrent activation LOGISTIC.
Definition in file neural_layer_lstm.c.
#define N_MU (6) |
Number of mutation rates applied to an LSTM layer.
Definition at line 33 of file neural_layer_lstm.c.
|
static |
Free memory used by an LSTM layer.
[in] | l | The layer to be freed. |
Definition at line 131 of file neural_layer_lstm.c.
References Layer::c, Layer::cell, Layer::dc, Layer::delta, Layer::f, Layer::g, Layer::h, Layer::i, Layer::o, Layer::output, Layer::prev_cell, Layer::prev_state, Layer::state, Layer::temp, Layer::temp2, and Layer::temp3.
Referenced by mutate_neurons(), and neural_layer_lstm_free().
|
static |
Allocate memory used by an LSTM layer.
[in] | l | The layer to be allocated memory. |
Definition at line 88 of file neural_layer_lstm.c.
References Layer::c, Layer::cell, Layer::dc, Layer::delta, Layer::f, Layer::g, Layer::h, Layer::i, layer_guard_outputs(), Layer::n_outputs, Layer::o, Layer::output, Layer::prev_cell, Layer::prev_state, Layer::state, Layer::temp, Layer::temp2, and Layer::temp3.
Referenced by mutate_neurons(), neural_layer_lstm_copy(), neural_layer_lstm_init(), and neural_layer_lstm_load().
|
static |
Allocate memory for the sub-layers.
[in] | l | The layer to be allocated memory. |
Definition at line 114 of file neural_layer_lstm.c.
References Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_load().
|
static |
Mutates the number of active weights in an LSTM layer.
[in] | l | The layer whose number of active weights is to be mutated. |
Definition at line 243 of file neural_layer_lstm.c.
References layer_mutate_connectivity(), Layer::mu, set_layer_n_active(), Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_mutate().
|
static |
Mutates the gradient descent rate used to update an LSTM layer.
[in] | l | The layer whose gradient descent rate is to be mutated. |
Definition at line 192 of file neural_layer_lstm.c.
References layer_mutate_eta(), Layer::mu, set_eta(), and Layer::uf.
Referenced by neural_layer_lstm_mutate().
|
static |
Mutates the number of neurons in an LSTM layer.
[in] | l | The layer whose number of neurons is to be mutated. |
Definition at line 207 of file neural_layer_lstm.c.
References free_layer_arrays(), layer_add_neurons(), layer_mutate_neurons(), layer_resize(), malloc_layer_arrays(), Layer::mu, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, set_layer_n_active(), set_layer_n_biases(), set_layer_n_weights(), Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_mutate().
|
static |
Mutates the magnitude of weights and biases in an LSTM layer.
[in] | l | The layer whose weights are to be mutated. |
Definition at line 264 of file neural_layer_lstm.c.
References layer_mutate_weights(), Layer::mu, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_mutate().
void neural_layer_lstm_backward | ( | const struct Layer * | l, |
const struct Net * | net, | ||
const double * | input, | ||
double * | delta | ||
) |
Backward propagates an LSTM layer.
[in] | l | The layer to backward propagate. |
[in] | net | Network containing the layer. |
[in] | input | The input to the layer. |
[out] | delta | The previous layer's error. |
Definition at line 461 of file neural_layer_lstm.c.
References blas_axpy(), blas_mul(), Layer::c, Layer::dc, Layer::delta, Layer::f, Layer::function, Layer::g, Layer::i, layer_backward(), Layer::n_outputs, neural_activate_array(), neural_gradient_array(), Layer::o, Layer::prev_cell, Layer::prev_state, Layer::recurrent_function, reset_layer_deltas(), Layer::temp, Layer::temp2, Layer::temp3, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Initialises and creates a copy of one LSTM layer from another.
[in] | src | The source layer. |
Definition at line 327 of file neural_layer_lstm.c.
References Layer::decay, Layer::eta, Layer::eta_max, Layer::function, layer_copy(), layer_defaults(), Layer::layer_vptr, LSTM, malloc_layer_arrays(), Layer::max_neuron_grow, Layer::max_outputs, Layer::momentum, Layer::mu, Layer::n_active, Layer::n_biases, Layer::n_inputs, N_MU, Layer::n_outputs, Layer::n_weights, Layer::options, Layer::out_c, Layer::out_h, Layer::out_w, Layer::recurrent_function, Layer::type, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
void neural_layer_lstm_forward | ( | const struct Layer * | l, |
const struct Net * | net, | ||
const double * | input | ||
) |
Forward propagates an LSTM layer.
[in] | l | The layer to forward propagate. |
[in] | net | Network containing the layer. |
[in] | input | The input to the layer. |
Definition at line 419 of file neural_layer_lstm.c.
References blas_axpy(), blas_mul(), Layer::c, Layer::cell, Layer::f, Layer::function, Layer::g, Layer::h, Layer::i, layer_forward(), Layer::n_outputs, neural_activate_array(), Layer::o, Layer::output, Layer::recurrent_function, Layer::temp, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
void neural_layer_lstm_free | ( | const struct Layer * | l | ) |
Free memory used by an LSTM layer.
[in] | l | The layer to be freed. |
Definition at line 373 of file neural_layer_lstm.c.
References free_layer_arrays(), layer_free(), Layer::mu, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Initialises a long short-term memory layer.
[in] | l | Layer to initialise. |
[in] | args | Parameters to initialise the layer. |
Definition at line 284 of file neural_layer_lstm.c.
References CONNECTED, Layer::decay, ArgsLayer::decay, ArgsLayer::eta, Layer::eta_max, Layer::function, ArgsLayer::function, layer_args_copy(), layer_args_opt(), layer_init(), LINEAR, malloc_layer_arrays(), Layer::max_neuron_grow, ArgsLayer::max_neuron_grow, Layer::max_outputs, Layer::momentum, ArgsLayer::momentum, Layer::mu, MU_TYPE, ArgsLayer::n_init, Layer::n_inputs, ArgsLayer::n_inputs, ArgsLayer::n_max, N_MU, Layer::n_outputs, Layer::options, Layer::out_c, Layer::out_h, Layer::out_w, Layer::recurrent_function, ArgsLayer::recurrent_function, sam_init(), set_eta(), set_layer_n_active(), set_layer_n_biases(), set_layer_n_weights(), ArgsLayer::type, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
char* neural_layer_lstm_json_export | ( | const struct Layer * | l, |
const bool | return_weights | ||
) |
Returns a json formatted string representation of an LSTM layer.
[in] | l | The layer to return. |
[in] | return_weights | Whether to returnprint the values of weights and biases. |
Definition at line 605 of file neural_layer_lstm.c.
References Layer::eta, Layer::function, layer_weight_json(), Layer::mu, Layer::n_inputs, N_MU, Layer::n_outputs, neural_activation_string(), Layer::recurrent_function, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_print().
size_t neural_layer_lstm_load | ( | struct Layer * | l, |
FILE * | fp | ||
) |
Reads an LSTM layer from a file.
[in] | l | The layer to load. |
[in] | fp | Pointer to the file to be read. |
Definition at line 709 of file neural_layer_lstm.c.
References Layer::c, Layer::cell, Layer::dc, Layer::decay, Layer::eta, Layer::eta_max, Layer::f, Layer::g, Layer::h, Layer::i, layer_load(), malloc_layer_arrays(), malloc_layers(), Layer::max_neuron_grow, Layer::max_outputs, Layer::momentum, Layer::mu, Layer::n_active, Layer::n_biases, Layer::n_inputs, N_MU, Layer::n_outputs, Layer::n_weights, Layer::o, Layer::options, Layer::out_c, Layer::out_h, Layer::out_w, Layer::prev_state, Layer::state, Layer::temp, Layer::temp2, Layer::temp3, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
bool neural_layer_lstm_mutate | ( | struct Layer * | l | ) |
Mutates an LSTM layer.
[in] | l | The layer to mutate. |
Definition at line 561 of file neural_layer_lstm.c.
References LAYER_EVOLVE_CONNECT, LAYER_EVOLVE_ETA, LAYER_EVOLVE_FUNCTIONS, LAYER_EVOLVE_NEURONS, LAYER_EVOLVE_WEIGHTS, layer_mutate_functions(), Layer::mu, MU_TYPE, mutate_connectivity(), mutate_eta(), mutate_neurons(), mutate_weights(), N_MU, Layer::options, and sam_adapt().
double* neural_layer_lstm_output | ( | const struct Layer * | l | ) |
Returns the output from an LSTM layer.
[in] | l | The layer whose output to return. |
Definition at line 550 of file neural_layer_lstm.c.
References Layer::output.
void neural_layer_lstm_print | ( | const struct Layer * | l, |
const bool | print_weights | ||
) |
Prints an LSTM layer.
[in] | l | The layer to print. |
[in] | print_weights | Whether to print the values of weights and biases. |
Definition at line 590 of file neural_layer_lstm.c.
References neural_layer_lstm_json_export().
void neural_layer_lstm_rand | ( | struct Layer * | l | ) |
Resizes an LSTM layer if the previous layer has changed size.
[in] | l | The layer to resize. |
[in] | prev | The layer previous to the one being resized. |
Definition at line 531 of file neural_layer_lstm.c.
References layer_resize(), Layer::n_inputs, Layer::n_outputs, set_layer_n_active(), set_layer_n_biases(), set_layer_n_weights(), Layer::uf, Layer::ug, Layer::ui, and Layer::uo.
size_t neural_layer_lstm_save | ( | const struct Layer * | l, |
FILE * | fp | ||
) |
Writes an LSTM layer to a file.
[in] | l | The layer to save. |
[in] | fp | Pointer to the file to be written. |
Definition at line 662 of file neural_layer_lstm.c.
References Layer::c, Layer::cell, Layer::dc, Layer::decay, Layer::eta, Layer::eta_max, Layer::f, Layer::g, Layer::h, Layer::i, layer_save(), Layer::max_neuron_grow, Layer::max_outputs, Layer::momentum, Layer::mu, Layer::n_active, Layer::n_biases, Layer::n_inputs, N_MU, Layer::n_outputs, Layer::n_weights, Layer::o, Layer::options, Layer::prev_state, Layer::state, Layer::temp, Layer::temp2, Layer::temp3, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
void neural_layer_lstm_update | ( | const struct Layer * | l | ) |
Updates the weights and biases of an LSTM layer.
[in] | l | The layer to update. |
Definition at line 511 of file neural_layer_lstm.c.
References Layer::eta, LAYER_SGD_WEIGHTS, layer_update(), Layer::options, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
|
static |
Zeros the deltas used to update an LSTM layer.
[in] | l | The layer whose deltas are to be reset. |
Definition at line 173 of file neural_layer_lstm.c.
References Layer::delta, Layer::n_outputs, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by neural_layer_lstm_backward().
|
static |
Sets the gradient descent rate used to update an LSTM layer.
[in] | l | The layer whose gradient descent rate is to be set. |
Definition at line 156 of file neural_layer_lstm.c.
References Layer::eta, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by mutate_eta(), and neural_layer_lstm_init().
|
static |
Sets the number of active (non-zero) weights in an LSTM layer.
[in] | l | The layer to update the number of active weights. |
Definition at line 76 of file neural_layer_lstm.c.
References Layer::n_active, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by mutate_connectivity(), mutate_neurons(), neural_layer_lstm_init(), and neural_layer_lstm_resize().
|
static |
Sets the total number of biases in an LSTM layer.
[in] | l | The layer to update the total number of biases. |
Definition at line 64 of file neural_layer_lstm.c.
References Layer::n_biases, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by mutate_neurons(), neural_layer_lstm_init(), and neural_layer_lstm_resize().
|
static |
Sets the total number of weights in an LSTM layer.
[in] | l | The layer to update the total number of weights. |
Definition at line 52 of file neural_layer_lstm.c.
References Layer::n_weights, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.
Referenced by mutate_neurons(), neural_layer_lstm_init(), and neural_layer_lstm_resize().
|
static |
Self-adaptation method for mutating an LSTM layer.
Definition at line 38 of file neural_layer_lstm.c.
Referenced by neural_layer_lstm_init(), and neural_layer_lstm_mutate().