XCSF  1.4.7
XCSF learning classifier system
neural_layer_lstm.h File Reference

An implementation of a long short-term memory layer. More...

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

Go to the source code of this file.

Functions

void neural_layer_lstm_init (struct Layer *l, const struct ArgsLayer *args)
 Initialises a long short-term memory layer. More...
 
struct Layerneural_layer_lstm_copy (const struct Layer *src)
 Initialises and creates a copy of one LSTM layer from another. 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_print (const struct Layer *l, const bool print_weights)
 Prints an LSTM layer. More...
 
bool neural_layer_lstm_mutate (struct Layer *l)
 Mutates an LSTM layer. More...
 
void neural_layer_lstm_free (const struct Layer *l)
 Free memory used by an LSTM layer. More...
 
double * neural_layer_lstm_output (const struct Layer *l)
 Returns the output from 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...
 
void neural_layer_lstm_resize (struct Layer *l, const struct Layer *prev)
 Resizes an LSTM layer if the previous layer has changed size. 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...
 

Variables

static struct LayerVtbl const layer_lstm_vtbl
 Neural long short-term memory layer implemented functions. More...
 

Detailed Description

An implementation of a long short-term memory layer.

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

Definition in file neural_layer_lstm.h.

Function Documentation

◆ neural_layer_lstm_backward()

void neural_layer_lstm_backward ( const struct Layer l,
const struct Net net,
const double *  input,
double *  delta 
)

Backward propagates an LSTM layer.

Parameters
[in]lThe layer to backward propagate.
[in]netNetwork containing the layer.
[in]inputThe input to the layer.
[out]deltaThe 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.

Here is the call graph for this function:

◆ neural_layer_lstm_copy()

struct Layer* neural_layer_lstm_copy ( const struct Layer src)

Initialises and creates a copy of one LSTM layer from another.

Parameters
[in]srcThe source layer.
Returns
A pointer to the new 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.

Here is the call graph for this function:

◆ neural_layer_lstm_forward()

void neural_layer_lstm_forward ( const struct Layer l,
const struct Net net,
const double *  input 
)

Forward propagates an LSTM layer.

Parameters
[in]lThe layer to forward propagate.
[in]netNetwork containing the layer.
[in]inputThe 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.

Here is the call graph for this function:

◆ neural_layer_lstm_free()

void neural_layer_lstm_free ( const struct Layer l)

Free memory used by an LSTM layer.

Parameters
[in]lThe 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.

Here is the call graph for this function:

◆ neural_layer_lstm_init()

void neural_layer_lstm_init ( struct Layer l,
const struct ArgsLayer args 
)

◆ neural_layer_lstm_json_export()

char* neural_layer_lstm_json_export ( const struct Layer l,
const bool  return_weights 
)

Returns a json formatted string representation of an LSTM layer.

Parameters
[in]lThe layer to return.
[in]return_weightsWhether to returnprint the values of weights and biases.
Returns
String encoded in json format.

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().

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

◆ neural_layer_lstm_load()

size_t neural_layer_lstm_load ( struct Layer l,
FILE *  fp 
)

Reads an LSTM layer from a file.

Parameters
[in]lThe layer to load.
[in]fpPointer to the file to be read.
Returns
The number of elements 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.

Here is the call graph for this function:

◆ neural_layer_lstm_mutate()

bool neural_layer_lstm_mutate ( struct Layer l)

Mutates an LSTM layer.

Parameters
[in]lThe layer to mutate.
Returns
Whether any alterations were made.

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().

Here is the call graph for this function:

◆ neural_layer_lstm_output()

double* neural_layer_lstm_output ( const struct Layer l)

Returns the output from an LSTM layer.

Parameters
[in]lThe layer whose output to return.
Returns
The layer output.

Definition at line 550 of file neural_layer_lstm.c.

References Layer::output.

◆ neural_layer_lstm_print()

void neural_layer_lstm_print ( const struct Layer l,
const bool  print_weights 
)

Prints an LSTM layer.

Parameters
[in]lThe layer to print.
[in]print_weightsWhether to print the values of weights and biases.

Definition at line 590 of file neural_layer_lstm.c.

References neural_layer_lstm_json_export().

Here is the call graph for this function:

◆ neural_layer_lstm_rand()

void neural_layer_lstm_rand ( struct Layer l)

Randomises an LSTM layer weights.

Parameters
[in]lThe layer to randomise.

Definition at line 400 of file neural_layer_lstm.c.

References layer_rand(), Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::wf, Layer::wg, Layer::wi, and Layer::wo.

Here is the call graph for this function:

◆ neural_layer_lstm_resize()

void neural_layer_lstm_resize ( struct Layer l,
const struct Layer prev 
)

Resizes an LSTM layer if the previous layer has changed size.

Parameters
[in]lThe layer to resize.
[in]prevThe 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.

Here is the call graph for this function:

◆ neural_layer_lstm_save()

size_t neural_layer_lstm_save ( const struct Layer l,
FILE *  fp 
)

Writes an LSTM layer to a file.

Parameters
[in]lThe layer to save.
[in]fpPointer to the file to be written.
Returns
The number of elements 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.

Here is the call graph for this function:

◆ neural_layer_lstm_update()

void neural_layer_lstm_update ( const struct Layer l)

Updates the weights and biases of an LSTM layer.

Parameters
[in]lThe 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.

Here is the call graph for this function:

Variable Documentation

◆ layer_lstm_vtbl

struct LayerVtbl const layer_lstm_vtbl
static
Initial value:
= {
}
void neural_layer_lstm_backward(const struct Layer *l, const struct Net *net, const double *input, double *delta)
Backward propagates an LSTM layer.
void neural_layer_lstm_rand(struct Layer *l)
Randomises an LSTM layer weights.
bool neural_layer_lstm_mutate(struct Layer *l)
Mutates an LSTM layer.
double * neural_layer_lstm_output(const struct Layer *l)
Returns the output from an LSTM layer.
void neural_layer_lstm_free(const struct Layer *l)
Free memory used by an LSTM layer.
struct Layer * neural_layer_lstm_copy(const struct Layer *src)
Initialises and creates a copy of one LSTM layer from another.
size_t neural_layer_lstm_load(struct Layer *l, FILE *fp)
Reads an LSTM layer from a file.
void neural_layer_lstm_resize(struct Layer *l, const struct Layer *prev)
Resizes an LSTM layer if the previous layer has changed size.
void neural_layer_lstm_print(const struct Layer *l, const bool print_weights)
Prints an LSTM layer.
size_t neural_layer_lstm_save(const struct Layer *l, FILE *fp)
Writes an LSTM layer to a file.
void neural_layer_lstm_update(const struct Layer *l)
Updates the weights and biases of an LSTM layer.
char * neural_layer_lstm_json_export(const struct Layer *l, const bool return_weights)
Returns a json formatted string representation of an LSTM layer.
void neural_layer_lstm_init(struct Layer *l, const struct ArgsLayer *args)
Initialises a long short-term memory layer.
void neural_layer_lstm_forward(const struct Layer *l, const struct Net *net, const double *input)
Forward propagates an LSTM layer.

Neural long short-term memory layer implemented functions.

Definition at line 70 of file neural_layer_lstm.h.

Referenced by layer_set_vptr().