Pools, grids and tuning
Scoring over a benchmark pool: VisualGeometryToolkitCore's light PoolPair record together with its num_points × num_models Float32 residual matrix, both in the pool frame NormalizedImageFrame (see Conventions). No function here opens a file; pool IO belongs to VisualGeometryToolkitEval.
Per-pair model selection
One pair's selection is VisualGeometryToolkitCore's best_pool_model(scoring, pair, R) for a scorer at its width: the Student-t marginal, or a loss-width family at a loss width, with_width(F(dg), LossWidth(w)). The loss-width families are VisualGeometryToolkitCore AbstractThresholdScorings, as RANSAC and MSAC are, and score through Core's one threshold score!: Σ quality in index order, the minimal sample's points at zero residual, a consensus set d² < w², and under a running best an early exit that never changes the selection.
RANSACScoringDoneRight.precompute_pair — Function
precompute_pair(pair::PoolPair, R) -> PrecomputedPairPer-pair staging precompute of pair and its residual matrix R (num_points × num_models, Float32, NormalizedImageFrame units). Each model column is squared in Float32, its minimal-sample points zeroed (exact inliers; an out-of-range index THROWS, as in every other scorer) and sorted; the selection error pool_imc is kept per model.
Grid selection: the pool-selection contract
VisualGeometryToolkitCore's select_on_grid!(idxs, P, scoring, grid, staged) fills idxs[p, t] with the model selected for pair p at width grid[t]. Every grid family of this package (StudentTUniformScoring, the width-free loss-width families, LossSpec, ScaleMarginal, SimFitPP) declares the staging :rsdr: stage_selection(selection_staging(scoring), pairs, residuals; backend) is one stage_ig_shared_from_pairs shared by all of them, and its select_on_grid! is one grid_evaluate (SIMFIT++: its host loop over simfitpp_select). pair_chunk_budget sizes the device chunks.
RANSACScoringDoneRight.pair_chunk_budget — Function
pair_chunk_budget(M_max, T) -> IntThe number of pairs per chunk of a device selection grid.
The grid has T columns over pools of up to M_max models; the chunk bounds the score block (Float64, pairs × M_max × T) plus argmax's broadcast temporary under ~6 GiB, clamped to [1, 256]. T-aware, so a wide miscalibration grid (T up to ~600) stays in device memory and narrow validation grids keep the chunk large.
Grid evaluation (CPU and GPU)
A pool is staged once (stage_ig_shared_from_pairs) and every scorer is evaluated over a grid of its native width by one verb, grid_evaluate, which dispatches on the scoring. The kernels are written with KernelAbstractions and run on CPU() or a CUDA backend.
RANSACScoringDoneRight.IGSharedData — Type
IGSharedData{Backend, F32A, F64A, IntA}Backend-agnostic flat-layout view of every PrecomputedPair in a pool. Built once per pool by stage_ig_shared_from_pairs and reused by every grid evaluator.
Memory layout — all distinct pairs flattened:
sorted_sq_flat::F32A(a vector of the pool's residual eltype on backend) contiguous concatenation of all (Ki × Mi) sortedsq matrices in column-major order: pair 1 model 1 (length K1), pair 1 model 2, …, pair 1 model M_1, pair 2 model 1, …pair_offset::IntA(length P+1)pair_offset[p]= absolute starting index of pair p insorted_sq_flat.pair_offset[P+1]= total length (sentinel).K_per_pair::IntA(length P) — # residuals for each pairM_per_pair::IntA(length P) — # models for each pairM_max::Int— max # of models across all pairs (kernel grid sizing)errors_imc_flat::F64A— concatenated per-model selection imc =pool_imc(H: Δrot; E/F: max(Δrot,Δtrans)), indexed byerrors_offset[p] + jerrors_offset::IntA—errors_offset[p]= start of pair p's imc segment
P is the number of pairs in the pool.
RANSACScoringDoneRight.stage_ig_shared_from_pairs — Function
stage_ig_shared_from_pairs(pairs, residuals; backend) -> IGSharedDataStage a pool once for every grid evaluator. The inputs are the light records pairs (AbstractVector{<:PoolPair}) with their residual matrices residuals (residuals[p] is pair p's num_points × num_models Float32 matrix, in NormalizedImageFrame units — the caller loads them; staging opens no file), each pair precomputed by precompute_pair into the flat IGSharedData layout on backend (by default VisualGeometryToolkitCore's default_device(): the accelerator when one is loaded and functional, else the CPU). No prior fit, no width grid baked in.
RANSACScoringDoneRight.grid_evaluate — Function
grid_evaluate(scoring::StudentTUniformScoring, staged::IGSharedData, outlier_halfwidths;
pair_chunk_size = 256, return_idxs = false) -> Matrix{Float64}The Student-t marginal grid (the IG/Jeffreys sort-and-sweep) on the staged pool's backend. It returns a (P, T) matrix of each pair's error at the model scoring selects at each outlier half-width in outlier_halfwidths (NormalizedImageFrame units). The grid REPLACES the scoring's own outlier half-width; its minimal sample size, codimension and scale prior are the scoring's. With return_idxs, also the (P, T) Int32 selected model indices.
Runs ig_sweep_kernel! on the shared chunked driver (_chunked_argmax_eval): pair-chunks of pair_chunk_size bound the score block, and the model argmax is the shared argmax_models_kernel!, which takes the FIRST strictly best model and SKIPS a NaN score. The device sweep scores the model-certain marginal with the flat label prior and a supplied outlier half-width only: a StudentTUniformScoring{Predictive}, a non-flat label prior or an outlier model that estimates the support is an ArgumentError, never scored as something else.
grid_evaluate([S = Float32,] scoring::LossWidthScoring, staged::IGSharedData, loss_widths;
aggregation = LogBinned(), return_idxs = false, pair_chunk_size = 256)
-> Matrix{Float64}Per-pair selection errors of a loss-width family over a loss-width grid. They form a (P, T) matrix of the error (imc) of the model scoring selects at each loss width in loss_widths (NormalizedImageFrame units; with return_idxs, also the selected pool indices). Runs on the staged data's backend — KernelAbstractions CPU() or a GPU.
aggregation is the LogBinned aggregation (default 200 bins per decade; the fast cross-validation path) of the family's one per-residual quality. The exact selection (every residual) is VisualGeometryToolkitCore's select_on_grid! on the :pool staging. S is the bin-index precision (Float32, the default, is the production setting); scores accumulate in Float64.
scoring is a LossWidthScoring member — build it with loss_width_scoring, supplying the problem's codimension.
grid_evaluate([S = Float32,] m::ScaleMarginal, staged::IGSharedData, prior_loss_widths;
NG = _MARG_NG, return_idxs = false, mem_budget = 6_000_000_000)
-> Matrix{Float64}Full-data scale-marginal scoring (WelschMarginal, SmoothTLSMarginal) at precision S (Float32 by default; Float64 for full precision), on the staged data's backend — KernelAbstractions CPU() or a GPU. The scale is integrated out by the package's one scale quadrature, the trapezoid logsumexp over NG log-scale nodes spanning t0 ± 7.0 around each grid point's prior centre (loss_spec(::ScaleMarginal)). Returns a (P, T) per-pair error matrix at the model each grid-point's marginal selects.
prior_loss_widths is THIS FAMILY'S tuned parameter — the IG-prior centre on the loss width (prior_loss_width, NormalizedImageFrame units), not a decision threshold. Grid point t is m's family with m's prior shape alpha0, Z̃ domain m.outlier_halfwidth (the declared outlier support, POOL_FRAME_R_MAX on pool data), centred at prior_loss_widths[t]: the grid REPLACES m's own centre. return_idxs=true also returns the selected pool indices. The pair-chunk is sized so the NG-per-work-item scratch and the score block stay under mem_budget bytes.
grid_evaluate([S = Float32,] spec::LossSpec, staged::IGSharedData, outlier_halfwidths;
model_dof, dg, return_idxs = false, mem_budget = 6_000_000_000)
-> Matrix{Float64}Track-B mixture-marginal grid evaluation, on the staged data's backend (KernelAbstractions CPU() or a GPU), the ONLY evaluation of this evidence. For the depth-Δ quadrature selector spec (built by loss_spec — Z̃ over the FIXED [0, r_max] domain), score every staged (pair, model) at every outlier half-width in outlier_halfwidths (NormalizedImageFrame units) and return the (P, T) per-pair error matrix at each grid-point's selected model (return_idxs=true also returns the selected pool indices). Three kernels per pair-chunk: marg_mix_evidence_kernel! (E over k; the NG-node trapezoid quadrature), marg_mix_profile_kernel! (the outlier-half-width profile re-argmax over k), and the shared argmax_models_kernel!. Precision S drives the evidence arithmetic — Float64 for full precision; Float32 is the fast production setting. The pair-chunk is sized so the E block + the NG-per-work-item Dscratch stay under mem_budget bytes. model_dof (the minimal sample size, whose points are the exact inliers at the front of each column) and dg (the codimension) are the problem's, and REQUIRED: a LossSpec carries neither.
RANSACScoringDoneRight.LogBinned — Type
LogBinned(bins_per_decade = 200)The fast cross-validation aggregation: residuals histogrammed on a log-spaced d² grid. The grid has bins_per_decade bins per decade, spanning 0.01·minlosswidth² to 100·maxlosswidth², and the family's quality is evaluated at the bin centres. Out-of-range and non-finite residuals score as outliers.
Native widths
Each scorer's hyperparameter lives on its own width axis: the outlier half-width for the marginal scores, the loss width for the threshold-based family. VisualGeometryToolkitCore's width_axis(scoring) names it (this package states it for its grid families); the maps from an efficiency constant to the native width, to_native and native_map, and the conversions outlier_halfwidth_to_loss_width / loss_width_to_outlier_halfwidth (at an operating_efficiency_constant), are VisualGeometryToolkitCore's.
Scale marginals of redescending losses
RANSACScoringDoneRight.WelschMarginal — Type
WelschMarginal(; alpha0=1.0, prior_loss_width, outlier_halfwidth)Marginal-Welsch scoring spec. prior_loss_width is the IG-prior centre on the Welsch loss width (beta0 = alpha0·prior_loss_width² ⇒ 2·alpha0 pseudo-observations at pseudo-squared-width prior_loss_width²); outlier_halfwidth bounds the density normalizer Z̃ — REQUIRED, as for every scale-marginal spec. alpha0/beta0 are the same two IG hyperparameters IGPrior names. For an (alpha0, beta0) prior not tied to a centre, ScaleMarginal{WelschShape}(alpha0, beta0; outlier_halfwidth).
The evidence is the trapezoid scale quadrature of loss_spec(::ScaleMarginal).
RANSACScoringDoneRight.LossSpec — Type
LossSpec{K<:AbstractLossShape}The depth-Δ quadrature-marginal spec of the redescending loss shape K: the shape, its well depth Δ, the quadrature grid with Z̃ baked at that depth over [0, r_max], and r_max.
Build it with loss_spec, which keeps Δ and the grid in step, and evaluate a staged pool with it through grid_evaluate.
RANSACScoringDoneRight.loss_spec — Function
loss_spec(shape, prior; Δ, r_max=POOL_FRAME_R_MAX, t_lo, t_hi, NG=1537) -> LossSpecBuild a depth-Δ quadrature-marginal spec for the loss shape under IG scale prior. Z̃ is normalised over the FIXED domain [0, r_max] (the declared outlier support POOL_FRAME_R_MAX, in the pool frame's half-diagonal unit), so the outlier half-width is decoupled from the quadrature. [t_lo, t_hi] are the log-scale grid bounds (use loss_scale_bounds(sq_distances, n)).
loss_spec(m::ScaleMarginal{K}; NG=_MARG_NG) -> LossSpecThe quadrature of the full-data scale marginal m: shape K at its canonical depth, m's IG prior, Z̃ over [0, m.outlier_halfwidth] and NG log-scale nodes spanning m.t0 ± _MARG_L. The nodes lie on the ABSOLUTE lattice t = i·h, h = 2·_MARG_L/(NG − 1) (the domain snapped by at most h/2), so the specs of every grid point share their nodes and grid_evaluate(::ScaleMarginal, …) sums each model's data term once for the whole grid.
RANSACScoringDoneRight.loss_scale_bounds — Function
loss_scale_bounds(sq_distances, n; pad=4.0) -> (t_lo, t_hi)Data-driven grid bounds on t = log sq_loss_width for a redescending-loss sweep over squared residuals sq_distances[1:n]. The scale-posterior peak for partition k lands near sq_loss_width ≈ RSS_k/(k−m), which ranges from ≈ the tightest residual scale (small k) to ≈ the all-point scale (k=n); the returned [t_lo, t_hi] brackets that range with pad decades (natural-log) of margin on each side so the trapezoid grid covers every k's peak. Supply to loss_spec(...; t_lo, t_hi).
Scale priors
The empirical-Bayes variants of the paper fit VisualGeometryToolkitCore's IGPrior from per-pair noise-variance estimates on a validation set: IG-MLE by type-II maximum likelihood, IG-Robust with α₀ = 1 and a median-anchored β₀. The fits (PriorSpec, fit_prior, ALL_PRIOR_SPECS) are VisualGeometryToolkitEval's Tuning; a fitted prior enters a scorer as StudentTUniformScoring(P, a; scale_prior, label_prior).
SIMFIT++ loss-width estimation
SIMFIT++ (Edstedt, CVPRW 2025; Parskatt/simfitpp) is VisualGeometryToolkitEstimation's: SimFitPP, simfitpp_loss_width and simfitpp_select (exported there), unbiased_median_variance and with_residual_unit (public there). This package gives SimFitPP its width axis (LossWidth), its tag "sim_fit_pp" and its grid on the pool-selection contract (above).