Quick Start¶
This walkthrough simulates data from a simple Rescorla-Wagner reinforcement-learning model, fits it back with EMModel, and inspects the resulting group- and subject-level estimates. It uses the same rw1a1b model family shown in the Model-Free Reinforcement Learning example.
Walking through the steps:
- Simulate.
true_paramsare drawn in unbounded Gaussian space (the space the EM optimizer works in) and mapped to natural-space values withnorm2beta(inverse temperature, bounded to(0, 20)) andnorm2alpha(learning rate, bounded to(0, 1)).rw1a1b_simtakes natural-space parameters and simulates choices and rewards for each subject across blocks and trials. - Package the data.
EMModelexpectsall_datato be a list with one entry per subject; each subject's entry is the exact list of positional arguments (afterparams) that the model's fit function expects — here[choices, rewards], matchingrw1a1b_fit(params, choices, rewards, ...). - Fit.
EMModel(...)bundles the data, the fit function, the parameter names, and theparam_xformlist (the samenorm2beta/norm2alphatransforms used to simulate) so that the optimizer can search in Gaussian space while reporting natural-space values..fit()runs the EM loop and returns aFitResult. - Inspect.
model.subject_params()returns MAP estimates in natural space, one row per subject.result.posterior_muis the fitted group-level mean (in Gaussian space), andresult.convergencereports whether the EM loop converged. Alsomodel.outfitcontains the per-subject diagnostics dictionary returned byrw1a1b_fit(..., output="all"), which includes the negative log-likelihood and any other trialwise quantities you choose to return.