hssm.likelihoods
The hssm.likelihoods submodule exports a few likelihood functions. These functions
are already used in the model building process for some supported models, such as ddm,
ddm_sdv, and full_ddm, so you typically would not have to deal with them. However,
they can be helpful if you want to use them to build a model yourself in PyMC. Please
checkout the this tutorial for more details.
hssm.likelihoods ¶
Likelihood functions and distributions that use them.
Modules:
-
analytical–pytensor implementation of the Wiener First Passage Time Distribution.
-
blackbox–Black box likelihoods written in Cython for "ddm" and "ddm_sdv" models.
-
rldm–The log-likelihood function for the RLDM model.
-
rldm_optimized–The log-likelihood function for the RLDM model.
Functions:
-
logp_ddm–Compute analytical likelihood for the DDM model with
sv. -
logp_ddm_bbox–Compute blackbox log-likelihoods for ddm models.
-
logp_ddm_sdv–Compute the log-likelihood of the drift diffusion model f(t|v,a,z).
-
logp_ddm_sdv_bbox–Compute blackbox log-likelihoods for ddm_sdv models.
-
logp_full_ddm–Compute blackbox log-likelihoods for full_ddm models.
-
logp_poisson_race–Compute analytical log-likelihoods for a 2-accumulator Poisson race.
hssm.likelihoods.logp_ddm ¶
logp_ddm(
data: ndarray,
v: float,
a: float,
z: float,
t: float,
err: float = 1e-15,
k_terms: int = 20,
epsilon: float = 1e-15,
) -> np.ndarray
Compute analytical likelihood for the DDM model with sv.
Computes the log-likelihood of the drift diffusion model f(t|v,a,z) using the method and implementation of Navarro & Fuss, 2009.
Parameters:
-
data(ndarray) –data: 2-column numpy array of (response time, response)
-
v(float) –Mean drift rate. (-inf, inf).
-
a(float) –Value of decision upper bound. (0, inf).
-
z(float) –Normalized decision starting point. (0, 1).
-
t(float) –Non-decision time [0, inf).
-
err(float, default:1e-15) –Error bound.
-
k_terms(int, default:20) –number of terms to use to approximate the PDF.
-
epsilon(float, default:1e-15) –A small positive number to prevent division by zero or taking the log of zero.
Returns:
-
ndarray–The analytical likelihoods for DDM.
hssm.likelihoods.logp_ddm_bbox ¶
Compute blackbox log-likelihoods for ddm models.
hssm.likelihoods.logp_ddm_sdv ¶
logp_ddm_sdv(
data: ndarray,
v: float,
a: float,
z: float,
t: float,
sv: float,
err: float = 1e-15,
k_terms: int = 20,
epsilon: float = 1e-15,
) -> np.ndarray
Compute the log-likelihood of the drift diffusion model f(t|v,a,z).
Using the method and implementation of Navarro & Fuss, 2009.
Parameters:
-
data(ndarray) –2-column numpy array of (response time, response)
-
v(float) –Mean drift rate. (-inf, inf).
-
a(float) –Value of decision upper bound. (0, inf).
-
z(float) –Normalized decision starting point. (0, 1).
-
t(float) –Non-decision time [0, inf).
-
sv(float) –Standard deviation of the drift rate [0, inf).
-
err(float, default:1e-15) –Error bound.
-
k_terms(int, default:20) –number of terms to use to approximate the PDF.
-
epsilon(float, default:1e-15) –A small positive number to prevent division by zero or taking the log of zero.
Returns:
-
ndarray–The log likelihood of the drift diffusion model with the standard deviation of sv.
hssm.likelihoods.logp_ddm_sdv_bbox ¶
Compute blackbox log-likelihoods for ddm_sdv models.
hssm.likelihoods.logp_full_ddm ¶
Compute blackbox log-likelihoods for full_ddm models.
hssm.likelihoods.logp_poisson_race ¶
logp_poisson_race(
data: ndarray,
r1: float,
r2: float,
k1: float,
k2: float,
t: float,
epsilon: float = 1e-15,
) -> np.ndarray
Compute analytical log-likelihoods for a 2-accumulator Poisson race.
Each accumulator time follows a Gamma distribution with continuous shape parameter k and rate r. The per-trial likelihood decomposes into the density of the winning accumulator evaluated at the observed decision time and the survival function of the losing accumulator at the same time.
Implemented as in https://link.springer.com/article/10.3758/BF03212980 with two modifications: 1. We allow continuous shape parameters (k1, k2) rather than just integers. 2. We do not condition on the underlying stimulus condition.
Parameters:
-
data(ndarray) –2-column tensor of (response time, response). Response > 0 indicates accumulator 2 (the second accumulator, parameters
r2/k2); otherwise accumulator 1 (the first accumulator,r1/k1). This matches simulators that encode choices as-1for winner index 0 and+1for winner index 1. -
r1(float) –Rates (> 0) for the two accumulators.
-
r2(float) –Rates (> 0) for the two accumulators.
-
k1(float) –Shape parameters (> 0) for the two accumulators.
-
k2(float) –Shape parameters (> 0) for the two accumulators.
-
t(float) –Non-decision time [0, inf).
-
epsilon(float, default:1e-15) –A small positive number to prevent division by zero or taking
log(0).
Returns:
-
ndarray–Per-trial log-likelihoods (shape:
(n_trials,)).Note that this function constructs a symbolic PyTensor graph; when used inside a PyMC/PyTensor model the returned object is a symbolic tensor, and evaluating/compiling the graph yields an ndarray.