Skip to content

Release 0.5.2 — EstimationTaskModel (magnitude estimation observer) - #7

Merged
Gilles86 merged 21 commits into
mainfrom
release/0.5.2
Nov 2, 2026
Merged

Gilles86 merged 21 commits into
mainfrom
release/0.5.2

Conversation

@Gilles86

@Gilles86 Gilles86 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

A new observer model for magnitude estimation (a slider / integer response
scale), bauer.models.EstimationTaskModel, developed for the retinonumeral
paper (two simultaneous numerosities, one cued for report). No changes to
existing models; the only change to shared code is a new beta_pooled
transform in bauer.core.build_hierarchical_nodes.

Added

  • bauer.models.EstimationTaskModel: hierarchical Bayesian observer for
    magnitude estimation on a bounded, discrete (integer) response scale, built
    from a few components:
    • encoding space PowerSpace(alpha) (Box-Cox; alpha=None = free,
      hierarchical), with LogSpace() (Weber) and LinearSpace() (constant
      noise) as fixed ends; efficient coding for a power-law prior is the same
      family (documented);
    • prior UniformPrior(lo, hi) (e.g. the task range) or GaussianPrior()
      (Gaussian in the encoding space; log-normal for log space);
    • posterior-mean readout, rounded and censored to the response scale;
      uniform lapse (default on); optional Gaussian motor noise;
    • optional subject-level covariates on a parameter's group mean
      (covariates={'nu': column}).
      Closed-form likelihood for log space + log-normal prior, otherwise an exact
      grid path (n_hat(m) inverted at the response-option edges). Observed
      pm.Categorical likelihood: LOO and posterior-predictive draws come from
      PyMC directly. simulate, predict, posterior_predictive,
      parameter_recovery.
  • tests/test_estimation_task.py: every component combination builds with
    finite gradients, closed form = grid, alpha -> 0 = log, uniform-prior
    compression, flat s.d. for linear + Gaussian, MAP and hierarchical NUTS
    recovery (incl. free alpha), covariates.
  • EstimationTaskModel extensions:
    • TruncatedGaussianPrior(lo, hi, discrete=True, space='internal'|'n')
      (prior restricted to the known task bounds; space='n' = Gaussian in
      items, independent of alpha) and a discrete UniformPrior;
    • censored responses (per-trial censor column, -1 / 0 / +1, e.g.
      time-outs at the slider ends);
    • condition=<column>, condition_parameters=(...): two-level condition
      offsets (e.g. cued side) on chosen parameters;
    • single-trial covariates: measurement_shift (shifts the measurement
      mean) and noise_modulator (scales the encoding noise per trial; the
      observer decodes with its trial noise);
    • the influence of a second, uncued magnitude (n_u, a column):
      leak (measurement centred on (1 - w) f(n) + w f(n_u)), prior_leak
      (prior centre shifted towards n_u), response_pull (report centre pulled
      towards n_u, weight growing with the encoding noise) and swap
      (occasionally reporting the other magnitude, rate may depend on n).
      Each reduces exactly to the plain model when its parameter is 0;
    • lapse='pooled': one lapse rate shared by all subjects (new
      beta_pooled transform). Use it when lapses are near zero: the
      hierarchical Beta concentration is then unidentified and NUTS funnels
      (in one dataset 26 min -> >24 h with raised target_accept; pooled:
      21-45 min, 0 divergences, identical other parameters);
    • grid likelihood computed per unique magnitude (or magnitude pair) and
      gathered per trial; 600-point measurement grid by default without
      motor noise.
  • tests/test_estimation_task.py covers the extensions (each reduces to the
    plain model, swap probability 1 = exchanged roles, pooled lapse = the
    hierarchical model at equal rates).

🤖 Generated with Claude Code

Gilles86 and others added 21 commits October 25, 2026 13:33
…on on a bounded integer scale

Weber / constant / power-law encoding noise; true, fitted or empirical prior;
posterior mean or median readout; censored discretised motor noise; free
lapse; optional leakage of an uncued magnitude (mixture or average). Observed
Categorical likelihood, so LOO and posterior-predictive draws come from PyMC.
Tests: builds + finite gradients for every option, analytic checks, MAP and
hierarchical NUTS parameter recovery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… GaussianPrior / lapse) replacing MagnitudeEstimationModel

Encoding is Gaussian in a Box-Cox power space f_alpha (alpha free or fixed;
0 = log/Weber, 1 = linear). Prior: uniform (e.g. the task range) or Gaussian
in the same space (log-normal for log). Posterior-mean readout, rounded and
censored to the response scale; lapse uniform over options; optional Gaussian
motor noise. Closed-form likelihood for log space + log-normal prior; else a
grid whose estimate n_hat(m) is inverted at the response-option edges, which
keeps the likelihood exact and smooth. Noise nu and prior width are in log
units at a reference magnitude so they stay comparable across alpha.
Tests: every combination builds with finite gradients, closed form = grid,
alpha -> 0 = log, uniform-prior compression, flat s.d. for linear + Gaussian,
MAP and hierarchical NUTS recovery (incl. free alpha).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mean; CHANGELOG

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aths, efficient-coding equivalence)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ncoding noise (r > .93 in a 19 x 500 recovery)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er trial

The motor-noise integral was a per-trial (T, M, R) tensor: 0.75 s per gradient
on 9,928 trials, so the hierarchical fits timed out at 12 h. Computing the
(S, K, R) option table per participant x unique magnitude (a batched matmul)
gives identical log-probabilities at 0.04 s per gradient (19x faster).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ault, or continuous) and discrete UniformPrior

The fitted Gaussian prior had support on the whole hypothesis grid (1..50), so
the observer did not know the task's bounds. TruncatedGaussianPrior(lo, hi)
restricts it to the task range; discrete=True puts the mass on the integers
lo..hi only (weights = the prior's density in n at each integer).
UniformPrior(lo, hi, discrete=True) likewise. The measurement grid no longer
depends on the hypothesis grid. Tests: narrow truncated = untruncated
Gaussian; very wide truncated = uniform in f_alpha space (= UniformPrior for
the linear space). Discrete vs continuous truncation differ by <= .002 in any
option probability at the fitted group parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A censored trial's likelihood is the summed option probability at and beyond
the final position (cumsum + one-hot gather), via pm.CustomDist with an
elementwise logp, so pointwise log-likelihoods / LOO still work; posterior-
predictive draws are the intended reports. Without a censor column the model
is unchanged (Categorical). Tests: censor = 0 reproduces the Categorical logp
and gradient exactly; a censored trial equals the tail sum of its option
probabilities; MAP with censoring recovers nu from simulated reports cut short
on a third of trials, ignoring the censoring does not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…draws

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tor noise; grid-accuracy test

Checked at fitted parameters against M = 4000 over a 3.5x wider range: with
motor noise 200 points give |dP| <= 5e-5 (total log-lik change <= .006 per
participant); the no-motor inversion of n_hat(m) needed 600 (|dP| 6.9e-3 ->
5.6e-4, log-lik .50 -> .08).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chosen parameters

x[s, c] = x_s + (1/2 - c)(delta + delta_s) on the untransformed scale, group
delta ({p}_cond_mu, level 0 minus level 1) and non-centred participant
deviations; the option table is computed per (participant, condition).
Test: builds, finite gradient, zero offsets reproduce the plain likelihood.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…~ N(f(n) + beta nu_f z, nu_f^2)) and noise_modulator (nu_t = nu exp(gamma u), the observer decodes with its trial noise)

Covariates are binned within participant into equally filled quantile bins
(bin means); the option table is computed per (participant, u bin) x
(n, z bin). Tests: zero effects reproduce the plain likelihood exactly; 7 bins
vs per-trial evaluation differ by .002 nats per trial at beta = .4, gamma = .3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dependent of alpha

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n) + w f(n_u) (uncued magnitude leaks into encoding; observer decodes as if from n); per unique (n, n_u) pair

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mu) per trial (parameter prior_leak_k), observer decodes with that prior; table per (participant, n_u); combines with leak

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(n_u - n_hat), w = pull_k (n_hat/15)^(1 - alpha), per (participant, n_u) rows; needs motor noise) and swap=<column> (mixture with the exchanged-roles option probabilities, logit p = swap_a + swap_b (n - 15)/10; lapses outside); both reduce exactly to the plain model

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'beta_pooled' -- one rate for all subjects, for datasets with lapses ~ 0 where the hierarchical Beta concentration is unidentified (centred funnel, NUTS saturates the tree depth); likelihood identical to the hierarchical model at equal rates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and the pooled lapse reduce exactly to the plain model; swap probability 1 = exchanged roles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… x 80 grid, 250 trials, 2 x 50 draws (~1.5 min locally; ~1 h on CI before, same recovery r > .95)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gilles86
Gilles86 merged commit f6c4a31 into main Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant