API reference#
Reference for simulation, fitting, parameters, and response-data utilities.
LBA model#
- class pyLBA.models.linear_ballistic_accumulator.LBAParameters(A, b, v, s, tau)#
Starting-point bound, threshold, drift mean/SD, and non-decision time.
- Parameters:
A (float | ndarray)
b (float | ndarray)
v (float | ndarray)
s (float | ndarray)
tau (float | ndarray)
- validate()#
Check numeric values have compatible shapes and valid LBA support.
- class pyLBA.models.linear_ballistic_accumulator.LBAModel#
An LBA race with normal drifts independently truncated above zero.
Each accumulator has a uniform starting point and constant drift per trial. The first accumulator to reach its threshold determines the response.
- generate_data(n_trials, parameters, n_acc=None, seed=None)#
Simulate response times and choices with an optional random seed.
- pdf(rt, response, parameters, n_acc=None)#
Return a symbolic joint density of response time and choice.
Scalars broadcast across accumulators. Vector parameters must match
n_acc. Density is zero outside parameter and response-time support.
- get_parameter_class()#
Return
LBAParameters.
- get_default_priors(n_acc, priors=None, rt_min=1.0)#
Create priors in the active PyMC model, with optional overrides.
Overrides are fixed numeric values or callables
(name, n_acc)returning a PyMC variable. Defaults use positive A, b=A+gap, unit drift SD, normal drift means, and tau below the shortest observed RT.
Simulation#
- pyLBA.synthetic.generate_LBA(n_trials, parameters, n_acc=None, seed=None)#
Generate synthetic response time and choice data for an accumulator model.
- Parameters:
n_trials (int) – Number of trials to simulate.
parameters (LBAParameters) – Model parameters with fields A, b, v, s, tau.
n_acc (int, optional) – Number of accumulators.
seed (int, optional) – Random seed for reproducibility.
- Returns:
DataFrame with columns ‘rt’ and ‘response’.
- Return type:
pd.DataFrame
Core interfaces#
Import core classes from pyLBA or pyLBA.core.
- class pyLBA.core.parameters.Parameter(name, value)#
A scalar or vector parameter, including symbolic PyTensor values.
- class pyLBA.core.parameters.ModelParameters#
Base dataclass for named scalar or vector parameters.
- to_dict()#
Return unwrapped parameter values, keyed by field name.
- classmethod from_dict(values)#
Create parameters from a mapping of field names to values.
- class pyLBA.core.accumulator.AccumulatorModel(name='AccumulatorModel')#
Abstract base class for accumulator models.
All accumulator models should inherit from this class and implement the required abstract methods.
- Parameters:
name (str)
- abstract pdf(rt, response, parameters, **kwargs)#
Compute the probability density function.
- Parameters:
rt (np.ndarray) – Response times
response (np.ndarray) – Response choices (0-indexed)
parameters (ModelParameters) – Model parameters
- Returns:
Probability density
- Return type:
pt.TensorVariable
- abstract get_parameter_class()#
Return the parameter class for this model.
- Return type:
type
- fit_mcmc(data, **kwargs)#
Fit model using MCMC.
- Parameters:
data (pd.DataFrame) – Data with columns ‘rt’ and ‘response’
**kwargs – Additional arguments passed to the fitter
- Returns:
Fitted model instance
- Return type:
- fit_em(data, **kwargs)#
Fit model using Expectation-Maximization.
- Parameters:
data (pd.DataFrame) – Data with columns ‘rt’ and ‘response’
**kwargs – Additional arguments passed to the fitter
- Returns:
Fitted model instance
- Return type:
- predict(n_trials, **kwargs)#
Generate predictions using posterior mean parameters.
- Parameters:
n_trials (int) – Number of trials to simulate
**kwargs – Additional arguments
- Returns:
Predicted data
- Return type:
pd.DataFrame
- property fitted: bool#
Check if model has been fitted.
- property trace#
Get MCMC trace if available.
- property parameters#
Get fitted parameters if available.
Fitters#
- class pyLBA.fitting.MCMCFitter(model)#
MCMC fitting using PyMC.
- fit(data, draws=1000, tune=1000, chains=4, cores=4, progressbar=True, priors=None, n_acc=None, **kwargs)#
Sample the posterior and return ArviZ InferenceData.
priorsmaps parameter names to fixed numeric values or callables(name, n_acc)creating PyMC variables inside the fitting model.n_accdefaults to the largest response label plus one. Set it explicitly when higher-numbered choices are absent from the data. Remaining keyword arguments are forwarded topymc.sample.
Utilities#
Utilities for parameter broadcasting and response data.
- pyLBA.utils.infer_n_acc(parameters, response=None, n_acc=None)#
Infer race size from parameter vectors and observed choice labels.
- pyLBA.utils.broadcast_parameters(n, *args)#
Broadcast numeric or symbolic scalars to vectors of length
n.
- pyLBA.utils.validate_data(data)#
Require finite positive times and non-negative integer response labels.
- pyLBA.utils.check_convergence(trace, r_hat_threshold=1.01)#
Return whether all reported R-hat values are finite and below a limit.