## `eigenkit.torch.layers.minmax`

### `MinMaxNorm`

Bases: `Module`

Min-max normalisation of each feature, with running statistics.

It rescales each feature to `[min_val, max_val]`. In training mode, it uses the minimum and maximum of each batch, and it updates an exponential moving average of these statistics. In evaluation mode, it uses the running statistics. A training batch of a single row has no range, so it uses the running statistics too, and if no batch with a range has been seen yet, it returns the row unchanged with a warning. Training and evaluation modes work as in the `BatchNorm` and `LayerNorm` layers of PyTorch, but the output is rescaled to a fixed interval instead of standardised.

It is useful to prepare the inputs of quantum encoding rotations, which expect angles in a bounded range such as `[0, π]`.

Parameters:

| Name          | Type    | Description                                                                                                 | Default    |
| ------------- | ------- | ----------------------------------------------------------------------------------------------------------- | ---------- |
| `feature_dim` | `int`   | The number of features in the last dimension of the input. The inputs have shape (batch_size, feature_dim). | *required* |
| `min_val`     | `float` | The lower bound of the target interval. Default: 0.0.                                                       | `0.0`      |
| `max_val`     | `float` | The upper bound of the target interval. Default: π.                                                         | `pi`       |
| `momentum`    | `float` | The momentum factor of the exponential moving average of the running statistics. Default: 0.1.              | `0.1`      |

Example

```python
import torch
from eigenkit import Ensemble, MinMaxNorm

norm = MinMaxNorm(feature_dim=16, min_val=0.0, max_val=torch.pi)
layer = Ensemble(in_features=16, n_qubits=4, depth=5)
out = layer(norm(torch.randn(32, 16)))
```

#### `forward(x)`

Run the layer.

Parameters:

| Name | Type     | Description                                     | Default    |
| ---- | -------- | ----------------------------------------------- | ---------- |
| `x`  | `Tensor` | The input batch, of shape (batch, feature_dim). | *required* |

Returns:

| Name  | Type     | Description                             |
| ----- | -------- | --------------------------------------- |
| `out` | `Tensor` | The output of the layer for that batch. |
