Skip to content

Separate noise estimation from sample weight computation #225

Description

@jeipollack

Description of Refactoring/Improvement
The SHE validation workflow requires access to the noise estimate associated with each observation to compute goodness-of-fit metrics for the WaveDiff model.

Currently, train_utils.calculate_sample_weights performs two distinct operations:

  • estimate the noise level using the utils.NoiseEstimator class;
  • convert this estimate into a scalar sample weight using a median-based reduction.

The current implementation does not expose the intermediate noise estimate independently, limiting its reuse for validation metrics such as reduced χ².

Goals and Objectives

  • Extract the noise estimation step into a dedicated estimate_noise_sigma function.
  • Update calculate_sample_weights to call estimate_noise_sigma internally.
  • Preserve the existing weighting behaviour (median-based reduction).
  • Maintain backwards compatibility with the current training pipeline.
  • Expose the per-observation noise estimate for use in future uncertainty models and goodness-of-fit calculations.

Current Code Behaviour
calculate_sample_weights currently combines two responsibilities:

  • Estimate the noise level for each observation using utils.NoiseEstimator, which uses a robust MAD-based estimator on unmasked background pixels.
  • Convert this estimate into a scalar sample weight used during training.

The coupling of these operations prevents the noise estimate from being accessed independently by downstream validation workflows.

Proposed Changes

Introduce a dedicated helper:

estimate_noise_sigma(...)

which returns the per-observation noise standard deviation estimated by utils.NoiseEstimator.

Refactor:

calculate_sample_weights(...)

to use:

sigma = estimate_noise_sigma(...)
weights = ...

while preserving the current training behaviour.

Expected Benefits

  • Separates data-derived noise estimation from training-specific weighting.
  • Makes the uncertainty information available for future goodness-of-fit calculations.
  • Improves clarity around the statistical assumptions used by the training pipeline.
  • Avoids duplicating noise estimation logic in validation workflows.

Dependencies

  • Compatibility with the SHE validation pipeline.
  • Conversion from noise estimates to an inverse covariance representation remains dependent on the uncertainty model adopted by the validation workflow and is outside the scope of this refactor.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

Projects

Status
No status

Relationships

None yet

Development

No branches or pull requests

Issue actions