public abstract class BaseLayer<LayerConfT extends BaseLayer> extends AbstractLayer<LayerConfT>
Layer.TrainingMode, Layer.Type| Modifier and Type | Field and Description |
|---|---|
protected Gradient |
gradient |
protected INDArray |
gradientsFlattened |
protected Map<String,INDArray> |
gradientViews |
protected ConvexOptimizer |
optimizer |
protected Map<String,INDArray> |
params |
protected INDArray |
paramsFlattened |
protected double |
score |
protected Solver |
solver |
protected Map<String,INDArray> |
weightNoiseParams |
cacheMode, conf, dataType, dropoutApplied, epochCount, index, input, inputModificationAllowed, iterationCount, maskArray, maskState, preOutput, trainingListeners| Constructor and Description |
|---|
BaseLayer(NeuralNetConfiguration conf,
DataType dataType) |
| Modifier and Type | Method and Description |
|---|---|
INDArray |
activate(boolean training,
LayerWorkspaceMgr workspaceMgr)
Perform forward pass and return the activations array with the last set input
|
Pair<Gradient,INDArray> |
backpropGradient(INDArray epsilon,
LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layer
|
double |
calcRegularizationScore(boolean backpropParamsOnly)
Calculate the regularization component of the score, for the parameters in this layer
For example, the L1, L2 and/or weight decay components of the loss function |
void |
clear()
Clear input
|
void |
clearNoiseWeightParams() |
Layer |
clone() |
void |
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the score
|
void |
fit()
All models have a fit method
|
void |
fit(INDArray input,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
INDArray |
getGradientsViewArray() |
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
INDArray |
getParam(String param)
Get the parameter
|
protected INDArray |
getParamWithNoise(String param,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Get the parameter, after applying any weight noise (such as DropConnect) if necessary.
|
Gradient |
gradient()
Get the gradient.
|
boolean |
hasBias()
Does this layer have no bias term? Many layers (dense, convolutional, output, embedding) have biases by
default, but no-bias versions are possible via configuration
|
boolean |
hasLayerNorm()
Does this layer support and is it enabled layer normalization? Only Dense and SimpleRNN Layers support
layer normalization.
|
LayerConfT |
layerConf() |
long |
numParams()
The number of parameters for the model
|
INDArray |
params()
Returns the parameters of the neural network as a flattened row vector
|
Map<String,INDArray> |
paramTable()
The param table
|
Map<String,INDArray> |
paramTable(boolean backpropParamsOnly)
Table of parameters by key, for backprop
For many models (dense layers, etc) - all parameters are backprop parameters
|
protected INDArray |
preOutput(boolean training,
LayerWorkspaceMgr workspaceMgr) |
protected Pair<INDArray,INDArray> |
preOutputWithPreNorm(boolean training,
boolean forBackprop,
LayerWorkspaceMgr workspaceMgr) |
double |
score()
Objective function: the specified objective
|
void |
setBackpropGradientsViewArray(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,
INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(INDArray params)
Set the parameters for this model.
|
protected void |
setParams(INDArray params,
char order) |
void |
setParamsViewArray(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,INDArray> paramTable)
Setter for the param table
|
protected void |
setScoreWithZ(INDArray z) |
String |
toString() |
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(INDArray gradient,
String paramType)
Perform one update applying the gradient
|
activate, addListeners, allowInputModification, applyConstraints, applyDropOutIfNecessary, applyMask, assertInputSet, backpropDropOutIfPresent, batchSize, close, conf, feedForwardMaskArray, getConfig, getEpochCount, getHelper, getIndex, getInput, getInputMiniBatchSize, getListeners, getMaskArray, gradientAndScore, init, input, layerId, numParams, setCacheMode, setConf, setEpochCount, setIndex, setInput, setInputMiniBatchSize, setListeners, setListeners, setMaskArray, type, updaterDivideByMinibatchequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetIterationCount, isPretrainLayer, setIterationCountprotected INDArray paramsFlattened
protected INDArray gradientsFlattened
protected double score
protected ConvexOptimizer optimizer
protected Gradient gradient
protected Solver solver
public BaseLayer(NeuralNetConfiguration conf, DataType dataType)
public LayerConfT layerConf()
layerConf in class AbstractLayer<LayerConfT extends BaseLayer>public Pair<Gradient,INDArray> backpropGradient(INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
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.workspaceMgr - Workspace managerArrayType.ACTIVATION_GRAD workspace via the workspace managerpublic void fit()
Modelfit in interface Modelfit in class AbstractLayer<LayerConfT extends BaseLayer>public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
ModelcomputeGradientAndScore in interface ModelcomputeGradientAndScore in class AbstractLayer<LayerConfT extends BaseLayer>protected void setScoreWithZ(INDArray z)
public double score()
score in interface Modelscore in class AbstractLayer<LayerConfT extends BaseLayer>public Gradient gradient()
ModelModel.computeGradientAndScore(LayerWorkspaceMgr) } .gradient in interface Modelgradient in class AbstractLayer<LayerConfT extends BaseLayer>public void update(Gradient gradient)
Modelupdate in interface Modelupdate in class AbstractLayer<LayerConfT extends BaseLayer>public void update(INDArray gradient, String paramType)
Modelupdate in interface Modelupdate in class AbstractLayer<LayerConfT extends BaseLayer>gradient - the gradient to applypublic ConvexOptimizer getOptimizer()
ModelgetOptimizer in interface ModelgetOptimizer in class AbstractLayer<LayerConfT extends BaseLayer>public INDArray params()
params in interface Modelparams in interface Trainableparams in class AbstractLayer<LayerConfT extends BaseLayer>public INDArray getParam(String param)
ModelgetParam in interface ModelgetParam in class AbstractLayer<LayerConfT extends BaseLayer>param - the key of the parameterpublic void setParam(String key, INDArray val)
ModelsetParam in interface ModelsetParam in class AbstractLayer<LayerConfT extends BaseLayer>key - the key to se tval - the new ndarraypublic void setParams(INDArray params)
ModelsetParams in interface ModelsetParams in class AbstractLayer<LayerConfT extends BaseLayer>params - the parameters for the modelprotected void setParams(INDArray params, char order)
setParams in class AbstractLayer<LayerConfT extends BaseLayer>public void setParamsViewArray(INDArray params)
ModelsetParamsViewArray in interface ModelsetParamsViewArray in class AbstractLayer<LayerConfT extends BaseLayer>params - a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic INDArray getGradientsViewArray()
getGradientsViewArray in interface ModelgetGradientsViewArray in interface TrainablegetGradientsViewArray in class AbstractLayer<LayerConfT extends BaseLayer>public void setBackpropGradientsViewArray(INDArray gradients)
ModelsetBackpropGradientsViewArray in interface ModelsetBackpropGradientsViewArray 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,INDArray> paramTable)
ModelsetParamTable in interface ModelsetParamTable in class AbstractLayer<LayerConfT extends BaseLayer>public Map<String,INDArray> paramTable()
ModelparamTable in interface ModelparamTable in class AbstractLayer<LayerConfT extends BaseLayer>public Map<String,INDArray> paramTable(boolean backpropParamsOnly)
ModelparamTable in interface ModelparamTable in interface TrainableparamTable in class AbstractLayer<LayerConfT extends BaseLayer>backpropParamsOnly - If true, return backprop params only. If false: return all params (equivalent to
paramsTable())protected INDArray getParamWithNoise(String param, boolean training, LayerWorkspaceMgr workspaceMgr)
param - Parameter keytraining - If true: during trainingprotected INDArray preOutput(boolean training, LayerWorkspaceMgr workspaceMgr)
protected Pair<INDArray,INDArray> preOutputWithPreNorm(boolean training, boolean forBackprop, LayerWorkspaceMgr workspaceMgr)
public INDArray activate(boolean training, LayerWorkspaceMgr workspaceMgr)
Layertraining - training or test modeworkspaceMgr - Workspace managerArrayType.ACTIVATIONS workspace via the workspace managerpublic double calcRegularizationScore(boolean backpropParamsOnly)
LayercalcRegularizationScore in interface LayercalcRegularizationScore in class AbstractLayer<LayerConfT extends BaseLayer>backpropParamsOnly - If true: calculate regularization score based on backprop params only. If false: calculate
based on all params (including pretrain params, if any)public long numParams()
numParams in interface ModelnumParams in interface TrainablenumParams in class AbstractLayer<LayerConfT extends BaseLayer>public void fit(INDArray input, LayerWorkspaceMgr workspaceMgr)
Modelfit in interface Modelfit in class AbstractLayer<LayerConfT extends BaseLayer>input - the data to fit the model topublic void clear()
Modelclear in interface Modelclear in class AbstractLayer<LayerConfT extends BaseLayer>public void clearNoiseWeightParams()
public boolean hasBias()
public boolean hasLayerNorm()
Copyright © 2021. All rights reserved.