public abstract class BaseLayer<LayerConfT extends Layer> extends Object implements Layer
Layer.TrainingMode, Layer.Type| Modifier and Type | Field and Description |
|---|---|
protected NeuralNetConfiguration |
conf |
protected boolean |
dropoutApplied |
protected org.nd4j.linalg.api.ndarray.INDArray |
dropoutMask |
protected Gradient |
gradient |
protected org.nd4j.linalg.api.ndarray.INDArray |
gradientsFlattened |
protected Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
gradientViews |
protected int |
index |
protected org.nd4j.linalg.api.ndarray.INDArray |
input |
protected Collection<IterationListener> |
iterationListeners |
protected org.nd4j.linalg.api.ndarray.INDArray |
maskArray |
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 |
| 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()
Trigger an activation with the last specified input
|
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)
Initialize the layer with the given input
and return the activation for this layer
given this input
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean 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(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
|
protected void |
applyDropOutIfNecessary(boolean training) |
void |
applyLearningRateScoreDecay()
Update learningRate using for this model.
|
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
|
int |
batchSize()
The current inputs batch size
|
Gradient |
calcGradient(Gradient layerError,
org.nd4j.linalg.api.ndarray.INDArray activation)
Calculate the gradient
|
double |
calcL1()
Calculate the l1 regularization term
0.0 if regularization is not used. |
double |
calcL2()
Calculate the l2 regularization term
0.0 if regularization is not used. |
void |
clear()
Clear input
|
Layer |
clone()
Clone the layer
|
void |
computeGradientAndScore()
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
protected Gradient |
createGradient(org.nd4j.linalg.api.ndarray.INDArray... gradients)
Create a gradient list based on the passed in parameters.
|
org.nd4j.linalg.api.ndarray.INDArray |
derivativeActivation(org.nd4j.linalg.api.ndarray.INDArray input)
Take the derivative of the given input
based on the activation
|
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
|
int |
getIndex()
Get the layer index.
|
org.nd4j.linalg.api.ndarray.INDArray |
getInput() |
int |
getInputMiniBatchSize()
Get current/last input mini-batch size, as set by setInputMiniBatchSize(int)
|
Collection<IterationListener> |
getListeners()
Get the iteration listeners for this layer.
|
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
org.nd4j.linalg.api.ndarray.INDArray |
getParam(String param)
Get the parameter
|
Gradient |
gradient()
Calculate a gradient
|
Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
void |
initParams()
Initialize the parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
input()
The input/feature matrix for the model
|
void |
iterate(org.nd4j.linalg.api.ndarray.INDArray input)
iterate one iteration of the network
|
protected 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
|
int |
numParams(boolean backwards)
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
|
org.nd4j.linalg.api.ndarray.INDArray |
preOutput(boolean training) |
org.nd4j.linalg.api.ndarray.INDArray |
preOutput(org.nd4j.linalg.api.ndarray.INDArray x)
Classify input
|
org.nd4j.linalg.api.ndarray.INDArray |
preOutput(org.nd4j.linalg.api.ndarray.INDArray x,
boolean training)
Raw activations
|
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 |
setConf(NeuralNetConfiguration conf)
Setter for the configuration
|
void |
setIndex(int index)
Set the layer index.
|
void |
setInput(org.nd4j.linalg.api.ndarray.INDArray input)
Get the layer input.
|
void |
setInputMiniBatchSize(int size)
Set current/last input mini-batch size.
Used for score and gradient calculations. |
void |
setListeners(Collection<IterationListener> listeners)
Set the iteration listeners for this layer.
|
void |
setListeners(IterationListener... listeners)
Set the iteration listeners for this layer.
|
void |
setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray) |
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)
|
Layer.Type |
type()
Returns the layer type
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(org.nd4j.linalg.api.ndarray.INDArray gradient,
String paramType)
Update layer weights and biases with gradient change
|
void |
validateInput()
Validate the input
|
protected org.nd4j.linalg.api.ndarray.INDArray input
protected org.nd4j.linalg.api.ndarray.INDArray paramsFlattened
protected org.nd4j.linalg.api.ndarray.INDArray gradientsFlattened
protected NeuralNetConfiguration conf
protected org.nd4j.linalg.api.ndarray.INDArray dropoutMask
protected boolean dropoutApplied
protected double score
protected ConvexOptimizer optimizer
protected Gradient gradient
protected Collection<IterationListener> iterationListeners
protected int index
protected org.nd4j.linalg.api.ndarray.INDArray maskArray
protected Solver solver
public BaseLayer(NeuralNetConfiguration conf)
public BaseLayer(NeuralNetConfiguration conf, org.nd4j.linalg.api.ndarray.INDArray input)
protected LayerConfT layerConf()
public org.nd4j.linalg.api.ndarray.INDArray getInput()
public void setInput(org.nd4j.linalg.api.ndarray.INDArray input)
Layerpublic int getIndex()
Layerpublic void setIndex(int index)
Layerpublic Collection<IterationListener> getListeners()
LayergetListeners in interface Layerpublic void setListeners(Collection<IterationListener> listeners)
LayersetListeners in interface Layerpublic void setListeners(IterationListener... listeners)
LayersetListeners in interface Layerpublic Gradient error(org.nd4j.linalg.api.ndarray.INDArray errorSignal)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray derivativeActivation(org.nd4j.linalg.api.ndarray.INDArray input)
LayerderivativeActivation in interface Layerinput - the input to take the derivative ofpublic Gradient calcGradient(Gradient layerError, org.nd4j.linalg.api.ndarray.INDArray activation)
LayercalcGradient in interface LayerlayerError - the layer errorpublic Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon)
LayerbackpropGradient in interface Layerepsilon - 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()
Modelpublic void computeGradientAndScore()
ModelcomputeGradientAndScore in interface Modelprotected 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)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray activate(Layer.TrainingMode training)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input,
Layer.TrainingMode training)
Layerpublic double score()
public void iterate(org.nd4j.linalg.api.ndarray.INDArray input)
public void update(Gradient gradient)
Layerpublic void update(org.nd4j.linalg.api.ndarray.INDArray gradient,
String paramType)
Layerpublic ConvexOptimizer getOptimizer()
ModelgetOptimizer in interface Modelpublic void setConf(NeuralNetConfiguration conf)
Modelpublic org.nd4j.linalg.api.ndarray.INDArray params()
public org.nd4j.linalg.api.ndarray.INDArray getParam(String param)
Modelpublic void setParam(String key, org.nd4j.linalg.api.ndarray.INDArray val)
Modelpublic void setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Modelprotected void setParams(org.nd4j.linalg.api.ndarray.INDArray params,
char order)
public void setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
ModelsetParamsViewArray in interface Modelparams - a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic void setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
ModelsetBackpropGradientsViewArray in interface Modelgradients - 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)
ModelsetParamTable in interface Modelpublic void initParams()
ModelinitParams in interface Modelpublic Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable()
ModelparamTable in interface Modelpublic org.nd4j.linalg.api.ndarray.INDArray preOutput(org.nd4j.linalg.api.ndarray.INDArray x,
boolean training)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray preOutput(boolean training)
public org.nd4j.linalg.api.ndarray.INDArray activate(boolean training)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training)
Layerpublic org.nd4j.linalg.api.ndarray.INDArray activate()
Layerpublic org.nd4j.linalg.api.ndarray.INDArray preOutput(org.nd4j.linalg.api.ndarray.INDArray x)
preOutput in interface Layerx - the input (can either be a matrix or vector)
If it's a matrix, each row is considered an example
and associated rows are classified accordingly.
Each row will be the likelihood of a label given that examplepublic double calcL2()
Layerpublic double calcL1()
Layerpublic int batchSize()
Modelpublic org.nd4j.linalg.api.ndarray.INDArray activationMean()
LayeractivationMean in interface Layerpublic NeuralNetConfiguration conf()
Modelpublic void clear()
Modelprotected void applyDropOutIfNecessary(boolean training)
public void merge(Layer l, int batchSize)
public Layer.Type type()
Layerpublic int numParams()
public int numParams(boolean backwards)
Modelpublic void fit(org.nd4j.linalg.api.ndarray.INDArray input)
Modelpublic Pair<Gradient,Double> gradientAndScore()
ModelgradientAndScore in interface Modelpublic org.nd4j.linalg.api.ndarray.INDArray input()
Modelpublic void validateInput()
ModelvalidateInput in interface Modelprotected Gradient createGradient(org.nd4j.linalg.api.ndarray.INDArray... gradients)
gradients - the gradients to create frompublic Layer transpose()
Layerpublic void accumulateScore(double accum)
ModelaccumulateScore in interface Modelaccum - the amount to accumpublic void setInputMiniBatchSize(int size)
LayersetInputMiniBatchSize in interface Layerpublic int getInputMiniBatchSize()
LayergetInputMiniBatchSize in interface LayerLayer.setInputMiniBatchSize(int)public void applyLearningRateScoreDecay()
ModelapplyLearningRateScoreDecay in interface Modelpublic void setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray)
setMaskArray in interface LayerCopyright © 2016. All Rights Reserved.