torcheval.metrics.BinaryNormalizedEntropy¶
- class torcheval.metrics.BinaryNormalizedEntropy(*, from_logits: bool = False, num_tasks: int = 1, device: device | None = None)¶
Compute the normalized binary cross entropy between predicted input and ground-truth binary target. Its functional version is
torcheval.metrics.functional.binary_normalized_entropy()
- Parameters:
from_logits (bool) – A boolean indicator whether the predicted value y_pred is a floating-point logit value (i.e., value in [-inf, inf] when from_logits=True) or a probablity value (i.e., value in [0., 1.] when from_logits=False) Default value is False.
num_tasks (int) – Number of tasks that need BinaryNormalizedEntropy calculation. Default value is 1. BinaryNormalizedEntropy for each task will be calculated independently.
Examples:
>>> import torch >>> from torcheval.metrics import BinaryNormalizedEntropy >>> metric = BinaryNormalizedEntropy() >>> metric.update(torch.tensor([0.2, 0.3]), torch.tensor([1.0, 0.0])) >>> metric.compute() tensor([1.4183], dtype=torch.float64) >>> metric = BinaryNormalizedEntropy() >>> metric.update(torch.tensor([0.2, 0.3]), torch.tensor([1.0, 0.0]), torch.tensor([5.0, 1.0])) >>> metric.compute() tensor([3.1087], dtype=torch.float64) >>> metric = BinaryNormalizedEntropy(from_logits = True) >>> metric.update(tensor([-1.3863, -0.8473]), torch.tensor([1.0, 0.0])) >>> metric.compute() tensor([1.4183], dtype=torch.float64) >>> metric = BinaryNormalizedEntropy(num_tasks=2) >>> metric.update(torch.tensor([[0.2, 0.3], [0.5, 0.1]]), torch.tensor([[1.0, 0.0], [0.0, 1.0]])) >>> metric.compute() tensor([1.4183, 2.1610], dtype=torch.float64)
- __init__(*, from_logits: bool = False, num_tasks: int = 1, device: device | None = None) None ¶
Initialize a metric object and its internal states.
Use
self._add_state()
to initialize state variables of your metric class. The state variables should be eithertorch.Tensor
, a list oftorch.Tensor
, a dictionary withtorch.Tensor
as values, or a deque oftorch.Tensor
.
Methods
__init__
(*[, from_logits, num_tasks, device])Initialize a metric object and its internal states.
compute
()Return the normalized binary cross entropy.
load_state_dict
(state_dict[, strict])Loads metric state variables from state_dict.
merge_state
(metrics)Merge the metric state with its counterparts from other metric instances.
reset
()Reset the metric state variables to their default value.
state_dict
()Save metric state variables in state_dict.
to
(device, *args, **kwargs)Move tensors in metric state variables to device.
update
(input, target, *[, weight])Update the metric state with the total entropy, total number of examples and total number of positive targets.
Attributes
device
The last input device of
Metric.to()
.