latte.metrics.base

Module Contents

Classes

LatteMetric

Base class for Latte metric objects.

MetricBundle

Base class for metric bundles

OptimizedMetricBundle

Just a type alias for metric bundles with optimized implementation. These bundles are in fact LatteMetric objects, but they are functionally more similar to MetricBundle objects.

Attributes

BaseMetricBundle

A 'fake' super class of MetricBundle and OptimizedMetricBundle. This is used to make the type checker happy.

class LatteMetric

Bases: abc.ABC

Base class for Latte metric objects.

Adapted from TorchMetrics implementation.

add_state(name, default)

Create a state variable for the metric.

Parameters:
  • name (str) – Name of the state

  • default (Union[list, np.ndarray]) – Default value of the state, can be an array or a (potentially empty) list.

abstract update_state()

Update metric states

reset_state()

Reset the states of the metric to the defaults.

abstract compute()

Compute metric value(s)

class MetricBundle(metrics)

Base class for metric bundles

Parameters:

metrics (Union[List[LatteMetric], Dict[str, LatteMetric]]) – A list of metrics or a dictionary of metric names mapping to metrics. If a list is provided, the key for each metric in the output will be the name of the metric.

update_state(**kwargs)

Update the internal states of all metric submodules. Currently, all arguments must be passed as a keyword argument to this function to allow correct mapping to respective metric submodules.

reset_state()

Reset the state of all metric submodules.

compute()

Compute the metric values for all metric submodules.

Returns:

A dictionary mapping metric names to metric values.

Return type:

Dict[str, np.ndarray]

class OptimizedMetricBundle

Bases: LatteMetric

Just a type alias for metric bundles with optimized implementation. These bundles are in fact LatteMetric objects, but they are functionally more similar to MetricBundle objects.

BaseMetricBundle

A ‘fake’ super class of MetricBundle and OptimizedMetricBundle. This is used to make the type checker happy.