Architecture module
ControllerFormats.Architecture
— ModuleArchitecture
Module containing data structures to represent controllers.
Neural networks
An artificial neural network can be used as a controller.
General interface
ControllerFormats.Architecture.AbstractNeuralNetwork
— TypeAbstractNeuralNetwork
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)
ControllerFormats.Architecture.layers
— Methodlayers(N::AbstractNeuralNetwork)
Return a list of the layers of a neural network.
Input
N
– neural network
Output
The list of layers.
The following non-standard methods are implemented:
ControllerFormats.Architecture.dim_in
— Methoddim_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_out
— Methoddim_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.dim
— Methoddim(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.FeedforwardNetwork
— TypeFeedforwardNetwork{L} <: AbstractNeuralNetwork
Standard implementation of a feedforward neural network which stores the layer operations.
Fields
layers
– vector of layer operations (seeAbstractLayerOp
)
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.AbstractLayerOp
— TypeAbstractLayerOp
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.dim_in
— Methoddim_in(L::AbstractLayerOp)
Return the input dimension of a layer operation.
Input
L
– layer operation
Output
The input dimension of L
.
ControllerFormats.Architecture.dim_out
— Methoddim_out(L::AbstractLayerOp)
Return the output dimension of a layer operation.
Input
L
– layer operation
Output
The output dimension of L
.
ControllerFormats.Architecture.dim
— Methoddim(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.AbstractPoolingLayerOp
— TypeAbstractPoolingLayerOp <: 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 sizeaggregation(::AbstractPoolingLayerOp)
– return the aggregation function (applied to a tensor)
Implementation
ControllerFormats.Architecture.DenseLayerOp
— TypeDenseLayerOp{F, M, B} <: AbstractLayerOp
A dense layer operation is an affine map followed by an activation function.
Fields
weights
– weight matrixbias
– bias vectoractivation
– activation function
Notes
Conversion from a Flux.Dense
is supported.
ControllerFormats.Architecture.ConvolutionalLayerOp
— TypeConvolutionalLayerOp{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 filterbias
– vector with one bias value for each filteractivation
– activation function
Notes
Conversion from a Flux.Conv
is supported.
ControllerFormats.Architecture.FlattenLayerOp
— TypeFlattenLayerOp <: 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
ControllerFormats.Architecture.MaxPoolingLayerOp
— TypeMaxPoolingLayerOp <: AbstractPoolingLayerOp
A max-pooling layer operation. The aggregation function is maximum
.
Fields
p
– horizontal window sizeq
– vertical window size
ControllerFormats.Architecture.MeanPoolingLayerOp
— TypeMeanPoolingLayerOp <: AbstractPoolingLayerOp
A mean-pooling layer operation. The aggregation function is Statistics.mean
.
Fields
p
– horizontal window sizeq
– vertical window size
Activation functions
ControllerFormats.Architecture.ActivationFunction
— TypeActivationFunction
Abstract type for activation functions.
ControllerFormats.Architecture.Id
— TypeId
Identity activation.
\[ f(x) = x\]
ControllerFormats.Architecture.ReLU
— TypeReLU
Rectified linear unit (ReLU) activation.
\[ f(x) = max(x, 0)\]
ControllerFormats.Architecture.Sigmoid
— TypeSigmoid
Sigmoid activation.
\[ f(x) = \frac{1}{1 + e^{-x}}\]
ControllerFormats.Architecture.Tanh
— TypeTanh
Hyperbolic tangent activation.
\[ f(x) = tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}\]
ControllerFormats.Architecture.LeakyReLU
— TypeLeakyReLU{N<:Number}
Leaky ReLU activation.
\[ fₐ(x) = x > 0 ? x : a x\]
where $a$ is the parameter.
Fields
slope
– parameter for negative inputs
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