public abstract class Evaluator
extends java.lang.Object
Evaluator
s that can be used to evaluate the performance of a model.
The Evaluator
s can all be monitored to make an assessment about the performance of the
model. However, only ones that further extend Loss
are suited to
being used to directly optimize a model.
In addition to computing the evaluation, an evaluator can accumulate values to compute a total
evaluation. For different purposes, it is possible to have multiple accumulators on a single
evaluator. Each accumulator must be added with a String key to identify the accumulator. Before
using an accumulator, you must addAccumulator(String)
. Then, call updateAccumulator(String, NDList, NDList)
to add more data to the accumulator. You can
use getAccumulator(String)
to retrieve the accumulated value and resetAccumulator(String)
to reset the accumulator to the same value as when just
added.
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Long> |
totalInstances |
Constructor and Description |
---|
Evaluator(java.lang.String name)
Creates an evaluator with abstract update methods.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
addAccumulator(java.lang.String key)
Adds an accumulator for the results of the evaluation with the given key.
|
protected void |
checkLabelShapes(NDArray labels,
NDArray predictions)
Checks the length of NDArrays.
|
protected void |
checkLabelShapes(NDArray labels,
NDArray predictions,
boolean checkDimOnly)
Checks if the two input
NDArray have the same length or shape. |
abstract NDArray |
evaluate(NDList labels,
NDList predictions)
Calculates the evaluation between the labels and the predictions.
|
abstract float |
getAccumulator(java.lang.String key)
Returns the accumulated evaluator value.
|
java.lang.String |
getName()
Returns the name of this
Evaluator . |
abstract void |
resetAccumulator(java.lang.String key)
Resets the evaluator value with the given key.
|
abstract void |
updateAccumulator(java.lang.String key,
NDList labels,
NDList predictions)
Updates the evaluator with the given key based on a
NDList of labels and predictions. |
public Evaluator(java.lang.String name)
name
- the name of the evaluatorpublic java.lang.String getName()
Evaluator
.Evaluator
public abstract NDArray evaluate(NDList labels, NDList predictions)
labels
- the correct valuespredictions
- the predicted valuespublic abstract void addAccumulator(java.lang.String key)
key
- the key for the new accumulatorpublic abstract void updateAccumulator(java.lang.String key, NDList labels, NDList predictions)
NDList
of labels and predictions.
This is a synchronized operation. You should only call it at the end of a batch or epoch.
key
- the key of the accumulator to updatelabels
- a NDList
of labelspredictions
- a NDList
of predictionspublic abstract void resetAccumulator(java.lang.String key)
key
- the key of the accumulator to resetpublic abstract float getAccumulator(java.lang.String key)
key
- the key of the accumulator to getjava.lang.IllegalArgumentException
- if no accumulator was added with the given keyprotected void checkLabelShapes(NDArray labels, NDArray predictions, boolean checkDimOnly)
NDArray
have the same length or shape.labels
- a NDArray
of labelspredictions
- a NDArray
of predictionscheckDimOnly
- whether to check for first dimension only