minmax
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 |
required |
min_val
|
float
|
The lower bound of the target interval. Default: |
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
|
Example
forward(x)
Run the layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The input batch, of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
out |
Tensor
|
The output of the layer for that batch. |