Layers
Each layer in the neural net corresponds to a struct
that simultaneously specifies: 1) the operation being carried out in the layer (recorded in the type of the struct
) and 2) the parameters for the operation (recorded in the values of the fields of the struct
).
When we pass an input array of real numbers to a layer struct
, we get an output array of real numbers that is the result of the layer operating on the input.
Conversely, when we pass an input array of JuMP
variables, we get an output array of JuMP
variables, with the appropriate mixed-integer constraints (as determined by the layer) imposed between the input and output.
Index
MIPVerify.MaxPool
MIPVerify.conv2d
MIPVerify.getoutputsize
MIPVerify.getpoolview
MIPVerify.getsliceindex
MIPVerify.matmul
MIPVerify.matmul
MIPVerify.permute_and_flatten
MIPVerify.pool
MIPVerify.poolmap
MIPVerify.Conv2d
MIPVerify.Conv2d
MIPVerify.Flatten
MIPVerify.Linear
MIPVerify.MaskedReLU
MIPVerify.Normalize
MIPVerify.Pool
MIPVerify.ReLU
MIPVerify.SkipBlock
MIPVerify.Zero
Public Interface
MIPVerify.Conv2d
— Typestruct Conv2d{T<:Union{Real, JuMP.VariableRef, JuMP.AffExpr}, U<:Union{Real, JuMP.VariableRef, JuMP.AffExpr}, V<:Integer} <: Layer
Represents 2-D convolution operation.
p(x)
is shorthand for conv2d(x, p)
when p
is an instance of Conv2d
.
Fields:
filter
bias
stride
padding
MIPVerify.Conv2d
— MethodConv2d(filter)
Convenience function to create a Conv2d
struct with the specified filter and zero bias.
MIPVerify.Flatten
— Typestruct Flatten{T<:Integer} <: Layer
Represents a flattening operation.
p(x)
is shorthand for permute_and_flatten(x, p.perm)
when p
is an instance of Flatten
.
Fields:
n_dim
perm
MIPVerify.Linear
— Typestruct Linear{T<:Real, U<:Real} <: Layer
Represents matrix multiplication.
p(x)
is shorthand for matmul(x, p)
when p
is an instance of Linear
.
Fields:
matrix
bias
MIPVerify.MaskedReLU
— Typestruct MaskedReLU{T<:Real} <: Layer
Represents a masked ReLU activation, with mask
controlling how the ReLU is applied to each output.
p(x)
is shorthand for masked_relu(x, p.mask)
when p
is an instance of MaskedReLU
.
Fields:
mask
tightening_algorithm
MIPVerify.Normalize
— Typestruct Normalize <: Layer
Represents a Normalization operation.
MIPVerify.MaxPool
— MethodMaxPool(strides)
Convenience function to create a Pool
struct for max-pooling.
MIPVerify.Pool
— Typestruct Pool{N} <: Layer
Represents a pooling operation.
p(x)
is shorthand for pool(x, p)
when p
is an instance of Pool
.
Fields:
strides
pooling_function
MIPVerify.ReLU
— Typestruct ReLU <: Layer
Represents a ReLU operation.
p(x)
is shorthand for relu(x)
when p
is an instance of ReLU
.
MIPVerify.SkipBlock
— Typestruct SkipBlock <: Layer
TODO (vtjeng)
Fields:
layers
MIPVerify.Zero
— Typestruct Zero <: Layer
Always outputs exactly zero.
Internal
MIPVerify.conv2d
— Methodconv2d(input, params)
Computes the result of convolving input
with the filter
and bias
stored in params
.
Mirrors tf.nn.conv2d
from the tensorflow
package, with strides = [1, params.stride, params.stride, 1]
.
Supports three types of padding:
- 'same': Specify via
SamePadding()
. Padding is added so that the output has the same size as the input. - 'valid': Specify via
FixedPadding()
. No padding is added. - 'fixed': Specify via:
- A single integer, interpreted as padding for both axes
- A tuple of two integers, interpreted as (ypadding, xpadding)
- A tuple of four integers, interpreted as (top, bottom, left, right)
Throws
- AssertionError if
input
andfilter
are not compatible.
MIPVerify.permute_and_flatten
— MethodPermute dimensions of array in specified order, then flattens the array.
MIPVerify.matmul
— Methodmatmul(x, params)
Computes the result of pre-multiplying x
by the transpose of params.matrix
and adding params.bias
.
MIPVerify.matmul
— Methodmatmul(x, params)
Computes the result of pre-multiplying x
by the transpose of params.matrix
and adding params.bias
. We write the computation out by hand when working with JuMPLinearType
so that we are able to simplify the output as the computation is carried out.
MIPVerify.getoutputsize
— Methodgetoutputsize(input_array, strides)
For pooling operations on an array, returns the expected size of the output array.
MIPVerify.getpoolview
— Methodgetpoolview(input_array, strides, output_index)
For pooling operations on an array, returns a view of the parent array corresponding to the output_index
in the output array.
MIPVerify.getsliceindex
— Methodgetsliceindex(input_array_size, stride, output_index)
For pooling operations on an array where a given element in the output array corresponds to equal-sized blocks in the input array, returns (for a given dimension) the index range in the input array corresponding to a particular index output_index
in the output array.
Returns an empty array if the output_index
does not correspond to any input indices.
Arguments
stride::Integer
: the size of the operating blocks along the active dimension.
MIPVerify.pool
— Methodpool(input, params)
Computes the result of applying the pooling function params.pooling_function
to non-overlapping cells of input
with sizes specified in params.strides
.
MIPVerify.poolmap
— Methodpoolmap(f, input_array, strides)
Returns output from applying f
to subarrays of input_array
, with the windows determined by the strides
.