Skip to content

fix: default FitPositionsSource to jacobian weighting; correct magnification normalisation #791

Closed

Description

@Jammy2211

Overview

FitPositionsSource defaults to the scalar "magnification" source-plane weighting, |β̂−c|² μ²/σ². Near critical curves this under-weights radial noise by about |μ|. On the point_source true model, the source χ² is 10,023, against 4.25 image-plane and 5.41 with "jacobian".

The "jacobian" weighting is the Gravity.jl source-plane likelihood (Lombardi 2024, Eq. 46). It is also the "proper" mode in Lenstool's code (forme 8). The current "magnification" normalisation is 1-D and model-dependent, so it rewards high μ, and it matches no Lenstool code path.

This issue does three things:

  • makes "jacobian" the default;
  • corrects the "magnification" normalisation;
  • fixes the workspace Lenstool example, which is really an image-plane fit.

Plan

  • Default FitPositionsSource.weighting to "jacobian". FitPositionsSourceSolved already defaults to it.
  • Keep "magnification" as an opt-in in both classes. Give it the model-independent 2-D normalisation log((2π)²σ⁴), i.e. Eq. 46 with B ≈ μ²Θ, and document its radial bias.
  • Rewrite the docstrings with citations: Gravity.jl Eqs. 46/58, Keeton 2001 Eq. 10, Jullo 2007 Eq. 10, Lenstool forme 8.
  • Re-derive the pinned test values, and add a test that the true model ranks first on an anisotropic, near-critical mock.
  • Workspace updates are part of this task. They follow the library PR (library first) and explain the new default:
    • What "jacobian" means: each source-plane residual is measured in the image-plane noise ellipse, so it is still a distance from the points to the source.
    • Why it is the default: it is Gravity.jl Eq. 46, it stays robust near critical curves, and it costs nothing extra over μ.
    • When to opt into "magnification", and its radial bias.
    • Where: this goes in point_source/fit.py, point_source/modeling.py, guides/point_source_pairing.py and cluster/likelihood_function.py. The Lenstool example is also pointed at the image-plane fit, because the Mahler input uses forme -1.
  • Re-measure the pinned values in autolens_workspace_test.
  • Add an autolens_profiling rerun note later, once the cluster-pointsolver-robust-settings claim is released.
  • Add a release note: results from source-plane χ² fits will change.

Tier: judge — merge mode: human /prm

Detailed implementation plan

Affected Repositories

  • PyAutoLens (primary)
  • autolens_workspace
  • autolens_workspace_test
  • autolens_profiling (rerun note only, deferred)

Branch Survey

Repository Current Branch Dirty?
./PyAutoLens main clean
./autolens_workspace main 1 untracked/dirty file (unrelated)
./autolens_workspace_test main —
./autolens_profiling main claimed by cluster-pointsolver-robust-settings

Suggested branch: feature/positions-source-jacobian-default

Implementation Steps

  1. autolens/point/fit/positions/source/separations.py
    • :37: set weighting = "jacobian".
    • noise_normalization (:201-214): both weightings return Σ log((2π)² σ⁴).
    • Update the class docstrings.
  2. FitPositionsSourceSolved (same file, :224-313)
    • Confirm the "magnification" branch uses the same normalisation, and that marginalization_term uses B = Σ μ²Θ.
    • Update the docstrings (autolens/point/fit/solved.py:105-110 says "near-critical tangential limit").
  3. Tests, test_autolens/point/fit/positions/source/test_separations.py
    • The :88 default assertion.
    • Re-derive tests 1 and 2: noise_normalization and log_likelihood (no mass); chi_squared_map (IsothermalSph).
    • Add an anisotropic near-critical mock where the true model must outrank perturbed models under "jacobian".
  4. Other tests:
    • test_fit_dataset.py:68 (−12.9947298).
    • test_solved.py:87,346.
    • plot/test_source_plane_panel.py:19-32,215: the default now draws the A·σ ellipse, not the σ/|μ| circle.
    • test_positions_panel.py:177,224 and test_fit_point_plots.py:88.
  5. autolens_workspace (in this task, after the library PR). Each script explains the default: what jacobian is, why it is the default, and when to use magnification.
    • scripts/point_source/fit.py:420 and markdown/point_source/fit.md:495.
    • scripts/point_source/modeling.py:388,426.
    • scripts/guides/point_source_pairing.py:119,144.
    • scripts/cluster/likelihood_function.py:10.
    • scripts/cluster/lenstool/modeling.py:34-37 and README.md:30 (+ notebook copies): switch to the image-plane fit class, citing forme -1.
  6. autolens_workspace_test
    • Re-measure the literals in scripts/point_source/jax_likelihood/source_plane.py (−331481.2598 vmap, −331481.2651 eager).
    • Re-check the assertions in scripts/cluster/likelihood_sanity.py.
    • Update the description in scripts/AGENTS.md:173.
  7. autolens_profiling (deferred): a note in wiki/campaigns/point_source_source_plane.md saying that plain-lane timings and logL values predate the default switch.

Key Files

  • autolens/point/fit/positions/source/separations.py: the weighting and normalisation.
  • autolens/point/fit/solved.py: the precision tensor helpers.
  • autolens/point/plot/source_plane_panel.py: reads fit.weighting (circle vs ellipse).

References

  • Lombardi 2024, arXiv:2406.15280, §5.1:
    • Eq. 46: log P = Σ[½ log|Θᵢ/2π| − ½ δᵀBᵢδ], with Bᵢ = Aᵢ⁻ᵀΘᵢAᵢ⁻¹.
    • Eqs. 54–58: the marginalised source.
  • Jullo et al. 2007, arXiv:0706.0048, Eq. 10: the scalar μ² form.
  • Lenstool 8.10.1 src/o_chi.c chi2_src():
    • forme 8/13 is the tensor form; the scalar modes use |μ|.
    • Normalisation: log(4π²/det W).
    • This was read from a personal mirror, not the official repo.
  • Keeton 2001, astro-ph/0102340, Eq. 10.

Original Prompt

Click to expand starting prompt

FitPositionsSource default "magnification" weighting mis-maps near-critical noise: check against Gravity.jl, consider defaulting…

Type: bug
Target: PyAutoLens
Repos:

  • PyAutoLens
  • autolens_profiling
  • autolens_visualization
  • autolens_workspace
  • HowToLens
    Difficulty: too-large
    Autonomy: human-required
    Priority: high
    Memory: reading-queue.md; wiki/lensing/sources/lens-modeling-methods.md; wiki/lensing/sources/dark-matter-substructure.md
    Status: formalised
    Consequence: judge
    Review-minutes: 25
    Unattended: never

@PyAutoLens @autolens_workspace @autolens_profiling

Request (human, 2026-10-21)

intake an issue on the bug thing, have the issue check against the gravity.jl paper

Finding (2026-10-21, while prototyping the source-plane fit panel)

FitPositionsSource (autolens/point/fit/positions/source/separations.py:174-177) defaults to weighting = "magnification":

  • χ²ᵢ = |β̂ᵢ − c|² · μᵢ² / σᵢ², i.e. an isotropic source-plane noise radius of σ/|μ|.
  • The true source-plane footprint of image-plane noise σ is the ellipse σ·AAᵀ. For an isothermal lens its radial semi-axis stays σ, so the scalar convention under-states radial noise by ~|μ| on near-critical images.

Numbers on the autolens_visualization point_source true model (σ = 5 mas, μ = 6.7/69/47/102):

Model Image-pair χ² Default source χ² (σ/|μ|) Source χ², weighting="jacobian"
True model 4.25 10,023 5.41
R_E + 0.01″ 53 167,321 120
Lens centre x + 0.005″ 6,243 20,364 6,012

On the multi-plane cluster true model, point_0's default source χ² is 81.8 (jacobian 4.46).

The jacobian weighting tracks the image-plane χ² ordering; the default does not.

Prior work (do not redo)

  • complete/2026/07/point-source-chi-squared-variants.md implemented the Lombardi 2024 (arXiv:2406.15280, Gravity.jl: Fast and accurate gravitational lens modeling in Julia, A&A 690, A346) solved likelihoods and added weighting = "jacobian"|"magnification".
  • Its benchmark (profiling#99) already found the scalar-μ² source plane "catastrophically biased" (truth −33788 vs wrong models −110 on a μ=367 image), with the tensor weighting as the fix.
  • FitPositionsSourceSolved defaults to "jacobian". FitPositionsSource kept "magnification", apparently for Lenstool-style comparability.

Scope

  1. Check against the Gravity.jl paper (full text): its source-plane χ² definition, weighting, and normalisation / log-det terms. Confirm exactly what our "jacobian" implements (precision Wᵢ = Aᵢ⁻ᵀΘᵢAᵢ⁻¹, observed-plane normalisation) and whether "magnification" corresponds to any convention the paper endorses. Quote the equations.
  2. Decide the default (human decision): switch FitPositionsSource to "jacobian", keep "magnification" with a loud docstring/warning, or deprecate it. Weigh backwards compatibility: existing results, the Lenstool comparisons, and the workspace/HowToLens text that describes the μ² weighting.
  3. If switching:
    • library change plus tests (truth ranks first on an anisotropic mock)
    • workspace and tutorial prose updates
    • an autolens_profiling/inference rerun note
    • a changelog/release-note line, since this changes source-χ² modelling results
  4. Cross-check with the new source-plane fit panel, which draws both the σ/|μ| circle and the A·σ ellipse. Prototypes are in /mnt/c/Users/Jammy/Science/scratch/eyes/autolens/source_plane_prototype/.

Findings (2026-10-21, start_dev session: paper + Lenstool source check)

Gravity.jl (Lombardi 2024, arXiv:2406.15280, §5.1):

  • Eq. 46: log P = Σ[½ log|Θᵢ/2π| − ½ (β̂ᵢ−β)ᵀ Bᵢ (β̂ᵢ−β)], with Bᵢ = Aᵢ⁻ᵀ Θᵢ Aᵢ⁻¹. The normalisation is image-plane only and model-independent.
  • Eqs. 49, 54–58: precision-weighted β̄ and analytic marginalisation of the source, adding −½ log|B/2π|.
  • No scalar-μ² approximation is discussed. Lenstool is mentioned only for timing and for agreement on lensing quantities.
  • Our "jacobian" equals Eq. 46 for the free centre. FitPositionsSourceSolved equals Eq. 58.

Lenstool:

  • Paper. Jullo et al. 2007 (arXiv:0706.0048), Eq. 10, writes the scalar form |β−⟨β⟩|² μ²/σ². It gives no source-plane normalisation.
  • Code. Lenstool 8.10.1 src/o_chi.c chi2_src(), read from the mirror github.com/tomresseguier/lenstool-perso (not the official CRAL repo). The source-plane mode is selected by image.forme:
    • forme 8/13 ("the proper way"): (A⁻¹δ)ᵀ W (A⁻¹δ). This is the same as Gravity.jl Bᵢ and Keeton 2001 Eq. 10.
    • Scalar modes: weight by |μ|/σ², or by a system-averaged det A. These are not μ²/σ².
    • Default forme -1: an image-plane fit.
    • Every source-plane mode adds log(4π²/det W). This is model-independent only in forme 8/13.
    • The centre is a plain or √μ-weighted mean, and the source is never marginalised.
  • Gravity.jl vs Lenstool. The two codes do not disagree: our "jacobian" with its normalisation equals Lenstool forme 8 for circular errors.
  • Our "magnification". It matches Jullo's Eq. 10 chi² but no Lenstool code path. Its normalisation Σ log(2πσ²/μ²) is 1-D and model-dependent (it rewards high μ) and matches no Lenstool mode.
  • The workspace Lenstool example is mislabelled. The Mahler SMACS0723 ICLv2 input.par uses forme -1, an image-plane fit. So autolens_workspace/scripts/cluster/lenstool/modeling.py:34-37 is wrong to map it to FitPositionsSource with the "scalar μ² convention".

Decisions (human, 2026-10-21)

  • Keep two weightings × two centres. Weighting is "jacobian" or "magnification". Centre is free (FitPositionsSource) or solved (FitPositionsSourceSolved). There is no separate barycentre option: Solved already gives the optimal centre, and a Lenstool-only reproduction is not wanted.
  • Default to "jacobian" in both classes. For FitPositionsSource this is a new default; FitPositionsSourceSolved already uses it.
  • Fix "magnification". Make it Eq. 46 with B ≈ μ²Θ, i.e. give it the model-independent 2-D normalisation log((2π)²σ⁴) in both classes. Document its radial-direction bias near critical curves.
  • Fix the workspace Lenstool example and its README: point them at the image-plane fit.
  • Defer the autolens_profiling rerun note until the cluster-pointsolver-robust-settings claim is released.
  • Tier judge → human /prm.

Activity

  1. Jammy2211 commented on Oct 21, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR created: #792 (pending-release).

    The PR does three things:

    • makes jacobian the FitPositionsSource default;
    • gives the opt-in magnification weighting the model-independent 2-D normalisation;
    • leaves FitPositionsSourceSolved values unchanged.

    test_autolens gives 911 passed. Source-plane χ² and log-likelihood values from FitPositionsSource change.

    Next: /start_workspace for autolens_workspace and autolens_workspace_test. That covers prose explaining the default, the Lenstool example fix (it uses forme -1, so it is an image-plane fit), and re-measuring the pinned values in jax_likelihood/source_plane.py. The autolens_profiling note is deferred until its claim is released.

  2. Jammy2211 commented on Oct 21, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped — 2026-10-21

    Merged:

    • PyAutoLens#792 (pending-release): FitPositionsSource defaults to "jacobian"; the "magnification" weighting is an opt-in with the model-independent 2-D normalisation.
    • autolens_workspace#593: a "Source-plane weighting" section in guides/point_source_pairing.py explains the default. The likelihood_function walkthrough is rewritten to the jacobian form. The Lenstool example now uses FitPositionsImagePairRepeat, because the Mahler fit is forme -1.
    • autolens_workspace_test#346: source_plane.py is re-pinned from −331481.26 to −104.67. This is fully accounted for: the normalisation change gives +2.11, and the rest is χ² dropping from 662,993 to 244.

    Re-filed separately:

    • the autolens_profiling rerun note, deferred until the repo is free;
    • two pre-existing script problems: the image-plane manual check in cluster/likelihood_function.py disagrees with the library (manual 26.2 vs library −1.5e5), and in likelihood_sanity.py point_0's images trace up to ~7″ from the truth.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions