multigeom.pipeline.metric_field_job#

Supporting functions of 3_local_metric_field.ipynb of multigeom-tutorials: paper Fig. 5, the local metric field projected onto the leading eigenvectors of G(x).

A reference image x0 is perturbed along the two leading eigenvectors of the reference
encoder's G(x) (Inception); at every point of the n x n grid both encoders' metrics G(x)
(and the Fisher metric J(x)) are projected onto that 2-D subspace and drawn as ellipses.
The computation is `multigeom.pipeline.metric_field` and the drawing `figures/fig5.py`
of multigeom-tutorials; this module only describes the job, estimates its cost, runs it
as a detached background process that survives a notebook crash, and shows the progress.

Step sizes. The perturbation of the reference image is x(a, b) = x0 + a*e1*v1 + b*e2*v2
along the leading two eigenvectors v1, v2 of the metric being drawn. For G(x) the steps
are 0.5*sqrt(lambda) (the stage default), about 0.3. J(x) has far larger eigenvalues, so
the same rule gives steps of 5 to 7, the perturbed images are clipped and the local
structure is lost (the Inception ellipses become smaller than the ResNet-50 ones
off-centre, the opposite of the paper's panel B). A small fixed step of 0.3, the size of
G's steps, gives smooth fields with the Inception ellipses outside the ResNet-50 ones,
as in the paper. The paper does not state its step sizes, so these are choices (see
`MetricFieldJob.steps`).

Cost: each grid point of each encoder needs one G(x) estimate (about 15 s on an RTX
5090), so the default 5 x 5 grid, two areas and two encoders take about 26 minutes on
one GPU. J(x) is cheap. The grid points are independent and seeded one by one, so they
could be split over GPUs without changing the result, but processes sharing one GPU are
slower than one, so a single process is used.

Functions

area_ratio(matrices_a, matrices_b)

Median over the grid points, the centre excluded, of the ratio of the ellipse areas (proportional to sqrt(det)) of field a to field b: above 1 means a is outside b.

clear_results(job[, runs_dir, dry_run])

Delete this job's result files (only those) so that it is recomputed from scratch; refuses while it runs.

estimate_cost(job[, seconds_per_g, ...])

Per area and metric: one evaluation at the reference image plus grid_size^2 points for each of the 2 encoders.

expected_files(job[, runs_dir])

One file per (metric, area), written when that part is finished.

is_complete(job[, runs_dir])

True if every (metric, area) part of job has its result file.

job_from_json(text)

Rebuild a job from the JSON written by job_to_json.

job_to_json(job)

Serialise job to JSON (to pass it to the background process).

launch(job, *[, runs_dir])

Start the computation as one detached process (its own session) that runs the local metric field computation once per metric, logging to <runs_dir>/logs/metric_field.log.

load_records(job[, runs_dir])

Stage-6 records keyed by (metric, area), for the files that exist.

main([argv])

Run a job (entry point of the background process).

metric_field_command(job, metric, *[, ...])

Command line of python -m multigeom.pipeline.metric_field for one metric of the job (the computation is not re-implemented here).

metric_field_commands(job, *[, runs_dir, ...])

One command per metric: the stage takes one step rule per run, and G and J use different ones.

out_dir(job[, runs_dir])

The folder with the results of job.

print_estimate(job)

Print what job will take and return the estimate.

progress(job[, runs_dir])

(parts finished, parts in total); a part is one (metric, area) file.

radial_score(matrices, coeffs)

How radially the ellipses of an [n, n, 2, 2] field are oriented around the grid centre: the mean over the grid points of abs(cos) between the major axis of the ellipse (see multigeom.geometry.metric_field.ellipse_params) and the direction from the centre to the point (a, b).

run(job[, runs_dir])

Run the local metric field computation for each metric of the job, one after the other (G first: it is the long one).

stop([runs_dir])

Stop the recorded process (also from a later session).

wait(job[, proc, runs_dir, poll_s, ...])

Block until the process ends, showing a progress line over the (metric, area) parts (the bar moves when a part is finished).

Classes

MetricFieldEstimate(g_estimates, ...)

Estimated number of G(x) estimates and time of a job.

MetricFieldJob([img_idx, grid_size, steps, ...])

What to compute for Fig.