Architecture module

Neural networks

An artificial neural network can be used as a controller.

General interface

ControllerFormats.Architecture.AbstractNeuralNetworkType
AbstractNeuralNetwork

Abstract type for neural networks.

Notes

Subtypes should implement the following method:

  • layers(::AbstractNeuralNetwork) - return a list of the layers

The following standard methods are implemented:

  • length(::AbstractNeuralNetwork)
  • getindex(::AbstractNeuralNetwork, indices)
  • lastindex(::AbstractNeuralNetwork)
  • ==(::AbstractNeuralNetwork, ::AbstractNeuralNetwork)

The following non-standard methods are implemented:

ControllerFormats.Architecture.dim_inMethod
dim_in(N::AbstractNeuralNetwork)

Return the input dimension of a neural network.

Input

  • N – neural network

Output

The dimension of the input layer of N.

ControllerFormats.Architecture.dim_outMethod
dim_out(N::AbstractNeuralNetwork)

Return the output dimension of a neural network.

Input

  • N – neural network

Output

The dimension of the output layer of N.

ControllerFormats.Architecture.dimMethod
dim(N::AbstractNeuralNetwork)

Return the input and output dimension of a neural network.

Input

  • N – neural network

Output

The pair $(i, o)$ where $i$ is the input dimension and $o$ is the output dimension of N.

Notes

This function is not exported due to name conflicts with other related packages.

Implementation

ControllerFormats.Architecture.FeedforwardNetworkType
FeedforwardNetwork{L} <: AbstractNeuralNetwork

Standard implementation of a feedforward neural network which stores the layer operations.

Fields

Notes

The field layers contains the layer operations, so the number of layers is length(layers) + 1.

Conversion from a Flux.Chain is supported.

Layer operations

ControllerFormats.Architecture.AbstractLayerOpType
AbstractLayerOp

Abstract type for layer operations.

Notes

An AbstractLayerOp represents a layer operation. A classical example is a "dense layer operation" with an affine map followed by an activation function.

The following non-standard methods are useful to implement:

ControllerFormats.Architecture.dimMethod
dim(L::AbstractLayerOp)

Return the input and output dimension of a layer operation.

Input

  • N – neural network

Output

The pair $(i, o)$ where $i$ is the input dimension and $o$ is the output dimension of N.

Notes

This function is not exported due to name conflicts with other related packages.

More specific layer interfaces

ControllerFormats.Architecture.AbstractPoolingLayerOpType
AbstractPoolingLayerOp <: AbstractLayerOp

Abstract type for pooling layer operations.

Notes

Pooling is an operation on a three-dimensional tensor that iterates over the first two dimensions in a window and aggregates the values, thus reducing the output dimension.

Implementation

The following (unexported) functions should be implemented:

  • window(::AbstractPoolingLayerOp) – return the pair $(p, q)$ representing the window size
  • aggregation(::AbstractPoolingLayerOp) – return the aggregation function (applied to a tensor)

Implementation

ControllerFormats.Architecture.DenseLayerOpType
DenseLayerOp{F, M, B} <: AbstractLayerOp

A dense layer operation is an affine map followed by an activation function.

Fields

  • weights – weight matrix
  • bias – bias vector
  • activation – activation function

Notes

Conversion from a Flux.Dense is supported.

ControllerFormats.Architecture.ConvolutionalLayerOpType
ConvolutionalLayerOp{F, M, B} <: AbstractLayerOp

A convolutional layer operation is a series of filters, each of which computes a small affine map followed by an activation function.

Fields

  • weights – vector with one weight matrix for each filter
  • bias – vector with one bias value for each filter
  • activation – activation function

Notes

Conversion from a Flux.Conv is supported.

ControllerFormats.Architecture.FlattenLayerOpType
FlattenLayerOp <: AbstractLayerOp

A flattening layer operation converts a multidimensional tensor into a vector.

Notes

The implementation uses row-major ordering for convenience with the machine-learning literature.

julia> T = reshape([1, 3, 2, 4, 5, 7, 6, 8], (2, 2, 2))
2×2×2 Array{Int64, 3}:
[:, :, 1] =
 1  2
 3  4

[:, :, 2] =
 5  6
 7  8

julia> FlattenLayerOp()(T)
8-element Vector{Int64}:
 1
 2
 3
 4
 5
 6
 7
 8

Activation functions

The following strings can be parsed as activation functions:

ControllerFormats.FileFormats.available_activations
Dict{String, ActivationFunction} with 12 entries:
  "ReLU"    => ReLU
  "logsig"  => Sigmoid
  "relu"    => ReLU
  "Affine"  => Id
  "Sigmoid" => Sigmoid
  "Id"      => Id
  "sigmoid" => Sigmoid
  "σ"       => Sigmoid
  "Tanh"    => Tanh
  "linear"  => Id
  "tanh"    => Tanh
  "Linear"  => Id