Class FullyConnectedLayer
java.lang.Object
deepnetts.net.layers.AbstractLayer<TensorBase, TensorBase, Tensor2D>
deepnetts.net.layers.FullyConnectedLayer
- All Implemented Interfaces:
Backward, Forward, Layer<TensorBase>, Serializable
Fully connected layer is used as a hidden layer in a neural network, and it
has a single row of units/nodes/neurons connected to all neurons in previous
and next layer. Previous layer can be input, fully connected, or flattened
layer, while next layer can be fully connected or output layer. This layer
calculates weighted sum of outputs from the previous layers (as matrix dot
product), and applies activation function to all that sum. Mathematical
formula is: Y = activation(W . X + B)
where Y is output tensor (1D for single input or 2D for batch) W is a 2D
weights tensor X is input tensor (1D for single input or 2D for batch) B is a
1D tensor of biases activation is an activation function
- See Also:
-
Field Summary
Fields inherited from class AbstractLayer
activation, activationType, backwardImpl, batchMode, batchSize, biases, cudaHandles, deltaBiases, deltas, deltaWeights, depth, forwardImpl, gradients, height, inputs, learningRate, mode, momentum, networkType, nextLayer, numThreads, optimizer, optimizerType, outputs, prevDeltaBiases, prevDeltaWeights, prevLayer, randomWeightsType, regL1, regL2, threadPool, trainable, weights, width -
Constructor Summary
ConstructorsConstructorDescriptionFullyConnectedLayer(int layerSize) Creates an instance of fully connected layer with specified number of neurons and ReLU activation function.FullyConnectedLayer(int layerSize, ActivationType actType) Creates an instance of a fully connected layer with specified width (number of neurons) and activation function type. -
Method Summary
Modifier and TypeMethodDescriptionvoidApplies weight changes to current weights Must be diferent for convolutional does nothing for MaxPooling Same for FullyConnected and OutputLayervoidbackward()This method should implement backward pass in subclassesvoidforward()This method should implement forward pass in subclassesfloatvoidinit()Creates all internal data structures: inputs, weights, biases, outputs, deltas, deltaWeights, deltaBiases prevDeltaWeights, prevDeltaBiases.voidvoidsetDropout(float dropout) toString()Methods inherited from class AbstractLayer
getActivation, getActivationType, getBackwardAcc, getBatchSize, getBiases, getDeltaBiases, getDeltas, getDeltaWeights, getDepth, getForwardAcc, getGradients, getHeight, getL1Regularization, getL1WeightSum, getL2Regularization, getL2WeightSum, getLearningRate, getMode, getMomentum, getNetworkType, getNextLayer, getNumThreads, getOptimizer, getOptimizerType, getOutputs, getPrevDeltaBiases, getPrevDeltaWeights, getPrevlayer, getWeights, getWidth, isBatchMode, isTrainable, setActivationType, setBatchMode, setBatchSize, setBiases, setCudaHandles, setDeltas, setL1Regularization, setL2Regularization, setLearningRate, setMode, setMomentum, setNetworkType, setNextlayer, setOptimizerType, setOutputs, setPrevDeltaWeights, setPrevLayer, setThreadPool, setTrainable, setWeights, setWeights
-
Constructor Details
-
FullyConnectedLayer
public FullyConnectedLayer(int layerSize) Creates an instance of fully connected layer with specified number of neurons and ReLU activation function.- Parameters:
layerSize- a number of neurons in this layer / layer size (same as number of outputs)
-
FullyConnectedLayer
Creates an instance of a fully connected layer with specified width (number of neurons) and activation function type.- Parameters:
layerSize- layer size / number of neurons in this layeractType- activation function type to use in this layer- See Also:
-
-
Method Details
-
init
public void init()Creates all internal data structures: inputs, weights, biases, outputs, deltas, deltaWeights, deltaBiases prevDeltaWeights, prevDeltaBiases. Init weights and biases. This method is called from network builder during initialization- Specified by:
initin classAbstractLayer<TensorBase, TensorBase, Tensor2D>
-
initTransientFields
public void initTransientFields()- Overrides:
initTransientFieldsin classAbstractLayer<TensorBase, TensorBase, Tensor2D>
-
forward
public void forward()Description copied from class:AbstractLayerThis method should implement forward pass in subclasses- Specified by:
forwardin interfaceForward- Specified by:
forwardin interfaceLayer<TensorBase>- Specified by:
forwardin classAbstractLayer<TensorBase, TensorBase, Tensor2D>
-
backward
public void backward()Description copied from class:AbstractLayerThis method should implement backward pass in subclasses- Specified by:
backwardin interfaceBackward- Specified by:
backwardin interfaceLayer<TensorBase>- Specified by:
backwardin classAbstractLayer<TensorBase, TensorBase, Tensor2D>
-
applyWeightChanges
public void applyWeightChanges()Description copied from class:AbstractLayerApplies weight changes to current weights Must be diferent for convolutional does nothing for MaxPooling Same for FullyConnected and OutputLayer- Specified by:
applyWeightChangesin classAbstractLayer<TensorBase, TensorBase, Tensor2D>
-
getDropout
public float getDropout() -
setDropout
public void setDropout(float dropout) -
toString
-