psyphy 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. psyphy-0.0.6/.gitignore +69 -0
  2. psyphy-0.0.6/CHANGELOG.md +432 -0
  3. {psyphy-0.0.4 → psyphy-0.0.6}/PKG-INFO +43 -11
  4. {psyphy-0.0.4 → psyphy-0.0.6}/README.md +20 -5
  5. psyphy-0.0.6/pyproject.toml +222 -0
  6. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/__init__.py +3 -2
  7. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/data/__init__.py +3 -1
  8. psyphy-0.0.6/src/psyphy/data/dataset.py +426 -0
  9. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/data/io.py +19 -27
  10. psyphy-0.0.6/src/psyphy/data/published/__init__.py +30 -0
  11. psyphy-0.0.6/src/psyphy/data/published/hong2025.py +859 -0
  12. psyphy-0.0.6/src/psyphy/inference/__init__.py +40 -0
  13. psyphy-0.0.6/src/psyphy/inference/base.py +62 -0
  14. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/inference/langevin.py +18 -38
  15. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/inference/laplace.py +32 -4
  16. psyphy-0.0.6/src/psyphy/inference/mala.py +179 -0
  17. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/inference/map_optimizer.py +139 -10
  18. psyphy-0.0.6/src/psyphy/inference/mcmc.py +240 -0
  19. psyphy-0.0.6/src/psyphy/inference/nuts.py +430 -0
  20. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/model/__init__.py +9 -2
  21. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/model/base.py +3 -3
  22. psyphy-0.0.6/src/psyphy/model/covariance_field.py +952 -0
  23. psyphy-0.0.6/src/psyphy/model/likelihood/__init__.py +37 -0
  24. psyphy-0.0.6/src/psyphy/model/likelihood/base.py +432 -0
  25. psyphy-0.0.4/src/psyphy/model/likelihood.py → psyphy-0.0.6/src/psyphy/model/likelihood/oddity.py +45 -208
  26. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/model/prior.py +100 -31
  27. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/model/wppm.py +105 -91
  28. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/posterior/__init__.py +14 -5
  29. psyphy-0.0.6/src/psyphy/posterior/mcmc_posterior.py +317 -0
  30. psyphy-0.0.6/src/psyphy/posterior/parameter_posterior.py +104 -0
  31. psyphy-0.0.6/src/psyphy/posterior/posterior.py +115 -0
  32. psyphy-0.0.6/src/psyphy/posterior/predictive_posterior.py +509 -0
  33. psyphy-0.0.6/src/psyphy/trial_placement/__init__.py +35 -0
  34. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/trial_placement/grid.py +1 -6
  35. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/trial_placement/sobol.py +8 -3
  36. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/utils/math.py +4 -8
  37. psyphy-0.0.6/src/psyphy/viz/__init__.py +40 -0
  38. psyphy-0.0.6/src/psyphy/viz/ellipses.py +252 -0
  39. psyphy-0.0.6/src/psyphy/viz/geometry.py +168 -0
  40. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_3stimulus_decision_rule.py +30 -36
  41. psyphy-0.0.6/tests/test_architecture.py +42 -0
  42. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_basis_input_domain.py +1 -4
  43. psyphy-0.0.6/tests/test_contour_band.py +347 -0
  44. psyphy-0.0.6/tests/test_covariance_arviz.py +189 -0
  45. psyphy-0.0.6/tests/test_covariance_field.py +193 -0
  46. psyphy-0.0.6/tests/test_covariance_field_samples.py +420 -0
  47. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_covariance_field_single_entry_point.py +41 -94
  48. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_covariance_positive_definite.py +0 -1
  49. psyphy-0.0.6/tests/test_data_format.py +285 -0
  50. psyphy-0.0.6/tests/test_data_published_hong2025.py +417 -0
  51. psyphy-0.0.6/tests/test_docs_recipe.py +136 -0
  52. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_embedding_dim.py +11 -22
  53. psyphy-0.0.6/tests/test_explicit_key.py +186 -0
  54. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_imports.py +1 -0
  55. psyphy-0.0.6/tests/test_inference_engine.py +73 -0
  56. psyphy-0.0.6/tests/test_input_dim_validation.py +60 -0
  57. psyphy-0.0.6/tests/test_key_argument_kind.py +74 -0
  58. psyphy-0.0.6/tests/test_likelihood_api_surface.py +292 -0
  59. psyphy-0.0.6/tests/test_likelihood_logic.py +119 -0
  60. psyphy-0.0.6/tests/test_mala_sampler.py +143 -0
  61. psyphy-0.0.6/tests/test_map_one_sample.py +194 -0
  62. psyphy-0.0.6/tests/test_map_optimizer_clipping.py +109 -0
  63. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_mc_likelihood.py +100 -88
  64. psyphy-0.0.6/tests/test_mcmc_chain_loop.py +121 -0
  65. psyphy-0.0.6/tests/test_mcmc_posterior.py +180 -0
  66. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_model_api.py +14 -16
  67. psyphy-0.0.6/tests/test_model_first.py +80 -0
  68. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_noise_models.py +2 -9
  69. psyphy-0.0.6/tests/test_nuts_sampler.py +323 -0
  70. psyphy-0.0.6/tests/test_parameter_source.py +272 -0
  71. psyphy-0.0.6/tests/test_posteriors.py +384 -0
  72. psyphy-0.0.6/tests/test_predictive_keys.py +195 -0
  73. psyphy-0.0.6/tests/test_prior_basis_degree.py +16 -0
  74. psyphy-0.0.6/tests/test_quick_start_recovery.py +208 -0
  75. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_rectangular_U.py +19 -23
  76. psyphy-0.0.6/tests/test_viz.py +203 -0
  77. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_wishart_covariance.py +7 -19
  78. {psyphy-0.0.4 → psyphy-0.0.6}/tests/test_wppm_model_kwargs_guard.py +11 -1
  79. psyphy-0.0.4/.gitignore +0 -33
  80. psyphy-0.0.4/pyproject.toml +0 -120
  81. psyphy-0.0.4/src/psyphy/data/dataset.py +0 -303
  82. psyphy-0.0.4/src/psyphy/inference/__init__.py +0 -39
  83. psyphy-0.0.4/src/psyphy/inference/base.py +0 -47
  84. psyphy-0.0.4/src/psyphy/model/covariance_field.py +0 -518
  85. psyphy-0.0.4/src/psyphy/posterior/parameter_posterior.py +0 -87
  86. psyphy-0.0.4/src/psyphy/posterior/posterior.py +0 -75
  87. psyphy-0.0.4/src/psyphy/posterior/predictive_posterior.py +0 -287
  88. psyphy-0.0.4/src/psyphy/trial_placement/__init__.py +0 -38
  89. psyphy-0.0.4/tests/test_covariance_field.py +0 -288
  90. psyphy-0.0.4/tests/test_input_dim_validation.py +0 -38
  91. psyphy-0.0.4/tests/test_posteriors.py +0 -236
  92. {psyphy-0.0.4 → psyphy-0.0.6}/LICENSE.md +0 -0
  93. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/model/noise.py +0 -0
  94. {psyphy-0.0.4 → psyphy-0.0.6}/src/psyphy/utils/__init__.py +0 -0
  95. {psyphy-0.0.4 → psyphy-0.0.6}/tests/conftest.py +0 -0
@@ -0,0 +1,69 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .pytest_cache/
4
+ .mypy_cache/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .venv/
9
+
10
+ *.sh
11
+
12
+ # MkDocs build output and caches
13
+ site/
14
+ .cache/
15
+ .mkdocs-cache/
16
+
17
+ # Ignore apple macOS system files
18
+ .DS_Store
19
+ # Ignore Jupyter Notebook checkpoints
20
+ .ipynb_checkpoints
21
+
22
+ # Ignore VSCode settings
23
+ .vscode/
24
+
25
+
26
+ .claude/
27
+
28
+ # Generated plot output directories
29
+ # docs/examples/**/plots/*
30
+
31
+ # common Python tooling artifacts
32
+ .ruff_cache/
33
+ .coverage
34
+ coverage.xml
35
+ htmlcov/
36
+ .env
37
+ env/
38
+ venv/
39
+ .python-version
40
+
41
+
42
+
43
+ NOTE_posterior_mean_shrinkage.md
44
+
45
+ research/**/
46
+ # docs/examples/wppm/hong2025_reproduction.md
47
+
48
+ docs/examples/wppm/plots/hong2025_quick_ellipses.png
49
+ docs/examples/wppm/plots/hong2025_quick_learning_curve.png
50
+ docs/examples/wppm/plots/hong2025_quick_thresholds_end_to_end.png
51
+
52
+ # Saved weights from stage 3. Quick-mode fits are smoke-test noise; the
53
+ # full-mode .npz is ~2 KB and worth committing, since it lets anyone
54
+ # regenerate the end-to-end figure without a GPU.
55
+ docs/examples/wppm/fits/hong2025_quick_fit.npz
56
+
57
+ # Same split for the NUTS example. The documentation is written from
58
+ # --mode balanced, so plots/nuts_*_balanced.* and fits/nuts_balanced_fit.npz
59
+ # are committed: with the cached fit, `--from-fit` regenerates every figure and
60
+ # every printed diagnostic on the page without a GPU. Quick mode writes the
61
+ # unsuffixed names, which are smoke-test output and must never be mistaken for
62
+ # the figures the docs embed.
63
+ docs/examples/wppm/fits/nuts_quick_fit.npz
64
+ docs/examples/wppm/plots/nuts_ellipses_uncertainty.jpg
65
+ docs/examples/wppm/plots/nuts_overlay.jpg
66
+ docs/examples/wppm/plots/nuts_vs_map_comparison.jpg
67
+ docs/examples/wppm/plots/nuts_threshold_band.jpg
68
+ docs/examples/wppm/plots/nuts_trace_sigma.png
69
+ docs/examples/wppm/plots/nuts_convergence_sigma.png
@@ -0,0 +1,432 @@
1
+ # Changelog
2
+
3
+ All notable changes to `psyphy` are documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `psyphy` is
6
+ pre-1.0: while the version is `0.0.x`, **any release may change the public API**, so
7
+ breaking changes are called out below but do not force a minor-version bump.
8
+
9
+ ## [Unreleased]
10
+
11
+ ## [0.0.6] - 2026-11-23
12
+
13
+ ### Breaking
14
+
15
+ - **One covariance field class, `WPPMCovarianceField`, holds N parameter sets, and the sample axis is always first in every result.** The constructor takes a posterior, and
16
+ `WPPMCovarianceField.from_params(model, params)` builds one from a ground truth or a
17
+ published $W$. `from_posterior`, `sqrt_cov_batch` and the `CovarianceField` protocol are
18
+ gone, and `psyphy.model` no longer exports `CovarianceField`.
19
+
20
+ The sample axis is the leading axis of a result, with 1 entry per parameter set. An MCMC
21
+ fit has 1 per sample. A MAP fit, a ground truth or a published $W$ is 1 parameter set,
22
+ so its results now start with an axis of length 1. In the shapes below:
23
+
24
+ - `x`: one stimulus location, shape `(d,)`
25
+ - `X`: the stimulus locations at which we evaluate the field, shape `(n_points, d)`, or
26
+ any batch `(..., d)` such as a grid `(n_rows, n_cols, d)`
27
+ - `d`: stimulus dimensions, the model's `input_dim`
28
+ - `m`: columns of $U(x)$, `input_dim + extra_embedding_dims`
29
+
30
+ `field(x)` has shape `(1, d, d)`, `field(X)` has `(1, n_points, d, d)`, and
31
+ `field.sqrt_cov(x)` has `(1, d, m)`. `field(x)[0]` is the covariance matrix at `x`.
32
+
33
+ Code written for the old shapes can run on the new ones and give wrong numbers with no
34
+ error, so check each result that used to be `(d, d)` or `(n_points, d, d)`. 2 cases:
35
+
36
+ ```python
37
+ jnp.trace(field(x)) # (d,): the first row of Σ(x), not its trace
38
+ jnp.trace(field(x)[0]) # the trace
39
+
40
+ # a 1-D model, X of shape (n_points, 1) and truth of shape (n_points,)
41
+ field(X)[:, 0, 0] - truth # (1, n_points): Σ at the first point minus every truth value
42
+ field(X)[0, :, 0, 0] - truth # (n_points,)
43
+ ```
44
+
45
+ `jax.vmap(field)(X)` evaluates the points one at a time and puts them first,
46
+ `(n_points, 1, d, d)`. Pass `X` to `field` directly for the samples first, or write
47
+ `jax.vmap(field, out_axes=1)(X)` inside code that has to `vmap` over the points.
48
+
49
+ ```python
50
+ # before
51
+ field = WPPMCovarianceField(model, map_posterior.params) # or .from_posterior(map_posterior)
52
+ truth = WPPMCovarianceField(model, truth_params)
53
+ prior = WPPMCovarianceField.from_prior(model, key)
54
+ field(x) # (d, d)
55
+ field.sqrt_cov_batch(X)
56
+
57
+ # now
58
+ field = WPPMCovarianceField(map_posterior) # no key
59
+ truth = WPPMCovarianceField.from_params(model, truth_params)
60
+ prior = WPPMCovarianceField.from_prior(model, n_samples=1, key=key)
61
+ field(x)[0] # (d, d); field(x) is (1, d, d)
62
+ field.sqrt_cov(X)[0] # (n_points, d, m)
63
+ ```
64
+
65
+ `from_prior(model, n_samples=1, key=key)` splits the key, so it draws a different sample
66
+ than the old `from_prior(model, key)`. For the old draw, use
67
+ `from_params(model, model.init_params(key))`. `n_samples` and `key` are keyword-only in
68
+ the constructor and in `from_prior`.
69
+
70
+ - **`cov()` and `cov_batch()` are gone from `WPPMCovarianceField`.** Both raised
71
+ `DeprecationWarning` in v0.0.5, and `field(x)` replaces both.
72
+
73
+ ```python
74
+ # before
75
+ field.cov(jnp.array([0.5, 0.3])) # (2, 2), single point only
76
+ field.cov_batch(jnp.zeros((10, 2))) # (10, 2, 2), batch only
77
+
78
+ # now
79
+ field(jnp.array([0.5, 0.3]))[0] # (2, 2)
80
+ field(jnp.zeros((10, 2)))[0] # (10, 2, 2)
81
+ ```
82
+
83
+ The numbers are unchanged: `cov()` forwarded to the same evaluation `field(x)` uses.
84
+
85
+ - **A Bernoulli task's `predict` returns `(log_p, log_1mp)`, not `(p_correct,)`.** These
86
+ are log p(correct) and log p(incorrect) for one trial. `loglik` takes one of the 2 by the
87
+ response and holds it in [1e-6, 1 - 1e-6], the bound `OddityTask.predict` applied to
88
+ p(correct) before. So the log-likelihood is the same, up to float 32 rounding. `predict`
89
+ itself no longer clips, and `WPPM.predict_prob` and `simulate` return `exp(log_p)`, which
90
+ can be exactly 1.0.
91
+
92
+ A task with a logit `z` returns `log_probs_from_logit(z)`, new in
93
+ `psyphy.model.likelihood`:
94
+
95
+ ```python
96
+ # before
97
+ def predict(self, params, stimuli, model, key=None):
98
+ return (jnp.clip(jax.nn.sigmoid(z), 1e-6, 1 - 1e-6),)
99
+
100
+ # now
101
+ def predict(self, params, stimuli, model, key=None):
102
+ return log_probs_from_logit(z)
103
+ ```
104
+
105
+ `predict` returns log-probabilities, not probabilities. For p(correct), take
106
+ `jnp.exp(predict(...)[0])` or call `model.predict_prob`.
107
+
108
+ - **`model`, `samples` and `n_samples` on `WPPMCovarianceField` are read-only.**
109
+
110
+ Before, `params` and `model` were plain attributes. After a batch call, `field(X)` kept
111
+ returning the values from its first call, while `field(x)` used the reassigned ones.
112
+ One object gave 2 different answers, and a loop that refits and assigns new parameters
113
+ got stale results from every batch call.
114
+
115
+ Now, assigning to one raises an `AttributeError`. `samples` returns a copy, so
116
+ `field.samples["W"] = ...` changes nothing either. `from_params(model, params)` copies
117
+ `params` too, so `params["W"] = ...` on the dict you passed in changes nothing.
118
+
119
+ ```python
120
+ # before
121
+ field.params = new_params # accepted, then field(X) returned the old values
122
+
123
+ # now
124
+ field.samples = new_samples # raises AttributeError
125
+ field = WPPMCovarianceField.from_params(model, new_params) # build a new object instead
126
+ ```
127
+
128
+ - **`Prior(basis_degree=None)` raises `ValueError`.** `basis_degree` must be an int of 0 or
129
+ more. v0.0.5 accepted `None`.
130
+
131
+ ```python
132
+ # before
133
+ Prior(basis_degree=None) # built, then raised in sample_params
134
+
135
+ # now
136
+ Prior(basis_degree=4) # None raises ValueError
137
+ ```
138
+
139
+ - **`WPPM` no longer takes `input_dim`, `extra_dims`, `variance_scale` or `decay_rate`.**
140
+ `Prior` takes them instead. `WPPM` stored `variance_scale` and `decay_rate` and never
141
+ read them, and `extra_dims` fed only `embedding_dim`, so it disagreed with the parameter
142
+ shape without an error whenever it differed from `Prior.extra_embedding_dims`.
143
+ `WPPM.input_dim`, `.embedding_dim`, `.variance_scale` and `.decay_rate` are now
144
+ read-only properties that read `self.prior`:
145
+
146
+ ```python
147
+ # before
148
+ WPPM(prior, likelihood, input_dim=2, extra_dims=1, variance_scale=4e-3, decay_rate=0.4)
149
+
150
+ # now
151
+ Prior(input_dim=2, extra_embedding_dims=1, variance_scale=4e-3, decay_rate=0.4)
152
+ WPPM(prior, likelihood)
153
+ ```
154
+
155
+ Passing any of the 4 names to `WPPM` raises `TypeError` and says to pass them to `Prior`.
156
+ `diag_term` is unchanged.
157
+
158
+ - **`ThresholdConfig.target_pc` is now `target_prob_correct`.** The default stays 2/3.
159
+
160
+ - **`WPPMPredictivePosterior` takes a required `key`, and `cov_field` is gone.** The
161
+ constructor splits the key once, into a key for drawing parameters and a key for the
162
+ threshold sweep:
163
+
164
+ ```python
165
+ # before
166
+ WPPMPredictivePosterior(posterior, X, n_samples=100)
167
+
168
+ # now
169
+ WPPMPredictivePosterior(posterior, X, n_samples=100, key=key)
170
+ ```
171
+
172
+ Before, both keys were fixed inside the class, so no key you chose could change the
173
+ result. `cov_field(X)` also computed E[Σ(X) | data] under a fixed key. Use
174
+ `WPPMCovarianceField(posterior).mean(x)`. `PredictivePosterior` no longer has a
175
+ `cov_field` member, so a model with no covariance field can satisfy it.
176
+
177
+ - **`MAPPosterior.sample` requires `n` and `key`, and `key` can be passed positionally.**
178
+ Before, `n` defaulted to 1 and `key` was keyword-only and optional. The signature now
179
+ matches the `ParameterSource` protocol. `key` is also accepted positionally by
180
+ `WPPM.log_likelihood_from_data`, `WPPM.log_posterior_from_data`, and `loglik`,
181
+ `simulate` and `predict` on the task likelihoods. Calls that name it still work.
182
+
183
+ ```python
184
+ # before
185
+ map_posterior.sample() # one draw
186
+
187
+ # now
188
+ map_posterior.sample(1, key=key) # the key goes unread for a point mass
189
+ map_posterior.sample(1, key) # also accepted
190
+ ```
191
+
192
+ - **The model comes first in `MAPPosterior`.** It now matches `fit(model, data)` and
193
+ `WPPMCovarianceField.from_params(model, params)`. `MCMCPosterior(model, samples)` takes
194
+ the same order. Calls that name the arguments still work.
195
+
196
+ ```python
197
+ MAPPosterior(model, params) # was MAPPosterior(params, model)
198
+ MAPPosterior(params=params, model=model) # unchanged
199
+ ```
200
+
201
+ The old order raises a `TypeError` when the object is built. Before, it built and failed
202
+ at the first evaluation with `AttributeError: 'dict' object has no attribute 'input_dim'`.
203
+
204
+ ### Added
205
+
206
+ - **`WPPMCovarianceField(posterior)` evaluates the covariance field for every sample.**
207
+ `field(x)` returns Σ for each sample, `(N, d, d)` for one point or `(N, ..., d, d)` for a
208
+ batch. `field.mean(x)` returns the mean matrix E[Σ(x)] over the samples, with no sample
209
+ axis. `field.sqrt_cov(x)` returns the square root `U` for every sample, `(N, d, m)`, and
210
+ `U U^T + diag_term * I` equals `field(x)[i]` for each `i`:
211
+
212
+ ```python
213
+ fields = WPPMCovarianceField(posterior)
214
+ covs = fields.mean(ref_points) # (n_points, d, d)
215
+ U = fields.sqrt_cov(x) # (N, d, m)
216
+ ```
217
+
218
+ To compute something per sample that psyphy has no method for, read the samples from
219
+ `fields.samples`. `from_params` takes the model first, and `from_params(params, model)`
220
+ raises `TypeError`.
221
+
222
+ - **`MAPPosterior` stores its 1 sample**, as `samples`, `n_chains` and `n_draws`, with
223
+ chains first and then samples. So `WPPMCovarianceField(map_posterior)` takes a MAP fit
224
+ with no `n_samples` and no key:
225
+
226
+ ```python
227
+ map_posterior.samples["W"].shape # (1, 1, 3, 3, 2, 3): 1 chain, 1 sample, then W
228
+ map_posterior.n_chains, map_posterior.n_draws # (1, 1)
229
+
230
+ WPPMCovarianceField(map_posterior) # n_samples == 1
231
+ ```
232
+
233
+ A posterior with no `samples`, `n_chains` and `n_draws` still raises and asks for
234
+ `n_samples` and a key.
235
+
236
+ - **`NUTSSampler` in `psyphy.inference`, `MCMCPosterior` in `psyphy.posterior`, and
237
+ `covariance_to_arviz` in `psyphy.model`.** `NUTSSampler` runs the No-U-Turn Sampler
238
+ (NUTS) from BlackJAX, a Markov chain Monte Carlo (MCMC) method. Its `fit` returns an
239
+ `MCMCPosterior`, which holds the samples of every chain:
240
+
241
+ ```python
242
+ sampler = NUTSSampler(num_warmup=500, num_samples=1000, num_chains=4)
243
+ posterior = sampler.fit(model, data, init_params=map_posterior.params)
244
+ posterior.samples["W"].shape # (4, 1000, 3, 3, 2, 3): 4 chains, 1000 samples each, then W
245
+ fields = WPPMCovarianceField(posterior)
246
+ ```
247
+
248
+ `mean_params` is the mean of the samples, for example to start another fit. `MCMCPosterior`
249
+ has no `params`. `sampler_stats` holds `acceptance_rate`, `diverging`, `energy` and
250
+ `n_steps` per sample.
251
+
252
+ `covariance_to_arviz(posterior, points)` returns Σ(x) at the points you choose, for every
253
+ sample, as an ArviZ `DataTree`. Use it for convergence diagnostics such as R-hat and the
254
+ effective sample size (ESS), not `posterior.to_arviz()`, which reads $W$.
255
+
256
+ 3 new extras:
257
+
258
+ ```bash
259
+ pip install 'psyphy[sampling]' # BlackJAX, Python 3.11 or later
260
+ pip install 'psyphy[diagnostics]' # ArviZ 1.x, Python 3.12 or later
261
+ pip install 'psyphy[progress]' # tqdm; without it show_progress=True prints nothing
262
+ ```
263
+
264
+ - **`MALASampler` in `psyphy.inference`**, an MCMC engine. It runs the
265
+ Metropolis-adjusted Langevin algorithm from BlackJAX, with one gradient per step and a
266
+ fixed step size. It returns an `MCMCPosterior` with the same layout as `NUTSSampler`, so
267
+ `covariance_to_arviz` and `WPPMCovarianceField` take either.
268
+
269
+ ```python
270
+ sampler = MALASampler(num_warmup=2000, num_samples=2000, step_size=1e-4)
271
+ posterior = sampler.fit(model, data, init_params=map_posterior.params)
272
+ posterior.sampler_stats["acceptance_rate"].mean() # aim for about 0.6
273
+ ```
274
+
275
+ `step_size` has no default. `sampler_stats` holds `acceptance_rate` and `is_accepted`,
276
+ with no `diverging`, `energy` or `n_steps`.
277
+
278
+ - **`ParameterSource` in `psyphy.posterior`**, a one-method protocol for anything we can
279
+ draw parameters from: `sample(n, *, key)` returning a PyTree with a leading axis of `n`.
280
+ `Prior`, `MAPPosterior` and `MCMCPosterior` all satisfy it, and `ParameterPosterior` now
281
+ extends it with `model`.
282
+
283
+ A function that only calls `sample` on a `ParameterSource` works on a prior and on a
284
+ fitted posterior. Chain structure and a density stay off it: `sample` pools the chains,
285
+ and `MCMCPosterior` has no `log_prob`.
286
+
287
+ - **`Prior.sample(n, *, key)`**, the vectorized form of `sample_params`. Draw `i` equals
288
+ `sample_params(jax.random.split(key, n)[i])`, so a prior ensemble matches the Python loop
289
+ it replaces:
290
+
291
+ ```python
292
+ # before
293
+ W = jnp.stack([prior.sample_params(k)["W"] for k in jr.split(key, 100)])
294
+
295
+ # now
296
+ prior.sample(100, key=key)["W"] # (100, 3, 3, 2, 3)
297
+ ```
298
+
299
+ `sample_params(key)` is unchanged and returns 1 unbatched draw.
300
+
301
+ - **Credible bands on the contour radii**: `contour_radii`,
302
+ `WPPMCovarianceField.credible_band` and `CredibleBand` in `psyphy.model`.
303
+ `contour_radii` gives the radius of a covariance's one-standard-deviation ellipse
304
+ (Mahalanobis-1 contour) per direction. For the oddity task that radius is the
305
+ discrimination threshold. `credible_band` reduces those radii over the samples to a
306
+ pointwise credible interval. With 1 sample, as after a MAP fit, it raises `ValueError`,
307
+ because a band of zero width reads as certainty.
308
+
309
+ ```python
310
+ WPPMCovarianceField(map_posterior).credible_band(points) # raises ValueError
311
+ WPPMCovarianceField(mcmc_posterior).credible_band(points) # the band
312
+ ```
313
+
314
+ - **New pages:** *Fit Your Own Data*, which replaces the Quickstart (`usage.md`) in the
315
+ nav, *Sampling the Posterior with NUTS*, *Checking MCMC Samples with ArviZ*, and
316
+ *Developer Notes*. The API design document is no longer in the nav.
317
+
318
+ ## [0.0.5] - 2026-10-09
319
+
320
+ Two new subpackages
321
+ (`psyphy.viz`, `psyphy.data.published`), a reproduction of a published figure, and two
322
+ breaking API changes in the model layer.
323
+
324
+ ### Breaking
325
+
326
+ - **`TaskLikelihood.predict` signature and return type changed** (#139). Stimuli are now
327
+ passed as one packed, slot-indexed array instead of separate arguments, and the return
328
+ is a tuple of sufficient statistics instead of a bare scalar:
329
+
330
+ ```python
331
+ # before (0.0.4)
332
+ def predict(self, params, ref, comparison, model, *, key=None) -> jnp.ndarray: ...
333
+ # returns p_correct
334
+
335
+ # now (0.0.5)
336
+ def predict(self, params, stimuli, model, *, key=None) -> tuple[jnp.ndarray, ...]: ...
337
+ # stimuli has shape (K, input_dim); OddityTask reads stimuli[0], stimuli[1]
338
+ # returns (p_correct,) for Bernoulli tasks, (mu, sigma) for Gaussian task likelihoods
339
+ ```
340
+
341
+ **If you wrote a custom `TaskLikelihood`, it must be updated.** Unpack `stimuli`
342
+ yourself and wrap the return in a tuple. Returning a bare array no longer works
343
+ correctly: `BernoulliTaskLikelihood.loglik` indexes element 0 of the returned tuple, so
344
+ a bare scalar silently collapses every trial onto the first trial's probability.
345
+
346
+ - **`TrialData` now stores stimuli as one array** (#136). `refs=` / `comparisons=` are
347
+ replaced by a single `stimuli` array of shape `(N, K, d)`, with `responses` of shape
348
+ `(N, R)`; `K` is the number of stimuli per trial, so tasks with more than two slots are
349
+ now representable.
350
+
351
+ ```python
352
+ # before
353
+ TrialData(refs=refs, comparisons=comparisons, responses=responses)
354
+ # now
355
+ TrialData(stimuli=jnp.stack([refs, comparisons], axis=1), responses=responses)
356
+ ```
357
+
358
+ A 1-D `responses` array of shape `(N,)` is still accepted and normalized to `(N, 1)`.
359
+ Slots may optionally be named, e.g., `stimulus_names=("ref", "comp")` enables
360
+ `data.stimulus("ref")` alongside positional `data.stimuli[:, 0, :]`.
361
+
362
+ **For the oddity task, `K` is 2, not 3.** The observer is shown three stimuli, but only
363
+ the two distinct means are stored; presenting the reference twice is encoded in
364
+ `OddityTask`, which draws two samples from the reference distribution and one from the
365
+ comparison. `K` counts stored stimuli, not presentations.
366
+
367
+ ### Added
368
+
369
+ - **`psyphy.data.published`** loaders for published datasets, starting with
370
+ `hong2025`: `fetch`, `fetch_calibration_matrix`, `load_calibration_matrix`,
371
+ `load_trials`, `load_reference_W`, `load_sigma_table`, `build_paper_model`,
372
+ `w2d_to_rgb`, `default_data_dir`. Datasets are downloaded on demand (resumable, cached
373
+ outside the repo) rather than shipped with the package.
374
+ - **`psyphy.viz`** : `plot_ellipses`, plus `auto_scale` and `ellipse_segments`. The
375
+ geometry is separated from the drawing layer so it is testable without a plotting
376
+ backend, and `matplotlib` is imported lazily.
377
+ - **Threshold prediction as first-class API** , `WPPMPredictivePosterior(...,
378
+ threshold_pred=True)` with a `ThresholdConfig`, recovering threshold contours by
379
+ numerically inverting `P(correct)`. In this mode `X` is bare reference points of shape
380
+ `(n_test, input_dim)` rather than paired stimuli.
381
+ - **1-D WPPM support** `input_dim=1` is now handled by the Chebyshev basis, the
382
+ prior, and the covariance-field computation, alongside the existing 2-D and 3-D cases.
383
+ - **A distributional layer in the likelihood hierarchy**
384
+ `BernoulliTaskLikelihood` and `GaussianTaskLikelihood` sit between `TaskLikelihood` and
385
+ concrete tasks, each providing `loglik` and `simulate` so a new task only implements
386
+ `predict`. `OddityTask` is now a `BernoulliTaskLikelihood`.
387
+ - **`reduction` on `MAPOptimizer`** `"mean"` (new default) or `"sum"`, controlling how
388
+ the per-trial objective is aggregated. This interacts with gradient clipping: under
389
+ `"sum"` the gradient scales with the number of trials, so a learning rate tuned on one
390
+ dataset size does not transfer. `"mean"` makes learning rates comparable to those
391
+ reported by Hong et al 2025.
392
+ - **Tutorials** reproduction of Hong et al. (2025) Figure 2B (threshold contours) from the published data,
393
+ recovery of Weber's law with a flexible WPPM, and ellipse-field plotting.
394
+ - **Tests**: `test_data_published_hong2025.py`, `test_viz.py`, `test_docs_recipe.py`
395
+ (parses the code quoted in the docs and checks every call against the live API),
396
+ `test_quick_start_recovery.py`, `test_map_optimizer_clipping.py`,
397
+ `test_likelihood_logic.py`, `test_data_format.py`.
398
+
399
+ ### Fixed
400
+
401
+ - **Response-shape broadcasting in the Bernoulli log-likelihood** (#140). With
402
+ `responses` of shape `(N, 1)` and probabilities of shape `(N,)`, `jnp.where` broadcast
403
+ to `(N, N)`, so the summed objective mixed every trial's response with every trial's
404
+ probability and the gradient was wrong. Responses are now reduced to `(N,)` first.
405
+ - **Deprecated `jax.tree_map` replaced** with `jax.tree.map` (#71, thanks
406
+ @rohansood10).
407
+
408
+ ### Changed
409
+
410
+ - `requires-python` is `>=3.10`; CI runs lint, type checks, and tests on 3.10, 3.11, and
411
+ 3.12.
412
+ - Documentation pages now quote code from the runnable scripts beside them via snippet
413
+ includes, so a page and its script cannot drift apart.
414
+
415
+ ## [0.0.4] - 2026-03-31
416
+
417
+ Likelihood refactor. `loglik` and `simulate` became concrete methods on
418
+ `TaskLikelihood`, so a concrete task implements only `predict`; `OddityTask` lost its own
419
+ `loglik` and the duplicated vectorised Monte Carlo path (`likelihood.py` net −200 lines).
420
+ Documentation restructuring.
421
+
422
+ ## [0.0.2] - 2026-03-27
423
+
424
+ First release published to PyPI. Full initial module set: `psyphy.model` (WPPM, priors,
425
+ noise models, the oddity task), `psyphy.inference` (MAP optimizer), `psyphy.posterior`,
426
+ `psyphy.data`, `psyphy.utils`.
427
+
428
+ [Unreleased]: https://github.com/flatironinstitute/psyphy/compare/v0.0.6...HEAD
429
+ [0.0.6]: https://github.com/flatironinstitute/psyphy/compare/v0.0.5...v0.0.6
430
+ [0.0.5]: https://github.com/flatironinstitute/psyphy/compare/v0.0.4...v0.0.5
431
+ [0.0.4]: https://github.com/flatironinstitute/psyphy/compare/v0.0.2...v0.0.4
432
+ [0.0.2]: https://github.com/flatironinstitute/psyphy/releases/tag/v0.0.2
@@ -1,10 +1,11 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: psyphy
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: Adaptive Trial Placement for Psychophysical Experiments
5
5
  Project-URL: Homepage, https://flatironinstitute.github.io/psyphy
6
6
  Project-URL: Repository, https://github.com/flatironinstitute/psyphy
7
7
  Project-URL: Issues, https://github.com/flatironinstitute/psyphy/issues
8
+ Project-URL: Changelog, https://flatironinstitute.github.io/psyphy/changelog/
8
9
  Author: Hanna Dettki, Alex Williams
9
10
  Maintainer: Hanna Dettki
10
11
  License: MIT License
@@ -37,15 +38,31 @@ Requires-Dist: jax>=0.4.28
37
38
  Requires-Dist: numpy>=1.22
38
39
  Requires-Dist: optax>=0.2.4
39
40
  Requires-Dist: scipy>=1.7
41
+ Provides-Extra: cuda
42
+ Requires-Dist: jax[cuda12]>=0.4.28; extra == 'cuda'
40
43
  Provides-Extra: dev
41
- Requires-Dist: mypy>=1.0; extra == 'dev'
44
+ Requires-Dist: mypy==2.4.0; extra == 'dev'
42
45
  Requires-Dist: pre-commit>=3.0; extra == 'dev'
43
46
  Requires-Dist: pytest>=8.0; extra == 'dev'
44
47
  Requires-Dist: ruff>=0.9; extra == 'dev'
48
+ Provides-Extra: diagnostics
49
+ Requires-Dist: arviz>=1.0; (python_version >= '3.12') and extra == 'diagnostics'
45
50
  Provides-Extra: docs
46
- Requires-Dist: jupyterlab>=4.0; extra == 'docs'
47
- Requires-Dist: matplotlib>=3.5; extra == 'docs'
48
- Requires-Dist: seaborn>=0.13; extra == 'docs'
51
+ Requires-Dist: mkdocs-material>=9.7; extra == 'docs'
52
+ Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
53
+ Requires-Dist: mkdocstrings[python]>=1.0; extra == 'docs'
54
+ Requires-Dist: pymdown-extensions>=11.0; extra == 'docs'
55
+ Provides-Extra: examples
56
+ Requires-Dist: jupyterlab>=4.0; extra == 'examples'
57
+ Requires-Dist: matplotlib>=3.5; extra == 'examples'
58
+ Requires-Dist: seaborn>=0.13; extra == 'examples'
59
+ Requires-Dist: tqdm>=4.66; extra == 'examples'
60
+ Provides-Extra: progress
61
+ Requires-Dist: tqdm>=4.66; extra == 'progress'
62
+ Provides-Extra: sampling
63
+ Requires-Dist: blackjax<2,>=1.4; (python_version >= '3.11') and extra == 'sampling'
64
+ Provides-Extra: viz
65
+ Requires-Dist: matplotlib>=3.5; extra == 'viz'
49
66
  Description-Content-Type: text/markdown
50
67
 
51
68
 
@@ -68,26 +85,41 @@ Description-Content-Type: text/markdown
68
85
 
69
86
  ## Overview
70
87
 
71
- `psyphy` is an open-source, JAX-based framework for psychophysics research. It leverages GPU acceleration and efficient approximate inference to power Bayesian, active-learning-driven adaptive experiments.
88
+ `psyphy` is an open-source, JAX-based package for psychophysics research. It fits Bayesian
89
+ models of perceptual discrimination, currently the Wishart Process Psychophysical Model
90
+ (WPPM), on CPU or GPU. A fit gives either a single maximum a posteriori (MAP) estimate or
91
+ samples from the full posterior with the No-U-Turn Sampler (NUTS). The aim is to use that
92
+ posterior to choose the next trial in an adaptive experiment.
72
93
 
73
- Designed to be modular and extensible, `psyphy` accelerates research workflows and enables real-time adaptive experiments. While currently focused on human color perception, it can be adapted to other perceptual modalities.
94
+ The examples so far are on human color perception, but the model applies to any stimulus
95
+ space where discrimination noise varies smoothly.
74
96
 
75
97
  The package is under active development, and we welcome contributions.
76
98
 
77
99
  ## Install
78
- `psyphy` only supports python 3.10+. We recommend installing `psyphy` under a virtual environment. Once you've created a virtual environment for `psyphy` and activated it, you can install `psyphy` using pip:
100
+ `psyphy` supports Python 3.10 and later. We recommend installing `psyphy` under a virtual environment. Once you've created a virtual environment for `psyphy` and activated it, you can install `psyphy` using pip:
79
101
 
80
102
  ```bash
81
103
  pip install psyphy
82
104
  ```
83
105
 
84
- If you're developer or want to use the latest features, you can install from GitHub using:
106
+ If you're a developer or want the latest features, install from GitHub:
85
107
  ```bash
86
- git clone https://flatironinstitute.github.io/psyphy.git
108
+ git clone https://github.com/flatironinstitute/psyphy.git
87
109
  cd psyphy
88
110
  pip install -e .
111
+ ```
112
+ Contributors can also use [uv](https://docs.astral.sh/uv/), which installs from the committed `uv.lock` for a reproducible environment instead of resolving the loose ranges above fresh each time; see [CONTRIBUTING.md](CONTRIBUTING.md) for the uv-based workflow.
89
113
 
114
+ ### GPU support
115
+ The commands above install a **CPU-only** `jax`. For an NVIDIA/CUDA GPU (including the Flatiron cluster), install the `cuda` extra instead:
116
+ ```bash
117
+ pip install "psyphy[cuda]" # from PyPI
118
+ pip install -e ".[cuda]" # from a clone
90
119
  ```
120
+ This pulls in JAX's own `cuda12` extra, which bundles a matching CUDA/cuDNN runtime as pip packages, so no system CUDA module needs to be loaded alongside it.
121
+
122
+ **Apple Silicon (M-series) GPUs are not supported.** JAX's Metal backend cannot do `float64`, which some `psyphy` examples require for published-precision comparisons (Apple/Google's own `jax-metal` package is also no longer maintained). On a Mac, `psyphy` runs on CPU.
91
123
 
92
124
  ## [Quickstart](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/)
93
125
  - Go [here](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/) for a light-weight tutorial that demonstrates how to instantiate, evaluate and fit a model quickly. You should be able to run the underlying [script](https://github.com/flatironinstitute/psyphy/blob/main/docs/examples/wppm/quick_start.py) on your CPU.
@@ -18,26 +18,41 @@
18
18
 
19
19
  ## Overview
20
20
 
21
- `psyphy` is an open-source, JAX-based framework for psychophysics research. It leverages GPU acceleration and efficient approximate inference to power Bayesian, active-learning-driven adaptive experiments.
21
+ `psyphy` is an open-source, JAX-based package for psychophysics research. It fits Bayesian
22
+ models of perceptual discrimination, currently the Wishart Process Psychophysical Model
23
+ (WPPM), on CPU or GPU. A fit gives either a single maximum a posteriori (MAP) estimate or
24
+ samples from the full posterior with the No-U-Turn Sampler (NUTS). The aim is to use that
25
+ posterior to choose the next trial in an adaptive experiment.
22
26
 
23
- Designed to be modular and extensible, `psyphy` accelerates research workflows and enables real-time adaptive experiments. While currently focused on human color perception, it can be adapted to other perceptual modalities.
27
+ The examples so far are on human color perception, but the model applies to any stimulus
28
+ space where discrimination noise varies smoothly.
24
29
 
25
30
  The package is under active development, and we welcome contributions.
26
31
 
27
32
  ## Install
28
- `psyphy` only supports python 3.10+. We recommend installing `psyphy` under a virtual environment. Once you've created a virtual environment for `psyphy` and activated it, you can install `psyphy` using pip:
33
+ `psyphy` supports Python 3.10 and later. We recommend installing `psyphy` under a virtual environment. Once you've created a virtual environment for `psyphy` and activated it, you can install `psyphy` using pip:
29
34
 
30
35
  ```bash
31
36
  pip install psyphy
32
37
  ```
33
38
 
34
- If you're developer or want to use the latest features, you can install from GitHub using:
39
+ If you're a developer or want the latest features, install from GitHub:
35
40
  ```bash
36
- git clone https://flatironinstitute.github.io/psyphy.git
41
+ git clone https://github.com/flatironinstitute/psyphy.git
37
42
  cd psyphy
38
43
  pip install -e .
44
+ ```
45
+ Contributors can also use [uv](https://docs.astral.sh/uv/), which installs from the committed `uv.lock` for a reproducible environment instead of resolving the loose ranges above fresh each time; see [CONTRIBUTING.md](CONTRIBUTING.md) for the uv-based workflow.
39
46
 
47
+ ### GPU support
48
+ The commands above install a **CPU-only** `jax`. For an NVIDIA/CUDA GPU (including the Flatiron cluster), install the `cuda` extra instead:
49
+ ```bash
50
+ pip install "psyphy[cuda]" # from PyPI
51
+ pip install -e ".[cuda]" # from a clone
40
52
  ```
53
+ This pulls in JAX's own `cuda12` extra, which bundles a matching CUDA/cuDNN runtime as pip packages, so no system CUDA module needs to be loaded alongside it.
54
+
55
+ **Apple Silicon (M-series) GPUs are not supported.** JAX's Metal backend cannot do `float64`, which some `psyphy` examples require for published-precision comparisons (Apple/Google's own `jax-metal` package is also no longer maintained). On a Mac, `psyphy` runs on CPU.
41
56
 
42
57
  ## [Quickstart](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/)
43
58
  - Go [here](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/) for a light-weight tutorial that demonstrates how to instantiate, evaluate and fit a model quickly. You should be able to run the underlying [script](https://github.com/flatironinstitute/psyphy/blob/main/docs/examples/wppm/quick_start.py) on your CPU.