public abstract class BaseLayer<LayerConfT extends BaseLayer> extends AbstractLayer<LayerConfT>
Layer.TrainingMode, Layer.Type
Modifier and Type | Field and Description |
---|---|
protected Gradient |
gradient |
protected org.nd4j.linalg.api.ndarray.INDArray |
gradientsFlattened |
protected Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
gradientViews |
protected ConvexOptimizer |
optimizer |
protected Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
params |
protected org.nd4j.linalg.api.ndarray.INDArray |
paramsFlattened |
protected double |
score |
protected Solver |
solver |
cacheMode, conf, dropoutApplied, dropoutMask, index, input, iterationListeners, maskArray, maskState, preOutput
Constructor and Description |
---|
BaseLayer(NeuralNetConfiguration conf) |
BaseLayer(NeuralNetConfiguration conf,
org.nd4j.linalg.api.ndarray.INDArray input) |
Modifier and Type | Method and Description |
---|---|
void |
accumulateScore(double accum)
Sets a rolling tally for the score.
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(boolean training)
Trigger an activation with the last specified input
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
Layer.TrainingMode training)
Initialize the layer with the given input
and return the activation for this layer
given this input
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(Layer.TrainingMode training)
Trigger an activation with the last specified input
|
org.nd4j.linalg.api.ndarray.INDArray |
activationMean()
Calculate the mean representation
for the activation for this layer
|
void |
applyLearningRateScoreDecay()
Update learningRate using for this model.
|
org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> |
backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon)
Calculate the gradient relative to the error in the next layer
|
Gradient |
calcGradient(Gradient layerError,
org.nd4j.linalg.api.ndarray.INDArray activation)
Calculate the gradient
|
double |
calcL1(boolean backpropParamsOnly)
Calculate the l1 regularization term
0.0 if regularization is not used. |
double |
calcL2(boolean backpropParamsOnly)
Calculate the l2 regularization term
0.0 if regularization is not used. |
Layer |
clone()
Clone the layer
|
void |
computeGradientAndScore()
Update the score
|
Gradient |
error(org.nd4j.linalg.api.ndarray.INDArray errorSignal)
Calculate error with respect to the
current layer.
|
void |
fit()
All models have a fit method
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray input)
Fit the model to the given data
|
org.nd4j.linalg.api.ndarray.INDArray |
getGradientsViewArray() |
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
org.nd4j.linalg.api.ndarray.INDArray |
getParam(String param)
Get the parameter
|
Gradient |
gradient()
Calculate a gradient
|
void |
initParams()
Initialize the parameters
|
void |
iterate(org.nd4j.linalg.api.ndarray.INDArray input)
iterate one iteration of the network
|
LayerConfT |
layerConf() |
void |
merge(Layer l,
int batchSize)
Averages the given logistic regression from a mini batch into this layer
|
int |
numParams()
The number of parameters for the model
|
org.nd4j.linalg.api.ndarray.INDArray |
params()
Returns the parameters of the neural network as a flattened row vector
|
Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable()
The param table
|
Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable(boolean backpropParamsOnly)
Table of parameters by key, for backprop
For many models (dense layers, etc) - all parameters are backprop parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
preOutput(boolean training) |
org.nd4j.linalg.api.ndarray.INDArray |
preOutput(org.nd4j.linalg.api.ndarray.INDArray x,
Layer.TrainingMode training)
Raw activations
|
double |
score()
Objective function: the specified objective
|
void |
setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
Set the gradients array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setParam(String key,
org.nd4j.linalg.api.ndarray.INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Set the parameters for this model.
|
protected void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params,
char order) |
void |
setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
Set the initial parameters array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setParamTable(Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Setter for the param table
|
protected void |
setScoreWithZ(org.nd4j.linalg.api.ndarray.INDArray z) |
String |
toString() |
Layer |
transpose()
Return a transposed copy of the weights/bias
(this means reverse the number of inputs and outputs on the weights)
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(org.nd4j.linalg.api.ndarray.INDArray gradient,
String paramType)
Perform one update applying the gradient
|
activate, activate, activate, addListeners, applyDropOutIfNecessary, applyMask, batchSize, clear, conf, derivativeActivation, feedForwardMaskArray, getIndex, getInput, getInputMiniBatchSize, getListeners, getMaskArray, gradientAndScore, init, input, layerId, numParams, preOutput, preOutput, setCacheMode, setConf, setIndex, setInput, setInputMiniBatchSize, setListeners, setListeners, setMaskArray, type, validateInput
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isPretrainLayer
protected org.nd4j.linalg.api.ndarray.INDArray paramsFlattened
protected org.nd4j.linalg.api.ndarray.INDArray gradientsFlattened
protected double score
protected ConvexOptimizer optimizer
protected Gradient gradient
protected Solver solver
public BaseLayer(NeuralNetConfiguration conf)
public BaseLayer(NeuralNetConfiguration conf, org.nd4j.linalg.api.ndarray.INDArray input)
public LayerConfT layerConf()
layerConf
in class AbstractLayer<LayerConfT extends BaseLayer>
public Gradient error(org.nd4j.linalg.api.ndarray.INDArray errorSignal)
Layer
error
in interface Layer
error
in class AbstractLayer<LayerConfT extends BaseLayer>
errorSignal
- the gradient for the forward layer
If this is the final layer, it will start
with the error from the output.
This is on the user to initialize.public Gradient calcGradient(Gradient layerError, org.nd4j.linalg.api.ndarray.INDArray activation)
Layer
calcGradient
in interface Layer
calcGradient
in class AbstractLayer<LayerConfT extends BaseLayer>
layerError
- the layer errorpublic org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon)
Layer
epsilon
- w^(L+1)*delta^(L+1). Or, equiv: dC/da, i.e., (dC/dz)*(dz/da) = dC/da, where C
is cost function a=sigma(z) is activation.public void fit()
Model
fit
in interface Model
fit
in class AbstractLayer<LayerConfT extends BaseLayer>
public void computeGradientAndScore()
Model
computeGradientAndScore
in interface Model
computeGradientAndScore
in class AbstractLayer<LayerConfT extends BaseLayer>
protected void setScoreWithZ(org.nd4j.linalg.api.ndarray.INDArray z)
public org.nd4j.linalg.api.ndarray.INDArray preOutput(org.nd4j.linalg.api.ndarray.INDArray x, Layer.TrainingMode training)
Layer
preOutput
in interface Layer
preOutput
in class AbstractLayer<LayerConfT extends BaseLayer>
x
- the input to transformpublic org.nd4j.linalg.api.ndarray.INDArray activate(Layer.TrainingMode training)
Layer
activate
in interface Layer
activate
in class AbstractLayer<LayerConfT extends BaseLayer>
training
- training or test modepublic org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input, Layer.TrainingMode training)
Layer
activate
in interface Layer
activate
in class AbstractLayer<LayerConfT extends BaseLayer>
input
- the input to usetraining
- train or test modepublic double score()
score
in interface Model
score
in class AbstractLayer<LayerConfT extends BaseLayer>
public Gradient gradient()
Model
gradient
in interface Model
gradient
in class AbstractLayer<LayerConfT extends BaseLayer>
public void iterate(org.nd4j.linalg.api.ndarray.INDArray input)
iterate
in interface Model
iterate
in class AbstractLayer<LayerConfT extends BaseLayer>
input
- the input to iterate onpublic void update(Gradient gradient)
Model
update
in interface Model
update
in class AbstractLayer<LayerConfT extends BaseLayer>
public void update(org.nd4j.linalg.api.ndarray.INDArray gradient, String paramType)
Model
update
in interface Model
update
in class AbstractLayer<LayerConfT extends BaseLayer>
gradient
- the gradient to applypublic ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
getOptimizer
in class AbstractLayer<LayerConfT extends BaseLayer>
public org.nd4j.linalg.api.ndarray.INDArray params()
params
in interface Model
params
in class AbstractLayer<LayerConfT extends BaseLayer>
public org.nd4j.linalg.api.ndarray.INDArray getParam(String param)
Model
getParam
in interface Model
getParam
in class AbstractLayer<LayerConfT extends BaseLayer>
param
- the key of the parameterpublic void setParam(String key, org.nd4j.linalg.api.ndarray.INDArray val)
Model
setParam
in interface Model
setParam
in class AbstractLayer<LayerConfT extends BaseLayer>
key
- the key to se tval
- the new ndarraypublic void setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Model
setParams
in interface Model
setParams
in class AbstractLayer<LayerConfT extends BaseLayer>
params
- the parameters for the modelprotected void setParams(org.nd4j.linalg.api.ndarray.INDArray params, char order)
setParams
in class AbstractLayer<LayerConfT extends BaseLayer>
public void setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
Model
setParamsViewArray
in interface Model
setParamsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
params
- a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic org.nd4j.linalg.api.ndarray.INDArray getGradientsViewArray()
getGradientsViewArray
in interface Model
getGradientsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
public void setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
Model
setBackpropGradientsViewArray
in interface Model
setBackpropGradientsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
gradients
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic void setParamTable(Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Model
setParamTable
in interface Model
setParamTable
in class AbstractLayer<LayerConfT extends BaseLayer>
public void initParams()
Model
initParams
in interface Model
initParams
in class AbstractLayer<LayerConfT extends BaseLayer>
public Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable()
Model
paramTable
in interface Model
paramTable
in class AbstractLayer<LayerConfT extends BaseLayer>
public Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable(boolean backpropParamsOnly)
Model
paramTable
in interface Model
paramTable
in class AbstractLayer<LayerConfT extends BaseLayer>
backpropParamsOnly
- If true, return backprop params only. If false: return all params (equivalent to
paramsTable())public org.nd4j.linalg.api.ndarray.INDArray preOutput(boolean training)
preOutput
in class AbstractLayer<LayerConfT extends BaseLayer>
public org.nd4j.linalg.api.ndarray.INDArray activate(boolean training)
Layer
training
- training or test modepublic double calcL2(boolean backpropParamsOnly)
Layer
calcL2
in interface Layer
calcL2
in class AbstractLayer<LayerConfT extends BaseLayer>
backpropParamsOnly
- If true: calculate L2 based on backprop params only. If false: calculate
based on all params (including pretrain params, if any)public double calcL1(boolean backpropParamsOnly)
Layer
calcL1
in interface Layer
calcL1
in class AbstractLayer<LayerConfT extends BaseLayer>
backpropParamsOnly
- If true: calculate L1 based on backprop params only. If false: calculate
based on all params (including pretrain params, if any)public org.nd4j.linalg.api.ndarray.INDArray activationMean()
Layer
public void merge(Layer l, int batchSize)
merge
in interface Layer
merge
in class AbstractLayer<LayerConfT extends BaseLayer>
l
- the logistic regression layer to average into this layerbatchSize
- the batch sizepublic Layer clone()
Layer
clone
in interface Layer
clone
in class AbstractLayer<LayerConfT extends BaseLayer>
public int numParams()
numParams
in interface Model
numParams
in class AbstractLayer<LayerConfT extends BaseLayer>
public void fit(org.nd4j.linalg.api.ndarray.INDArray input)
Model
fit
in interface Model
fit
in class AbstractLayer<LayerConfT extends BaseLayer>
input
- the data to fit the model topublic Layer transpose()
Layer
transpose
in interface Layer
transpose
in class AbstractLayer<LayerConfT extends BaseLayer>
public void accumulateScore(double accum)
Model
accumulateScore
in interface Model
accumulateScore
in class AbstractLayer<LayerConfT extends BaseLayer>
accum
- the amount to accumpublic void applyLearningRateScoreDecay()
Model
applyLearningRateScoreDecay
in interface Model
applyLearningRateScoreDecay
in class AbstractLayer<LayerConfT extends BaseLayer>
Copyright © 2017. All rights reserved.