multigeom.pipeline.alignment#

Stage 5: Aggregate cross-(encoder, area) similarity metrics from the per-image G(x) and J(x) eigendecompositions written by Stage 4.

For every unordered pair of (encoder, area) configurations, for both metrics
(G = multi-scale Fisher, J = Fisher), and on every image the two share, we
compute as a function of k = 1, ..., max_k:

  - the subspace alignment 𝒜_k = (1/k)‖V_Aᵀ V_B‖_F²     (Fig. 4D-E;
    same definition as multigeom.analysis.subspace_alignment)
  - the Bures-Wasserstein distance d_BW between the rank-k
    reconstructions V Λ Vᵀ of the two metrics            (appendix BW figure)

and report the mean and s.e.m. across images.

The paper compares models fitted to the same area ("cross_model") with the
same model fitted to different areas ("cross_area"). Those comparisons are
also listed under named keys in the output, e.g.

    cross_model_V1_inception_resnet50,  cross_area_inception

Output: <out_dir>/cross_encoder_metrics.json

Usage:
    python -m multigeom.pipeline.alignment --runs-dir runs --out-dir runs/metrics

Functions

aggregate_pair(A, B, metric, max_k)

Alignment and Bures-Wasserstein curves for k = 1..K over shared images.

compute_metrics([runs_dir, out_dir])

Run the alignment (the former stage 5: alignment and Bures-Wasserstein distance between every pair of configurations, over the images they share).

configs_with_images([runs_dir])

The (encoder, area) configurations that have per-image files under runs_dir.

discover_configs(per_image_root)

(encoder, area) pairs with at least one per-image file, in a fixed order.

input_summary([runs_dir])

What Stage 5 would work on: per configuration the indices of its per-image files, and per pair of configurations the number of shared images (the alignment and distance are averaged over those).

load_metrics(path)

Read a metrics file written by compute_metrics.

load_per_image(per_image_root, encoder, area)

Load every img{N}.pt for one (encoder, area), keyed by image index.

main([argv])

Compare every pair of configurations and write the metrics file (command-line entry point).

named_comparisons(configs)

The paper's comparisons: same model across areas, same area across models.

ordering(metrics)

The mean over k of d_BW for the two cross-model comparisons (V1, V4) and the two cross-area ones (Inception, ResNet-50), per metric, and whether the ordering is the paper's (G: cross-model below cross-area; J: reversed).

pair_label(a, b, metric)

Name of the comparison of two (encoder, area) configurations for one metric (G or J).

parse_args([argv])

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

print_inputs([runs_dir, paper_n_images])

Print the images per configuration and warn when there are fewer than the paper's 200.

print_ordering(metrics)

Print, for G and for J, the mean Bures-Wasserstein distance of the cross-model and the cross-area comparisons and whether their order is the paper's (G: cross-model below cross-area; J: above).