# `Tinkex.MetricsReduction`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/metrics_reduction.ex#L1)

Metric reduction for chunked forward/backward results.

Mirrors Python's `chunked_fwdbwd_helpers._metrics_reduction` helper by
reducing metrics based on the suffix that comes after the last `:` in the
metric name. Only metrics present in the first chunk are considered, and keys
missing from later chunks are ignored (they are not treated as zero).

# `metrics`

```elixir
@type metrics() :: %{required(String.t()) =&gt; number()}
```

# `reduce`

```elixir
@spec reduce([Tinkex.Types.ForwardBackwardOutput.t()]) :: metrics()
```

Reduce metrics from chunked forward/backward results.

* Weights use the number of `loss_fn_outputs` for each chunk.
* Unknown suffixes fall back to the weighted mean reducer.
* `:unique` metrics retain every value by emitting suffixed keys (`key_2`, `key_3`, ...).
* Weighted reducers return `0.0` when the total weight is `0`.
* `:hash_unordered` returns an **integer** hash (not a float) for order-insensitive
  identity checks. Suitable for verifying batch composition across distributed chunks.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
