Skip to content

Add back z-scoreing for flow matching #1623

Closed

Description

@manuelgloeckler

🚀 Feature Request

This was diabled because naive z-scoreing as input layer can have very negative consequence performancewise. This however can be done similar to how it is done in NPSE with access to the time-dependent moments.

For the simple FM we have implemented with $\mu_0=0$ and $\sigma_0=1$, $\mu_1 = \text{theta.mean(0))}$ and $\sigma_1 = \text{theta.std(0)}$ this should be given by
$$\mu_t = t\mu_1$$
and
$$\sigma_t = \sqrt{t^2 \sigma_1^2 + (1-t)^2 }$$

Z-scoreing can then be doen automatically as for all the other estimators.

Activity

  1. added
    enhancement
    on Jul 16, 2025
  2. satwiksps commented on Jan 25, 2026

    @satwiksps
    Collaborator

    Hi @manuelgloeckler @janfb , I would like to pick up this issue.

    I plan to re-introduce z-scoring for Flow Matching using the time-dependent moments as suggested. Here is my proposed implementation plan:

    Mathematical Approach

    To avoid the issues with naive z-scoring at $t=0$, I will interpolate the normalization statistics based on time $t$:

    $$\mu_t = t \cdot \mu_{data}$$ $$\sigma_t = \sqrt{t^2 \sigma_{data}^2 + (1-t)^2}$$

    Implementation Details

    1. Builder (vector_field_nets.py): Update build_vector_field_estimator to capture the training data statistics (mean and std) and pass them into the FlowMatchingEstimator constructor as mean_1 and std_1.
    2. Estimator (flowmatching_estimator.py):
      • Register mean_1 and std_1 as buffers.
      • In the forward pass, calculate $\mu_t$ and $\sigma_t$ dynamically.
      • Normalize the input: $\hat{\theta}_t = (\theta_t - \mu_t) / \sigma_t$.
      • Crucially: Rescale the output vector field $v$ by $\sigma_t$ to ensure the ODE integration remains consistent with the original scale.
    3. Testing: Add an integration test in linearGaussian_vector_field_test.py to verify that z_score_x='structured' correctly registers these buffers and that the forward pass executes without shape mismatches.

    I have verified this logic locally and confirmed that the statistics are learned correctly. Does this align with your vision? If so, I am ready to open a PR.

  3. manuelgloeckler commented on Feb 2, 2026

    @manuelgloeckler
    ContributorAuthor

    Dear @satwiksps,

    this sounds good! Happy to accept a PR on this.

    To check on any performance implications, would be good to run pytest --bm --bm-mode fmpe for a quick check.

    Crucially: Rescale the output vector field

    Agree, the "preconditioning" of the network can help! At t=0 the optimal prediction is the base distribution mean (i.e. 0). Not sure what scaling you had in mind (i.e. there are quite a few options e.g. based on Gaussian assumptions) but happy for anything if it helps.

    Kind regards,
    Manuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions