• Docs >
  • Metrics >
  • torcheval.metrics.WindowedBinaryNormalizedEntropy
Shortcuts

torcheval.metrics.WindowedBinaryNormalizedEntropy

class torcheval.metrics.WindowedBinaryNormalizedEntropy(*, from_logits: bool = False, num_tasks: int = 1, max_num_updates: int = 100, enable_lifetime: bool = True, device: device | None = None)

The windowed version of BinaryNormalizedEntropy that provides both windowed and liftime values. Windowed value is calculated from the input and target of the last window_size number of update() calls. Lifetime value is calculated from all past input and target of update() calls.

Compute the normalized binary cross entropy between predicted input and ground-truth binary target.

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.

  • max_num_updates (int) – The max window size that can accommodate the number of updates.

  • enable_lifetime (bool) – A boolean indicator whether to calculate lifetime values.

Examples:

>>> import torch
>>> from torcheval.metrics import WindowedBinaryNormalizedEntropy

>>> metric = WindowedBinaryNormalizedEntropy(max_num_updates=2)
>>> metric.update(torch.tensor([0.2, 0.3]), torch.tensor([1.0, 0.0]))
>>> metric.update(torch.tensor([0.5, 0.6]), torch.tensor([1.0, 1.0]))
>>> metric.update(torch.tensor([0.6, 0.2]), torch.tensor([0.0, 1.0]))
>>> metric.num_examples, metric.windowed_num_examples
(tensor([6.], dtype=torch.float64), tensor([[2., 2.]], dtype=torch.float64))
>>> metric.compute()
(tensor([1.4914], dtype=torch.float64), tensor([1.6581], dtype=torch.float64))

>>> metric = WindowedBinaryNormalizedEntropy(max_num_updates=2, enable_lifetime=False)
>>> metric.update(torch.tensor([0.2, 0.3]), torch.tensor([1.0, 0.0]))
>>> metric.update(torch.tensor([0.5, 0.6]), torch.tensor([1.0, 1.0]))
>>> metric.update(torch.tensor([0.6, 0.2]), torch.tensor([0.0, 1.0]))
>>> metric.windowed_num_examples
tensor([[2., 2.]], dtype=torch.float64)
>>> metric.compute()
tensor([1.6581], dtype=torch.float64)

>>> metric = WindowedBinaryNormalizedEntropy(max_num_updates=2, 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.update(torch.tensor([[0.8, 0.3], [0.6, 0.1]]), torch.tensor([[1.0, 1.0], [1.0, 0.0]]))
>>> metric.update(torch.tensor([[0.5, 0.1], [0.3, 0.9]]), torch.tensor([[0.0, 1.0], [0.0, 0.0]]))
>>> metric.num_examples, metric.windowed_num_examples
(tensor([6., 6.], dtype=torch.float64),
tensor([[2., 2.],
        [2., 2.]], dtype=torch.float64))
>>> metric.compute()
(tensor([1.6729, 1.6421], dtype=torch.float64),
tensor([1.9663, 1.4562], dtype=torch.float64))
__init__(*, from_logits: bool = False, num_tasks: int = 1, max_num_updates: int = 100, enable_lifetime: bool = True, 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 either torch.Tensor, a list of torch.Tensor, a dictionary with torch.Tensor as values, or a deque of torch.Tensor.

Methods

__init__(*[, from_logits, num_tasks, ...])

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().

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources