Module Standardize#
standardize
#
| CLASS | DESCRIPTION |
|---|---|
StandardizeLayer |
Neural network layer for data standardization. |
WeightedBatchNorm1d |
Weighted batch normalization for 1D inputs. |
Classes#
StandardizeLayer(mean: torch.Tensor, std: torch.Tensor, eps: float = torch.finfo(torch.float32).eps)
#
Bases: Module
Neural network layer for data standardization.
Applies z-score normalization using precomputed statistics: \((X - \mu) / (\sigma + \epsilon)\), where \(\mu\) is the mean, \(\sigma\) is the standard deviation, and \(\epsilon\) is a small constant for numerical stability. The layer does not learn parameters and is intended for use when data statistics are known in advance.
| PARAMETER | DESCRIPTION |
|---|---|
mean
|
Precomputed mean values for normalization.
TYPE:
|
std
|
Precomputed standard deviation values for normalization.
TYPE:
|
eps
|
Small value added to
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Apply standardization to input tensor. |
Source code in spectre/module/standardize.py
WeightedBatchNorm1d(in_features: int, momentum: float = 0.1, eps: float = torch.finfo(torch.float32).eps, affine: bool = True, track_running_stats: bool = True, dtype: torch.dtype = torch.float32, device: torch.device | str | None = None)
#
Bases: Module
Weighted batch normalization for 1D inputs.
Extends standard batch normalization to support sample weighting during training. In training mode, computes weighted statistics and updates running statistics. In evaluation mode, uses running statistics for normalization.
| PARAMETER | DESCRIPTION |
|---|---|
in_features
|
Number of features in input tensor.
TYPE:
|
momentum
|
Momentum for running statistics update.
TYPE:
|
eps
|
Small value for numerical stability.
TYPE:
|
affine
|
Whether to learn affine transformation parameters.
TYPE:
|
track_running_stats
|
Whether to track running mean and variance.
TYPE:
|
dtype
|
TYPE:
|
dtype
|
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
reset_running_stats |
Reset running statistics to initial values. |
reset_parameters |
Reset learnable parameters to initial values. |
forward |
Apply weighted batch normalization. |
Source code in spectre/module/standardize.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
Functions#
reset_running_stats() -> None
#
Reset running statistics to initial values.
reset_parameters() -> None
#
forward(X: torch.Tensor, weights: torch.Tensor | None = None) -> torch.Tensor
#
Apply weighted batch normalization.
In training mode (train=True), uses weighted batch statistics and updates
running statistics. In evaluation mode (train=False), uses running statistics
(weights are ignored).
| PARAMETER | DESCRIPTION |
|---|---|
X
|
Input tensor of shape (batch_size, in_features).
TYPE:
|
weights
|
Sample weights of shape (batch_size,), if None, uniform weights are used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Normalized tensor with same shape as input. |