XCSF  1.4.7
XCSF learning classifier system
neural_layer_avgpool.c File Reference

An implementation of an average pooling layer. More...

#include "neural_layer_avgpool.h"
#include "neural_activations.h"
#include "utils.h"
Include dependency graph for neural_layer_avgpool.c:

Go to the source code of this file.

Functions

static void malloc_layer_arrays (struct Layer *l)
 Allocate memory used by an average pooling layer. More...
 
static void realloc_layer_arrays (struct Layer *l)
 Resize memory used by an average pooling layer. More...
 
void neural_layer_avgpool_free (const struct Layer *l)
 Free memory used by an average pooling layer. More...
 
void neural_layer_avgpool_init (struct Layer *l, const struct ArgsLayer *args)
 Initialises an average pooling layer. More...
 
struct Layerneural_layer_avgpool_copy (const struct Layer *src)
 Initialises and copies one average pooling layer from another. More...
 
void neural_layer_avgpool_rand (struct Layer *l)
 Dummy function since average pooling layers have no weights. More...
 
void neural_layer_avgpool_forward (const struct Layer *l, const struct Net *net, const double *input)
 Forward propagates an average pooling layer. More...
 
void neural_layer_avgpool_backward (const struct Layer *l, const struct Net *net, const double *input, double *delta)
 Backward propagates an average pooling layer. More...
 
void neural_layer_avgpool_update (const struct Layer *l)
 Dummy function since average pooling layers have no weights. More...
 
bool neural_layer_avgpool_mutate (struct Layer *l)
 Dummy function since average pooling layers cannot be mutated. More...
 
void neural_layer_avgpool_resize (struct Layer *l, const struct Layer *prev)
 Resizes an avg pooling layer if the previous layer has changed size. More...
 
double * neural_layer_avgpool_output (const struct Layer *l)
 Returns the output from an average pooling layer. More...
 
void neural_layer_avgpool_print (const struct Layer *l, const bool print_weights)
 Prints an average pooling layer. More...
 
char * neural_layer_avgpool_json_export (const struct Layer *l, const bool return_weights)
 Returns a json formatted string of an average pool layer. More...
 
size_t neural_layer_avgpool_save (const struct Layer *l, FILE *fp)
 Writes an average pooling layer to a file. More...
 
size_t neural_layer_avgpool_load (struct Layer *l, FILE *fp)
 Reads an average pooling layer from a file. More...
 

Detailed Description

An implementation of an average pooling layer.

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

Definition in file neural_layer_avgpool.c.

Function Documentation

◆ malloc_layer_arrays()

static void malloc_layer_arrays ( struct Layer l)
static

Allocate memory used by an average pooling layer.

Parameters
[in]lThe layer to be allocated memory.

Definition at line 33 of file neural_layer_avgpool.c.

References Layer::delta, layer_guard_outputs(), Layer::n_outputs, and Layer::output.

Referenced by neural_layer_avgpool_copy(), neural_layer_avgpool_init(), and neural_layer_avgpool_load().

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

◆ neural_layer_avgpool_backward()

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

Backward propagates an average pooling 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 151 of file neural_layer_avgpool.c.

References Layer::channels, Layer::delta, Layer::height, Layer::i, and Layer::width.

◆ neural_layer_avgpool_copy()

struct Layer* neural_layer_avgpool_copy ( const struct Layer src)

Initialises and copies one average pooling layer from another.

Parameters
[in]srcThe source layer.
Returns
A pointer to the new layer.

Definition at line 89 of file neural_layer_avgpool.c.

References AVGPOOL, Layer::channels, Layer::height, layer_defaults(), Layer::layer_vptr, malloc_layer_arrays(), Layer::max_outputs, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, Layer::type, and Layer::width.

Here is the call graph for this function:

◆ neural_layer_avgpool_forward()

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

Forward propagates an average pooling layer.

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

Definition at line 129 of file neural_layer_avgpool.c.

References Layer::channels, Layer::height, Layer::i, Layer::output, and Layer::width.

◆ neural_layer_avgpool_free()

void neural_layer_avgpool_free ( const struct Layer l)

Free memory used by an average pooling layer.

Parameters
[in]lThe layer to be freed.

Definition at line 57 of file neural_layer_avgpool.c.

References Layer::delta, and Layer::output.

◆ neural_layer_avgpool_init()

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

Initialises an average pooling layer.

Parameters
[in]lLayer to initialise.
[in]argsParameters to initialise the layer.

Definition at line 69 of file neural_layer_avgpool.c.

References Layer::channels, ArgsLayer::channels, Layer::height, ArgsLayer::height, malloc_layer_arrays(), Layer::max_outputs, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, Layer::width, and ArgsLayer::width.

Here is the call graph for this function:

◆ neural_layer_avgpool_json_export()

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

Returns a json formatted string of an average pool layer.

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 241 of file neural_layer_avgpool.c.

References Layer::channels, Layer::height, Layer::n_inputs, Layer::n_outputs, and Layer::width.

Referenced by neural_layer_avgpool_print().

Here is the caller graph for this function:

◆ neural_layer_avgpool_load()

size_t neural_layer_avgpool_load ( struct Layer l,
FILE *  fp 
)

Reads an average pooling 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 286 of file neural_layer_avgpool.c.

References Layer::channels, Layer::height, malloc_layer_arrays(), Layer::max_outputs, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, and Layer::width.

Here is the call graph for this function:

◆ neural_layer_avgpool_mutate()

bool neural_layer_avgpool_mutate ( struct Layer l)

Dummy function since average pooling layers cannot be mutated.

Parameters
[in]lAn average pooling layer.
Returns
False.

Definition at line 182 of file neural_layer_avgpool.c.

◆ neural_layer_avgpool_output()

double* neural_layer_avgpool_output ( const struct Layer l)

Returns the output from an average pooling layer.

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

Definition at line 215 of file neural_layer_avgpool.c.

References Layer::output.

◆ neural_layer_avgpool_print()

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

Prints an average pooling layer.

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

Definition at line 226 of file neural_layer_avgpool.c.

References neural_layer_avgpool_json_export().

Here is the call graph for this function:

◆ neural_layer_avgpool_rand()

void neural_layer_avgpool_rand ( struct Layer l)

Dummy function since average pooling layers have no weights.

Parameters
[in]lAn average pooling layer.

Definition at line 117 of file neural_layer_avgpool.c.

◆ neural_layer_avgpool_resize()

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

Resizes an avg pooling 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 194 of file neural_layer_avgpool.c.

References Layer::c, Layer::channels, Layer::h, Layer::height, Layer::max_outputs, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, realloc_layer_arrays(), and Layer::width.

Here is the call graph for this function:

◆ neural_layer_avgpool_save()

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

Writes an average pooling 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 264 of file neural_layer_avgpool.c.

References Layer::channels, Layer::height, Layer::max_outputs, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, and Layer::width.

◆ neural_layer_avgpool_update()

void neural_layer_avgpool_update ( const struct Layer l)

Dummy function since average pooling layers have no weights.

Parameters
[in]lAn average pooling layer.

Definition at line 171 of file neural_layer_avgpool.c.

◆ realloc_layer_arrays()

static void realloc_layer_arrays ( struct Layer l)
static

Resize memory used by an average pooling layer.

Parameters
[in]lThe layer to be allocated memory.

Definition at line 45 of file neural_layer_avgpool.c.

References Layer::delta, layer_guard_outputs(), Layer::n_outputs, and Layer::output.

Referenced by neural_layer_avgpool_resize().

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