code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public Set<String> inferenceVariables() { return inferenceVariables; }
Get required inference variables
ListenerVariables::inferenceVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Set<String> requiredVariables(Operation op) { switch (op) { case TRAINING: return trainingVariables; case TRAINING_VALIDATION: return validationVariables; case INFERENCE: return inferenceVariables; case EVALUATION: return evaluationVariables; } throw new IllegalArgumentException("Unknown operation " + op); }
Get required variables for specified op
ListenerVariables::requiredVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public ListenerVariables merge(ListenerVariables other) { return new ListenerVariables( Sets.newHashSet(Sets.union(trainingVariables, other.trainingVariables)), Sets.newHashSet(Sets.union(validationVariables, other.validationVariables)), Sets.newHashSet(Sets.union(evaluationVariables, other.evaluationVariables)), Sets.newHashSet(Sets.union(inferenceVariables, other.inferenceVariables))); }
Return a new ListenerVariables that contains the variables of this ListenerVariables and of other
ListenerVariables::merge
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Builder requireVariables(@NonNull Operation op, @NonNull String... variables) { switch (op) { case TRAINING: trainingVariables.addAll(Arrays.asList(variables)); break; case TRAINING_VALIDATION: validationVariables.addAll(Arrays.asList(variables)); break; case INFERENCE: inferenceVariables.addAll(Arrays.asList(variables)); break; case EVALUATION: evaluationVariables.addAll(Arrays.asList(variables)); break; } return this; }
Add required variables for the specified op @param op The op to require the variable for
Builder::requireVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Builder trainingVariables(@NonNull String... variables) { return requireVariables(Operation.TRAINING, variables); }
Add required variables for training
Builder::trainingVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Builder validationVariables(@NonNull String... variables) { return requireVariables(Operation.TRAINING_VALIDATION, variables); }
Add required variables for validation
Builder::validationVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Builder inferenceVariables(@NonNull String... variables) { return requireVariables(Operation.INFERENCE, variables); }
Add required variables for inference
Builder::inferenceVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Builder evaluationVariables(@NonNull String... variables) { return requireVariables(Operation.EVALUATION, variables); }
Add required variables for evaluation
Builder::evaluationVariables
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/ListenerVariables.java
Apache-2.0
public Loss(@NonNull List<String> lossNames, @NonNull double[] losses) { Preconditions.checkState(lossNames.size() == losses.length, "Expected equal number of loss names and loss values"); this.lossNames = lossNames; this.losses = losses; }
@param lossNames Names of the losses @param losses Values for each loss. Must be same length as lossNames
Loss::Loss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public int numLosses() { return lossNames.size(); }
@return Number of loss values (i.e., length of lossNames and losses)
Loss::numLosses
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public List<String> lossNames() { return lossNames; }
@return Names of all of the loss components
Loss::lossNames
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public double[] lossValues() { return losses; }
@return Values corresponding to each of the losses (same order as lossNames())
Loss::lossValues
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public double getLoss(@NonNull String lossName) { int idx = lossNames.indexOf(lossName); Preconditions.checkState(idx >= 0, "No loss with name \"%s\" exists. All loss names: %s", lossName, lossNames); return losses[idx]; }
Get the specified loss by name @param lossName Name of the loss (must exist) @return Specified loss value
Loss::getLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public double totalLoss() { double sum = 0.0; for (double d : losses) { sum += d; } return sum; }
@return The total loss (sum of all loss components)
Loss::totalLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/Loss.java
Apache-2.0
public static At defaultAt(){ return new At(0, 0, 0, 0, null, Operation.INFERENCE); }
@return A new instance with everything set to 0, and operation set to INFERENCE
At::defaultAt
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public static At defaultAt(@NonNull Operation op){ return new At(0, 0, 0, 0, null, op); }
@param op Operation @return A new instance with everything set to 0, except for the specified operation
At::defaultAt
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public int epoch(){ return epoch; }
@return The current training epoch
At::epoch
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public int iteration(){ return iteration; }
@return The current training iteration
At::iteration
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public int trainingThreadNum(){ return trainingThreadNum; }
@return The number of the SameDiff thread
At::trainingThreadNum
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public long javaThreadNum(){ return javaThreadNum; }
@return The Java/JVM thread number for training
At::javaThreadNum
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public Operation operation(){ return operation; }
@return The current operation
At::operation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public At copy(){ return new At(epoch, iteration, trainingThreadNum, javaThreadNum, frameIter, operation); }
@return A copy of the current At instance
At::copy
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public At copy(Operation operation){ return new At(epoch, iteration, trainingThreadNum, javaThreadNum, frameIter, operation); }
@param operation Operation to set in the new instance @return A copy of the current instance, but with the specified operation
At::copy
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/At.java
Apache-2.0
public static ObjectMapper jsonMapper() { ObjectMapper json = new ObjectMapper(); json.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); json.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); json.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, false); json.disable(SerializationFeature.INDENT_OUTPUT); //One line return json; }
Get a new JSON mapper for use in serializing/deserializing JSON format
ProfilingListener::jsonMapper
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public static Builder builder(File outputFile) { return new Builder(outputFile); }
Create a new builder @param outputFile Output file. Will be overwritten if file already exists
ProfilingListener::builder
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public Builder recordAll() { this.all = true; this.nIter = -1; this.nMs = -1; return this; }
If called, all data will be profiled with no limits (other than a warmup, if set)
Builder::recordAll
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public Builder warmup(int iterations) { this.warmup = iterations; return this; }
Specify the number of warmup iterations - i.e., these will be excluded from profiling results
Builder::warmup
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public Builder maxProfileIterations(int iterations) { this.nIter = iterations; this.all = false; return this; }
Set a limit on the maximum number of iterations to profile (after warmup, if any). Any ops executed after the specified number of iterations will not be profiled/recorded
Builder::maxProfileIterations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public Builder maxProfilerMilliseconds(long ms) { this.nMs = ms; this.all = false; return this; }
Set a limit on the maximum duration for profiling, in milliseconds. Any ops executed after the specified amount of time since the first (non-warmup) operation start will not be profiled/recorded
Builder::maxProfilerMilliseconds
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public Builder operations(Operation... operations) { this.operations = operations; return this; }
Specify the operations (training, inference, etc) to profile. If not set, all operations are profiled
Builder::operations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public ProfilingListener build() { return new ProfilingListener(outputFile, all, warmup, nIter, nMs, operations); }
Create the profiling listener
Builder::build
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/profiler/ProfilingListener.java
Apache-2.0
public OpBenchmarkListener(Operation operation, @NonNull Mode mode, long minRuntime) { this.operation = operation; this.mode = mode; this.minRuntime = minRuntime; }
@param operation Operation to collect stats for @param mode Mode - see {@link OpBenchmarkListener} @param minRuntime Minimum runtime - only applies to Mode.SINGLE_ITER_PRINT. If op runtime below this: don't print
Mode::OpBenchmarkListener
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/debugging/OpBenchmarkListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/debugging/OpBenchmarkListener.java
Apache-2.0
public ExecDebuggingListener(PrintMode printMode, int maxIterations, boolean logIter){ this.printMode = printMode; this.maxIterations = maxIterations; this.logIter = logIter; }
@param printMode Print mode, see {@link PrintMode} @param maxIterations Maximum number of iterations to print. <= 0 for "all iterations" @param logIter If true: prefix iteration/epoch, such as "(iter=1,epoch=0,op=3)" to the output
PrintMode::ExecDebuggingListener
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/debugging/ExecDebuggingListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/debugging/ExecDebuggingListener.java
Apache-2.0
public List<EvaluationRecord> trainingEval(){ return trainingHistory; }
Get the training evaluations
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<EvaluationRecord> validationEval(){ return validationHistory; }
Get the validation evaluations
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public LossCurve lossCurve(){ return lossCurve; }
Get the loss curve
History::lossCurve
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public long trainingTimeMillis(){ return trainingTimeMillis; }
Get the total training time, in milliseconds
History::trainingTimeMillis
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Long> validationTimesMillis(){ return validationTimesMillis; }
Get the total validation time, in milliseconds
History::validationTimesMillis
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public int trainingEpochs(){ return trainingHistory.size(); }
Get the number of epochs trained for
History::trainingEpochs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public int validationEpochs(){ return validationHistory.size(); }
Get the number of epochs validation was ran on
History::validationEpochs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> trainingEval(String param, IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : trainingHistory) data.add(er.getValue(param, metric)); return data; }
Get the results of a training evaluation on a given parameter for a given metric Only works if there is only one evaluation with the given metric for param
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> trainingEval(String param, int index, IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : trainingHistory) data.add(er.getValue(param, index, metric)); return data; }
Get the results of a training evaluation on a given parameter at a given index, for a given metric Note that it returns all recorded evaluations. Index determines the evaluation used not the epoch's results to return.
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> trainingEval(IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : trainingHistory) data.add(er.getValue(metric)); return data; }
Get the results of a training evaluation for a given metric Only works if there is only one evaluation with the given metric
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<IEvaluation> trainingEval(String param) { List<IEvaluation> data = new ArrayList<>(); for(EvaluationRecord er : trainingHistory) data.add(er.evaluation(param)); return data; }
Get the results of a training evaluation on a given parameter Only works if there is only one evaluation for param.
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<IEvaluation> trainingEval(String param, int index) { List<IEvaluation> data = new ArrayList<>(); for(EvaluationRecord er : trainingHistory) data.add(er.evaluation(param, index)); return data; }
Get the results of a training evaluation on a given parameter at a given index Note that it returns all recorded evaluations. Index determines the evaluation used not the epoch's results to return.
History::trainingEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> validationEval(String param, IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : validationHistory) data.add(er.getValue(param, metric)); return data; }
Get the results of a validation evaluation on a given parameter for a given metric Only works if there is only one evaluation with the given metric for param
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> validationEval(String param, int index, IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : validationHistory) data.add(er.getValue(param, index, metric)); return data; }
Get the results of a validation evaluation on a given parameter at a given index, for a given metric Note that it returns all recorded evaluations. Index determines the evaluation used not the epoch's results to return.
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<Double> validationEval(IMetric metric) { List<Double> data = new ArrayList<>(); for(EvaluationRecord er : validationHistory) data.add(er.getValue(metric)); return data; }
Get the results of a validation evaluation for a given metric Only works if there is only one evaluation with the given metric
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<IEvaluation> validationEval(String param) { List<IEvaluation> data = new ArrayList<>(); for(EvaluationRecord er : validationHistory) data.add(er.evaluation(param)); return data; }
Get the results of a validation evaluation on a given parameter Only works if there is only one evaluation for param.
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public List<IEvaluation> validationEval(String param, int index) { List<IEvaluation> data = new ArrayList<>(); for(EvaluationRecord er : validationHistory) data.add(er.evaluation(param, index)); return data; }
Get the results of a validation evaluation on a given parameter at a given index Note that it returns all recorded evaluations. Index determines the evaluation used not the epoch's results to return.
History::validationEval
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public EvaluationRecord finalTrainingEvaluations() { Preconditions.checkState(!trainingHistory.isEmpty(), "Cannot get final training evaluation - history is empty"); return trainingHistory.get(trainingHistory.size() - 1); }
Gets the training evaluations ran during the last epoch
History::finalTrainingEvaluations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public EvaluationRecord finalValidationEvaluations() { Preconditions.checkState(!validationHistory.isEmpty(), "Cannot get final validation evaluation - history is empty"); return validationHistory.get(validationHistory.size() - 1); }
Gets the validation evaluations ran during the last epoch
History::finalValidationEvaluations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public EvaluationRecord trainingEvaluations(int epoch) { if(epoch >= 0){ return trainingHistory.get(epoch); } else { return trainingHistory.get(trainingHistory.size() - epoch); } }
Gets the evaluation record for a given epoch. @param epoch The epoch to get results for. If negative, returns results for the epoch that many epochs from the end.
History::trainingEvaluations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/History.java
Apache-2.0
public Map<String, List<IEvaluation>> evaluations() { return evaluations; }
Get all evaluations
EvaluationRecord::evaluations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public List<IEvaluation> evaluations(String param) { Preconditions.checkArgument(evaluations.containsKey(param), "No evaluations for %s.", param); return evaluations.get(param); }
Get evaluations for a given param/variable @param param The target param/variable
EvaluationRecord::evaluations
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public IEvaluation evaluation(String param, int index) { return evaluations(param).get(index); }
Get the evaluation for param at the specified index
EvaluationRecord::evaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public <T extends IEvaluation> T evaluation(String param) { Preconditions.checkArgument(evaluations.containsKey(param), "No evaluations for %s.", param); Preconditions.checkArgument(evaluations.get(param).size() == 1, "Multiple evaluations for %s. Use evaluations().", param); return (T) evaluations.get(param).get(0); }
Get the evaluation for a given param/variable <p> Will throw an exception if there are more than one or no evaluations for the param @param param The target param/variable
EvaluationRecord::evaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public <T extends IEvaluation<T>> T evaluation(Class<T> evalClass) { Preconditions.checkArgument(classEvaluations.containsKey(evalClass), "Can't get evaluation for %s. Either no evaluations with that class are present, or more than one are.", evalClass); return (T) classEvaluations.get(evalClass); }
Get the evaluation of a given type <p> Will throw an exception if there are more than one or no evaluations of that type @param evalClass The type of evaluation to look for
EvaluationRecord::evaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public <T extends IEvaluation<T>> T evaluation(String param, Class<T> evalClass) { Collection<IEvaluation> evals = Collections2.filter(evaluations(param), Predicates.instanceOf(evalClass)); Preconditions.checkArgument(evals.size() == 1, "Multiple or no evaluations of type %s for param %s.", evalClass, param); return (T) evals.iterator().next(); }
Get the evaluation of a given type, for a given param/variable <p> Will throw an exception if there are more than one or no evaluations of that type for the given param @param param The target param/variable @param evalClass The type of evaluation to look for
EvaluationRecord::evaluation
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public double getValue(IMetric metric) { return evaluation(metric.getEvaluationClass()).getValue(metric); }
Get the metric's value for the evaluation of the metric's type <p> Will throw an exception if there are more than one or no evaluations of that type @param metric The metric to calculate
EvaluationRecord::getValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public double getValue(String param, IMetric metric) { return evaluation(param, metric.getEvaluationClass()).getValue(metric); }
Get the metric's value for the evaluation of the metric's type, for a given param/variable <p> Will throw an exception if there are more than one or no evaluations of that type for the given param @param param The target param/variable @param metric The metric to calculate
EvaluationRecord::getValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public double getValue(String param, int index, IMetric metric) { return evaluation(param, index).getValue(metric); }
Get the metric's value for the evaluation for a given param/variable at the given index <p> Will throw an exception if the target evaluation doesn't support the given metric @param param The target param/variable @param index The index of the target evaluation on the param @param metric The metric to calculate
EvaluationRecord::getValue
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/EvaluationRecord.java
Apache-2.0
public Loss meanLoss(int epoch){ if(epoch >= 0){ return new Loss(lossNames, lossValues.getRow(epoch).toDoubleVector()); } else { return new Loss(lossNames, lossValues.getRow(lossValues.rows() + epoch).toDoubleVector()); } }
Get the mean loss for a given epoch If epoch is negative, counts backwards from the end. E.g. losses(-1) gets the last epoch. @param epoch The epoch to get. If negative, returns results for the epoch that many epochs from the end
LossCurve::meanLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public Loss lastMeanLoss(){ return meanLoss(-1); }
Get the mean loss for the last epoch.
LossCurve::lastMeanLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public float[] meanLoss(@NonNull String lossName){ int idx = lossNames.indexOf(lossName); Preconditions.checkArgument(idx >= 0, "No loss value for %s. Existing losses: %s", lossName, lossNames); float[] loss = new float[(int) lossValues.size(0)]; for(int i = 0 ; i < lossValues.size(0) ; i++){ loss[i] = lossValues.getFloat(i, idx); } return loss; }
Return all mean loss values for a given variable
LossCurve::meanLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public float meanLoss(@NonNull String lossName, int epoch){ int idx = lossNames.indexOf(lossName); Preconditions.checkArgument(idx >= 0, "No loss value for %s. Existing losses: %s", lossName, lossNames); if(epoch >= 0) { return lossValues.getFloat(epoch, idx); } else { return lossValues.getFloat(lossValues.rows() + epoch, idx); } }
Return the mean loss value for a given variable on a given epoch. See {@link #meanLoss(int)}
LossCurve::meanLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public float lastMeanLoss(@NonNull String lossName){ int idx = lossNames.indexOf(lossName); Preconditions.checkArgument(idx >= 0, "No loss value for %s. Existing losses: %s", lossName, lossNames); return lossValues.getFloat(lossValues.rows() - 1, idx); }
Return the mean loss value for a given variable on the last epoch.
LossCurve::lastMeanLoss
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public Loss lastMeanDelta(){ return lastMeanLoss().sub(meanLoss(-2)); }
Return the loss delta between the last epoch and the one before it. Equivalent to meanLoss(-1) - meanLoss(-2). A positive delta means the loss is increasing, and a negative delta means it is decreasing.
LossCurve::lastMeanDelta
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public double lastMeanDelta(String lossName){ return lastMeanDelta().getLoss(lossName); }
Return the loss delta between the last epoch and the one before it, for a given variable. Equivalent to meanLoss(-1) - meanLoss(-2). A positive delta means the loss is increasing, and a negative delta means it is decreasing.
LossCurve::lastMeanDelta
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public LossCurve addLossAndCopy(Loss loss){ return addLossAndCopy(loss.getLosses(), loss.lossNames()); }
Return a new LossCurve with the given losses added on as the most recent epoch
LossCurve::addLossAndCopy
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/records/LossCurve.java
Apache-2.0
public ScoreListener() { this(10, true); }
Create a ScoreListener reporting every 10 iterations, and at the end of each epoch
ScoreListener::ScoreListener
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
Apache-2.0
public ScoreListener(int frequency) { this(frequency, true); }
Create a ScoreListener reporting every N iterations, and at the end of each epoch
ScoreListener::ScoreListener
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
Apache-2.0
public ScoreListener(int frequency, boolean reportEpochs) { this(frequency, reportEpochs, true); }
Create a ScoreListener reporting every N iterations, and optionally at the end of each epoch
ScoreListener::ScoreListener
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/impl/ScoreListener.java
Apache-2.0
public List<Checkpoint> availableCheckpoints(){ if(!checkpointRecordFile.exists()){ return Collections.emptyList(); } return availableCheckpoints(rootDir); }
List all available checkpoints. A checkpoint is 'available' if the file can be loaded. Any checkpoint files that have been automatically deleted (given the configuration) will not be returned here. @return List of checkpoint files that can be loaded
KeepMode::availableCheckpoints
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public static List<Checkpoint> availableCheckpoints(File directory){ File checkpointRecordFile = new File(directory, "checkpointInfo.txt"); Preconditions.checkState(checkpointRecordFile.exists(), "Could not find checkpoint record file at expected path %s", checkpointRecordFile.getAbsolutePath()); List<String> lines; try(InputStream is = new BufferedInputStream(new FileInputStream(checkpointRecordFile))){ lines = IOUtils.readLines(is); } catch (IOException e){ throw new RuntimeException("Error loading checkpoint data from file: " + checkpointRecordFile.getAbsolutePath(), e); } List<Checkpoint> out = new ArrayList<>(lines.size()-1); //Assume first line is header for( int i=1; i<lines.size(); i++ ){ Checkpoint c = Checkpoint.fromFileString(lines.get(i)); if(new File(directory, c.getFilename()).exists()){ out.add(c); } } return out; }
List all available checkpoints. A checkpoint is 'available' if the file can be loaded. Any checkpoint files that have been automatically deleted (given the configuration) will not be returned here. Note that the checkpointInfo.txt file must exist, as this stores checkpoint information @return List of checkpoint files that can be loaded from the specified directory
KeepMode::availableCheckpoints
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public Checkpoint lastCheckpoint(){ if(!checkpointRecordFile.exists()){ return null; } return lastCheckpoint(rootDir); }
Return the most recent checkpoint, if one exists - otherwise returns null @return Checkpoint
KeepMode::lastCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public static Checkpoint lastCheckpoint(File rootDir){ List<Checkpoint> all = availableCheckpoints(rootDir); if(all.isEmpty()){ return null; } return all.get(all.size()-1); }
Return the most recent checkpoint, if one exists - otherwise returns null @param rootDir Root direcotry for the checkpoint files @return Checkpoint
KeepMode::lastCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public File getFileForCheckpoint(Checkpoint checkpoint){ return getFileForCheckpoint(checkpoint.getCheckpointNum()); }
Get the model file for the given checkpoint. Checkpoint model file must exist @param checkpoint Checkpoint to get the model file for @return Model file for the checkpoint
KeepMode::getFileForCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public File getFileForCheckpoint(int checkpointNum) { return getFileForCheckpoint(rootDir, checkpointNum); }
Get the model file for the given checkpoint number. Checkpoint model file must exist @param checkpointNum Checkpoint number to get the model file for @return Model file for the checkpoint
KeepMode::getFileForCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public SameDiff loadCheckpoint(int checkpointNum, boolean loadUpdaterState){ return loadCheckpoint(rootDir, checkpointNum, loadUpdaterState); }
Load a given checkpoint number @param loadUpdaterState If true: load the updater state. See {@link SameDiff#load(File, boolean)} for more details
KeepMode::loadCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public static SameDiff loadCheckpoint(File rootDir, int checkpointNum, boolean loadUpdaterState) { File f = getFileForCheckpoint(rootDir, checkpointNum); return SameDiff.load(f, loadUpdaterState); }
Load a SameDiff instance for the given checkpoint that resides in the specified root directory @param rootDir Directory that the checkpoint resides in @param checkpointNum Checkpoint model number to load @param loadUpdaterState If true: load the updater state. See {@link SameDiff#load(File, boolean)} for more details @return The loaded model
KeepMode::loadCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public static SameDiff loadLastCheckpoint(File rootDir, boolean loadUpdaterState){ Checkpoint last = lastCheckpoint(rootDir); return loadCheckpoint(rootDir, last.getCheckpointNum(), loadUpdaterState); }
Load the last (most recent) checkpoint from the specified root directory @param rootDir Root directory to load checpoint from @return ComputationGraph for last checkpoint
KeepMode::loadLastCheckpoint
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public Builder saveUpdaterState(boolean saveUpdaterState){ this.saveUpdaterState = saveUpdaterState; return this; }
Whether the updater state (history/state for Adam, Nesterov momentum, etc) should be saved with each checkpoint.<br> Updater state is saved by default. If you expect to continue training on any of the checkpoints, this should be set to true. However, it will increase the file size. @param saveUpdaterState If true: updater state will be saved with checkpoints. False: not saved.
Builder::saveUpdaterState
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/listeners/checkpoint/CheckpointListener.java
Apache-2.0
public DifferentialFunction(SameDiff sameDiff,NodeDef nodeDef, Map<String, AttrValue> attributesForNode, GraphDef graph) { this.sameDiff = sameDiff; setInstanceId(); initFromTensorFlow(nodeDef, sameDiff,attributesForNode ,graph); recordCreation(); }
Initialize the function from the given {@link NodeDef} @param nodeDef
DifferentialFunction::DifferentialFunction
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/functions/DifferentialFunction.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/functions/DifferentialFunction.java
Apache-2.0
public DifferentialFunction(SameDiff sameDiff, Onnx.NodeProto node, Map<String, Onnx.AttributeProto> attributesForNode, Onnx.GraphProto graph) { this.sameDiff = sameDiff; setInstanceId(); initFromOnnx(node, sameDiff, attributesForNode, graph); recordCreation(); }
Initialize the function from the given {@link Onnx.NodeProto} @param node
DifferentialFunction::DifferentialFunction
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/functions/DifferentialFunction.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/functions/DifferentialFunction.java
Apache-2.0
public static SDVariable[] initializeLoopBody(String[] namesToUse,SameDiff loopBody,int maxIterations) { Preconditions.checkState( namesToUse != null && namesToUse.length == 2,"Number of input names must be 2."); SDVariable[] ret = new SDVariable[] { loopBody.constant(namesToUse[1], maxIterations), loopBody.var(namesToUse[0], Nd4j.zeros(1)), }; return ret; }
Initializes the loop variables with default parameters. The variables are as follows: current iteration max number of iterations extra condition to use The passed in variable names will be assumed to be names for each of these variables mentioned above respectively. Please ensure that these are the intended names of the variables. @param namesToUse the names of the variables to use. Must be length 2. @param loopBody the loop body to initialize @param maxIterations the max iterations to iterate over
ControlFlow::initializeLoopBody
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable[] initializeLoopBody(String[] namesToUse,SameDiff loopBody,int maxIterations,boolean extraCond) { Preconditions.checkState( namesToUse != null && namesToUse.length == 3,"Number of input names must be 3."); SDVariable[] ret = new SDVariable[] { loopBody.var(namesToUse[0], Nd4j.zeros(1)), loopBody.constant(namesToUse[1], maxIterations), loopBody.constant(namesToUse[2], extraCond) }; return ret; }
Initializes the loop variables with default parameters. The variables are as follows: current iteration max number of iterations extra condition to use The passed in variable names will be assumed to be names for each of these variables mentioned above respectively. Please ensure that these are the intended names of the variables. @param namesToUse the names of the variables to use. Must be length 3. @param loopBody the loop body to initialize @param maxIterations the max iterations to iterate over @param extraCond the extra condition to use
ControlFlow::initializeLoopBody
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable[] args(SDVariable maxIterations,SDVariable condIn,SDVariable startIterations,SDVariable[] extraArgs) { return LoopArgs.builder().extraArgs(extraArgs) .condIn(condIn) .maxIters(maxIterations) .startIter(startIterations).build().toArgs(); }
Create the arguments used in {@link #condBody()} and {@link #loopWithConditions(String[], String, SameDiff, SameDiff, String, SDVariable[], String[], String[])} @param maxIterations the max number of iterations @param condIn the input conditions @param startIterations the start iterations @param extraArgs the extra arguments for the user @return the ordered arguments
ControlFlow::args
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable ifCond(SameDiff sameDiff,String outputName, String ifName, @NonNull SameDiffNoArgSingleLambda cond, @NonNull SameDiffNoArgSingleLambda trueBody, @NonNull SameDiffNoArgSingleLambda falseBody){ ifName = sameDiff.newBlockName(ifName == null ? "if" : ifName); NameScope ifScope = sameDiff.withNameScope(ifName); NameScope condScope = sameDiff.withNameScope("cond"); final SDVariable pred = cond.define(sameDiff); condScope.close(); if (pred.dataType() != DataType.BOOL) { //cleanup partially added block for(SDVariable v : sameDiff.getVariablesInScope(ifScope)) sameDiff.getVariables().remove(v.name()); for(SameDiffOp op : sameDiff.getOpsInScope(ifScope)) { for(String in : op.getInputsToOp()){ sameDiff.removeArgFromOp(in, op.getOp()); } sameDiff.getOps().remove(op.getName()); } throw new IllegalStateException("Can not use " + pred.name() + " as the condition of an If statement, the condition must be a boolean."); } final Map<String, SDVariable[]> switches = new HashMap<>(); final Set<String> declared = Sets.newHashSet(sameDiff.variableMap().keySet()); sameDiff.addArgumentInterceptor(argument -> { if(argument == null) return null; // if its declared in the if, we don't care about it if(declared == null || !declared.contains(argument.name())) return argument; // if we've already added a switch, move on if(switches.containsKey(argument.name())) return switches.get(argument.name())[1]; SDVariable[] s = sameDiff.switchOp(argument, pred); switches.put(argument.name(), s); return s[1]; }); NameScope trueScope = sameDiff.withNameScope("trueBody"); SDVariable trueOut = trueBody.define(sameDiff); sameDiff.removeArgumentInterceptor(); if(declared.contains(trueOut.name())) { SDVariable[] s = sameDiff.switchOp(trueOut, pred); switches.put(trueOut.name(), s); trueOut = s[1]; } trueScope.close(); final Set<String> declared2 = Sets.newHashSet(sameDiff.variableMap().keySet()); sameDiff.addArgumentInterceptor(argument -> { // if its declared in the if, we don't care about it if(!declared2.contains(argument.name())) return argument; // if we've already added a switch, move on if(switches.containsKey(argument.name())) return switches.get(argument.name())[0]; SDVariable[] s = sameDiff.switchOp(argument, pred); switches.put(argument.name(), s); return s[0]; }); NameScope falseScope = sameDiff.withNameScope("falseBody"); SDVariable falseOut = falseBody.define(sameDiff); sameDiff.removeArgumentInterceptor(); if(declared2.contains(falseOut.name())) { SDVariable[] s = sameDiff.switchOp(falseOut, pred); switches.put(falseOut.name(), s); falseOut = s[0]; } falseScope.close(); SDVariable output = sameDiff.merge(trueOut, falseOut); ifScope.close(); return sameDiff.updateVariableNameAndReference(output, outputName); }
Constructs a If statement using the tensorflow style control flow operations (Switch and Merge) If the result of cond is true, returns the result of trueBody, otherwise returns the result of falseBody Note that cond and body lambdas are only called once to construct the graph. The constructed graph is used to evaluate. See <a href="http://download.tensorflow.org/paper/white_paper_tf_control_flow_implementation_2017_11_1.pdf">Tensorflow Control Flow Implementation</a> @param outputName Name to give the output variable. If null, doesn't rename @param ifName The name of the if block. If null, uses "if" @param cond A lambda evaluating to the if condition @param trueBody A lambda to be executed if cond is true (the if block) @param falseBody A lambda to be executed if cond is false (the else block) @return The value of trueBody if cond is true, or falseBody if it isn't
ControlFlow::ifCond
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable[] loopWithConditions(LoopParams loopParams) { return loopWithConditions(loopParams.outputVarNames, loopParams.loopName,loopParams.parent, loopParams.functionBody, loopParams.functionName, loopParams.loopVars, loopParams.functionBodyInputs, loopParams.functionBodyOutputs); }
A simplified function using {@link LoopParams} invoking the same function as {@link #loopWithConditions(String[], String, SameDiff, SameDiff, String, SDVariable[], String[], String[])} @param loopParams the loop parameters to use @return
LoopParams::loopWithConditions
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable[] loopWithConditions( String[] outputVarNames, String loopName, SameDiff parent, SameDiff functionBody, String functionName, SDVariable[] loopVars, String[] functionBodyInputs, String[] functionBodyOutputs) { Preconditions.checkState(functionBodyInputs != null && functionBodyOutputs != null && functionBodyInputs.length == functionBodyOutputs.length,"Sub graph input and output names must be defined and equal in length."); Preconditions.checkState(loopVars.length == functionBodyInputs.length,"Loop variables and function body inputs must be equal in length."); for(SDVariable variable : loopVars) { if(variable.getSameDiff() != parent) { throw new IllegalArgumentException("Variable named " + variable.name() + " does not have correct samediff instance. Must have parent outer samediff instance."); } } SameDiffSingleLambda cond = condBody(); SameDiffLambda loopBody = loopBody(parent,functionBody,functionName,functionBodyInputs,functionBodyOutputs); return parent.whileLoop(outputVarNames,loopName,loopVars,cond,loopBody); }
Loop with conditions allows a user to provide a lambda to invoke any number of times. @param outputVarNames the output variable names to use @param loopName the name of the loop to use when creating the variables/ops @param parent the parent samediff instance to put the loop @param functionBody the function body to use @param functionName the name of the function to use within the samediff instance @param loopVars the loop variables to use during execution @param functionBodyInputs the inputs to invoke the function with @param functionBodyOutputs the outputs to be retrieved from the function itself @return the output exit variables at the end of the loop
LoopParams::loopWithConditions
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static LoopLambdaArgs argsFromInputs(SDVariable[] inputs) { SDVariable[] extraArgs = inputs.length > 3 ? new SDVariable[inputs.length - 3] : new SDVariable[0]; //add extra arguments offset by 3 representing custom inputs if(extraArgs.length > 0) { for(int i = 0; i < extraArgs.length; i++) { extraArgs[i] = inputs[i + 3]; } } return LoopLambdaArgs.builder() .iterCount(inputs[1]) .iterStart(inputs[0]) .condIn(inputs[2]) .extraArgs(extraArgs) .build(); }
Create {@link LoopLambdaArgs} from the given arguments. This is used to properly order arguments for use with {@link #loopBody(SameDiff, SameDiff, String, String[], String[])} and {@link #condBody()} @param inputs the inputs to order, these generally should be from within a lambda. The first 3 arguments are: current iter count, maximum number of iterations, extra arguments if any @return
LoopParams::argsFromInputs
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public Invoke.InvokeParams invokeParams(String functionName,String[] subGraphInputNames,String[] subGraphOutputNames) { List<SDVariable> inputs = new ArrayList<>(); //starting iteration inputs.add(iterStart); //ending iteration inputs.add(iterCount); //user custom condition inputs.add(condIn); inputs.addAll(Arrays.asList(extraArgs)); return Invoke.InvokeParams.builder() .functionName(functionName) .inputs(inputs.toArray(new SDVariable[inputs.size()])) .subGraphInputVarNames(subGraphInputNames) .subGraphOutputVarNames(subGraphOutputNames) .inputVarNames(inputs.stream().map(input -> input.name()).collect(Collectors.toList()) .toArray(new String[inputs.size()])) .build(); }
Construct {@link org.nd4j.linalg.api.ops.custom.Invoke.InvokeParams} for usage with {@link SameDiff#invoke(Invoke.InvokeParams)} the variables here reflect what is used in the loop. A user can use {@link LoopLambdaArgs} to create an appropriately configured {@link org.nd4j.linalg.api.ops.custom.Invoke.InvokeParams} to be used with the body. @param functionName the name of the function to invoke @param subGraphInputNames the subgraph input names to invoke the function with @param subGraphOutputNames the subgraph output names to expect returned from the function @return the appropriate invoke parameters for use with {@link #condBody()} and {@link #loopBody(SameDiff, SameDiff, String, String[], String[])}
LoopLambdaArgs::invokeParams
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SameDiffLambda loopBody(SameDiff parent, SameDiff functionBody, String functionName, String[] subGraphInputNames, String[] subGraphOutputNames) { Preconditions.checkState(subGraphInputNames != null && subGraphOutputNames != null && subGraphInputNames.length == subGraphOutputNames.length,"Sub graph input and output names must be defined and equal in length."); if(parent.getFunction(functionName) == null) parent.putSubFunction(functionName,functionBody); return (sameDiff, inputs) -> { LoopLambdaArgs loopLambdaArgs = ControlFlow.argsFromInputs(inputs); Invoke.InvokeParams invokeParams = loopLambdaArgs.invokeParams(functionName, subGraphInputNames, subGraphOutputNames); SDVariable[] invoke = sameDiff.invoke(invokeParams); List<SDVariable> retList = new ArrayList<>(); //current iterations + 1 (each time the body is invoked update the current iteration) retList.add(inputs[0].add(1.0)); retList.add(inputs[1]); retList.add(invoke[2]); //assign extra parameters to the invoke output //loop over non condition out variables starting from the end for(int i = 3; i < invoke.length; i++) { retList.add(invoke[i]); } return retList.toArray(new SDVariable[retList.size()]); }; }
Create a {@link SameDiffLambda} to be used in combination with {@link #condBody()} and {@link SameDiff#invoke(Invoke.InvokeParams)} this lambda will use samediff invoke as the function bdoy and setup the appropriate parameters to create a looping construct as described in {@link #loopBody(SameDiff, SameDiff, String, String[], String[])} @param parent @param functionBody @param functionName @param subGraphInputNames the subgraph input names for use to invoke the graph with @param subGraphOutputNames the subgraph output names to expect to be returned from the subgraph invoke @return
LoopLambdaArgs::loopBody
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SDVariable[] whileLoop(SameDiff sameDiff, String[] outputNames, final String loopName, @NonNull SDVariable[] loopVars, @NonNull SameDiffSingleLambda cond, @NonNull SameDiffLambda body) { final String frameName = sameDiff.newBlockName(loopName == null ? "while" : loopName); NameScope loopScope = sameDiff.withNameScope(frameName); SDVariable counter = sameDiff.scalar(sameDiff.generateNewVarName("counter", 0), 0); SDVariable[] entered = new SDVariable[loopVars.length]; for (int i = 0; i < loopVars.length; i++) { entered[i] = new Enter(sameDiff, frameName, loopVars[i]).outputVariable(); } SDVariable[] merged = new SDVariable[loopVars.length]; Merge[] mergeOps = new Merge[loopVars.length]; for (int i = 0; i < loopVars.length; i++) { // the second arg will later be replaced with the output of NextIteration // but that isn't available yet (and can't be, as it depends on this) mergeOps[i] = new Merge(sameDiff, entered[i], entered[i]); mergeOps[i].setFrameName(frameName); merged[i] = mergeOps[i].outputVariable(); } Merge counterMerge = new Merge(sameDiff, counter, counter); counter = counterMerge.outputVariable(); counterMerge.setFrameName(frameName); NameScope condScope = sameDiff.withNameScope("cond"); SDVariable condResult = cond.define(sameDiff, merged); condScope.close(); if (condResult.dataType() != DataType.BOOL) throw new IllegalStateException("Can not use " + condResult.name() + " as the condition of an While loop, the condition must be a boolean."); final Set<String> alreadyEntered = Sets.newHashSet(); SDVariable[] trueSwitches = new SDVariable[loopVars.length]; SDVariable[] exits = new SDVariable[loopVars.length]; for (int i = 0; i < loopVars.length; i++) { SDVariable[] s = sameDiff.switchOp(merged[i], condResult); trueSwitches[i] = s[1]; alreadyEntered.add(s[1].name()); Exit exit = new Exit(sameDiff, s[0]); exit.setFrameName(frameName); exits[i] = exit.outputVariable(); } final Set<String> declared = Sets.newHashSet(sameDiff.variableMap().keySet()); final Map<String, SDVariable> done = new HashMap<>(); final SameDiff sd = sameDiff; sameDiff.addArgumentInterceptor(argument -> { if (argument == null) return null; if (!declared.contains(argument.name())) return argument; if (alreadyEntered.contains(argument.name())) return argument; if (done.containsKey(argument.name())) return done.get(argument.name()); SDVariable e = new Enter(sd, frameName, argument, true).outputVariable(); done.put(argument.name(), e); return e; }); NameScope bodyScope = sameDiff.withNameScope("body"); SDVariable[] outs = body.define(sameDiff, trueSwitches); if (outs.length != mergeOps.length) throw new IllegalArgumentException("Number of loop variables must be equal to number of outputs."); bodyScope.close(); sameDiff.removeArgumentInterceptor(); counter.add(1); for (int i = 0; i < outs.length; i++) { NextIteration nextIteration = new NextIteration(sameDiff, outs[i]); nextIteration.setFrameName(frameName); SDVariable n = nextIteration.outputVariable(); mergeOps[i].replaceArg(1, n); } counterMerge.replaceArg(1, counter); loopScope.close(); return sameDiff.updateVariableNamesAndReferences(exits, outputNames); }
Constructs a While loop using the tensorflow style control flow operations (Switch, Merge, Enter, Exit, and NextIteration) <p> Repeatedly executes body on the loop variables and updates them with the results, until cond evaluates to false <p> Note that cond and body lambdas are only called once to construct the graph. The constructed graph is used for further iterations. <p> See <a href="http://download.tensorflow.org/paper/white_paper_tf_control_flow_implementation_2017_11_1.pdf">Tensorflow Control Flow Implementation</a> @param outputNames Names to give the output variables. If null, doesn't rename @param loopName The name of the loop block and frame (must be unique). If null, uses "if" @param loopVars Loop variables' inputs @param cond A lambda evaluating to the loop condition @param body A lambda doing the loop operation and returning the new loop variable values @return The values of the loop variables once condition is false
LoopLambdaArgs::whileLoop
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public static SameDiffSingleLambda condBody() { // combine for loop and while loop together return (sameDiff, inputs) -> { SDVariable currIteration = inputs[0]; SDVariable maxIterations = inputs[1]; SDVariable extraCond = inputs[2]; SDVariable and = sameDiff.bitwise().and( currIteration.lt(maxIterations.castTo(currIteration.dataType())) .castTo(DataType.INT64), extraCond.castTo(DataType.INT64)); SDVariable ret = and.castTo( DataType.BOOL); return ret; }; }
Returns a lambda that takes in a custom condition and a built-in for loop counter concept in the following manner: int currIteration = 0; boolean cond = ...; int maxIterations = ...; for(int i = currIteration; i < maxIterations && cond; i++) { //body.... } The inputs to the lambda are the following order: currIteration (the starting iteration) maxIterations (the number of times to loop) cond: the custom condition the user passes in @return the lambda described above for usage in the {@link #whileLoop(SameDiff, String[], String, SDVariable[], SameDiffSingleLambda, SameDiffLambda)} routine
LoopLambdaArgs::condBody
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/ControlFlow.java
Apache-2.0
public String name(){ return varName; }
Get the name of the SDVariable @return Name of the variable
SDVariable::name
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
Apache-2.0
public boolean isPlaceHolder() { return variableType == VariableType.PLACEHOLDER; }
Returns true if this variable is a placeholder @return
SDVariable::isPlaceHolder
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
Apache-2.0
public INDArray getArr() { return getArr(false); }
A getter for the allocated ndarray with this {@link SDVariable}. This getter will lazy initialize an array if one is not found based on the associated shape and {@link WeightInitScheme} - if this is possible. If this is not possible (due to shapes being unknown, etc) null is returned @return the {@link INDArray} associated with this variable.
SDVariable::getArr
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
Apache-2.0
public INDArray getArr(boolean enforceExistence) { if(sameDiff.arrayAlreadyExistsForVarName(getVarName())) return sameDiff.getArrForVarName(getVarName()); if(variableType == VariableType.ARRAY && enforceExistence) { throw new UnsupportedOperationException("Cannot get array for ARRAY type SDVariable - use SDVariable.exec or SameDiff.output instead"); } else if(variableType == VariableType.ARRAY) { if(sameDiff.isEagerMode()) { return sameDiff.getEagerArrForVarName(name()); } return null; } INDArray ret = sameDiff.getArrForVarName(getVarName()); if(enforceExistence && ret == null) { throw new IllegalStateException("No array exists for variable \"" + name() + "\""); } return ret; }
A getter for the allocated ndarray with this {@link SDVariable}. This getter will lazy initialize an array if one is not found based on the associated shape and {@link WeightInitScheme} - if this is possible.<br> If this is not possible (due to shapes being unknown, etc) either:<br> (a) null is returned - if enforceExistence == false, or<br> (b) an IllegalStateException is thrown, if enforceExistence == true @return the {@link INDArray} associated with this variable.
SDVariable::getArr
java
deeplearning4j/deeplearning4j
nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
https://github.com/deeplearning4j/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SDVariable.java
Apache-2.0