XCSF  1.4.7
XCSF learning classifier system
neural_layer_maxpool.c File Reference

An implementation of a 2D maxpooling layer. More...

#include "neural_layer_maxpool.h"
#include "neural_activations.h"
#include "utils.h"
#include <float.h>
Include dependency graph for neural_layer_maxpool.c:

Go to the source code of this file.

Functions

static void malloc_layer_arrays (struct Layer *l)
 Allocate memory used by a maxpooling layer. More...
 
static void realloc_layer_arrays (struct Layer *l)
 Resize memory used by a maxpooling layer. More...
 
void neural_layer_maxpool_init (struct Layer *l, const struct ArgsLayer *args)
 Initialises a 2D maxpooling layer. More...
 
struct Layerneural_layer_maxpool_copy (const struct Layer *src)
 Initialises and creates a copy of one maxpooling layer from another. More...
 
void neural_layer_maxpool_free (const struct Layer *l)
 Free memory used by a maxpooling layer. More...
 
void neural_layer_maxpool_rand (struct Layer *l)
 Dummy function since maxpooling layers have no weights. More...
 
static int max_pool (const struct Layer *l, const double *input, const int i, const int j, const int k)
 Returns the index of the maximum input value corresponding to a specified output height, width, and channel for a maxpooling layer. More...
 
void neural_layer_maxpool_forward (const struct Layer *l, const struct Net *net, const double *input)
 Forward propagates a maxpooling layer. More...
 
void neural_layer_maxpool_backward (const struct Layer *l, const struct Net *net, const double *input, double *delta)
 Backward propagates a maxpooling layer. More...
 
void neural_layer_maxpool_update (const struct Layer *l)
 Dummy function since a maxpooling layer has no weights. More...
 
bool neural_layer_maxpool_mutate (struct Layer *l)
 Dummy function since a maxpooling layer cannot be mutated. More...
 
void neural_layer_maxpool_resize (struct Layer *l, const struct Layer *prev)
 Resizes a maxpooling layer if the previous layer has changed size. More...
 
double * neural_layer_maxpool_output (const struct Layer *l)
 Returns the output from a maxpooling layer. More...
 
void neural_layer_maxpool_print (const struct Layer *l, const bool print_weights)
 Prints a maxpooling layer. More...
 
char * neural_layer_maxpool_json_export (const struct Layer *l, const bool return_weights)
 Returns a json formatted string representation of a maxpooling layer. More...
 
size_t neural_layer_maxpool_save (const struct Layer *l, FILE *fp)
 Writes a maxpooling layer to a file. More...
 
size_t neural_layer_maxpool_load (struct Layer *l, FILE *fp)
 Reads a maxpooling layer from a file. More...
 

Detailed Description

An implementation of a 2D maxpooling layer.

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

Definition in file neural_layer_maxpool.c.

Function Documentation

◆ malloc_layer_arrays()

static void malloc_layer_arrays ( struct Layer l)
static

Allocate memory used by a maxpooling layer.

Parameters
[in]lThe layer to be allocated memory.

Definition at line 34 of file neural_layer_maxpool.c.

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

Referenced by neural_layer_maxpool_copy(), neural_layer_maxpool_init(), and neural_layer_maxpool_load().

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

◆ max_pool()

static int max_pool ( const struct Layer l,
const double *  input,
const int  i,
const int  j,
const int  k 
)
static

Returns the index of the maximum input value corresponding to a specified output height, width, and channel for a maxpooling layer.

Parameters
[in]lA maxpooling layer.
[in]inputThe input to perform a maxpooling operation.
[in]iOutput height index.
[in]jOutput width index.
[in]kOutput channel index.
Returns
The index of the maximum value.

Definition at line 143 of file neural_layer_maxpool.c.

References Layer::height, Layer::i, layer_print(), Layer::n_inputs, Layer::pad, Layer::size, Layer::stride, and Layer::width.

Referenced by neural_layer_maxpool_forward().

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

◆ neural_layer_maxpool_backward()

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

Backward propagates a maxpooling 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 203 of file neural_layer_maxpool.c.

References Layer::delta, Layer::i, Layer::indexes, and Layer::n_outputs.

◆ neural_layer_maxpool_copy()

struct Layer* neural_layer_maxpool_copy ( const struct Layer src)

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

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

Definition at line 84 of file neural_layer_maxpool.c.

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

Here is the call graph for this function:

◆ neural_layer_maxpool_forward()

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

Forward propagates a maxpooling layer.

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

Definition at line 177 of file neural_layer_maxpool.c.

References Layer::channels, Layer::i, Layer::indexes, max_pool(), Layer::n_outputs, Layer::out_h, Layer::out_w, and Layer::output.

Here is the call graph for this function:

◆ neural_layer_maxpool_free()

void neural_layer_maxpool_free ( const struct Layer l)

Free memory used by a maxpooling layer.

Parameters
[in]lThe layer to be freed.

Definition at line 115 of file neural_layer_maxpool.c.

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

◆ neural_layer_maxpool_init()

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

Initialises a 2D maxpooling layer.

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

Definition at line 61 of file neural_layer_maxpool.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::pad, ArgsLayer::pad, Layer::size, ArgsLayer::size, Layer::stride, ArgsLayer::stride, Layer::width, and ArgsLayer::width.

Here is the call graph for this function:

◆ neural_layer_maxpool_json_export()

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

Returns a json formatted string representation of a maxpooling 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 292 of file neural_layer_maxpool.c.

References Layer::channels, Layer::height, Layer::n_inputs, Layer::n_outputs, Layer::out_c, Layer::out_h, Layer::out_w, Layer::pad, Layer::size, Layer::stride, and Layer::width.

Referenced by neural_layer_maxpool_print().

Here is the caller graph for this function:

◆ neural_layer_maxpool_load()

size_t neural_layer_maxpool_load ( struct Layer l,
FILE *  fp 
)

Reads a maxpooling 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 346 of file neural_layer_maxpool.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, Layer::pad, Layer::size, Layer::stride, and Layer::width.

Here is the call graph for this function:

◆ neural_layer_maxpool_mutate()

bool neural_layer_maxpool_mutate ( struct Layer l)

Dummy function since a maxpooling layer cannot be mutated.

Parameters
[in]lA maxpooling layer.
Returns
False.

Definition at line 231 of file neural_layer_maxpool.c.

◆ neural_layer_maxpool_output()

double* neural_layer_maxpool_output ( const struct Layer l)

Returns the output from a maxpooling layer.

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

Definition at line 266 of file neural_layer_maxpool.c.

References Layer::output.

◆ neural_layer_maxpool_print()

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

Prints a maxpooling layer.

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

Definition at line 277 of file neural_layer_maxpool.c.

References neural_layer_maxpool_json_export().

Here is the call graph for this function:

◆ neural_layer_maxpool_rand()

void neural_layer_maxpool_rand ( struct Layer l)

Dummy function since maxpooling layers have no weights.

Parameters
[in]lA maxpooling layer.

Definition at line 127 of file neural_layer_maxpool.c.

◆ neural_layer_maxpool_resize()

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

Resizes a maxpooling 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 243 of file neural_layer_maxpool.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, Layer::pad, realloc_layer_arrays(), Layer::size, Layer::stride, and Layer::width.

Here is the call graph for this function:

◆ neural_layer_maxpool_save()

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

Writes a maxpooling 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 321 of file neural_layer_maxpool.c.

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

◆ neural_layer_maxpool_update()

void neural_layer_maxpool_update ( const struct Layer l)

Dummy function since a maxpooling layer has no weights.

Parameters
[in]lA maxpooling layer.

Definition at line 220 of file neural_layer_maxpool.c.

◆ realloc_layer_arrays()

static void realloc_layer_arrays ( struct Layer l)
static

Resize memory used by a maxpooling layer.

Parameters
[in]lThe layer to be allocated memory.

Definition at line 47 of file neural_layer_maxpool.c.

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

Referenced by neural_layer_maxpool_resize().

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