public class ComputationGraph extends Object implements Serializable, Model, NeuralNetwork
Modifier and Type | Field and Description |
---|---|
protected boolean |
clearTbpttState |
protected ComputationGraphConfiguration |
configuration |
protected INDArray |
flattenedGradients |
protected INDArray |
flattenedParams |
protected Gradient |
gradient |
protected GraphIndices |
graphIndices
Topological sort and vertex index/name + name/index mapping
|
protected Map<String,org.bytedeco.javacpp.Pointer> |
helperWorkspaces |
protected boolean |
initCalled |
protected ThreadLocal<Long> |
lastEtlTime |
protected Layer[] |
layers
A list of layers.
|
protected double |
score |
protected Solver |
solver |
protected int[] |
topologicalOrder
Indexes of graph vertices, in topological order.
|
protected GraphVertex[] |
vertices
All GraphVertex objects in the network.
|
protected Map<String,GraphVertex> |
verticesMap
Map of vertices by name
|
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 WorkspaceConfiguration |
WS_ALL_LAYERS_ACT_CONFIG |
protected 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 WorkspaceConfiguration |
WS_LAYER_WORKING_MEM_CONFIG |
protected static String |
WS_OUTPUT_MEM
Workspace for output methods that use OutputAdapter
|
protected static String |
WS_RNN_LOOP_WORKING_MEM
Workspace for working memory in RNNs - opened and closed once per RNN time step
|
protected static WorkspaceConfiguration |
WS_RNN_LOOP_WORKING_MEM_CONFIG |
Constructor and Description |
---|
ComputationGraph(ComputationGraphConfiguration configuration) |
Modifier and Type | Method and Description |
---|---|
void |
addListeners(TrainingListener... listeners)
This method ADDS additional TrainingListener to existing listeners
|
void |
applyConstraints(int iteration,
int epoch)
Apply any constraints to the model
|
Gradient |
backpropGradient(INDArray... epsilons)
Calculate the gradient of the network with respect to some external errors.
|
int |
batchSize()
The current inputs batch size
|
protected void |
calcBackpropGradients(boolean clearLayers,
boolean truncatedBPTT,
INDArray... externalEpsilons)
Do backprop (gradient calculation)
|
double |
calcRegularizationScore(boolean backpropParamsOnly) |
GraphIndices |
calculateIndices()
Calculate the indices needed for the network:
(a) topological sort order (b) Map: vertex index -> vertex name (c) Map: vertex name -> vertex index |
void |
clear()
Clear input
|
void |
clearLayerMaskArrays()
Remove the mask arrays from all layers.
See setLayerMaskArrays(INDArray[], INDArray[]) for details on mask arrays. |
void |
clearLayersStates()
This method just makes sure there's no state preserved within layers
|
ComputationGraph |
clone() |
void |
close()
Close the network and deallocate all native memory, including: parameters, gradients, updater memory and workspaces
Note that the network should not be used again for any purpose after it has been closed
|
void |
computeGradientAndScore() |
void |
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
ComputationGraph |
convertDataType(@NonNull DataType dataType)
Return a copy of the network with the parameters and activations set to use the specified (floating point) data type.
|
<T extends IEvaluation> |
doEvaluation(DataSetIterator iterator,
T... evaluations)
Perform evaluation on the given data (DataSetIterator) with the given
IEvaluation instance |
<T extends IEvaluation> |
doEvaluation(MultiDataSetIterator iterator,
T... evaluations)
Perform evaluation on the given data (MultiDataSetIterator) with the given
IEvaluation instance |
protected void |
doTruncatedBPTT(INDArray[] inputs,
INDArray[] labels,
INDArray[] featureMasks,
INDArray[] labelMasks,
LayerWorkspaceMgr workspaceMgr)
Fit the network using truncated BPTT
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
<T extends Evaluation> |
evaluate(DataSetIterator iterator)
Evaluate the network (classification performance - single output ComputationGraphs only)
|
<T extends Evaluation> |
evaluate(DataSetIterator iterator,
List<String> labelsList)
Evaluate the network on the provided data set (single output ComputationGraphs only).
|
<T extends Evaluation> |
evaluate(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.
|
<T extends IEvaluation> |
evaluate(DataSetIterator iterator,
Map<Integer,T[]> evaluations)
Perform evaluation for networks with multiple outputs.
|
<T extends Evaluation> |
evaluate(MultiDataSetIterator iterator)
Evaluate the network (classification performance - single output ComputationGraphs only)
|
<T extends Evaluation> |
evaluate(MultiDataSetIterator iterator,
List<String> labelsList)
Evaluate the network on the provided data set (single output ComputationGraphs only).
|
<T extends Evaluation> |
evaluate(MultiDataSetIterator 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.
|
<T extends IEvaluation> |
evaluate(MultiDataSetIterator iterator,
Map<Integer,T[]> evaluations)
Perform evaluation for networks with multiple outputs.
|
<T extends RegressionEvaluation> |
evaluateRegression(DataSetIterator iterator)
Evaluate the (single output layer only) network for regression performance
|
<T extends RegressionEvaluation> |
evaluateRegression(DataSetIterator iterator,
List<String> columnNames)
Evaluate the (single output layer only) network for regression performance
|
<T extends RegressionEvaluation> |
evaluateRegression(MultiDataSetIterator iterator)
Evaluate the (single output layer only) network for regression performance
|
<T extends RegressionEvaluation> |
evaluateRegression(MultiDataSetIterator iterator,
List<String> columnNames)
Evaluate the (single output layer only) network for regression performance
|
<T extends ROC> |
evaluateROC(DataSetIterator iterator)
Deprecated.
To be removed - use
evaluateROC(DataSetIterator, int) to enforce selection of appropriate ROC/threshold configuration |
<T extends ROC> |
evaluateROC(DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network (must be a binary classifier) on the specified data, using the
ROC class |
<T extends ROC> |
evaluateROC(MultiDataSetIterator iterator)
Deprecated.
To be removed - use
evaluateROC(DataSetIterator, int) to enforce selection of appropriate ROC/threshold configuration |
<T extends ROC> |
evaluateROC(MultiDataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network (must be a binary classifier) on the specified data, using the
ROC class |
<T extends ROCMultiClass> |
evaluateROCMultiClass(DataSetIterator iterator)
Deprecated.
To be removed - use
evaluateROCMultiClass(DataSetIterator, int) to enforce selection of appropriate ROC/threshold configuration |
<T extends ROCMultiClass> |
evaluateROCMultiClass(DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network on the specified data, using the
ROCMultiClass class |
<T extends ROCMultiClass> |
evaluateROCMultiClass(MultiDataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network on the specified data, using the
ROCMultiClass class |
Map<String,INDArray> |
feedForward()
Conduct forward pass using the stored inputs, at test time
|
Map<String,INDArray> |
feedForward(boolean train)
Conduct forward pass using the stored inputs
|
Map<String,INDArray> |
feedForward(boolean train,
boolean excludeOutputLayers,
boolean includeNonLayerVertexActivations) |
Map<String,INDArray> |
feedForward(boolean train,
int layerTillIndex)
Conduct forward pass using the stored inputs
|
Map<String,INDArray> |
feedForward(INDArray[] input,
boolean train)
Conduct forward pass using an array of inputs
|
Map<String,INDArray> |
feedForward(INDArray[] input,
boolean train,
boolean clearInputs)
Conduct forward pass using an array of inputs.
|
Map<String,INDArray> |
feedForward(INDArray[] input,
int layerTillIndex,
boolean train)
Conduct forward pass using an array of inputs
|
Map<String,INDArray> |
feedForward(INDArray[] input,
int layerTillIndex,
boolean train,
boolean clearInputs)
Conduct forward pass using an array of inputs.
|
Map<String,INDArray> |
feedForward(INDArray input,
boolean train)
Conduct forward pass using a single input array.
|
Map<String,INDArray> |
feedForward(INDArray input,
int layerTillIndex,
boolean train)
Conduct forward pass using a single input array.
|
protected Map<String,INDArray> |
ffToLayerActivationsDetached(boolean train,
@NonNull FwdPassType fwdPassType,
boolean storeLastForTBPTT,
int layerIndex,
int[] excludeIdxs,
@NonNull INDArray[] features,
INDArray[] fMask,
INDArray[] lMask,
boolean clearLayers)
Feed-forward through the network - returning all array activations detached from any workspace.
|
protected Map<String,INDArray> |
ffToLayerActivationsInWS(boolean train,
int layerIndex,
int[] excludeIdxs,
FwdPassType fwdPassType,
boolean storeLastForTBPTT,
INDArray[] input,
INDArray[] fMask,
INDArray[] lMask,
boolean clearInputs)
Feed-forward through the network - if workspaces are used, all returned activations will be present in workspace
WS_ALL_LAYERS_ACT.
Note: if using workspaces for training, requires that WS_ALL_LAYERS_ACT is open externally. |
void |
fit()
All models have a fit method
|
void |
fit(DataSet dataSet)
Fit the ComputationGraph using a DataSet.
|
void |
fit(@NonNull DataSetIterator iterator)
Fit the ComputationGraph using a DataSetIterator.
Note that this method can only be used with ComputationGraphs with 1 input and 1 output Method doesn't do layerwise pretraining. For pretraining use method pretrain.. |
void |
fit(@NonNull DataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the DataSetIterator, for the specified number of epochs.
|
void |
fit(INDArray[] inputs,
INDArray[] labels)
Fit the ComputationGraph given arrays of inputs and labels.
|
void |
fit(INDArray[] inputs,
INDArray[] labels,
INDArray[] featureMaskArrays,
INDArray[] labelMaskArrays)
Fit the ComputationGraph using the specified inputs and labels (and mask arrays)
|
void |
fit(INDArray data,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
void |
fit(MultiDataSet multiDataSet)
Fit the ComputationGraph using a MultiDataSet
|
void |
fit(MultiDataSetIterator multi)
Fit the ComputationGraph using a MultiDataSetIterator
Method doesn't do layerwise pretraining.
For pretraining use method pretrain.. |
void |
fit(@NonNull MultiDataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the MultiDataSetIterator, for the specified number of epochs.
|
ComputationGraphConfiguration |
getConfiguration()
This method returns configuration of this ComputationGraph
|
int |
getEpochCount()
Returns the number of epochs that the ComputationGraph has done.
|
INDArray |
getGradientsViewArray() |
INDArray |
getInput(int inputNum)
Get the previously set input for the ComputationGraph
|
INDArray[] |
getInputMaskArrays()
Get the previously set feature/input mask arrays for the ComputationGraph
|
INDArray[] |
getInputs()
Get the previously set inputs for the ComputationGraph
|
int |
getIterationCount()
Returns the number of iterations (parameter updates) that the ComputationGraph has done
|
INDArray[] |
getLabelMaskArrays()
Get the previously set label/output mask arrays for the ComputationGraph
|
long |
getLastEtlTime()
This method returns ETL time field value
|
Layer |
getLayer(int idx)
Get the layer by the number of that layer, in range 0 to getNumLayers()-1
NOTE: This is different from the internal GraphVertex index for the layer
|
Layer |
getLayer(String name)
Get a given layer by name.
|
Layer[] |
getLayers()
Get all layers in the ComputationGraph
|
Double |
getLearningRate(String layerName)
Get the current learning rate, for the specified layer, from the network.
|
Collection<TrainingListener> |
getListeners()
Get the trainingListeners for the ComputationGraph
|
int |
getNumInputArrays()
The number of inputs to this network
|
int |
getNumLayers()
Returns the number of layers in the ComputationGraph
|
int |
getNumOutputArrays()
The number of output (arrays) for this network
|
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
Layer |
getOutputLayer(int outputLayerIdx)
Get the specified output layer, by index.
|
protected int[] |
getOutputLayerIndices() |
INDArray |
getParam(String paramName)
Get the parameter
|
ComputationGraphUpdater |
getUpdater()
Get the ComputationGraphUpdater for the network.
|
ComputationGraphUpdater |
getUpdater(boolean initializeIfAbsent)
Get the ComputationGraphUpdater for this network
|
GraphVertex |
getVertex(String name)
Return a given GraphVertex by name, or null if no vertex with that name exists
|
GraphVertex[] |
getVertices()
Returns an array of all GraphVertex objects.
|
Gradient |
gradient()
Get the gradient.
|
Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
void |
incrementEpochCount()
Increment the epoch count (in the underlying
ComputationGraphConfiguration by 1). |
void |
init()
Initialize the ComputationGraph network
|
void |
init(INDArray parameters,
boolean cloneParametersArray)
Initialize the ComputationGraph, 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.
|
INDArray |
input()
The input/feature matrix for the model
|
long |
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. |
long |
layerInputSize(String layerName)
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. |
long |
layerSize(int layer)
Return the layer size (number of units) for the specified layer.
|
long |
layerSize(String layerName)
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 ComputationGraph |
load(File f,
boolean loadUpdater)
Restore a ComputationGraph to a file, saved using
save(File) or ModelSerializer |
String |
memoryInfo(int minibatch,
InputType... inputTypes)
Generate information regarding memory use for the network, for the given input types and minibatch size.
|
long |
numParams()
the number of parameters for the model
|
long |
numParams(boolean backwards)
the number of parameters for the model
|
INDArray[] |
output(boolean train,
boolean clearInputs,
INDArray... input)
An output method for the network, with optional clearing of the layer inputs.
Note: most users should use output(boolean, INDArray...) or similar methods, unless they are doing
non-standard operations (like providing the input arrays externally) |
INDArray[] |
output(boolean train,
INDArray... input)
Return an array of network outputs (predictions), given the specified network inputs
Network outputs are for output layers only.
|
INDArray[] |
output(boolean train,
@NonNull INDArray[] input,
INDArray[] inputMasks)
Return an array of network outputs (predictions), given the specified network inputs
Network outputs are for output layers only.
|
INDArray[] |
output(boolean train,
@NonNull INDArray[] input,
INDArray[] inputMasks,
INDArray[] labelMasks)
Return an array of network outputs (predictions), given the specified network inputs
Network outputs are for output layers only.
|
INDArray[] |
output(boolean train,
@NonNull INDArray[] input,
INDArray[] inputMasks,
INDArray[] labelMasks,
MemoryWorkspace outputWorkspace)
Return an array of network outputs (predictions), given the specified network inputs
Network outputs are for output layers only.
If no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
INDArray[] |
output(boolean train,
MemoryWorkspace outputWorkspace,
INDArray... input)
Return an array of network outputs (predictions), given the specified network inputs
Network outputs are for output layers only.
If no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
INDArray[] |
output(DataSetIterator iterator)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array
per network output
|
INDArray[] |
output(INDArray... input)
Return an array of network outputs (predictions) at test time, given the specified network inputs
Network outputs are for output layers only.
|
<T> T |
output(@NonNull INDArray[] inputs,
INDArray[] inputMasks,
INDArray[] labelMasks,
@NonNull OutputAdapter<T> outputAdapter)
This method uses provided OutputAdapter to return custom object built from INDArray
PLEASE NOTE: This method uses dedicated Workspace for output generation to avoid redundant allocations
|
INDArray[] |
output(List<String> layers,
boolean train,
INDArray[] features,
INDArray[] featureMasks)
Get the activations for the specific layers only
|
INDArray[] |
output(MultiDataSetIterator iterator)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array
per network output
|
protected INDArray[] |
outputOfLayersDetached(boolean train,
@NonNull FwdPassType fwdPassType,
@NonNull int[] layerIndexes,
@NonNull INDArray[] features,
INDArray[] fMask,
INDArray[] lMasks,
boolean clearLayerInputs,
boolean detachedInputs,
MemoryWorkspace outputWorkspace)
Provide the output of the specified layers, detached from any workspace.
|
INDArray |
outputSingle(boolean train,
boolean clearInputs,
INDArray... input)
Identical to
outputSingle(boolean, boolean, INDArray...) but has the option of not clearing the input
arrays (useful when later backpropagating external errors). |
INDArray |
outputSingle(boolean train,
INDArray... input)
A convenience method that returns a single INDArray, instead of an INDArray[].
|
INDArray |
outputSingle(DataSetIterator iterator)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array.
|
INDArray |
outputSingle(INDArray... input)
A convenience method that returns a single INDArray, instead of an INDArray[].
|
INDArray |
outputSingle(MultiDataSetIterator iterator)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array.
|
INDArray |
params()
Parameters of the model (if any)
|
INDArray |
params(boolean backwardOnly)
Deprecated.
To be removed. Use
params() |
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
|
void |
pretrain(DataSetIterator iter)
Perform layerwise pretraining for one epoch - see
pretrain(DataSetIterator, int) |
void |
pretrain(DataSetIterator iter,
int numEpochs)
Pretrain network with a single input and single output.
|
void |
pretrain(MultiDataSetIterator iter)
Pretrain network with multiple inputs and/or outputs
|
void |
pretrain(MultiDataSetIterator iter,
int numEpochs)
Pretrain network with multiple inputs and/or outputs
This method performs layerwise pretraining on all pre-trainable layers in the network (VAEs, Autoencoders, etc), for the specified number of epochs each. |
void |
pretrainLayer(String layerName,
DataSetIterator dataSetIterator)
Pretrain a specified layer with the given DataSetIterator
|
void |
pretrainLayer(String layerName,
MultiDataSetIterator iter)
Pretrain a specified layer with the given MultiDataSetIterator
|
Map<String,INDArray> |
rnnActivateUsingStoredState(INDArray[] inputs,
boolean training,
boolean storeLastForTBPTT)
Similar to rnnTimeStep and feedForward() methods.
|
void |
rnnClearPreviousState()
Clear the previous state of the RNN layers (if any), used in
rnnTimeStep(INDArray...) |
Map<String,INDArray> |
rnnGetPreviousState(int layer)
Get the state of the RNN layer, as used in
rnnTimeStep(INDArray...) . |
Map<String,INDArray> |
rnnGetPreviousState(String layerName)
Get the state of the RNN layer, as used in
rnnTimeStep(INDArray...) . |
Map<String,Map<String,INDArray>> |
rnnGetPreviousStates()
Get a map of states for ALL RNN layers, as used in
rnnTimeStep(INDArray...) . |
void |
rnnSetPreviousState(int layer,
Map<String,INDArray> state)
Set the state of the RNN layer, for use in
rnnTimeStep(INDArray...) |
void |
rnnSetPreviousState(String layerName,
Map<String,INDArray> state)
Set the state of the RNN layer, for use in
rnnTimeStep(INDArray...) |
void |
rnnSetPreviousStates(Map<String,Map<String,INDArray>> previousStates)
Set the states for all RNN layers, for use in
rnnTimeStep(INDArray...) |
INDArray[] |
rnnTimeStep(INDArray... inputs)
If this ComputationGraph contains one or more RNN layers: conduct forward pass (prediction)
but using previous stored state for any RNN layers.
|
INDArray[] |
rnnTimeStep(MemoryWorkspace outputWorkspace,
INDArray... inputs)
See
rnnTimeStep(INDArray...) for details.If no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
protected void |
rnnUpdateStateWithTBPTTState()
Update the internal state of RNN layers after a truncated BPTT fit call
|
void |
save(File f)
Save the ComputationGraph to a file.
|
void |
save(File f,
boolean saveUpdater)
Save the ComputationGraph to a file.
|
double |
score()
The score for the model
|
double |
score(DataSet dataSet)
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==true.NOTE: this version of the score function can only be used with ComputationGraph networks that have a single input and a single output. |
double |
score(DataSet dataSet,
boolean training)
Sets the input and labels and returns a score for the prediction with respect to the true labels
NOTE: this version of the score function can only be used with ComputationGraph networks that have a single input and a single output. |
double |
score(MultiDataSet dataSet)
Score the network given the MultiDataSet, at test time
|
double |
score(MultiDataSet dataSet,
boolean training)
Sets the input and labels and returns a score for the prediction with respect to the true labels
|
INDArray |
scoreExamples(DataSet data,
boolean addRegularizationTerms)
Calculate the score for each example in a DataSet individually.
|
INDArray |
scoreExamples(MultiDataSet dataSet,
boolean addRegularizationTerms)
Calculate the score for each example in a DataSet individually.
|
void |
setBackpropGradientsViewArray(INDArray gradient)
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 |
setGradientsAccumulator(GradientsAccumulator accumulator)
This method allows you to specificy GradientsAccumulator instance to be used with this model
|
void |
setInput(int inputNum,
INDArray input)
Set the specified input for the ComputationGraph
|
void |
setInputs(INDArray... inputs)
Set all inputs for the ComputationGraph network
|
void |
setLabel(int labelNum,
INDArray label)
Set the specified label for the ComputationGraph
|
void |
setLabels(INDArray... labels)
Set all labels for the ComputationGraph network
|
void |
setLastEtlTime(long time)
This method allows to set ETL field time, useful for performance tracking
|
void |
setLayerMaskArrays(INDArray[] featureMaskArrays,
INDArray[] labelMaskArrays)
Set the mask arrays for features and labels.
|
void |
setLearningRate(double newLr)
Set the learning rate for all layers in the network to the specified value.
|
void |
setLearningRate(ISchedule newLr)
Set the learning rate schedule for all layers in the network to the specified schedule.
|
void |
setLearningRate(String layerName,
double newLr)
Set the learning rate for a single layer in the network to the specified value.
|
void |
setLearningRate(String layerName,
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 |
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 |
setParam(String key,
INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(INDArray params)
Set the parameters for this model.
|
void |
setParamsViewArray(INDArray gradient)
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(@NonNull Map<String,INDArray> paramTable)
Setter for the param table
|
void |
setScore(double score) |
void |
setUpdater(ComputationGraphUpdater updater)
Set the computationGraphUpdater for the network
|
String |
summary()
String detailing the architecture of the computation graph.
|
String |
summary(InputType... inputTypes)
String detailing the architecture of the computation graph.
|
protected void |
synchronizeIterEpochCounts() |
int[] |
topologicalSortOrder()
Calculate a topological sort order for the vertices in the graph.
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(INDArray gradient,
String paramType)
Perform one update applying the gradient
|
INDArray |
updaterState()
This method returns updater state (if applicable), null otherwise
|
protected void |
validateArrayWorkspaces(LayerWorkspaceMgr mgr,
INDArray array,
ArrayType arrayType,
String vertexName,
boolean isInputVertex,
String op) |
protected ComputationGraphConfiguration configuration
protected boolean initCalled
protected transient Solver solver
protected INDArray flattenedParams
protected transient INDArray flattenedGradients
protected Gradient gradient
protected double score
protected boolean clearTbpttState
protected static final String WS_LAYER_WORKING_MEM
protected static final String WS_ALL_LAYERS_ACT
protected static final String WS_RNN_LOOP_WORKING_MEM
protected static final String WS_OUTPUT_MEM
protected final WorkspaceConfiguration WS_LAYER_WORKING_MEM_CONFIG
protected static final WorkspaceConfiguration WS_ALL_LAYERS_ACT_CONFIG
protected final WorkspaceConfiguration WS_LAYER_ACT_X_CONFIG
protected static final WorkspaceConfiguration WS_RNN_LOOP_WORKING_MEM_CONFIG
protected transient ThreadLocal<Long> lastEtlTime
protected GraphVertex[] vertices
protected Map<String,GraphVertex> verticesMap
protected int[] topologicalOrder
protected GraphIndices graphIndices
protected Layer[] layers
public ComputationGraph(ComputationGraphConfiguration configuration)
public void setLastEtlTime(long time)
time
- public long getLastEtlTime()
public void setCacheMode(CacheMode mode)
mode
- public ComputationGraphConfiguration getConfiguration()
public int getNumLayers()
public Layer getLayer(int idx)
public Layer[] getLayers()
public GraphVertex[] getVertices()
public GraphVertex getVertex(String name)
public int getNumInputArrays()
public int getNumOutputArrays()
public void setInput(int inputNum, INDArray input)
public void setInputs(INDArray... inputs)
public INDArray getInput(int inputNum)
public INDArray[] getInputs()
public INDArray[] getInputMaskArrays()
public INDArray[] getLabelMaskArrays()
public void setLabel(int labelNum, INDArray label)
public void setLabels(INDArray... labels)
public void setGradientsAccumulator(GradientsAccumulator accumulator)
PLEASE NOTE: Do not use this method unless you understand how to use GradientsAccumulator & updates sharing. PLEASE NOTE: Do not use this method on standalone model
accumulator
- public void init()
init
in interface Model
init
in interface NeuralNetwork
public void init(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 initGradientsView()
protected int[] getOutputLayerIndices()
public void pretrain(DataSetIterator iter)
pretrain(DataSetIterator, int)
public void pretrain(DataSetIterator iter, int numEpochs)
pretrain(MultiDataSetIterator)
public void pretrain(MultiDataSetIterator iter)
public void pretrain(MultiDataSetIterator iter, int numEpochs)
iter
- Training datanumEpochs
- Number of epochs to fit each layer withpretrainLayer(String, MultiDataSetIterator)
public void pretrainLayer(String layerName, DataSetIterator dataSetIterator)
layerName
- Layer namedataSetIterator
- Datapublic void pretrainLayer(String layerName, MultiDataSetIterator iter)
layerName
- Layer nameiter
- Training datapublic void fit(DataSet dataSet)
fit(MultiDataSetIterator)
fit
in interface NeuralNetwork
public void fit(@NonNull @NonNull 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(@NonNull @NonNull DataSetIterator iterator)
pretrain(DataSetIterator)
fit
in interface NeuralNetwork
iterator
- Training data (DataSetIterator)public void fit(MultiDataSet multiDataSet)
fit
in interface NeuralNetwork
public void fit(@NonNull @NonNull 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(MultiDataSetIterator multi)
pretrain(MultiDataSetIterator)
fit
in interface NeuralNetwork
multi
- Training data (MultiDataSetIterator)public void fit(INDArray[] inputs, INDArray[] labels)
inputs
- The network inptuslabels
- The labelspublic void fit(INDArray[] inputs, INDArray[] labels, INDArray[] featureMaskArrays, INDArray[] labelMaskArrays)
inputs
- The network inputs (features)labels
- The network labelsfeatureMaskArrays
- Mask arrays for inputs/features. Typically used for RNN training. May be null.labelMaskArrays
- Mas arrays for the labels/outputs. Typically used for RNN training. May be null.public int[] topologicalSortOrder()
Specifically, gradients/params/forward pass are executed on vertex[topologicalSortOrder[i]], for i=0..nVertices-1
public GraphIndices calculateIndices()
public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Model
computeGradientAndScore
in interface Model
public void computeGradientAndScore()
public Map<String,INDArray> feedForward(INDArray input, int layerTillIndex, boolean train)
input
- The input arraylayerTillIndex
- the layer to feed forward totrain
- If true: do forward pass at training timepublic Map<String,INDArray> feedForward(INDArray[] input, int layerTillIndex, boolean train, boolean clearInputs)
input
- An array of ComputationGraph inputslayerTillIndex
- the index of the layer to feed forward totrain
- If true: do forward pass at training time; false: do forward pass at test timeclearInputs
- If true (default for other methods): clear the inputs of all layers after doing forward
pass. False don't clear layer inputs.public Map<String,INDArray> feedForward(INDArray[] input, int layerTillIndex, boolean train)
input
- An array of ComputationGraph inputslayerTillIndex
- the index of the layer to feed forward totrain
- If true: do forward pass at training time; false: do forward pass at test timepublic Map<String,INDArray> feedForward(boolean train, int layerTillIndex)
train
- If true: do forward pass at training time; false: do forward pass at test timelayerTillIndex
- the index of the layer to feed forward topublic Map<String,INDArray> feedForward(INDArray input, boolean train)
input
- The input arraytrain
- If true: do forward pass at training timepublic Map<String,INDArray> feedForward(INDArray[] input, boolean train)
input
- An array of ComputationGraph inputstrain
- If true: do forward pass at training time; false: do forward pass at test timepublic Map<String,INDArray> feedForward(INDArray[] input, boolean train, boolean clearInputs)
input
- An array of ComputationGraph inputstrain
- If true: do forward pass at training time; false: do forward pass at test timeclearInputs
- If true (default for other methods): clear the inputs of all layers after doing forward
pass. False don't clear layer inputs.public Map<String,INDArray> feedForward()
public Map<String,INDArray> feedForward(boolean train)
train
- If true: do forward pass at training time; false: do forward pass at test timepublic Map<String,INDArray> feedForward(boolean train, boolean excludeOutputLayers, boolean includeNonLayerVertexActivations)
train
- True: training time. False: test timeexcludeOutputLayers
- Should we exclude the output layers during forward pass? (usually: false)includeNonLayerVertexActivations
- Include non-layer vertices in the output may?public INDArray[] output(INDArray... input)
input
- Inputs to the networkpublic INDArray outputSingle(INDArray... input)
output(INDArray...)
input
- Inputs to the networkpublic INDArray[] output(boolean train, INDArray... input)
train
- If true: do forward pass at training time; false: do forward pass at test timeinput
- Inputs to the networkpublic INDArray[] output(boolean train, MemoryWorkspace outputWorkspace, INDArray... input)
train
- If true: do forward pass at training time; false: do forward pass at test timeoutputWorkspace
- May be null. If not null: the workspace MUST be opened before calling this method.input
- Inputs to the networkpublic INDArray[] output(boolean train, @NonNull @NonNull INDArray[] input, INDArray[] inputMasks)
train
- If true: forward pass for training mode. False: test modeinput
- Input arrays to the netwonkinputMasks
- Optional input mask arrays (may be null)public INDArray[] output(boolean train, @NonNull @NonNull INDArray[] input, INDArray[] inputMasks, INDArray[] labelMasks)
train
- If true: forward pass for training mode. False: test modeinput
- Input arrays to the netwonkinputMasks
- Optional input mask arrays (may be null)labelMasks
- Optional label mask arrays (may be nullpublic <T> T output(@NonNull @NonNull INDArray[] inputs, INDArray[] inputMasks, INDArray[] labelMasks, @NonNull @NonNull OutputAdapter<T> outputAdapter)
T
- T extends Objectinputs
- Input arrays to the netwonkinputMasks
- Optional input mask arrays (may be null)labelMasks
- Optional label mask arrays (may be nulloutputAdapter
- OutputAdapterpublic INDArray[] output(boolean train, @NonNull @NonNull INDArray[] input, INDArray[] inputMasks, INDArray[] labelMasks, MemoryWorkspace outputWorkspace)
train
- If true: forward pass for training mode. False: test modeinput
- Input arrays to the netwonkinputMasks
- Optional input mask arrays (may be null)labelMasks
- Optional label mask arrays (may be nulloutputWorkspace
- May be null. If not null: the workspace MUST be opened before calling this method.public INDArray outputSingle(boolean train, INDArray... input)
output(boolean, INDArray...)
train
- If true: do forward pass at training time; false: do forward pass at test timeinput
- Inputs to the networkpublic INDArray outputSingle(boolean train, boolean clearInputs, INDArray... input)
outputSingle(boolean, boolean, INDArray...)
but has the option of not clearing the input
arrays (useful when later backpropagating external errors). Most users should use outputSingle(boolean, INDArray...)
in preference to this method.public INDArray[] output(boolean train, boolean clearInputs, INDArray... input)
output(boolean, INDArray...)
or similar methods, unless they are doing
non-standard operations (like providing the input arrays externally)train
- If true: output during training. False: output during testing. Affects some things such as
dropoutclearInputs
- If true: clear the input arrays for all layers. False: leave the input arrays as-is - which
can be useful for "external errors" (no output layer) backprop use casesinput
- Input to the networkpublic INDArray[] output(DataSetIterator iterator)
iterator
- Data to pass through the networkpublic INDArray[] output(MultiDataSetIterator iterator)
iterator
- Data to pass through the networkpublic INDArray outputSingle(DataSetIterator iterator)
iterator
- Data to pass through the networkpublic INDArray outputSingle(MultiDataSetIterator iterator)
iterator
- Data to pass through the networkpublic INDArray[] output(List<String> layers, boolean train, INDArray[] features, INDArray[] featureMasks)
layers
- Layers to get the specified activations fortrain
- If true: train mode. False: test (inference) modefeatures
- Features arrayfeatureMasks
- Feature masks array. May be nullprotected void validateArrayWorkspaces(LayerWorkspaceMgr mgr, INDArray array, ArrayType arrayType, String vertexName, boolean isInputVertex, String op)
protected Map<String,INDArray> ffToLayerActivationsDetached(boolean train, @NonNull @NonNull FwdPassType fwdPassType, boolean storeLastForTBPTT, int layerIndex, int[] excludeIdxs, @NonNull @NonNull INDArray[] features, INDArray[] fMask, INDArray[] lMask, boolean clearLayers)
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-1excludeIdxs
- Layers (vertices) to exclude from forward pass. These layers will be skipped, and hence
are usually output layers or at the end of the network. May be null.features
- Input feature arraysfMask
- Feature mask arrays. May be null.lMask
- Label mask array. May be null.clearLayers
- Whether the layer inputs should be clearedprotected Map<String,INDArray> ffToLayerActivationsInWS(boolean train, int layerIndex, int[] excludeIdxs, FwdPassType fwdPassType, boolean storeLastForTBPTT, INDArray[] input, INDArray[] fMask, INDArray[] lMask, boolean clearInputs)
train
- Training mode (true) or test/inference mode (false)layerIndex
- Index (inclusive) to stop forward pass at. For all layers, use -1excludeIdxs
- Layers (vertices) to exclude from forward pass. These layers will be skipped, and hence
are usually output layers or at the end of the network. May be null.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_STATEinput
- Input feature arraysfMask
- Feature mask arrays. May be null.lMask
- Label mask array. May be null.clearInputs
- Whether the layer inputs should be clearedprotected INDArray[] outputOfLayersDetached(boolean train, @NonNull @NonNull FwdPassType fwdPassType, @NonNull @NonNull int[] layerIndexes, @NonNull @NonNull INDArray[] features, INDArray[] fMask, INDArray[] lMasks, boolean clearLayerInputs, boolean detachedInputs, MemoryWorkspace outputWorkspace)
ffToLayerActivationsDetached(boolean, FwdPassType, boolean, int, int[], INDArray[], INDArray[], INDArray[], boolean)
and ffToLayerActivationsInWS(boolean, int, int[], FwdPassType, boolean, INDArray[], INDArray[], INDArray[], boolean)
.train
- Training mode (true) or test/inference mode (false)fwdPassType
- Type of forward pass to perform (STANDARD or RNN_TIMESTEP only)layerIndexes
- Indexes of the layers to get the activations forfeatures
- Input features for the networkfMask
- Input/feature mask array. May be null.lMasks
- Labels mask array. May be nullclearLayerInputs
- If true: the layer input fields will be cleareddetachedInputs
- If true: the layer input fields will be detached. Usually used for external errors casesoutputWorkspace
- Optional - if provided, outputs should be placed in this workspace. NOTE: this workspace
must be openpublic Gradient backpropGradient(INDArray... epsilons)
epsilons
- Epsilons (errors) at the output. Same order with which the output layers are defined in configuration setOutputs(String...)protected void calcBackpropGradients(boolean clearLayers, boolean truncatedBPTT, INDArray... externalEpsilons)
truncatedBPTT
- false: normal backprop. true: calculate gradients using truncated BPTT for RNN layersexternalEpsilons
- null usually (for typical supervised learning). If not null (and length > 0) then assume that
the user has provided some errors externally, as they would do for example in reinforcement
learning situations.public ComputationGraph clone()
public double calcRegularizationScore(boolean backpropParamsOnly)
public void setListeners(Collection<TrainingListener> listeners)
setListeners
in interface Model
public void setListeners(TrainingListener... listeners)
setListeners
in interface Model
public void addListeners(TrainingListener... listeners)
addListeners
in interface Model
listeners
- Listeners to addpublic Collection<TrainingListener> getListeners()
public ComputationGraphUpdater getUpdater()
public ComputationGraphUpdater getUpdater(boolean initializeIfAbsent)
initializeIfAbsent
- If true: create the updater if one is absent. False: return null if absent.public void setUpdater(ComputationGraphUpdater updater)
public Layer getOutputLayer(int outputLayerIdx)
getNumOutputArrays()
-1@Deprecated public INDArray params(boolean backwardOnly)
params()
public double score(DataSet dataSet)
score(DataSet, boolean)
with training==true.dataSet
- the data to scorescore(DataSet, boolean)
public double score(DataSet dataSet, boolean training)
score(MultiDataSet, boolean)
for multiple input/output networksdataSet
- the data to scoretraining
- whether score is being calculated at training time (true) or test time (false)score(DataSet, boolean)
public double score(MultiDataSet dataSet)
public double score(MultiDataSet dataSet, boolean training)
dataSet
- the data to scoretraining
- whether score is being calculated at training time (true) or test time (false)public INDArray scoreExamples(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 INDArray scoreExamples(MultiDataSet dataSet, boolean addRegularizationTerms)
score(MultiDataSet)
and score(MultiDataSet, 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.dataSet
- 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(INDArray gradient, String paramType)
Model
public void update(Gradient gradient)
Model
public double score()
Model
public void setScore(double score)
public INDArray params()
Model
params
in interface Model
params
in interface NeuralNetwork
public INDArray updaterState()
NeuralNetwork
updaterState
in interface NeuralNetwork
public long numParams()
Model
public long numParams(boolean backwards)
Model
public void setParams(INDArray params)
Model
public void setParamsViewArray(INDArray gradient)
Model
setParamsViewArray
in interface Model
gradient
- a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic INDArray getGradientsViewArray()
getGradientsViewArray
in interface Model
public void setBackpropGradientsViewArray(INDArray gradient)
Model
setBackpropGradientsViewArray
in interface Model
gradient
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic void fit(INDArray data, LayerWorkspaceMgr workspaceMgr)
Model
public Gradient gradient()
Model
Model.computeGradientAndScore(LayerWorkspaceMgr)
} .public Pair<Gradient,Double> gradientAndScore()
Model
gradientAndScore
in interface Model
public int batchSize()
Model
public NeuralNetConfiguration conf()
Model
public void setConf(NeuralNetConfiguration conf)
Model
public INDArray input()
Model
public ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
getOptimizer
in interface NeuralNetwork
public INDArray getParam(String paramName)
Model
public Map<String,INDArray> paramTable()
Model
paramTable
in interface Model
public Map<String,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(@NonNull @NonNull Map<String,INDArray> paramTable)
Model
setParamTable
in interface Model
public void setParam(String key, INDArray val)
Model
public void clear()
Model
public void applyConstraints(int iteration, int epoch)
Model
applyConstraints
in interface Model
public INDArray[] rnnTimeStep(INDArray... inputs)
inputs
- 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 INDArray[] rnnTimeStep(MemoryWorkspace outputWorkspace, INDArray... inputs)
rnnTimeStep(INDArray...)
for details.inputs
- Input activationsoutputWorkspace
- Output workspace. May be nullpublic Map<String,INDArray> rnnGetPreviousState(int layer)
rnnTimeStep(INDArray...)
.layer
- Number/index of the layer.public Map<String,INDArray> rnnGetPreviousState(String layerName)
rnnTimeStep(INDArray...)
.layerName
- name of the layerpublic Map<String,Map<String,INDArray>> rnnGetPreviousStates()
rnnTimeStep(INDArray...)
.
Layers that are not RNN layers will not have an entry in the returned maprnnSetPreviousStates(Map)
public void rnnSetPreviousState(int layer, Map<String,INDArray> state)
rnnTimeStep(INDArray...)
layer
- The number/index of the layer.state
- The state to set the specified layer topublic void rnnSetPreviousState(String layerName, Map<String,INDArray> state)
rnnTimeStep(INDArray...)
layerName
- The name of the layer.state
- The state to set the specified layer topublic void rnnSetPreviousStates(Map<String,Map<String,INDArray>> previousStates)
rnnTimeStep(INDArray...)
previousStates
- The previous time step states for all layers (key: layer name. Value: layer states)rnnGetPreviousStates()
public void rnnClearPreviousState()
rnnTimeStep(INDArray...)
protected void doTruncatedBPTT(INDArray[] inputs, INDArray[] labels, INDArray[] featureMasks, INDArray[] labelMasks, LayerWorkspaceMgr workspaceMgr)
public Map<String,INDArray> rnnActivateUsingStoredState(INDArray[] inputs, boolean training, boolean storeLastForTBPTT)
inputs
- Input to networktraining
- Whether training or notstoreLastForTBPTT
- set to true if used as part of truncated BPTT trainingpublic void setLayerMaskArrays(INDArray[] featureMaskArrays, INDArray[] labelMaskArrays)
featureMaskArrays
- Mask array for features (input)labelMaskArrays
- Mask array for labels (output)clearLayerMaskArrays()
public void clearLayerMaskArrays()
setLayerMaskArrays(INDArray[], INDArray[])
for details on mask arrays.protected void rnnUpdateStateWithTBPTTState()
public <T extends Evaluation> T evaluate(DataSetIterator iterator)
iterator
- Iterator to evaluate onpublic <T extends Evaluation> T evaluate(MultiDataSetIterator iterator)
iterator
- Iterator to evaluate onpublic <T extends Evaluation> T evaluate(DataSetIterator iterator, List<String> labelsList)
iterator
- Data to undertake evaluation onpublic <T extends Evaluation> T evaluate(MultiDataSetIterator iterator, List<String> labelsList)
iterator
- Data to undertake evaluation onpublic <T extends Evaluation> T evaluate(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 evaluationpublic <T extends Evaluation> T evaluate(MultiDataSetIterator 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 evaluationpublic <T extends RegressionEvaluation> T evaluateRegression(DataSetIterator iterator)
iterator
- Data to evaluate onpublic <T extends RegressionEvaluation> T evaluateRegression(MultiDataSetIterator iterator)
iterator
- Data to evaluate onpublic <T extends RegressionEvaluation> T evaluateRegression(DataSetIterator iterator, List<String> columnNames)
iterator
- Data to evaluate oncolumnNames
- Column names for the regression evaluation. May be null.public <T extends RegressionEvaluation> T evaluateRegression(MultiDataSetIterator iterator, List<String> columnNames)
iterator
- Data to evaluate on@Deprecated public <T extends ROC> T evaluateROC(DataSetIterator iterator)
evaluateROC(DataSetIterator, int)
to enforce selection of appropriate ROC/threshold configurationpublic <T extends ROC> T evaluateROC(DataSetIterator iterator, int rocThresholdSteps)
ROC
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROC
@Deprecated public <T extends ROC> T evaluateROC(MultiDataSetIterator iterator)
evaluateROC(DataSetIterator, int)
to enforce selection of appropriate ROC/threshold configurationpublic <T extends ROC> T evaluateROC(MultiDataSetIterator iterator, int rocThresholdSteps)
ROC
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROC
@Deprecated public <T extends ROCMultiClass> T evaluateROCMultiClass(DataSetIterator iterator)
evaluateROCMultiClass(DataSetIterator, int)
to enforce selection of appropriate ROC/threshold configurationpublic <T extends ROCMultiClass> T evaluateROCMultiClass(DataSetIterator iterator, int rocThresholdSteps)
ROCMultiClass
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROCMultiClass
public <T extends ROCMultiClass> T evaluateROCMultiClass(MultiDataSetIterator iterator, int rocThresholdSteps)
ROCMultiClass
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROCMultiClass
public <T extends IEvaluation> T[] doEvaluation(DataSetIterator iterator, T... evaluations)
IEvaluation
instancedoEvaluation
in interface NeuralNetwork
T
- Type of the IEvaluation instanceiterator
- Test data to evaluate onevaluations
- IEvaluation instancespublic <T extends IEvaluation> T[] doEvaluation(MultiDataSetIterator iterator, T... evaluations)
IEvaluation
instancedoEvaluation
in interface NeuralNetwork
T
- Type of the IEvaluation instanceiterator
- Test data to evaluate onevaluations
- IEvaluation insntancepublic <T extends IEvaluation> Map<Integer,T[]> evaluate(DataSetIterator iterator, Map<Integer,T[]> evaluations)
iterator
- Data to evaluateevaluations
- Evaluation instances. Key: the network output number (0 to numOutputs-1). Value: the IEvaluation
instances to perform evaluation with, for that output only. Note that not every output needs to
have an IEvaluation[] defined.public <T extends IEvaluation> Map<Integer,T[]> evaluate(MultiDataSetIterator iterator, Map<Integer,T[]> evaluations)
iterator
- Data to evaluateevaluations
- Evaluation instances. Key: the network output number (0 to numOutputs-1). Value: the IEvaluation
instances to perform evaluation with, for that output only. Note that not every output needs to
have an IEvaluation[] defined.public String summary()
memoryInfo(int, InputType...)
public String summary(InputType... inputTypes)
memoryInfo(int, InputType...)
public String memoryInfo(int minibatch, InputType... inputTypes)
minibatch
- Minibatch size to estimate memory forinputTypes
- Input types to the networkpublic void clearLayersStates()
public void incrementEpochCount()
ComputationGraphConfiguration
by 1).
Note that this is done automatically when using iterator-based fitting methods, such as
fit(DataSetIterator)
or fit(MultiDataSet)
. However, when using non-iterator fit methods
(DataSet, MultiDataSet, INDArrays 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.ComputationGraph.getConfiguration().getEpochCount()
protected void synchronizeIterEpochCounts()
public int getIterationCount()
public int getEpochCount()
fit(DataSetIterator)
, fit(MultiDataSetIterator)
,
fit(DataSetIterator, int)
or fit(MultiDataSetIterator, int)
are used.
The epoch count can also be manually incremented using incrementEpochCount()
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 ComputationGraph 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 convertDataType(@NonNull @NonNull DataType dataType)
dataType
- Datatype to convert the network topublic void setLearningRate(double newLr)
newLr
- New learning rate for all layerssetLearningRate(ISchedule)
,
setLearningRate(String, double)
public void setLearningRate(ISchedule newLr)
ComputationGraphConfiguration#setIterationCount(int)
and ComputationGraphConfiguration#setEpochCount(int)
if this is requirednewLr
- New learning rate schedule for all layerssetLearningRate(ISchedule)
,
setLearningRate(String, double)
public void setLearningRate(String layerName, double newLr)
setLearningRate(double)
should also be used in preference, when all layers need to be set to a new LRlayerName
- Name of the layer to set the LR fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(String, double)
public void setLearningRate(String layerName, ISchedule newLr)
setLearningRate(ISchedule)
should also be used in preference, when all layers need
to be set to a new LR schedule.ComputationGraphConfiguration#setIterationCount(int)
and ComputationGraphConfiguration#setEpochCount(int)
if this is requiredlayerName
- Name of the layer to set the LR schedule fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(String, double)
public Double getLearningRate(String layerName)
layerName
- Layer namepublic long layerSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic long layerInputSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic long layerSize(String layerName)
layerName
- Name of the layer to get the size ofpublic long layerInputSize(String layerName)
layerName
- Name of the layer to get the size ofpublic 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 © 2020. All rights reserved.