Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a2f43f
MagnitudeEstimationModel: hierarchical Bayesian observer for estimati…
Gilles86 Oct 25, 2026
65399aa
EstimationTaskModel: small component API (PowerSpace / UniformPrior /…
Gilles86 Oct 25, 2026
cb252a4
EstimationTaskModel: subject-level covariates on a parameter's group …
Gilles86 Oct 25, 2026
a8b1b40
docs: EstimationTaskModel page (components, quick start, likelihood p…
Gilles86 Oct 25, 2026
95f1ca9
EstimationTaskModel docstring: motor noise is recoverable alongside e…
Gilles86 Oct 25, 2026
0ccf2d4
EstimationTaskModel: grid likelihood per unique magnitude, gathered p…
Gilles86 Oct 26, 2026
800a936
EstimationTaskModel: TruncatedGaussianPrior (discrete integers by def…
Gilles86 Oct 26, 2026
4c54816
EstimationTaskModel: censored responses (per-trial censor -1/0/+1)
Gilles86 Oct 26, 2026
334cdc0
EstimationTaskModel: integer dtype for censored posterior-predictive …
Gilles86 Oct 26, 2026
b498bd1
EstimationTaskModel: 600-point measurement grid by default without mo…
Gilles86 Oct 26, 2026
4acae9a
EstimationTaskModel: two-level condition offsets (e.g. cued side) on …
Gilles86 Oct 26, 2026
4f90289
EstimationTaskModel: single-trial covariates -- measurement_shift (m …
Gilles86 Oct 26, 2026
9b54adb
TruncatedGaussianPrior(space='n'): Gaussian in numerosity (items), in…
Gilles86 Oct 26, 2026
da6f45c
EstimationTaskModel: leak=<column>: measurement centred on (1 - w) f(…
Gilles86 Oct 27, 2026
94fab45
EstimationTaskModel: prior_leak=<column>: prior centre mu + k (n_u - …
Gilles86 Oct 29, 2026
31df799
EstimationTaskModel: response_pull=<column> (report centre n_hat + w …
Gilles86 Oct 29, 2026
89e56ed
Pooled lapse option: EstimationTaskModel(lapse='pooled') / transform …
Gilles86 Nov 1, 2026
dd8333a
Merge branch 'estimation-model' into release/0.5.2
Gilles86 Nov 2, 2026
2473950
Tests: uncued-magnitude terms (leak, prior_leak, response_pull, swap)…
Gilles86 Nov 2, 2026
e7b0dd6
Release 0.5.2
Gilles86 Nov 2, 2026
8f36eeb
Speed up the slow EstimationTaskModel NUTS recovery test: numpyro, 60…
Gilles86 Nov 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,66 @@
All notable changes to **bauer** are documented here. This project loosely
follows [Keep a Changelog](https://keepachangelog.com/) and semantic versioning.

## 0.5.2 (2026-11-02)

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).

## 0.5.1 (2026-10-26)

### Fixed
Expand Down Expand Up @@ -41,6 +101,7 @@ follows [Keep a Changelog](https://keepachangelog.com/) and semantic versioning.
- `ppc` / `posterior_predicted_moments` compile the trial density once and
swap parameter values per draw (~0.1 s per draw instead of ~2 s).

||||||| d338120
## 0.5.0 (2026-10-18)

The headline of this release is a much-extended `bauer.efficient_coding`
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type: software
license: MIT
repository-code: "https://github.com/ruffgroup/bauer"
url: "https://ruffgroup.github.io/bauer/"
version: "0.5.1"
version: "0.5.2"
authors:
- family-names: "de Hollander"
given-names: "Gilles"
Expand Down
2 changes: 1 addition & 1 deletion bauer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Gilles de Hollander"""
__email__ = 'giles.de.hollander@gmail.com'
__version__ = '0.5.1'
__version__ = '0.5.2'
25 changes: 18 additions & 7 deletions bauer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ def build_prior(self, name, mu_intercept=None, sigma_intercept=None, transform='
pm.Flat(name)
elif transform == 'softplus':
pm.HalfFlat(name)
elif transform in ('logistic', 'beta'):
elif transform in ('logistic', 'beta', 'beta_pooled'):
pm.Uniform(name, lower=0, upper=1)
else:
raise NotImplementedError
return

if transform == 'beta':
if transform in ('beta', 'beta_pooled'):
# Single-subject Beta prior with the same small-mean / heavy-tail
# shape used by the hierarchical 'beta' group prior (see
# build_hierarchical_nodes). Concentration = beta_mu_kappa.
Expand Down Expand Up @@ -819,7 +819,7 @@ def build_hierarchical_nodes(self, name, mu_intercept=None, sigma_intercept=None
beta_kappa_sd=3.0, **kwargs):
"""Build a hierarchical (group_mu, group_sd, per-subject offset) node.

``transform`` ∈ {'identity', 'softplus', 'logistic', 'beta'}. When
``transform`` ∈ {'identity', 'softplus', 'logistic', 'beta', 'beta_pooled'}. When
``transform`` is 'softplus' and ``min_value > 0``, the transformed
parameter has a hard lower bound: ``param = min_value + softplus(x)``.
Used to keep e.g. the DDM/RDM threshold ``a`` away from the a→0 collapse
Expand Down Expand Up @@ -856,6 +856,15 @@ def build_hierarchical_nodes(self, name, mu_intercept=None, sigma_intercept=None
``get_groupwise_parameter_estimates`` keeps working via ``{name}_mu``).
"""

if transform == 'beta_pooled':
# one rate shared by all subjects (prior as the 'beta' group mean); for rates
# ~ 0 with little information per subject, where the hierarchical Beta's
# concentration (kappa) is unidentified and the centred p[s] | kappa funnels
group_mu = pm.Beta(f'{name}_mu', alpha=beta_mu_mean * beta_mu_kappa,
beta=(1.0 - beta_mu_mean) * beta_mu_kappa)
n_sub = len(pm.modelcontext(None).coords['subject'])
return pm.Deterministic(name, group_mu * pt.ones(n_sub), dims=('subject',))

if transform == 'beta':
a0 = beta_mu_mean * beta_mu_kappa
b0 = (1.0 - beta_mu_mean) * beta_mu_kappa
Expand Down Expand Up @@ -939,7 +948,9 @@ def get_groupwise_parameter_estimates(self, idata=None, parameters=None, include
def _spread(par):
if par + '_sd' in idata.posterior:
return idata.posterior[par + '_sd'].to_dataframe()
return idata.posterior[par + '_kappa'].to_dataframe()
if par + '_kappa' in idata.posterior:
return idata.posterior[par + '_kappa'].to_dataframe()
return (0 * idata.posterior[par + '_mu']).to_dataframe() # pooled: no spread
sd_pars = pd.concat([_spread(par) for par in self.free_parameters], axis=1, keys=self.free_parameters, names=['parameter']).droplevel(1, axis=1)
pars = pd.concat((mu_pars, sd_pars), keys=['mu', 'sd'], names=['type'], axis=1)

Expand Down Expand Up @@ -973,7 +984,7 @@ def sample_parameters_from_prior(self, n_subjects=None):
if 'transform' not in pars.keys():
pars['transform'] = 'identity'

if pars['transform'] == 'beta':
if pars['transform'] in ('beta', 'beta_pooled'):
mean = pars.get('beta_mu_mean', 0.05)
kappa = pars.get('beta_mu_kappa', 8.0)
samples_pars[key] = np.random.beta(mean * kappa,
Expand All @@ -997,7 +1008,7 @@ def sample_parameters_from_prior(self, n_subjects=None):
def forward_transform(self, data, parameter):
transform = self.free_parameters[parameter]['transform']

if transform in ('identity', 'beta'):
if transform in ('identity', 'beta', 'beta_pooled'):
# 'beta' rates already live in (0, 1) — natural == sampling scale.
return data
elif transform == 'softplus':
Expand All @@ -1008,7 +1019,7 @@ def forward_transform(self, data, parameter):
def backward_transform(self, data, parameter):
transform = self.free_parameters[parameter]['transform']

if transform in ('identity', 'beta'):
if transform in ('identity', 'beta', 'beta_pooled'):
return data
elif transform == 'softplus':
return inverse_softplus_np(data)
Expand Down
6 changes: 6 additions & 0 deletions bauer/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@
RaceDiffusionPowerLawNoiseRiskRegressionModel,
logp_race_diffusion_2,
)

from .estimation_task import (
EstimationTaskModel,
PowerSpace, LogSpace, LinearSpace,
UniformPrior, GaussianPrior, LogNormalPrior, TruncatedGaussianPrior,
)
Loading
Loading