multigeom.pipeline.metric_field#

Stage 6: Local metric field around one reference image (paper Fig. 5).

For a reference image x₀ (index into the same TinyImageNet validation list as
Stage 4), each area, and each metric M ∈ {G, J}:

  1. Compute the top eigenpairs of M(x₀) for the reference encoder
     (Inception by default) and keep the leading two, (λ₁, v₁), (λ₂, v₂).
     Panel A of Fig. 5 uses the G eigenvectors, panel B the J eigenvectors,
     both of the reference encoder.
  2. Build the n × n grid of perturbed images
         x(a, b) = clip(x₀ + a ε₁ v₁ + b ε₂ v₂, −1, 1),   a, b ∈ {−h, …, h},
     with ε_i = step_size · √λ_i by default ("perturbations scaled by the
     principal eigenvalues at the reference image", paper Sec. 6), or
     ε_i = step_size with --step-rule fixed.
  3. At every grid point compute M(x(a, b)) for BOTH the reference and the
     comparison encoder (ResNet-50 by default) and project it onto the fixed
     reference plane: M₂ = Vᵀ M V, V = [v₁, v₂]. Both encoders are therefore
     evaluated on the same images and read in the same 2-D basis.
  4. Convert each 2 × 2 matrix to ellipse parameters (width = 2√μ_max,
     height = 2√μ_min, angle of the major axis from the v₁ axis in degrees;
     see multigeom/geometry/metric_field.py for why this convention).

G is estimated with the conditional-pair estimator (multigeom.geometry.estimator) and
the settings of the packaged estimator config; J in closed form
(multigeom.geometry.fisher) with the same σ. The G eigenpairs at x₀ use the Stage-4 seed
(seed + img_idx), so they reproduce Stage 4's runs/per_image file for that image. Grid
point (i, j) uses its own generator (multigeom.geometry.metric_field.point_seed), shared
by the two encoders.

Outputs, one file per (metric, area):
    <out_dir>/{G,J}_{V1,V4}.pt
with matrices_2x2[encoder] [n, n, 2, 2] and ellipses[encoder] [n, n, 3]
indexed [i, j] ↔ (a, b) = (grid_coefficients[i], grid_coefficients[j]),
plus v1, v2, λ1, λ2, ε1, ε2, x0, the perturbed images [n, n, 64, 64],
settings and provenance. `figures/fig5.py` of multigeom-tutorials draws them.

Usage: python -m multigeom.pipeline.metric_field --img-idx 0 --out-dir
runs/metric_field/img0000

Functions

eigendecomposition(metric, x, encoder, unet, ...)

Top-k eigenpairs (eigenvalues [k], eigenvectors [k, P]) of G(x) or J(x).

load_models(encoder_name, area, runs_dir, ...)

Encoder f_φ (and diffusion network ε_θ if needed) for one configuration.

main([argv])

Compute the local metric field around a reference image (command-line entry point).

parse_args([argv])

Command-line arguments of python -m multigeom.pipeline.metric_field.