You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #131 from hmd101/likelihood-api
### Likelihood refactor:
- subclasses of likelihood now only need to implement predict, because log_likelihood vmaps over predict
- added a simulate method that creates synthetic data based on a task likelihood
Copy file name to clipboardExpand all lines: docs/examples/wppm/full_wppm_fit_example.md
+8-39Lines changed: 8 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,8 +69,7 @@ For OddityTask, we store trials as (ref, comparison) even though the task involv
69
69
70
70
Note on data used in this script: here, we simulate data (and hence have a ground truth to compare agains). To how to conveniently simulate data yourself, checkout the [script](https://github.com/flatironinstitute/psyphy/blob/main/docs/examples/wppm/full_wppm_fit_example.py)
71
71
72
-
<details>
73
-
<summary>### 2 ways of representing data in `psyphy` (important)</summary>
72
+
### 2 ways of representing data in `psyphy` (important)
74
73
`psyphy` provides two lightweight containers for trial data (defined in [`src/psyphy/data/dataset.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/data/dataset.py)):
75
74
76
75
**`TrialData` (compute-first; used for fitting):**
Note that here, we simlulate data, for details check out [`full_wppm_fit_example.py`](full_wppm_fit_example.py) directly resulting in a `TrialData` object.
99
-
</details>
98
+
100
99
101
100
---
102
101
@@ -109,8 +108,7 @@ The WPPM parameters are basis weights stored as a dict:
109
108
where `W` is a tensor of Chebyshev-basis coefficients.
110
109
111
110
112
-
<details>
113
-
<summary>### Prior distribution over weights:</summary>
111
+
### Prior distribution over weights:
114
112
115
113
`Prior.sample_params(key)` samples weights `W` from a **zero-mean Gaussian** with a *degree-dependent variance*.
This is the state of the WPPM: **before any data**, WPPM draws smooth random fields because high-frequency coefficients are shrunk by the decay.
149
-
</details>
147
+
150
148
151
149
---
152
150
@@ -240,43 +238,14 @@ To see how we generate the covariance field figures, checkout the plotting code
240
238
---
241
239
242
240
## To recap: Minimal recipe (copy/paste mental model)
241
+
We are Bayesian, so we need to define the Prior and Likelihood and choose an inference method (here MAP) that will hand us the posterior distribution over the parameters.
243
242
244
-
To use WPPM on your own data, these are the essential calls:
For an even more minimal code setup that doesn't require a GPU but will run on your CPU in < 1 min, you may find [`quickstart`](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/) helpful.
275
244
---
276
245
277
246
## Notes and pitfalls
278
247
279
-
-**CPU vs GPU:** this example can be heavy because the oddity likelihood uses Monte Carlo. A GPU can help a lot.
248
+
-**CPU vs GPU:** this example can be heavy because the oddity likelihood uses Monte Carlo. A GPU can help a lot, see [`quickstart`](https://flatironinstitute.github.io/psyphy/examples/wppm/quick_start/) for a CPU friendly version.
280
249
-**Positive definiteness:**`diag_term` is important. If you ever see a non-PD covariance, increase `diag_term` slightly.
281
250
-**MC variance:** optimization stability depends on `MC_SAMPLES`. Too small means noisy gradients.
282
251
@@ -308,7 +277,7 @@ instead of using relative filesystem paths.
308
277
- MAP fitting: [`src/psyphy/inference/map_optimizer.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/inference/map_optimizer.py) (see `MAPOptimizer`)
309
278
- Data container: [`src/psyphy/data/dataset.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/data/dataset.py) (see `ResponseData`)
310
279
311
-
If you want to “follow the call graph”:
280
+
If you want to "follow the call graph":
312
281
313
282
1.`WPPM.init_params(...)` (defined in [`src/psyphy/model/wppm.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/model/wppm.py)) → delegates to the prior’s `Prior.sample_params(...)` (defined in [`src/psyphy/model/prior.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/model/prior.py)).
314
283
2.`OddityTask.predict_with_kwargs(...)` / `OddityTask.loglik(...)` (defined in [`src/psyphy/model/likelihood.py`](https://github.com/flatironinstitute/psyphy/blob/main/src/psyphy/model/likelihood.py)) → calls into the model to get $\Sigma(x)$ and then runs the task’s decision rule (Monte Carlo in the full model).
0 commit comments