public class MultiLayerNetwork extends Object implements Serializable, Classifier, Layer, NeuralNetwork
ComputationGraph
which allows for an arbitrary directed acyclic graph connection structure between layers.
MultiLayerNetwork is trainable via backprop, with optional pretraining, depending on the type of layers it contains.Layer.TrainingMode, Layer.Type
Modifier and Type | Field and Description |
---|---|
protected boolean |
clearTbpttState |
protected NeuralNetConfiguration |
defaultConfiguration |
protected org.nd4j.linalg.api.ndarray.INDArray |
flattenedGradients |
protected org.nd4j.linalg.api.ndarray.INDArray |
flattenedParams |
protected Gradient |
gradient |
protected boolean |
initCalled |
protected boolean |
initDone |
protected org.nd4j.linalg.api.ndarray.INDArray |
input |
protected org.nd4j.linalg.api.ndarray.INDArray |
labels |
protected ThreadLocal<Long> |
lastEtlTime |
protected int |
layerIndex |
protected LinkedHashMap<String,Layer> |
layerMap |
protected Layer[] |
layers |
protected MultiLayerConfiguration |
layerWiseConfigurations |
protected org.nd4j.linalg.api.ndarray.INDArray |
mask |
protected double |
score |
protected Solver |
solver |
protected Collection<TrainingListener> |
trainingListeners |
protected static String |
WS_ALL_LAYERS_ACT
Workspace for storing all layers' activations - used only to store activations (layer inputs) as part of backprop
Not used for inference
|
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_ALL_LAYERS_ACT_CONFIG |
protected static String |
WS_LAYER_ACT_1
Next 2 workspaces: used for:
(a) Inference: holds activations for one layer only
(b) Backprop: holds activation gradients for one layer only
In both cases, they are opened and closed on every second layer
|
protected static String |
WS_LAYER_ACT_2 |
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_LAYER_ACT_X_CONFIG |
protected static String |
WS_LAYER_WORKING_MEM
Workspace for working memory for a single layer: forward pass and backward pass
Note that this is opened/closed once per op (activate/backpropGradient call)
|
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_LAYER_WORKING_MEM_CONFIG |
protected static String |
WS_RNN_LOOP_WORKING_MEM
Workspace for working memory in RNNs - opened and closed once per RNN time step
|
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_RNN_LOOP_WORKING_MEM_CONFIG |
Constructor and Description |
---|
MultiLayerNetwork(MultiLayerConfiguration conf) |
MultiLayerNetwork(MultiLayerConfiguration conf,
org.nd4j.linalg.api.ndarray.INDArray params)
Initialize the network based on the configuraiton
|
MultiLayerNetwork(String conf,
org.nd4j.linalg.api.ndarray.INDArray params)
Initialize the network based on the configuration
|
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,
LayerWorkspaceMgr mgr)
Perform forward pass and return the activations array with the last set input
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input)
Deprecated.
Use
output(INDArray) |
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
LayerWorkspaceMgr mgr)
Perform forward pass and return the activations array with the specified input
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
Layer.TrainingMode training) |
org.nd4j.linalg.api.ndarray.INDArray |
activate(Layer.TrainingMode training) |
org.nd4j.linalg.api.ndarray.INDArray |
activateSelectedLayers(int from,
int to,
org.nd4j.linalg.api.ndarray.INDArray input)
Calculate activation for few layers at once.
|
org.nd4j.linalg.api.ndarray.INDArray |
activationFromPrevLayer(int curr,
org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
LayerWorkspaceMgr mgr) |
void |
addListeners(TrainingListener... listeners)
This method ADDS additional TrainingListener to existing listeners
|
void |
applyConstraints(int iteration,
int epoch)
Apply any constraints to the model
|
org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> |
backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon,
LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layer
|
int |
batchSize()
The current inputs batch size
|
protected org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> |
calcBackpropGradients(org.nd4j.linalg.api.ndarray.INDArray epsilon,
boolean withOutputLayer,
boolean tbptt,
boolean returnInputActGrad)
Calculate gradients and errors.
|
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. |
org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> |
calculateGradients(org.nd4j.linalg.api.ndarray.INDArray features,
org.nd4j.linalg.api.ndarray.INDArray label,
org.nd4j.linalg.api.ndarray.INDArray fMask,
org.nd4j.linalg.api.ndarray.INDArray labelMask)
Calculate parameter gradients and input activation gradients given the input and labels
|
void |
clear()
Clear the inputs.
|
void |
clearLayerMaskArrays()
Remove the mask arrays from all layers.
See setLayerMaskArrays(INDArray, INDArray) for details on mask arrays. |
protected void |
clearLayersStates()
This method just makes sure there's no state preserved within layers
|
void |
clearNoiseWeightParams() |
MultiLayerNetwork |
clone()
Clones the multilayernetwork
|
void |
computeGradientAndScore() |
void |
computeGradientAndScore(LayerWorkspaceMgr layerWorkspaceMgr)
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
<T extends IEvaluation> |
doEvaluation(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
T... evaluations)
Perform evaluation using an arbitrary IEvaluation instance.
|
<T extends IEvaluation> |
doEvaluation(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator,
T[] evaluations)
This method executes evaluation of the model against given iterator and evaluation implementations
|
protected void |
doTruncatedBPTT(org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray labels,
org.nd4j.linalg.api.ndarray.INDArray featuresMaskArray,
org.nd4j.linalg.api.ndarray.INDArray labelsMaskArray,
LayerWorkspaceMgr workspaceMgr) |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
Evaluation |
evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Evaluate the network (classification performance)
|
Evaluation |
evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
List<String> labelsList)
Evaluate the network on the provided data set.
|
Evaluation |
evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
List<String> labelsList,
int topN)
Evaluate the network (for classification) on the provided data set, with top N accuracy in addition to standard accuracy.
|
RegressionEvaluation |
evaluateRegression(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Evaluate the network for regression performance
|
ROC |
evaluateROC(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Evaluate the network (must be a binary classifier) on the specified data, using the
ROC class. |
ROC |
evaluateROC(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network (must be a binary classifier) on the specified data, using the
ROC class |
ROCMultiClass |
evaluateROCMultiClass(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Evaluate the network on the specified data, using the
ROCMultiClass class. |
ROCMultiClass |
evaluateROCMultiClass(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network on the specified data, using the
ROCMultiClass class |
double |
f1Score(org.nd4j.linalg.dataset.api.DataSet data)
Sets the input and labels and returns a score for the prediction
wrt true labels
|
double |
f1Score(org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray labels)
Sets the input and labels and returns a score for the prediction
wrt true labels
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward()
Compute activations from input to output of the output layer
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward(boolean train)
Compute activations from input to output of the output layer
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward(boolean train,
boolean clearInputs)
Perform feed-forward, optionally (not) clearing the layer input arrays.
Note: this method should NOT be used with clearInputs = true, unless you know what you are doing. |
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward(org.nd4j.linalg.api.ndarray.INDArray input)
Compute activations from input to output of the output layer
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward(org.nd4j.linalg.api.ndarray.INDArray input,
boolean train)
Compute activations from input to output of the output layer
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForward(org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray featuresMask,
org.nd4j.linalg.api.ndarray.INDArray labelsMask)
Compute the activations from the input to the output layer, given mask arrays (that may be null)
The masking arrays are used in situations such an one-to-many and many-to-one rucerrent neural network (RNN)
designs, as well as for supporting time series of varying lengths within the same minibatch for RNNs.
|
org.nd4j.linalg.primitives.Pair<org.nd4j.linalg.api.ndarray.INDArray,MaskState> |
feedForwardMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray,
MaskState currentMaskState,
int minibatchSize)
Feed forward the input mask array, setting in in the layer as appropriate.
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForwardToLayer(int layerNum,
boolean train)
Compute the activations from the input to the specified layer, using the currently set input for the network.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForwardToLayer(int layerNum,
org.nd4j.linalg.api.ndarray.INDArray input)
Compute the activations from the input to the specified layer.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
List<org.nd4j.linalg.api.ndarray.INDArray> |
feedForwardToLayer(int layerNum,
org.nd4j.linalg.api.ndarray.INDArray input,
boolean train)
Compute the activations from the input to the specified layer.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
protected List<org.nd4j.linalg.api.ndarray.INDArray> |
ffToLayerActivationsDetached(boolean train,
FwdPassType fwdPassType,
boolean storeLastForTBPTT,
int layerIndex,
org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray fMask,
org.nd4j.linalg.api.ndarray.INDArray lMask,
boolean clearInputs)
Feed-forward through the network - returning all array activations in a list, detached from any workspace.
|
protected List<org.nd4j.linalg.api.ndarray.INDArray> |
ffToLayerActivationsInWs(int layerIndex,
FwdPassType fwdPassType,
boolean storeLastForTBPTT,
org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray fMask,
org.nd4j.linalg.api.ndarray.INDArray lMask)
Feed-forward through the network at training time - returning a list of all activations in a workspace (WS_ALL_LAYERS_ACT)
if workspaces are enabled for training; or detached if no workspaces are used.
Note: if using workspaces for training, this method requires that WS_ALL_LAYERS_ACT is open externally. If using NO workspaces, requires that no external workspace is open Note that this method does NOT clear the inputs to each layer - instead, they are in the WS_ALL_LAYERS_ACT workspace for use in later backprop. |
void |
finetune()
Run SGD based on the given labels
|
void |
fit()
All models have a fit method
|
void |
fit(org.nd4j.linalg.dataset.api.DataSet data)
Fit the model
|
void |
fit(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Perform minibatch training on all minibatches in the DataSetIterator.
Note that this method does not do layerwise pretraining. For pretraining use method pretrain.. |
void |
fit(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the DataSetIterator, for the specified number of epochs.
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray data,
org.nd4j.linalg.api.ndarray.INDArray labels)
Fit the model
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray features,
org.nd4j.linalg.api.ndarray.INDArray labels,
org.nd4j.linalg.api.ndarray.INDArray featuresMask,
org.nd4j.linalg.api.ndarray.INDArray labelsMask)
Fit the model
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray examples,
int[] labels)
Fit the model
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray data,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
void |
fit(org.nd4j.linalg.dataset.api.MultiDataSet dataSet)
This method fits model with a given MultiDataSet
|
void |
fit(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator)
Perform minibatch training on all minibatches in the MultiDataSetIterator.
Note: The MultiDataSets in the MultiDataSetIterator must have exactly 1 input and output array (as MultiLayerNetwork only supports 1 input and 1 output) |
void |
fit(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the MultiDataSetIterator, for the specified number of epochs.
|
NeuralNetConfiguration |
getDefaultConfiguration() |
int |
getEpochCount() |
org.nd4j.linalg.api.ndarray.INDArray |
getGradientsViewArray() |
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)
|
int |
getIterationCount() |
org.nd4j.linalg.api.ndarray.INDArray |
getLabels() |
long |
getLastEtlTime() |
Layer |
getLayer(int i) |
Layer |
getLayer(String name) |
List<String> |
getLayerNames() |
Layer[] |
getLayers() |
MultiLayerConfiguration |
getLayerWiseConfigurations() |
Collection<TrainingListener> |
getListeners()
Get the iteration listeners for this layer.
|
org.nd4j.linalg.api.ndarray.INDArray |
getMask() |
org.nd4j.linalg.api.ndarray.INDArray |
getMaskArray() |
int |
getnLayers()
Get the number of layers in the network
|
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
Layer |
getOutputLayer()
Get the output layer
|
org.nd4j.linalg.api.ndarray.INDArray |
getParam(String param)
Get the parameter
|
Collection<TrainingListener> |
getTrainingListeners() |
Updater |
getUpdater()
Get the updater for this MultiLayerNetwork
|
Gradient |
gradient()
Get the gradient.
|
org.nd4j.linalg.primitives.Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
protected boolean |
hasAFrozenLayer() |
void |
incrementEpochCount()
Increment the epoch count (in the underlying
MultiLayerConfiguration by 1). |
void |
init()
Initialize the MultiLayerNetwork.
|
void |
init(org.nd4j.linalg.api.ndarray.INDArray parameters,
boolean cloneParametersArray)
Initialize the MultiLayerNetwork, optionally with an existing parameters array.
|
void |
initGradientsView()
This method: initializes the flattened gradients array (used in backprop) and sets the appropriate subset in all layers.
|
void |
initParams()
Initialize the parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
input()
The input/feature matrix for the model
|
protected void |
intializeConfigurations() |
boolean |
isInitCalled() |
boolean |
isPretrainLayer()
Returns true if the layer can be trained in an unsupervised/pretrain manner (AE, VAE, etc)
|
org.nd4j.linalg.api.ndarray.INDArray |
labelProbabilities(org.nd4j.linalg.api.ndarray.INDArray examples)
Returns the probabilities for each label
for each example row wise
|
int |
layerInputSize(int layer)
Return the input size (number of inputs) for the specified layer.
Note that the meaning of the "input size" can depend on the type of layer. |
int |
layerSize(int layer)
Return the layer size (number of units) for the specified layer.
Note that the meaning of the "layer size" can depend on the type of layer. |
static MultiLayerNetwork |
load(File f,
boolean loadUpdater)
Restore a MultiLayerNetwork to a file, saved using
save(File) or ModelSerializer |
int |
numLabels()
Returns the number of possible labels
|
int |
numParams()
Returns a 1 x m vector where the vector is composed of
a flattened vector of all of the weights for the
various neuralNets and output layer
|
int |
numParams(boolean backwards)
the number of parameters for the model
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator,
boolean train)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.api.ndarray.INDArray input)
Label the probabilities of the input
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.api.ndarray.INDArray input,
boolean train)
Label the probabilities of the input
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.api.ndarray.INDArray input,
boolean train,
org.nd4j.linalg.api.ndarray.INDArray featuresMask,
org.nd4j.linalg.api.ndarray.INDArray labelsMask)
Calculate the output of the network, with masking arrays.
|
org.nd4j.linalg.api.ndarray.INDArray |
output(org.nd4j.linalg.api.ndarray.INDArray input,
Layer.TrainingMode train)
Label the probabilities of the input
|
protected org.nd4j.linalg.api.ndarray.INDArray |
outputOfLayerDetached(boolean train,
FwdPassType fwdPassType,
int layerIndex,
org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray featureMask,
org.nd4j.linalg.api.ndarray.INDArray labelsMask)
Provide the output of the specified layer, detached from any workspace.
|
org.nd4j.linalg.api.ndarray.INDArray |
params()
Returns a 1 x m vector where the vector is composed of
a flattened vector of all of the weights for the
various neuralNets(w,hbias NOT VBIAS) and output layer
|
org.nd4j.linalg.api.ndarray.INDArray |
params(boolean backwardOnly)
Returns a 1 x m vector where the vector is composed of
a flattened vector of all of the weights for the
various neuralNets(w,hbias NOT VBIAS) and output layer
|
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
|
List<String> |
predict(org.nd4j.linalg.dataset.api.DataSet dataSet)
Return predicted label names
|
int[] |
predict(org.nd4j.linalg.api.ndarray.INDArray d)
Returns the predictions for each example in the dataset
|
void |
pretrain(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Perform layerwise pretraining on all pre-trainable layers in the network (VAEs, Autoencoders, etc)
Note that pretraining will be performed on one layer after the other, resetting the DataSetIterator between iterations. For multiple epochs per layer, appropriately wrap the iterator (for example, a MultipleEpochsIterator) or train each layer manually using pretrainLayer(int, DataSetIterator) |
void |
pretrainLayer(int layerIdx,
org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Perform layerwise unsupervised training on a single pre-trainable layer in the network (VAEs, Autoencoders, etc)
If the specified layer index (0 to numLayers - 1) is not a pretrainable layer, this is a no-op. |
void |
pretrainLayer(int layerIdx,
org.nd4j.linalg.api.ndarray.INDArray features)
Perform layerwise unsupervised training on a single pre-trainable layer in the network (VAEs, Autoencoders, etc)
If the specified layer index (0 to numLayers - 1) is not a pretrainable layer, this is a no-op. |
void |
printConfiguration()
Prints the configuration
|
org.nd4j.linalg.api.ndarray.INDArray |
reconstruct(org.nd4j.linalg.api.ndarray.INDArray x,
int layerNum)
Reconstructs the input.
|
List<org.nd4j.linalg.api.ndarray.INDArray> |
rnnActivateUsingStoredState(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
boolean storeLastForTBPTT)
Similar to rnnTimeStep and feedForward() methods.
|
void |
rnnClearPreviousState()
Clear the previous state of the RNN layers (if any).
|
Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
rnnGetPreviousState(int layer)
Get the state of the RNN layer, as used in rnnTimeStep().
|
void |
rnnSetPreviousState(int layer,
Map<String,org.nd4j.linalg.api.ndarray.INDArray> state)
Set the state of the RNN layer.
|
org.nd4j.linalg.api.ndarray.INDArray |
rnnTimeStep(org.nd4j.linalg.api.ndarray.INDArray input)
If this MultiLayerNetwork contains one or more RNN layers: conduct forward pass (prediction)
but using previous stored state for any RNN layers.
|
void |
save(File f)
Save the MultiLayerNetwork to a file.
|
void |
save(File f,
boolean saveUpdater)
Save the MultiLayerNetwork to a file.
|
double |
score()
Score of the model (relative to the objective function)
|
double |
score(org.nd4j.linalg.dataset.DataSet data)
Sets the input and labels and returns a score for the prediction with respect to the true labels
This is equivalent to score(DataSet, boolean) with training==false. |
double |
score(org.nd4j.linalg.dataset.DataSet data,
boolean training)
Calculate the score (loss function) of the prediction with respect to the true labels
|
org.nd4j.linalg.api.ndarray.INDArray |
scoreExamples(org.nd4j.linalg.dataset.DataSet data,
boolean addRegularizationTerms)
Calculate the score for each example in a DataSet individually.
|
org.nd4j.linalg.api.ndarray.INDArray |
scoreExamples(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter,
boolean addRegularizationTerms) |
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 |
setCacheMode(CacheMode mode)
This method sets specified CacheMode for all layers within network
|
void |
setConf(NeuralNetConfiguration conf)
Setter for the configuration
|
void |
setEpochCount(int epochCount)
Set the current epoch count (number of epochs passed ) for the layer/network
|
void |
setGradientsAccumulator(GradientsAccumulator accumulator)
This method allows you to specificy GradientsAccumulator instance to be used with this model
PLEASE NOTE: Do not use this method unless you understand how to use GradientsAccumulator & updates sharing.
|
void |
setIndex(int index)
Set the layer index.
|
void |
setInput(org.nd4j.linalg.api.ndarray.INDArray input)
Note that if input isn't null
and the neuralNets are null, this is a way
of initializing the neural network
|
void |
setInput(org.nd4j.linalg.api.ndarray.INDArray input,
LayerWorkspaceMgr mgr)
Set the layer input.
|
void |
setInputMiniBatchSize(int size)
Set current/last input mini-batch size.
Used for score and gradient calculations. |
void |
setIterationCount(int iterationCount)
Set the current iteration count (number of parameter updates) for the layer/network
|
void |
setLabels(org.nd4j.linalg.api.ndarray.INDArray labels) |
void |
setLastEtlTime(long time) |
void |
setLayerMaskArrays(org.nd4j.linalg.api.ndarray.INDArray featuresMaskArray,
org.nd4j.linalg.api.ndarray.INDArray labelsMaskArray)
Set the mask arrays for features and labels.
|
void |
setLayers(Layer[] layers) |
void |
setLayerWiseConfigurations(MultiLayerConfiguration layerWiseConfigurations) |
void |
setLearningRate(double newLr)
Set the learning rate for all layers in the network to the specified value.
|
void |
setLearningRate(int layerNumber,
double newLr)
Set the learning rate for a single layer in the network to the specified value.
|
void |
setLearningRate(int layerNumber,
org.nd4j.linalg.schedule.ISchedule newLr)
Set the learning rate schedule for a single layer in the network to the specified value.
Note also that setLearningRate(ISchedule) should also be used in preference, when all layers need
to be set to a new LR schedule.This schedule will replace any/all existing schedules, and also any fixed learning rate values. Note also that the iteration/epoch counts will not be reset. |
void |
setLearningRate(org.nd4j.linalg.schedule.ISchedule newLr)
Set the learning rate schedule for all layers in the network to the specified schedule.
|
void |
setListeners(Collection<TrainingListener> listeners)
Set the trainingListeners for the ComputationGraph (and all layers in the network)
|
void |
setListeners(TrainingListener... listeners)
Set the trainingListeners for the ComputationGraph (and all layers in the network)
|
void |
setMask(org.nd4j.linalg.api.ndarray.INDArray mask) |
void |
setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray)
Set the mask array.
|
void |
setParam(String key,
org.nd4j.linalg.api.ndarray.INDArray val)
Set the parameter with a new ndarray
|
void |
setParameters(org.nd4j.linalg.api.ndarray.INDArray params)
Sets parameters for the model.
|
void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Set the parameters for this model.
|
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
|
void |
setScore(double score) |
void |
setUpdater(Updater updater)
Set the updater for the MultiLayerNetwork
|
String |
summary()
String detailing the architecture of the multilayernetwork.
|
String |
summary(InputType inputType)
String detailing the architecture of the multilayernetwork.
|
protected void |
synchronizeIterEpochCounts() |
ComputationGraph |
toComputationGraph()
Convert this MultiLayerNetwork to a ComputationGraph
|
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)
Perform one update applying the gradient
|
void |
update(MultiLayerNetwork network)
Assigns the parameters of this model to the ones specified by this
network.
|
protected void |
update(org.nd4j.linalg.heartbeat.reports.Task task) |
void |
updateRnnStateWithTBPTTState() |
org.nd4j.linalg.api.ndarray.INDArray |
updaterState()
This method returns updater state (if applicable), null otherwise
|
protected void |
validateArrayWorkspaces(LayerWorkspaceMgr mgr,
org.nd4j.linalg.api.ndarray.INDArray array,
ArrayType arrayType,
int layerIdx,
boolean isPreprocessor,
String op) |
void |
validateInput()
Validate the input
|
protected Layer[] layers
protected LinkedHashMap<String,Layer> layerMap
protected org.nd4j.linalg.api.ndarray.INDArray input
protected org.nd4j.linalg.api.ndarray.INDArray labels
protected boolean initCalled
protected Collection<TrainingListener> trainingListeners
protected NeuralNetConfiguration defaultConfiguration
protected MultiLayerConfiguration layerWiseConfigurations
protected Gradient gradient
protected double score
protected boolean initDone
protected org.nd4j.linalg.api.ndarray.INDArray flattenedParams
protected transient org.nd4j.linalg.api.ndarray.INDArray flattenedGradients
protected boolean clearTbpttState
protected transient ThreadLocal<Long> lastEtlTime
protected org.nd4j.linalg.api.ndarray.INDArray mask
protected int layerIndex
protected transient Solver solver
protected static final String WS_LAYER_WORKING_MEM
protected static final String WS_ALL_LAYERS_ACT
protected static final String WS_LAYER_ACT_1
protected static final String WS_LAYER_ACT_2
protected static final String WS_RNN_LOOP_WORKING_MEM
protected final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_LAYER_WORKING_MEM_CONFIG
protected static final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_ALL_LAYERS_ACT_CONFIG
protected final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_LAYER_ACT_X_CONFIG
protected static final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_RNN_LOOP_WORKING_MEM_CONFIG
public MultiLayerNetwork(MultiLayerConfiguration conf)
public MultiLayerNetwork(String conf, org.nd4j.linalg.api.ndarray.INDArray params)
conf
- the configuration jsonparams
- the parameterspublic MultiLayerNetwork(MultiLayerConfiguration conf, org.nd4j.linalg.api.ndarray.INDArray params)
conf
- the configurationparams
- the parameterspublic void setCacheMode(CacheMode mode)
setCacheMode
in interface Layer
mode
- public void setLastEtlTime(long time)
public long getLastEtlTime()
protected void intializeConfigurations()
public void pretrain(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
pretrainLayer(int, DataSetIterator)
iter
- Training datapublic void pretrainLayer(int layerIdx, org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
layerIdx
- Index of the layer to train (0 to numLayers-1)iter
- Training datapublic void pretrainLayer(int layerIdx, org.nd4j.linalg.api.ndarray.INDArray features)
layerIdx
- Index of the layer to train (0 to numLayers-1)features
- Training data arraypublic int batchSize()
Model
public NeuralNetConfiguration conf()
Model
public void setConf(NeuralNetConfiguration conf)
Model
public org.nd4j.linalg.api.ndarray.INDArray input()
Model
public void validateInput()
Model
validateInput
in interface Model
public ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
getOptimizer
in interface NeuralNetwork
public org.nd4j.linalg.api.ndarray.INDArray getParam(String param)
Model
public void initParams()
Model
initParams
in interface Model
public Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable()
Model
paramTable
in interface Model
public Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable(boolean backpropParamsOnly)
Model
paramTable
in interface Model
backpropParamsOnly
- If true, return backprop params only. If false: return all params (equivalent to
paramsTable())public void setParamTable(Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Model
setParamTable
in interface Model
public void setParam(String key, org.nd4j.linalg.api.ndarray.INDArray val)
Model
public MultiLayerConfiguration getLayerWiseConfigurations()
public void setLayerWiseConfigurations(MultiLayerConfiguration layerWiseConfigurations)
public void init()
init(null, false)
.init
in interface Model
init
in interface NeuralNetwork
init(INDArray, boolean)
public void init(org.nd4j.linalg.api.ndarray.INDArray parameters, boolean cloneParametersArray)
parameters
- Network parameter. May be null. If null: randomly initialize.cloneParametersArray
- Whether the parameter array (if any) should be cloned, or used directlypublic void setGradientsAccumulator(GradientsAccumulator accumulator)
accumulator
- public boolean isInitCalled()
public void initGradientsView()
@Deprecated public org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input)
output(INDArray)
public org.nd4j.linalg.api.ndarray.INDArray activationFromPrevLayer(int curr, org.nd4j.linalg.api.ndarray.INDArray input, boolean training, LayerWorkspaceMgr mgr)
public org.nd4j.linalg.api.ndarray.INDArray activateSelectedLayers(int from, int to, org.nd4j.linalg.api.ndarray.INDArray input)
from
- first layer to be activated, inclusiveto
- last layer to be activated, inclusivepublic List<org.nd4j.linalg.api.ndarray.INDArray> feedForward(org.nd4j.linalg.api.ndarray.INDArray input, boolean train)
public List<org.nd4j.linalg.api.ndarray.INDArray> feedForward(boolean train)
public List<org.nd4j.linalg.api.ndarray.INDArray> feedForward(boolean train, boolean clearInputs)
train
- training modeclearInputs
- If false: don't clear the layer inputspublic List<org.nd4j.linalg.api.ndarray.INDArray> feedForwardToLayer(int layerNum, org.nd4j.linalg.api.ndarray.INDArray input)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)input
- Input to the networkpublic List<org.nd4j.linalg.api.ndarray.INDArray> feedForwardToLayer(int layerNum, org.nd4j.linalg.api.ndarray.INDArray input, boolean train)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)input
- Input to the networktrain
- true for training, false for test (i.e., false if using network after training)public List<org.nd4j.linalg.api.ndarray.INDArray> feedForwardToLayer(int layerNum, boolean train)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)train
- true for training, false for test (i.e., false if using network after training)protected void validateArrayWorkspaces(LayerWorkspaceMgr mgr, org.nd4j.linalg.api.ndarray.INDArray array, ArrayType arrayType, int layerIdx, boolean isPreprocessor, String op)
protected List<org.nd4j.linalg.api.ndarray.INDArray> ffToLayerActivationsDetached(boolean train, @NonNull FwdPassType fwdPassType, boolean storeLastForTBPTT, int layerIndex, @NonNull org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray fMask, org.nd4j.linalg.api.ndarray.INDArray lMask, boolean clearInputs)
train
- Training mode (true) or test/inference mode (false)fwdPassType
- Type of forward pass to perform (STANDARD or RNN_ACTIVATE_WITH_STORED_STATE only)storeLastForTBPTT
- ONLY used if fwdPassType == FwdPassType.RNN_ACTIVATE_WITH_STORED_STATElayerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1input
- Input to the networkfMask
- Feature mask array. May be null.lMask
- Label mask array. May be null.clearInputs
- Whether the layer inputs should be clearedprotected List<org.nd4j.linalg.api.ndarray.INDArray> ffToLayerActivationsInWs(int layerIndex, @NonNull FwdPassType fwdPassType, boolean storeLastForTBPTT, @NonNull org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray fMask, org.nd4j.linalg.api.ndarray.INDArray lMask)
layerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1fwdPassType
- Type of forward pass to perform (STANDARD or RNN_ACTIVATE_WITH_STORED_STATE only)storeLastForTBPTT
- ONLY used if fwdPassType == FwdPassType.RNN_ACTIVATE_WITH_STORED_STATEinput
- Input to networkfMask
- Feature mask array. May be nulllMask
- Label mask aray. May be null.protected org.nd4j.linalg.api.ndarray.INDArray outputOfLayerDetached(boolean train, @NonNull FwdPassType fwdPassType, int layerIndex, @NonNull org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray featureMask, org.nd4j.linalg.api.ndarray.INDArray labelsMask)
ffToLayerActivationsDetached(boolean, FwdPassType, boolean, int, INDArray, INDArray, INDArray, boolean)
and ffToLayerActivationsInWs(int, FwdPassType, boolean, INDArray, INDArray, INDArray)
.train
- Training mode (true) or test/inference mode (false)fwdPassType
- Type of forward pass to perform (STANDARD, RNN_TIMESTEP or RNN_ACTIVATE_WITH_STORED_STATE)layerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1input
- Input to the networkfeatureMask
- Input/feature mask array. May be null.labelsMask
- Labels mask array. May be nullpublic List<org.nd4j.linalg.api.ndarray.INDArray> feedForward()
public List<org.nd4j.linalg.api.ndarray.INDArray> feedForward(org.nd4j.linalg.api.ndarray.INDArray input)
public List<org.nd4j.linalg.api.ndarray.INDArray> feedForward(org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray featuresMask, org.nd4j.linalg.api.ndarray.INDArray labelsMask)
public Gradient gradient()
Model
Model#computeGradientAndScore()
.public org.nd4j.linalg.primitives.Pair<Gradient,Double> gradientAndScore()
Model
gradientAndScore
in interface Model
public MultiLayerNetwork clone()
protected boolean hasAFrozenLayer()
public org.nd4j.linalg.api.ndarray.INDArray params(boolean backwardOnly)
public org.nd4j.linalg.api.ndarray.INDArray params()
params
in interface Model
params
in interface NeuralNetwork
public void setParams(org.nd4j.linalg.api.ndarray.INDArray params)
public void setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
Model
setParamsViewArray
in interface Model
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
public void setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
Model
setBackpropGradientsViewArray
in interface Model
gradients
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic int numParams()
public int numParams(boolean backwards)
Model
public double f1Score(org.nd4j.linalg.dataset.api.DataSet data)
f1Score
in interface Classifier
data
- the data to scorepublic void fit(@NonNull org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, int numEpochs)
fit(DataSetIterator)
numEpochs times in a loopiterator
- Training data (DataSetIterator). Iterator must support resettingnumEpochs
- Number of training epochs, >= 1public void fit(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
pretrain(DataSetIterator)
fit
in interface Classifier
fit
in interface NeuralNetwork
iterator
- Training data (DataSetIterator)public org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> calculateGradients(@NonNull org.nd4j.linalg.api.ndarray.INDArray features, @NonNull org.nd4j.linalg.api.ndarray.INDArray label, org.nd4j.linalg.api.ndarray.INDArray fMask, org.nd4j.linalg.api.ndarray.INDArray labelMask)
features
- Features for gradient calculationlabel
- Labels for gradientfMask
- Features mask array (may be null)labelMask
- Label mask array (may be null)protected org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> calcBackpropGradients(org.nd4j.linalg.api.ndarray.INDArray epsilon, boolean withOutputLayer, boolean tbptt, boolean returnInputActGrad)
epsilon
- Errors (technically errors .* activations). Not used if withOutputLayer = truewithOutputLayer
- if true: assume last layer is output layer, and calculate errors based on labels. In this
case, the epsilon input is not used (may/should be null).
If false: calculate backprop gradientsreturnInputActGrad
- If true: terun the input activation gradients (detached). False: don't returnprotected void doTruncatedBPTT(org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray labels, org.nd4j.linalg.api.ndarray.INDArray featuresMaskArray, org.nd4j.linalg.api.ndarray.INDArray labelsMaskArray, LayerWorkspaceMgr workspaceMgr)
public void updateRnnStateWithTBPTTState()
public Collection<TrainingListener> getListeners()
Layer
getListeners
in interface Layer
public Collection<TrainingListener> getTrainingListeners()
public void setListeners(Collection<TrainingListener> listeners)
Model
setListeners
in interface Layer
setListeners
in interface Model
public void addListeners(TrainingListener... listeners)
addListeners
in interface Model
listeners
- public void setListeners(TrainingListener... listeners)
Model
setListeners
in interface Layer
setListeners
in interface Model
public void finetune()
public int[] predict(org.nd4j.linalg.api.ndarray.INDArray d)
predict
in interface Classifier
d
- the matrix to predictpublic List<String> predict(org.nd4j.linalg.dataset.api.DataSet dataSet)
predict
in interface Classifier
dataSet
- to predictpublic org.nd4j.linalg.api.ndarray.INDArray labelProbabilities(org.nd4j.linalg.api.ndarray.INDArray examples)
labelProbabilities
in interface Classifier
examples
- the examples to classify (one example in each row)public void fit(org.nd4j.linalg.api.ndarray.INDArray data, org.nd4j.linalg.api.ndarray.INDArray labels)
fit
in interface Classifier
data
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)public void fit(org.nd4j.linalg.api.ndarray.INDArray features, org.nd4j.linalg.api.ndarray.INDArray labels, org.nd4j.linalg.api.ndarray.INDArray featuresMask, org.nd4j.linalg.api.ndarray.INDArray labelsMask)
features
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)featuresMask
- The mask array for the features (used for variable length time series, etc). May be null.labelsMask
- The mask array for the labels (used for variable length time series, etc). May be null.public void fit(org.nd4j.linalg.api.ndarray.INDArray data, LayerWorkspaceMgr workspaceMgr)
Model
public void fit(org.nd4j.linalg.dataset.api.DataSet data)
fit
in interface Classifier
fit
in interface NeuralNetwork
data
- the data to train onpublic void fit(org.nd4j.linalg.api.ndarray.INDArray examples, int[] labels)
fit
in interface Classifier
examples
- the examples to classify (one example in each row)labels
- the labels for each example (the number of labels must matchpublic org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.api.ndarray.INDArray input, Layer.TrainingMode train)
input
- the input to labeltrain
- whether the output
is test or train. This mainly
affect hyper parameters such as
drop out where certain things should
be applied with activationsThis is typically of the form: [0.5, 0.5] or some other probability distribution summing to one
public org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.api.ndarray.INDArray input, boolean train)
input
- the input to labeltrain
- whether the output
is test or train. This mainly
affect hyper parameters such as
drop out where certain things should
be applied with activationsThis is typically of the form: [0.5, 0.5] or some other probability distribution summing to one
public org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.api.ndarray.INDArray input, boolean train, org.nd4j.linalg.api.ndarray.INDArray featuresMask, org.nd4j.linalg.api.ndarray.INDArray labelsMask)
public org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.api.ndarray.INDArray input)
input
- the input to labelThis is typically of the form: [0.5, 0.5] or some other probability distribution summing to one
public org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, boolean train)
iterator
- Data to pass through the networkpublic org.nd4j.linalg.api.ndarray.INDArray output(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
iterator
- Data to pass through the networkpublic org.nd4j.linalg.api.ndarray.INDArray reconstruct(org.nd4j.linalg.api.ndarray.INDArray x, int layerNum)
x
- the input to transformlayerNum
- the layer to output for encodingThis is typically of the form: [0.5, 0.5] or some other probability distribution summing to one
public void printConfiguration()
public void update(MultiLayerNetwork network)
network
- the network to get parameters frompublic double f1Score(org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray labels)
f1Score
in interface Classifier
input
- the input to scorelabels
- the true labelspublic int numLabels()
numLabels
in interface Classifier
public double score(org.nd4j.linalg.dataset.DataSet data)
score(DataSet, boolean)
with training==false.data
- the data to scorescore(DataSet, boolean)
public double score(org.nd4j.linalg.dataset.DataSet data, boolean training)
data
- data to calculate score fortraining
- If true: score during training. If false: score at test time. This can affect the application of
certain features, such as dropout and dropconnect (which are applied at training time only)public org.nd4j.linalg.api.ndarray.INDArray scoreExamples(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter, boolean addRegularizationTerms)
public org.nd4j.linalg.api.ndarray.INDArray scoreExamples(org.nd4j.linalg.dataset.DataSet data, boolean addRegularizationTerms)
score(DataSet)
and score(DataSet, boolean)
this method does not average/sum over examples. This method allows for examples to be scored individually (at test time only), which
may be useful for example for autoencoder architectures and the like.data
- The data to scoreaddRegularizationTerms
- If true: add l1/l2 regularization terms (if any) to the score. If false: don't add regularization termspublic void fit()
Model
public void update(org.nd4j.linalg.api.ndarray.INDArray gradient, String paramType)
Model
public double score()
public void setScore(double score)
public void computeGradientAndScore(LayerWorkspaceMgr layerWorkspaceMgr)
Model
computeGradientAndScore
in interface Model
public void computeGradientAndScore()
public void accumulateScore(double accum)
Model
accumulateScore
in interface Model
accum
- the amount to accumpublic void clear()
public void applyConstraints(int iteration, int epoch)
Model
applyConstraints
in interface Model
public void setInput(org.nd4j.linalg.api.ndarray.INDArray input)
input
- public void setInput(org.nd4j.linalg.api.ndarray.INDArray input, LayerWorkspaceMgr mgr)
Layer
public Layer getOutputLayer()
public void setParameters(org.nd4j.linalg.api.ndarray.INDArray params)
params
- a parameter vector equal 1,numParameterspublic NeuralNetConfiguration getDefaultConfiguration()
public org.nd4j.linalg.api.ndarray.INDArray getLabels()
public org.nd4j.linalg.api.ndarray.INDArray getInput()
public void setLabels(org.nd4j.linalg.api.ndarray.INDArray labels)
labels
- public int getnLayers()
public Layer[] getLayers()
public Layer getLayer(int i)
public void setLayers(Layer[] layers)
public org.nd4j.linalg.api.ndarray.INDArray getMask()
public void setMask(org.nd4j.linalg.api.ndarray.INDArray mask)
public org.nd4j.linalg.api.ndarray.INDArray getMaskArray()
getMaskArray
in interface Layer
public boolean isPretrainLayer()
Layer
isPretrainLayer
in interface Layer
public void clearNoiseWeightParams()
clearNoiseWeightParams
in interface Layer
public org.nd4j.linalg.primitives.Pair<org.nd4j.linalg.api.ndarray.INDArray,MaskState> feedForwardMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray, MaskState currentMaskState, int minibatchSize)
Layer
feedForwardMaskArray
in interface Layer
maskArray
- Mask array to setcurrentMaskState
- Current state of the mask - see MaskState
minibatchSize
- Current minibatch size. Needs to be known as it cannot always be inferred from the activations
array due to reshaping (such as a DenseLayer within a recurrent neural network)public Layer.Type type()
Layer
public org.nd4j.linalg.api.ndarray.INDArray activate(Layer.TrainingMode training)
public org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input, Layer.TrainingMode training)
public Layer transpose()
Layer
public org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
Layer
backpropGradient
in interface 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.workspaceMgr
- Workspace managerArrayType.ACTIVATION_GRAD
workspace via the workspace managerpublic void setIndex(int index)
Layer
public int getIndex()
Layer
public int getIterationCount()
getIterationCount
in interface Layer
public int getEpochCount()
getEpochCount
in interface Layer
public void setIterationCount(int iterationCount)
Layer
setIterationCount
in interface Layer
public void setEpochCount(int epochCount)
Layer
setEpochCount
in interface Layer
public double calcL2(boolean backpropParamsOnly)
Layer
public double calcL1(boolean backpropParamsOnly)
Layer
public void update(Gradient gradient)
Model
public org.nd4j.linalg.api.ndarray.INDArray activate(boolean training, LayerWorkspaceMgr mgr)
Layer
activate
in interface Layer
training
- training or test modemgr
- Workspace managerArrayType.ACTIVATIONS
workspace via the workspace managerpublic org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input, boolean training, LayerWorkspaceMgr mgr)
Layer
activate
in interface Layer
input
- the input to usetraining
- train or test modemgr
- Workspace manager.ArrayType.ACTIVATIONS
workspace via the workspace managerpublic void setInputMiniBatchSize(int size)
Layer
setInputMiniBatchSize
in interface Layer
public int getInputMiniBatchSize()
Layer
getInputMiniBatchSize
in interface Layer
Layer.setInputMiniBatchSize(int)
public void setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray)
Layer
Layer.feedForwardMaskArray(INDArray, MaskState, int)
should be used in
preference to this.setMaskArray
in interface Layer
maskArray
- Mask array to setpublic org.nd4j.linalg.api.ndarray.INDArray rnnTimeStep(org.nd4j.linalg.api.ndarray.INDArray input)
input
- Input to network. May be for one or multiple time steps. For single time step:
input has shape [miniBatchSize,inputSize] or [miniBatchSize,inputSize,1]. miniBatchSize=1 for single example.public Map<String,org.nd4j.linalg.api.ndarray.INDArray> rnnGetPreviousState(int layer)
layer
- Number/index of the layer.public void rnnSetPreviousState(int layer, Map<String,org.nd4j.linalg.api.ndarray.INDArray> state)
layer
- The number/index of the layer.state
- The state to set the specified layer topublic void rnnClearPreviousState()
public List<org.nd4j.linalg.api.ndarray.INDArray> rnnActivateUsingStoredState(org.nd4j.linalg.api.ndarray.INDArray input, boolean training, boolean storeLastForTBPTT)
input
- Input to networktraining
- Whether training or notstoreLastForTBPTT
- set to true if used as part of truncated BPTT trainingpublic Updater getUpdater()
public void setUpdater(Updater updater)
public void setLayerMaskArrays(org.nd4j.linalg.api.ndarray.INDArray featuresMaskArray, org.nd4j.linalg.api.ndarray.INDArray labelsMaskArray)
feedForward(INDArray, INDArray, INDArray)
and output(INDArray, boolean, INDArray, INDArray)
handle setting of masking internally.featuresMaskArray
- Mask array for features (input)labelsMaskArray
- Mask array for labels (output)clearLayerMaskArrays()
public void clearLayerMaskArrays()
setLayerMaskArrays(INDArray, INDArray)
for details on mask arrays.public Evaluation evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
iterator
- Iterator to evaluate onpublic RegressionEvaluation evaluateRegression(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
iterator
- Data to evaluate onpublic ROC evaluateROC(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
ROC
class.
Defaults to exact mode for ROC
instead of thresholdediterator
- Data to evaluate onpublic ROC evaluateROC(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, int rocThresholdSteps)
ROC
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROC
public ROCMultiClass evaluateROCMultiClass(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator)
ROCMultiClass
class. Defaults to exact mode for
ROCMultiClass
instead of thresholdediterator
- Data to evaluate onpublic ROCMultiClass evaluateROCMultiClass(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, int rocThresholdSteps)
ROCMultiClass
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROCMultiClass
public <T extends IEvaluation> T[] doEvaluation(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, T... evaluations)
doEvaluation
in interface NeuralNetwork
iterator
- data to evaluate onpublic Evaluation evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, List<String> labelsList)
iterator
- Data to undertake evaluation onpublic org.nd4j.linalg.api.ndarray.INDArray updaterState()
NeuralNetwork
updaterState
in interface NeuralNetwork
public void fit(org.nd4j.linalg.dataset.api.MultiDataSet dataSet)
NeuralNetwork
fit
in interface NeuralNetwork
public void fit(@NonNull org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator, int numEpochs)
fit(MultiDataSetIterator)
numEpochs times in a loopiterator
- Training data (DataSetIterator). Iterator must support resettingnumEpochs
- Number of training epochs, >= 1public void fit(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator)
fit
in interface NeuralNetwork
iterator
- Training data (DataSetIterator). Iterator must support resettingpublic <T extends IEvaluation> T[] doEvaluation(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator iterator, T[] evaluations)
NeuralNetwork
doEvaluation
in interface NeuralNetwork
public Evaluation evaluate(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iterator, List<String> labelsList, int topN)
iterator
- Iterator (data) to evaluate onlabelsList
- List of labels. May be null.topN
- N value for top N accuracy evaluationprotected void update(org.nd4j.linalg.heartbeat.reports.Task task)
public String summary()
public String summary(InputType inputType)
protected void clearLayersStates()
public void incrementEpochCount()
MultiLayerConfiguration
by 1).
Note that this is done automatically when using iterator-based fitting methods, such as
fit(DataSetIterator)
. However, when using non-iterator fit methods (DataSet, INDArray/INDArray etc),
the network has no way to know when one epoch ends and another starts. In such situations, this method
can be used to increment the epoch counter.MultiLayerConfiguration.getLayerwiseConfiguration().getEpochCount()
protected void synchronizeIterEpochCounts()
public void save(File f) throws IOException
load(File, boolean)
.
Note that this saves the updater (i.e., the state array for momentum/Adam/rmsprop etc), which is desirable
if further training will be undertaken.f
- File to save the network toIOException
ModelSerializer for more details (and saving/loading via streams)
,
save(File, boolean)
public void save(File f, boolean saveUpdater) throws IOException
load(File, boolean)
.f
- File to save the network tosaveUpdater
- If true: save the updater (i.e., the state array for momentum/Adam/rmsprop etc), which should
usually be saved if further training is requiredIOException
ModelSerializer for more details (and saving/loading via streams)
,
save(File, boolean)
public static MultiLayerNetwork load(File f, boolean loadUpdater) throws IOException
save(File)
or ModelSerializer
f
- File to load the network fromloadUpdater
- If true: load the updater if it is available (i.e., the state array for momentum/Adam/rmsprop
etc) - use false if no further training is required, or true if further training
will be undertakenIOException
ModelSerializer for more details (and saving/loading via streams)
public ComputationGraph toComputationGraph()
public void setLearningRate(double newLr)
newLr
- New learning rate for all layerssetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(org.nd4j.linalg.schedule.ISchedule newLr)
MultiLayerConfiguration#setIterationCount(int)
and MultiLayerConfiguration#setEpochCount(int)
if this is requirednewLr
- New learning rate schedule for all layerssetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(int layerNumber, double newLr)
setLearningRate(double)
should also be used in preference, when all layers need to be set to a new LRlayerNumber
- Number of the layer to set the LR fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(int layerNumber, org.nd4j.linalg.schedule.ISchedule newLr)
setLearningRate(ISchedule)
should also be used in preference, when all layers need
to be set to a new LR schedule.MultiLayerConfiguration#setIterationCount(int)
and MultiLayerConfiguration#setEpochCount(int)
if this is requiredlayerNumber
- Number of the layer to set the LR schedule fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(int, double)
public int layerSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic int layerInputSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic boolean equals(Object obj)
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
Copyright © 2018. All rights reserved.