XCSF  1.4.7
XCSF learning classifier system
neural_layer.h File Reference

Interface for neural network layers. More...

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

Go to the source code of this file.

Data Structures

struct  Layer
 Neural network layer data structure. More...
 
struct  LayerVtbl
 Neural network layer interface data structure. More...
 

Macros

#define CONNECTED   (0)
 Layer type connected. More...
 
#define DROPOUT   (1)
 Layer type dropout. More...
 
#define NOISE   (2)
 Layer type noise. More...
 
#define SOFTMAX   (3)
 Layer type softmax. More...
 
#define RECURRENT   (4)
 Layer type recurrent. More...
 
#define LSTM   (5)
 Layer type LSTM. More...
 
#define MAXPOOL   (6)
 Layer type maxpooling. More...
 
#define CONVOLUTIONAL   (7)
 Layer type convolutional. More...
 
#define AVGPOOL   (8)
 Layer type average pooling. More...
 
#define UPSAMPLE   (9)
 Layer type upsample. More...
 
#define STRING_CONNECTED   ("connected\0")
 Connected. More...
 
#define STRING_DROPOUT   ("dropout\0")
 Dropout. More...
 
#define STRING_NOISE   ("noise\0")
 Noise. More...
 
#define STRING_SOFTMAX   ("softmax\0")
 Softmax. More...
 
#define STRING_RECURRENT   ("recurrent\0")
 Recurrent. More...
 
#define STRING_LSTM   ("lstm\0")
 LSTM. More...
 
#define STRING_MAXPOOL   ("maxpool\0")
 Maxpool. More...
 
#define STRING_CONVOLUTIONAL   ("convolutional\0")
 Convolutional. More...
 
#define STRING_AVGPOOL   ("avgpool\0")
 Avgpool. More...
 
#define STRING_UPSAMPLE   ("upsample\0")
 Upsample. More...
 
#define LAYER_EVOLVE_WEIGHTS   (1 << 0)
 Layer may evolve weights. More...
 
#define LAYER_EVOLVE_NEURONS   (1 << 1)
 Layer may evolve neurons. More...
 
#define LAYER_EVOLVE_FUNCTIONS   (1 << 2)
 Layer may evolve functions. More...
 
#define LAYER_SGD_WEIGHTS   (1 << 3)
 Layer may perform gradient descent. More...
 
#define LAYER_EVOLVE_ETA   (1 << 4)
 Layer may evolve rate of gradient descent. More...
 
#define LAYER_EVOLVE_CONNECT   (1 << 5)
 Layer may evolve connectivity. More...
 
#define NEURON_MIN   (-100)
 Minimum neuron state. More...
 
#define NEURON_MAX   (100)
 Maximum neuron state. More...
 
#define WEIGHT_MIN   (-10)
 Minimum value of a weight or bias. More...
 
#define WEIGHT_MAX   (10)
 Maximum value of a weight or bias. More...
 
#define N_WEIGHTS_MAX   (20000000)
 Maximum number of weights per layer. More...
 
#define N_INPUTS_MAX   (2000000)
 Maximum number of inputs per layer. More...
 
#define N_OUTPUTS_MAX   (2000000)
 Maximum number of outputs per layer. More...
 
#define WEIGHT_SD_INIT   (0.1)
 Std dev of Gaussian for weight initialisation. More...
 
#define WEIGHT_SD   (0.1)
 Std dev of Gaussian for weight resizing. More...
 
#define WEIGHT_SD_RAND   (1.0)
 Std dev of Gaussian for weight randomising. More...
 

Functions

static double * layer_output (const struct Layer *l)
 Returns the outputs of a layer. More...
 
static void layer_forward (const struct Layer *l, const struct Net *net, const double *input)
 Forward propagates an input through the layer. More...
 
static void layer_backward (const struct Layer *l, const struct Net *net, const double *input, double *delta)
 Backward propagates the error through a layer. More...
 
static void layer_update (const struct Layer *l)
 Updates the weights and biases of a layer. More...
 
static bool layer_mutate (struct Layer *l)
 Performs layer mutation. More...
 
static void layer_resize (struct Layer *l, const struct Layer *prev)
 Resizes a layer using the previous layer's inputs. More...
 
static struct Layerlayer_copy (const struct Layer *src)
 Creates and returns a copy of a specified layer. More...
 
static void layer_free (const struct Layer *l)
 Frees the memory used by the layer. More...
 
static void layer_rand (struct Layer *l)
 Randomises a layer. More...
 
static void layer_print (const struct Layer *l, const bool print_weights)
 Prints the layer. More...
 
static char * layer_json_export (const struct Layer *l, const bool return_weights)
 Returns a json formatted string representation of a layer. More...
 
bool layer_mutate_connectivity (struct Layer *l, const double mu_enable, const double mu_disable)
 Mutates a layer's connectivity by zeroing weights. More...
 
bool layer_mutate_eta (struct Layer *l, const double mu)
 Mutates the gradient descent rate of a neural layer. More...
 
bool layer_mutate_functions (struct Layer *l, const double mu)
 Mutates a layer's activation function by random selection. More...
 
bool layer_mutate_weights (struct Layer *l, const double mu)
 Mutates a layer's weights and biases by adding random numbers from a Gaussian normal distribution with zero mean and standard deviation equal to the mutation rate. More...
 
int layer_mutate_neurons (const struct Layer *l, const double mu)
 Returns the number of neurons to add or remove from a layer. More...
 
void layer_add_neurons (struct Layer *l, const int n)
 Adds N neurons to a layer. Negative N removes neurons. More...
 
void layer_calc_n_active (struct Layer *l)
 Recalculates the number of active connections within a layer. More...
 
void layer_defaults (struct Layer *l)
 Initialises a layer to default values. More...
 
void layer_init_eta (struct Layer *l)
 Initialises a layer's gradient descent rate. More...
 
void layer_set_vptr (struct Layer *l)
 Sets a neural network layer's functions to the implementations. More...
 
void layer_weight_clamp (const struct Layer *l)
 Clamps a layer's weights and biases in range [WEIGHT_MIN, WEIGHT_MAX]. More...
 
void layer_weight_print (const struct Layer *l, const bool print_weights)
 Prints a layer's weights and biases. More...
 
char * layer_weight_json (const struct Layer *l, const bool return_weights)
 Returns a json formatted string representation of a layer's weights. More...
 
void layer_weight_rand (struct Layer *l)
 Randomises a layer's weights and biases. More...
 
void layer_ensure_input_represention (struct Layer *l)
 Ensures that each neuron is connected to at least one input and each input is connected to at least one neuron. More...
 
const char * layer_type_as_string (const int type)
 Returns a string representation of a layer type from an integer. More...
 
int layer_type_as_int (const char *type)
 Returns the integer representation of a layer type given a name. More...
 
bool layer_receives_images (const int type)
 Returns a whether a layer type expects images as input. More...
 
void layer_guard_biases (const struct Layer *l)
 Check number of biases is within bounds. More...
 
void layer_guard_outputs (const struct Layer *l)
 Check number of outputs is within bounds. More...
 
void layer_guard_weights (const struct Layer *l)
 Check number of weights is within bounds. More...
 
static struct Layerlayer_init (const struct ArgsLayer *args)
 Creates and initialises a new layer. More...
 
static size_t layer_save (const struct Layer *l, FILE *fp)
 Writes the layer to a file. More...
 
static size_t layer_load (struct Layer *l, FILE *fp)
 Reads the layer from a file. More...
 

Detailed Description

Interface for neural network layers.

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

Definition in file neural_layer.h.

Macro Definition Documentation

◆ AVGPOOL

#define AVGPOOL   (8)

Layer type average pooling.

Definition at line 37 of file neural_layer.h.

◆ CONNECTED

#define CONNECTED   (0)

Layer type connected.

Definition at line 29 of file neural_layer.h.

◆ CONVOLUTIONAL

#define CONVOLUTIONAL   (7)

Layer type convolutional.

Definition at line 36 of file neural_layer.h.

◆ DROPOUT

#define DROPOUT   (1)

Layer type dropout.

Definition at line 30 of file neural_layer.h.

◆ LAYER_EVOLVE_CONNECT

#define LAYER_EVOLVE_CONNECT   (1 << 5)

Layer may evolve connectivity.

Definition at line 56 of file neural_layer.h.

◆ LAYER_EVOLVE_ETA

#define LAYER_EVOLVE_ETA   (1 << 4)

Layer may evolve rate of gradient descent.

Definition at line 55 of file neural_layer.h.

◆ LAYER_EVOLVE_FUNCTIONS

#define LAYER_EVOLVE_FUNCTIONS   (1 << 2)

Layer may evolve functions.

Definition at line 53 of file neural_layer.h.

◆ LAYER_EVOLVE_NEURONS

#define LAYER_EVOLVE_NEURONS   (1 << 1)

Layer may evolve neurons.

Definition at line 52 of file neural_layer.h.

◆ LAYER_EVOLVE_WEIGHTS

#define LAYER_EVOLVE_WEIGHTS   (1 << 0)

Layer may evolve weights.

Definition at line 51 of file neural_layer.h.

◆ LAYER_SGD_WEIGHTS

#define LAYER_SGD_WEIGHTS   (1 << 3)

Layer may perform gradient descent.

Definition at line 54 of file neural_layer.h.

◆ LSTM

#define LSTM   (5)

Layer type LSTM.

Definition at line 34 of file neural_layer.h.

◆ MAXPOOL

#define MAXPOOL   (6)

Layer type maxpooling.

Definition at line 35 of file neural_layer.h.

◆ N_INPUTS_MAX

#define N_INPUTS_MAX   (2000000)

Maximum number of inputs per layer.

Definition at line 63 of file neural_layer.h.

◆ N_OUTPUTS_MAX

#define N_OUTPUTS_MAX   (2000000)

Maximum number of outputs per layer.

Definition at line 64 of file neural_layer.h.

◆ N_WEIGHTS_MAX

#define N_WEIGHTS_MAX   (20000000)

Maximum number of weights per layer.

Definition at line 62 of file neural_layer.h.

◆ NEURON_MAX

#define NEURON_MAX   (100)

Maximum neuron state.

Definition at line 59 of file neural_layer.h.

◆ NEURON_MIN

#define NEURON_MIN   (-100)

Minimum neuron state.

Definition at line 58 of file neural_layer.h.

◆ NOISE

#define NOISE   (2)

Layer type noise.

Definition at line 31 of file neural_layer.h.

◆ RECURRENT

#define RECURRENT   (4)

Layer type recurrent.

Definition at line 33 of file neural_layer.h.

◆ SOFTMAX

#define SOFTMAX   (3)

Layer type softmax.

Definition at line 32 of file neural_layer.h.

◆ STRING_AVGPOOL

#define STRING_AVGPOOL   ("avgpool\0")

Avgpool.

Definition at line 48 of file neural_layer.h.

◆ STRING_CONNECTED

#define STRING_CONNECTED   ("connected\0")

Connected.

Definition at line 40 of file neural_layer.h.

◆ STRING_CONVOLUTIONAL

#define STRING_CONVOLUTIONAL   ("convolutional\0")

Convolutional.

Definition at line 47 of file neural_layer.h.

◆ STRING_DROPOUT

#define STRING_DROPOUT   ("dropout\0")

Dropout.

Definition at line 41 of file neural_layer.h.

◆ STRING_LSTM

#define STRING_LSTM   ("lstm\0")

LSTM.

Definition at line 45 of file neural_layer.h.

◆ STRING_MAXPOOL

#define STRING_MAXPOOL   ("maxpool\0")

Maxpool.

Definition at line 46 of file neural_layer.h.

◆ STRING_NOISE

#define STRING_NOISE   ("noise\0")

Noise.

Definition at line 42 of file neural_layer.h.

◆ STRING_RECURRENT

#define STRING_RECURRENT   ("recurrent\0")

Recurrent.

Definition at line 44 of file neural_layer.h.

◆ STRING_SOFTMAX

#define STRING_SOFTMAX   ("softmax\0")

Softmax.

Definition at line 43 of file neural_layer.h.

◆ STRING_UPSAMPLE

#define STRING_UPSAMPLE   ("upsample\0")

Upsample.

Definition at line 49 of file neural_layer.h.

◆ UPSAMPLE

#define UPSAMPLE   (9)

Layer type upsample.

Definition at line 38 of file neural_layer.h.

◆ WEIGHT_MAX

#define WEIGHT_MAX   (10)

Maximum value of a weight or bias.

Definition at line 61 of file neural_layer.h.

◆ WEIGHT_MIN

#define WEIGHT_MIN   (-10)

Minimum value of a weight or bias.

Definition at line 60 of file neural_layer.h.

◆ WEIGHT_SD

#define WEIGHT_SD   (0.1)

Std dev of Gaussian for weight resizing.

Definition at line 67 of file neural_layer.h.

◆ WEIGHT_SD_INIT

#define WEIGHT_SD_INIT   (0.1)

Std dev of Gaussian for weight initialisation.

Definition at line 66 of file neural_layer.h.

◆ WEIGHT_SD_RAND

#define WEIGHT_SD_RAND   (1.0)

Std dev of Gaussian for weight randomising.

Definition at line 68 of file neural_layer.h.

Function Documentation

◆ layer_add_neurons()

void layer_add_neurons ( struct Layer l,
const int  N 
)

Adds N neurons to a layer. Negative N removes neurons.

Precondition
N must be appropriately bounds checked for the layer.
Parameters
[in]lThe neural network layer to mutate.
[in]NThe number of neurons to add.

Definition at line 130 of file neural_layer.c.

References Layer::bias_updates, Layer::biases, Layer::delta, layer_calc_n_active(), LAYER_EVOLVE_CONNECT, layer_guard_outputs(), layer_guard_weights(), Layer::n_biases, Layer::n_inputs, Layer::n_outputs, Layer::n_weights, Layer::options, Layer::output, rand_normal(), rand_uniform(), Layer::state, Layer::weight_active, WEIGHT_SD, Layer::weight_updates, and Layer::weights.

Referenced by mutate_neurons(), and neural_layer_connected_mutate().

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

◆ layer_backward()

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

Backward propagates the error through a layer.

Parameters
[in]lThe layer to be backward propagated.
[in]netNetwork containing the layer.
[in]inputThe input to the layer.
[out]deltaThe previous layer's delta.

Definition at line 194 of file neural_layer.h.

References Layer::delta, LayerVtbl::layer_impl_backward, and Layer::layer_vptr.

Referenced by neural_layer_lstm_backward(), neural_layer_recurrent_backward(), and neural_learn().

Here is the caller graph for this function:

◆ layer_calc_n_active()

void layer_calc_n_active ( struct Layer l)

Recalculates the number of active connections within a layer.

Parameters
[in]lThe layer to recalculate the number of active connections.

Definition at line 384 of file neural_layer.c.

References Layer::n_active, Layer::n_weights, and Layer::weight_active.

Referenced by layer_add_neurons(), neural_layer_connected_resize(), neural_layer_convolutional_add_filters(), and neural_layer_convolutional_resize().

Here is the caller graph for this function:

◆ layer_copy()

static struct Layer* layer_copy ( const struct Layer src)
static

Creates and returns a copy of a specified layer.

Parameters
[in]srcThe source layer.
Returns
A new copied layer.

Definition at line 239 of file neural_layer.h.

References LayerVtbl::layer_impl_copy, and Layer::layer_vptr.

Referenced by neural_copy(), neural_layer_lstm_copy(), and neural_layer_recurrent_copy().

Here is the caller graph for this function:

◆ layer_defaults()

void layer_defaults ( struct Layer l)

Initialises a layer to default values.

Parameters
[in]lThe layer to initialise.

Definition at line 413 of file neural_layer.c.

References Layer::bias_updates, Layer::biases, Layer::c, Layer::cell, Layer::channels, Layer::dc, Layer::decay, Layer::delta, Layer::eta, Layer::eta_max, Layer::eta_min, Layer::f, Layer::function, Layer::g, Layer::h, Layer::height, Layer::i, Layer::indexes, Layer::input_layer, Layer::layer_vptr, Layer::max_neuron_grow, Layer::max_outputs, Layer::momentum, Layer::mu, Layer::n_active, Layer::n_biases, Layer::n_filters, Layer::n_inputs, Layer::n_outputs, Layer::n_weights, Layer::o, Layer::options, Layer::out_c, Layer::out_h, Layer::out_w, Layer::output, Layer::output_layer, Layer::pad, Layer::prev_cell, Layer::prev_state, Layer::probability, Layer::recurrent_function, Layer::scale, Layer::self_layer, Layer::size, Layer::state, Layer::stride, Layer::temp, Layer::temp2, Layer::temp3, Layer::type, Layer::uf, Layer::ug, Layer::ui, Layer::uo, Layer::weight_active, Layer::weight_updates, Layer::weights, Layer::wf, Layer::wg, Layer::wi, Layer::width, and Layer::wo.

Referenced by layer_init(), layer_load(), neural_layer_avgpool_copy(), neural_layer_connected_copy(), neural_layer_convolutional_copy(), neural_layer_dropout_copy(), neural_layer_lstm_copy(), neural_layer_maxpool_copy(), neural_layer_noise_copy(), neural_layer_recurrent_copy(), neural_layer_softmax_copy(), and neural_layer_upsample_copy().

Here is the caller graph for this function:

◆ layer_ensure_input_represention()

void layer_ensure_input_represention ( struct Layer l)

Ensures that each neuron is connected to at least one input and each input is connected to at least one neuron.

Parameters
[in]lA neural network layer.

Definition at line 204 of file neural_layer.c.

References Layer::n_active, Layer::n_inputs, Layer::n_outputs, rand_normal(), rand_uniform_int(), Layer::weight_active, WEIGHT_SD, and Layer::weights.

Referenced by neural_layer_connected_mutate(), and neural_layer_connected_resize().

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

◆ layer_forward()

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

Forward propagates an input through the layer.

Parameters
[in]lLayer to be forward propagated.
[in]netNetwork containing the layer.
[in]inputInput to the layer.

Definition at line 181 of file neural_layer.h.

References LayerVtbl::layer_impl_forward, and Layer::layer_vptr.

Referenced by neural_layer_lstm_forward(), neural_layer_recurrent_forward(), and neural_propagate().

Here is the caller graph for this function:

◆ layer_free()

static void layer_free ( const struct Layer l)
static

Frees the memory used by the layer.

Parameters
[in]lThe layer to be freed.

Definition at line 249 of file neural_layer.h.

References LayerVtbl::layer_impl_free, and Layer::layer_vptr.

Referenced by neural_free(), neural_layer_lstm_free(), neural_layer_recurrent_free(), and neural_remove().

Here is the caller graph for this function:

◆ layer_guard_biases()

void layer_guard_biases ( const struct Layer l)

Check number of biases is within bounds.

Parameters
[in]lLayer to check.

Definition at line 581 of file neural_layer.c.

References layer_print(), Layer::n_biases, and N_OUTPUTS_MAX.

Referenced by guard_malloc().

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

◆ layer_guard_outputs()

void layer_guard_outputs ( const struct Layer l)

Check number of outputs is within bounds.

Parameters
[in]lLayer to check.

Definition at line 595 of file neural_layer.c.

References layer_print(), Layer::n_outputs, and N_OUTPUTS_MAX.

Referenced by guard_malloc(), layer_add_neurons(), malloc_layer_arrays(), and realloc_layer_arrays().

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

◆ layer_guard_weights()

void layer_guard_weights ( const struct Layer l)

Check number of weights is within bounds.

Parameters
[in]lLayer to check.

Definition at line 609 of file neural_layer.c.

References layer_print(), Layer::n_weights, and N_WEIGHTS_MAX.

Referenced by guard_malloc(), layer_add_neurons(), and malloc_layer_arrays().

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

◆ layer_init()

static struct Layer* layer_init ( const struct ArgsLayer args)
static

Creates and initialises a new layer.

Parameters
[in]argsLayer parameters used to initialise the layer.
Returns
A pointer to the new layer.

Definition at line 356 of file neural_layer.h.

References layer_defaults(), LayerVtbl::layer_impl_init, layer_set_vptr(), Layer::layer_vptr, Layer::type, and ArgsLayer::type.

Referenced by neural_create(), neural_layer_lstm_init(), neural_layer_recurrent_init(), pred_neural_ae_to_classifier(), and pred_neural_expand().

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

◆ layer_init_eta()

void layer_init_eta ( struct Layer l)

Initialises a layer's gradient descent rate.

Parameters
[in]lThe layer to initialise.

Definition at line 399 of file neural_layer.c.

References Layer::eta, Layer::eta_max, Layer::eta_min, LAYER_EVOLVE_ETA, Layer::options, and rand_uniform().

Referenced by neural_layer_connected_init(), and neural_layer_convolutional_init().

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

◆ layer_json_export()

static char* layer_json_export ( const struct Layer l,
const bool  return_weights 
)
static

Returns a json formatted string representation of a layer.

Parameters
[in]lThe layer to be returned.
[in]return_weightsWhether to return the weights.

Definition at line 281 of file neural_layer.h.

References LayerVtbl::layer_impl_json_export, and Layer::layer_vptr.

Referenced by neural_json_export().

Here is the caller graph for this function:

◆ layer_load()

static size_t layer_load ( struct Layer l,
FILE *  fp 
)
static

Reads the layer from a file.

Parameters
[in]lThe layer to be read.
[in]fpPointer to the file to be read.
Returns
The number of elements read.

Definition at line 387 of file neural_layer.h.

References layer_defaults(), LayerVtbl::layer_impl_load, layer_set_vptr(), Layer::layer_vptr, and Layer::type.

Referenced by neural_layer_lstm_load(), neural_layer_recurrent_load(), and neural_load().

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

◆ layer_mutate()

static bool layer_mutate ( struct Layer l)
static

Performs layer mutation.

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

Definition at line 216 of file neural_layer.h.

References LayerVtbl::layer_impl_mutate, and Layer::layer_vptr.

Referenced by neural_mutate().

Here is the caller graph for this function:

◆ layer_mutate_connectivity()

bool layer_mutate_connectivity ( struct Layer l,
const double  mu_enable,
const double  mu_disable 
)

Mutates a layer's connectivity by zeroing weights.

Parameters
[in]lThe neural network layer to mutate.
[in]mu_enableProbability of enabling a currently disabled weight.
[in]mu_disableProbability of disabling a currently enabled weight.
Returns
Whether any alterations were made.

Definition at line 176 of file neural_layer.c.

References Layer::n_active, Layer::n_inputs, Layer::n_outputs, Layer::n_weights, rand_normal(), rand_uniform(), Layer::weight_active, WEIGHT_SD, and Layer::weights.

Referenced by mutate_connectivity(), neural_layer_connected_mutate(), and neural_layer_convolutional_mutate().

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

◆ layer_mutate_eta()

bool layer_mutate_eta ( struct Layer l,
const double  mu 
)

Mutates the gradient descent rate of a neural layer.

Parameters
[in]lThe neural network layer to mutate.
[in]muThe rate of mutation.
Returns
Whether any alterations were made.

Definition at line 88 of file neural_layer.c.

References clamp(), Layer::eta, Layer::eta_max, Layer::eta_min, and rand_normal().

Referenced by mutate_eta(), neural_layer_connected_mutate(), and neural_layer_convolutional_mutate().

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

◆ layer_mutate_functions()

bool layer_mutate_functions ( struct Layer l,
const double  mu 
)

Mutates a layer's activation function by random selection.

Parameters
[in]lThe neural network layer to mutate.
[in]muThe rate of mutation.
Returns
Whether any alterations were made.

Definition at line 283 of file neural_layer.c.

References Layer::function, LSTM, NUM_ACTIVATIONS, rand_uniform(), rand_uniform_int(), Layer::recurrent_function, and Layer::type.

Referenced by mutate_functions(), neural_layer_connected_mutate(), neural_layer_convolutional_mutate(), and neural_layer_lstm_mutate().

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

◆ layer_mutate_neurons()

int layer_mutate_neurons ( const struct Layer l,
const double  mu 
)

Returns the number of neurons to add or remove from a layer.

Parameters
[in]lThe neural network layer to mutate.
[in]muThe rate of mutation.
Returns
The number of neurons to be added or removed.

Definition at line 106 of file neural_layer.c.

References clamp(), Layer::max_neuron_grow, Layer::max_outputs, Layer::n_outputs, rand_normal(), and rand_uniform().

Referenced by mutate_neurons(), and neural_layer_connected_mutate().

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

◆ layer_mutate_weights()

bool layer_mutate_weights ( struct Layer l,
const double  mu 
)

Mutates a layer's weights and biases by adding random numbers from a Gaussian normal distribution with zero mean and standard deviation equal to the mutation rate.

Parameters
[in]lThe neural network layer to mutate.
[in]muThe rate of mutation.
Returns
Whether any alterations were made.

Definition at line 252 of file neural_layer.c.

References Layer::biases, clamp(), Layer::n_biases, Layer::n_weights, rand_normal(), Layer::weight_active, WEIGHT_MAX, WEIGHT_MIN, and Layer::weights.

Referenced by mutate_weights(), neural_layer_connected_mutate(), and neural_layer_convolutional_mutate().

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

◆ layer_output()

static double* layer_output ( const struct Layer l)
static

Returns the outputs of a layer.

Parameters
[in]lThe layer whose outputs are to be returned.
Returns
The layer outputs.

Definition at line 169 of file neural_layer.h.

References LayerVtbl::layer_impl_output, and Layer::layer_vptr.

Referenced by neural_output(), neural_outputs(), and neural_propagate().

Here is the caller graph for this function:

◆ layer_print()

static void layer_print ( const struct Layer l,
const bool  print_weights 
)
static

Prints the layer.

Parameters
[in]lThe layer to be printed.
[in]print_weightsWhether to print the weights.

Definition at line 270 of file neural_layer.h.

References LayerVtbl::layer_impl_print, and Layer::layer_vptr.

Referenced by get_workspace_size(), layer_guard_biases(), layer_guard_outputs(), layer_guard_weights(), max_pool(), and neural_layer_connected_resize().

Here is the caller graph for this function:

◆ layer_rand()

static void layer_rand ( struct Layer l)
static

Randomises a layer.

Parameters
[in]lThe layer to be randomised.

Definition at line 259 of file neural_layer.h.

References LayerVtbl::layer_impl_rand, and Layer::layer_vptr.

Referenced by neural_layer_lstm_rand(), neural_layer_recurrent_rand(), and neural_rand().

Here is the caller graph for this function:

◆ layer_receives_images()

bool layer_receives_images ( const int  type)

Returns a whether a layer type expects images as input.

Parameters
[in]typeInteger representation of a layer type.
Returns
Whether images (height × width × channels) are expected as inputs.

Definition at line 521 of file neural_layer.c.

References AVGPOOL, CONVOLUTIONAL, MAXPOOL, and UPSAMPLE.

Referenced by layer_args_json_export_inputs(), and layer_args_validate_inputs().

Here is the caller graph for this function:

◆ layer_resize()

static void layer_resize ( struct Layer l,
const struct Layer prev 
)
static

Resizes a layer using the previous layer's inputs.

Parameters
[in]lThe layer to mutate.
[in]prevThe layer prior to the one being mutated.
Returns
Whether any alterations were made.

Definition at line 228 of file neural_layer.h.

References LayerVtbl::layer_impl_resize, and Layer::layer_vptr.

Referenced by mutate_neurons(), neural_layer_lstm_resize(), neural_layer_recurrent_resize(), neural_mutate(), and neural_resize().

Here is the caller graph for this function:

◆ layer_save()

static size_t layer_save ( const struct Layer l,
FILE *  fp 
)
static

Writes the layer to a file.

Parameters
[in]lThe layer to be written.
[in]fpPointer to the file to be written.
Returns
The number of elements written.

Definition at line 373 of file neural_layer.h.

References LayerVtbl::layer_impl_save, Layer::layer_vptr, and Layer::type.

Referenced by neural_layer_lstm_save(), neural_layer_recurrent_save(), and neural_save().

Here is the caller graph for this function:

◆ layer_set_vptr()

void layer_set_vptr ( struct Layer l)

Sets a neural network layer's functions to the implementations.

Parameters
[in]lThe neural network layer to set.

Definition at line 42 of file neural_layer.c.

References AVGPOOL, CONNECTED, CONVOLUTIONAL, DROPOUT, layer_avgpool_vtbl, layer_connected_vtbl, layer_convolutional_vtbl, layer_dropout_vtbl, layer_lstm_vtbl, layer_maxpool_vtbl, layer_noise_vtbl, layer_recurrent_vtbl, layer_softmax_vtbl, layer_upsample_vtbl, Layer::layer_vptr, LSTM, MAXPOOL, NOISE, RECURRENT, SOFTMAX, Layer::type, and UPSAMPLE.

Referenced by layer_init(), and layer_load().

Here is the caller graph for this function:

◆ layer_type_as_int()

int layer_type_as_int ( const char *  type)

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

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

Definition at line 540 of file neural_layer.c.

References AVGPOOL, CONNECTED, CONVOLUTIONAL, DROPOUT, LSTM, MAXPOOL, NOISE, RECURRENT, SOFTMAX, STRING_AVGPOOL, STRING_CONNECTED, STRING_CONVOLUTIONAL, STRING_DROPOUT, STRING_LSTM, STRING_MAXPOOL, STRING_NOISE, STRING_RECURRENT, STRING_SOFTMAX, STRING_UPSAMPLE, and UPSAMPLE.

Referenced by layer_args_json_import().

Here is the caller graph for this function:

◆ layer_type_as_string()

const char* layer_type_as_string ( const int  type)

Returns a string representation of a layer type from an integer.

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

Definition at line 486 of file neural_layer.c.

References AVGPOOL, CONNECTED, CONVOLUTIONAL, DROPOUT, LSTM, MAXPOOL, NOISE, RECURRENT, SOFTMAX, STRING_AVGPOOL, STRING_CONNECTED, STRING_CONVOLUTIONAL, STRING_DROPOUT, STRING_LSTM, STRING_MAXPOOL, STRING_NOISE, STRING_RECURRENT, STRING_SOFTMAX, STRING_UPSAMPLE, and UPSAMPLE.

Referenced by layer_args_json_export().

Here is the caller graph for this function:

◆ layer_update()

static void layer_update ( const struct Layer l)
static

Updates the weights and biases of a layer.

Parameters
[in]lThe layer to be updated.

Definition at line 205 of file neural_layer.h.

References LayerVtbl::layer_impl_update, and Layer::layer_vptr.

Referenced by neural_layer_lstm_update(), neural_layer_recurrent_update(), and neural_learn().

Here is the caller graph for this function:

◆ layer_weight_clamp()

void layer_weight_clamp ( const struct Layer l)

Clamps a layer's weights and biases in range [WEIGHT_MIN, WEIGHT_MAX].

Parameters
[in]lThe neural network layer to clamp.

Definition at line 365 of file neural_layer.c.

References Layer::biases, clamp(), Layer::n_biases, Layer::n_weights, Layer::weight_active, WEIGHT_MAX, WEIGHT_MIN, and Layer::weights.

Referenced by neural_layer_connected_update(), and neural_layer_convolutional_update().

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

◆ layer_weight_json()

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

Returns a json formatted string representation of a layer's weights.

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

Definition at line 324 of file neural_layer.c.

References Layer::biases, Layer::n_active, Layer::n_biases, Layer::n_weights, and Layer::weights.

Referenced by layer_weight_print(), neural_layer_connected_json_export(), neural_layer_convolutional_json_export(), neural_layer_lstm_json_export(), and neural_layer_recurrent_json_export().

Here is the caller graph for this function:

◆ layer_weight_print()

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

Prints a layer's weights and biases.

Parameters
[in]lThe neural network layer to print.
[in]print_weightsWhether to print each individual weight and bias.

Definition at line 309 of file neural_layer.c.

References layer_weight_json().

Here is the call graph for this function:

◆ layer_weight_rand()

void layer_weight_rand ( struct Layer l)

Randomises a layer's weights and biases.

Parameters
[in]lThe neural network layer to randomise.

Definition at line 348 of file neural_layer.c.

References Layer::biases, Layer::n_active, Layer::n_biases, Layer::n_weights, rand_normal(), Layer::weight_active, WEIGHT_SD_RAND, and Layer::weights.

Referenced by neural_layer_connected_rand(), and neural_layer_convolutional_rand().

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