noether.data.stats

Classes

RunningMoments

Calculates running moments of data (mean, variance, min, max) for data normalization purposes.

RunningStats

Calculates statistics of data (min, max, mean and variance) for data normalization purposes.

Module Contents

class noether.data.stats.RunningMoments(log_scale=False)

Bases: torch.nn.Module

Calculates running moments of data (mean, variance, min, max) for data normalization purposes.

This class implements Welford’s online algorithm for computing mean and variance in a single pass, making it memory-efficient for large datasets.

Initialize a RunningMoments instance.

Parameters:

log_scale (bool) – Whether to apply log scaling to the data before calculating moments. This affects all operations unless overridden.

log_scale = False
push_tensor(x, dim=1, log_scale=None)

Add a tensor to the moment calculation. Calculations are carried out in float64 to avoid numerical imprecisions.

Parameters:
  • x (torch.Tensor) – Tensor to push. Shape should be compatible with dim parameter.

  • dim (int) – Which dimension contains the feature dimension. For example: - In a pointcloud (N, 3), dim=1 calculates statistics per coordinate (x, y, z) - In an RGB image (B, C, H, W), dim=1 calculates per-channel statistics

  • log_scale (bool | None) – Whether to apply log scaling to this tensor. If None, uses the class default.

Raises:

ValueError – If tensor has invalid dimensions or is incompatible with previous data

Return type:

None

push_scalar(x, log_scale=None)

Add a scalar to the moment calculation. Calculations are carried out in float64.

Parameters:
  • x (float) – Scalar value to add to the moment calculations.

  • log_scale (bool | None) – Whether to apply log scaling to this scalar. If None, uses the class default.

Raises:

TypeError – If x is not a Python float

Return type:

None

property mean: float | torch.Tensor
Return type:

Union[float, torch.Tensor]

property var: float | torch.Tensor
Return type:

Union[float, torch.Tensor]

property std: float | torch.Tensor
Return type:

Union[float, torch.Tensor]

property min: float | torch.Tensor
Return type:

Union[float, torch.Tensor]

property max: float | torch.Tensor
Return type:

Union[float, torch.Tensor]

property count: int
Return type:

int

print()

Print the calculated statistics in a readable format.

Return type:

None

dump()
Return type:

dict[str, Union[float, torch.Tensor]]

reset()

Reset the statistics, clearing all accumulated data.

Return type:

None

is_empty()
Return type:

bool

class noether.data.stats.RunningStats(name=None)

Calculates statistics of data (min, max, mean and variance) for data normalization purposes.

Parameters:

name (str | None)

name = None
push_tensor(x, dim=1)

Add a tensor to the statistics. Calculations are carried out in float64 to avoid numerical imprecision.

Parameters:
  • x (torch.Tensor)

  • dim (int)

Return type:

None

property min: torch.Tensor
Return type:

torch.Tensor

property max: torch.Tensor
Return type:

torch.Tensor

property mean: torch.Tensor
Return type:

torch.Tensor

property var: torch.Tensor
Return type:

torch.Tensor

property std: torch.Tensor
Return type:

torch.Tensor

property logmean: torch.Tensor
Return type:

torch.Tensor

property logvar: torch.Tensor
Return type:

torch.Tensor

property logstd: torch.Tensor
Return type:

torch.Tensor