Class Precision<T extends TNumber>
- Type Parameters:
T- The data type for the metric result
- All Implemented Interfaces:
Metric
The metric creates two local variables, truePositives and falsePositives that
are used to compute the precision. This value is ultimately returned as precision, an idempotent
operation that simply divides truePositives by the sum of truePositives and
falsePositives.
If sampleWeights is null, weights default to 1. Use sampleWeights of 0 to mask
values.
If topK is set, the metric calculates precision as how often on average a class among
the top-k classes with the highest predicted values of a batch entry is correct and can be found
in the label for that entry.
If classId is specified, the metric calculates precision by considering only the
entries in the batch for which classId is above the thresholds and/or in the
top-k highest predictions, and computing the fraction of them for which classId is
indeed a correct label.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values.Creates a Precision Metric with a name ofClass.getSimpleName()Creates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values.Creates a Precision Metric with a name ofClass.getSimpleName()Creates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values and with a threshold ofDEFAULT_THRESHOLD.Creates a Precision Metric with no topK or classId values.Creates a Precision Metric.Creates a Precision Metric with no topK or classId values.Creates a Precision Metric.Creates a Precision Metric with no topK or classId values with a threshold ofDEFAULT_THRESHOLD. -
Method Summary
Modifier and TypeMethodDescriptionGets the classId, may be nullGets the falsePositives variableGets the name of the falsePositives variablefloat[]Gets the thresholdsgetTopK()Gets the topK value, may be nullGets the truePositives variableGets the name of the truePositives variableprotected voidInitialize the TensorFlow OpsresetStates(Ops tf) Resets any state variables to their initial valuesGets the current result of the metricupdateStateList(Ops tf, Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions, Operand<? extends TNumber> sampleWeights) Accumulates true positive and false positive statistics.Methods inherited from class BaseMetric
callOnce, checkIsGraph, getName, getSeed, getTF, getVariableName, isInitialized, setInitialized, setName, setTF, updateState, updateState, updateStateList
-
Field Details
-
TRUE_POSITIVES
- See Also:
-
FALSE_POSITIVES
- See Also:
-
DEFAULT_THRESHOLD
public static final float DEFAULT_THRESHOLD- See Also:
-
-
Constructor Details
-
Precision
Creates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values and with a threshold ofDEFAULT_THRESHOLD.- Parameters:
seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with no topK or classId values with a threshold ofDEFAULT_THRESHOLD.- Parameters:
name- name of the metric instance. If null, name defaults toClass.getSimpleName().seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values.- Parameters:
threshold- Optional threshold value in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with a name ofClass.getSimpleName()and no topK or classId values.- Parameters:
thresholds- Optional threshold values in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with no topK or classId values.- Parameters:
name- name of the metric instance. If null, name defaults toClass.getSimpleName().threshold- Optional threshold value in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with no topK or classId values.- Parameters:
name- name of the metric instance. If null, name defaults toClass.getSimpleName().thresholds- Optional threshold values in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with a name ofClass.getSimpleName()- Parameters:
threshold- Optional threshold value in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.topK- An optional value specifying the top-k predictions to consider when calculating precision.classId- Optional Integer class ID for which we want binary metrics. This must be in the half-open interval [0, numClasses], where numClasses is the last dimension of predictions.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
Creates a Precision Metric with a name ofClass.getSimpleName()- Parameters:
thresholds- Optional threshold values in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.topK- An optional value specifying the top-k predictions to consider when calculating precision.classId- Optional Integer class ID for which we want binary metrics. This must be in the half-open interval [0, numClasses], where numClasses is the last dimension of predictions.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
public Precision(String name, float threshold, Integer topK, Integer classId, long seed, Class<T> type) Creates a Precision Metric.- Parameters:
name- name of the metric instance. If null, name defaults toClass.getSimpleName().threshold- Optional threshold value in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.topK- An optional value specifying the top-k predictions to consider when calculating precision.classId- Optional Integer class ID for which we want binary metrics. This must be in the half-open interval [0, numClasses], where numClasses is the last dimension of predictions.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
Precision
public Precision(String name, float[] thresholds, Integer topK, Integer classId, long seed, Class<T> type) Creates a Precision Metric.- Parameters:
name- name of the metric instance. If null, name defaults toClass.getSimpleName().thresholds- Optional threshold values in the range[0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is true, below is false). One metric value is generated for each threshold value.topK- An optional value specifying the top-k predictions to consider when calculating precision.classId- Optional Integer class ID for which we want binary metrics. This must be in the half-open interval [0, numClasses], where numClasses is the last dimension of predictions.seed- the seed for random number generation. An initializer created with a given seed will always produce the same random tensor for a given shape and data type.type- the data type for the variables
-
-
Method Details
-
init
Initialize the TensorFlow Ops- Specified by:
initin classBaseMetric- Parameters:
tf- the TensorFlow Ops encapsulating aGraphenvironment.
-
updateStateList
public List<Op> updateStateList(Ops tf, Operand<? extends TNumber> labels, Operand<? extends TNumber> predictions, Operand<? extends TNumber> sampleWeights) Accumulates true positive and false positive statistics.- Specified by:
updateStateListin interfaceMetric- Overrides:
updateStateListin classBaseMetric- Parameters:
tf- the TensorFlow Ops encapsulating aGraphenvironment.labels- the labels The ground truth values, with the same dimensions as predictions. Will be cast toTBool.predictions- the predictions, each element must be in the range[0, 1].sampleWeights- Optional weighting of each example. Defaults to 1. Rank is either 0, or * the same rank as labels, and must be broadcastable to labels.- Returns:
- a List of Operations to update the metric state.
-
result
Gets the current result of the metric- Type Parameters:
U- the date type for the result- Parameters:
tf- the TensorFlow Ops encapsulating aGraphenvironment.resultType- the data type for the result- Returns:
- the result, possibly with control dependencies
-
resetStates
-
getThresholds
public float[] getThresholds()Gets the thresholds- Returns:
- the thresholds
-
getTopK
-
getClassId
-
getTruePositives
-
getFalsePositives
-
getTruePositivesName
Gets the name of the truePositives variable- Returns:
- the truePositivesName
-
getFalsePositivesName
Gets the name of the falsePositives variable- Returns:
- the falsePositivesName
-