code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 844
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
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(SDVariable param, IMetric metric){
return trainingEval(param.name(), metric);
} |
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(SDVariable param, int index, IMetric metric) {
return trainingEval(param.name(), index, metric);
} |
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(SDVariable param){
return trainingEval(param.name());
} |
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<IEvaluation> trainingEval(SDVariable param, int index){
return trainingEval(param.name(), index);
} |
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(SDVariable param, IMetric metric) {
return validationEval(param.name(), metric);
} |
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(SDVariable param, int index, IMetric metric) {
return validationEval(param.name(), index, metric);
} |
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(SDVariable param){
return validationEval(param.name());
} |
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 List<IEvaluation> validationEval(SDVariable param, int index){
return validationEval(param.name(), index);
} |
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 EvaluationRecord validationEvaluations(int epoch) {
if(epoch >= 0){
return trainingHistory.get(epoch);
} else {
return validationHistory.get(validationHistory.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::validationEvaluations | 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 List<IEvaluation> evaluations(SDVariable param) {
return evaluations(param.name());
} |
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 IEvaluation evaluation(SDVariable param, int index) {
return evaluation(param.name(), 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 evaluation(SDVariable param) {
return evaluation(param.name());
} |
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 <T extends IEvaluation<T>> T evaluation(SDVariable param, Class<T> evalClass) {
return evaluation(param.name(), evalClass);
} |
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(SDVariable param, IMetric metric) {
return getValue(param.name(), 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 double getValue(SDVariable param, int index, IMetric metric) {
return getValue(param.name(), index, 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 SDVariable loss){
return meanLoss(loss.name());
} |
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 meanLoss(@NonNull SDVariable loss, int epoch){
return meanLoss(loss.name(), epoch);
} |
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 float lastMeanLoss(@NonNull SDVariable loss){
return lastMeanLoss(loss.name());
} |
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 double lastMeanDelta(SDVariable loss){
return lastMeanDelta(loss.name());
} |
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 LossCurve addLossAndCopy(double[] values, List<String> lossNames){
return new LossCurve(
Nd4j.concat(0, lossValues,
Nd4j.createFromArray(new double[][]{values}).castTo(DataType.FLOAT)),
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(@NonNull String rootDir){
this(new File(rootDir));
} |
@param rootDir Root directory to save models to
| Builder::Builder | 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(@NonNull File rootDir){
this.rootDir = rootDir;
} |
@param rootDir Root directory to save models to
| Builder::Builder | 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 saveEveryEpoch(){
return saveEveryNEpochs(1);
} |
Save a model at the end of every epoch
| Builder::saveEveryEpoch | 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 saveEveryNEpochs(int n){
this.saveEveryNEpochs = n;
return this;
} |
Save a model at the end of every N epochs
| Builder::saveEveryNEpochs | 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 saveEveryNIterations(int n){
return saveEveryNIterations(n, false);
} |
Save a model every N iterations
| Builder::saveEveryNIterations | 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 saveEveryNIterations(int n, boolean sinceLast){
this.saveEveryNIterations = n;
this.saveEveryNIterSinceLast = sinceLast;
return this;
} |
Save a model every N iterations (if sinceLast == false), or if N iterations have passed since
the last model vas saved (if sinceLast == true)
| Builder::saveEveryNIterations | 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 saveEvery(long amount, TimeUnit timeUnit){
return saveEvery(amount, timeUnit, false);
} |
Save a model periodically
@param amount Quantity of the specified time unit
@param timeUnit Time unit
| Builder::saveEvery | 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 saveEvery(long amount, TimeUnit timeUnit, boolean sinceLast){
this.saveEveryAmount = amount;
this.saveEveryUnit = timeUnit;
this.saveEverySinceLast = sinceLast;
return this;
} |
Save a model periodically (if sinceLast == false), or if the specified amount of time has elapsed since
the last model was saved (if sinceLast == true)
@param amount Quantity of the specified time unit
@param timeUnit Time unit
| Builder::saveEvery | 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 keepAll(){
this.keepMode = KeepMode.ALL;
return this;
} |
Keep all model checkpoints - i.e., don't delete any. Note that this is the default.
| Builder::keepAll | 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 keepLast(int n){
if(n <= 0){
throw new IllegalArgumentException("Number of model files to keep should be > 0 (got: " + n + ")");
}
this.keepMode = KeepMode.LAST;
this.keepLast = n;
return this;
} |
Keep only the last N most recent model checkpoint files. Older checkpoints will automatically be deleted.
@param n Number of most recent checkpoints to keep
| Builder::keepLast | 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 keepLastAndEvery(int nLast, int everyN){
if(nLast <= 0){
throw new IllegalArgumentException("Most recent number of model files to keep should be > 0 (got: "
+ nLast + ")");
}
if(everyN <= 0){
throw new IllegalArgumentException("Every n model files to keep should be > 0 (got: "
+ everyN + ")");
}
this.keepMode = KeepMode.LAST_AND_EVERY;
this.keepLast = nLast;
this.keepEvery = everyN;
return this;
} |
Keep the last N most recent model checkpoint files, <i>and</i> every M checkpoint files.<br>
For example: suppose you save every 100 iterations, for 2050 iteration, and use keepLastAndEvery(3,5).
This means after 2050 iterations you would have saved 20 checkpoints - some of which will be deleted.
Those remaining in this example: iterations 500, 1000, 1500, 1800, 1900, 2000.
@param nLast Most recent checkpoints to keep
@param everyN Every N checkpoints to keep (regardless of age)
| Builder::keepLastAndEvery | 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 logSaving(boolean logSaving){
this.logSaving = logSaving;
return this;
} |
If true (the default) log a message every time a model is saved
@param logSaving Whether checkpoint saves should be logged or not
| Builder::logSaving | 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 Builder deleteExisting(boolean deleteExisting){
this.deleteExisting = deleteExisting;
return this;
} |
If the checkpoint listener is set to save to a non-empty directory, should the CheckpointListener-related
content be deleted?<br>
This is disabled by default (and instead, an exception will be thrown if existing data is found)<br>
WARNING: Be careful when enabling this, as it deletes all saved checkpoint models in the specified directory!
| Builder::deleteExisting | 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 |
public SDVariable gradient() {
return getGradient();
} |
Alias for the gradient variable - same as {@link #getGradient()}.
The gradient variable is the variable that represents the derivative of the loss function with respect
to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the
variable representing dL/dX.<br>
Note that only floating point variables can have gradients.
| SDVariable::gradient | 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 SDVariable getGradient() {
return sameDiff.getGradForVariable(getVarName());
} |
The gradient variable is the variable that represents the derivative of the loss function with respect
to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the
variable representing dL/dX<br>
Note that only floating point variables can have gradients.<br>
Note also that a gradient may not yet be defined, and/or if no loss function variables have been set.<br>
You can set the loss function variables using {@link SameDiff#setLossVariables(String...)} and then create the
gradient functions using {@link SameDiff#createGradFunction()}. Alternatively, the gradient function will be
created automatically when training is performed.
| SDVariable::getGradient | 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 long[] getShape() {
if (variableType == VariableType.PLACEHOLDER || shape != null) {
return shape;
} else if(variableType == VariableType.VARIABLE || variableType == VariableType.CONSTANT) {
if(getArr() != null)
return getArr().shape();
}
return null;
} |
Returns the shape of this variable
@return Shape of the variable
| SDVariable::getShape | 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 SDVariable dup() {
return sameDiff.var(this);
} |
Create a new SDVariable, the contents of which is copied from this current variable
@return The new variable
| SDVariable::dup | 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 SDVariable assign(Number value) {
return sameDiff.scalarSet(this, value.doubleValue());
} |
Return a variable with equal shape to the input, but all elements set to the specified value
@param value Value for returned variable
@return new variable
| SDVariable::assign | 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 SDVariable neg(){
return sameDiff.math.neg(this);
} |
Negate op - returns a new variable with the values of the current variable negated
@return Negated variable
| SDVariable::neg | 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 SDVariable neg(String name){
return sameDiff.math().neg(name, this);
} |
Negate op - returns a new variable with the values of the current variable negated
@param name Name of the new variable
@return Negated variable
| SDVariable::neg | 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 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.