hssm.HSSM
Use hssm.HSSM class to construct an HSSM model.
hssm.HSSM ¶
HSSM(
data: DataFrame,
model: SupportedModels | str = "ddm",
choices: list[int] | None = None,
include: list[dict[str, Any] | Any] | None = None,
model_config: ModelConfig | dict | None = None,
loglik: str
| PathLike
| Callable
| Distribution
| type[Distribution]
| None = None,
loglik_kind: LoglikKind | None = None,
p_outlier: float | dict | Prior | None = 0.05,
lapse: float | dict | Prior | None = None,
global_formula: str | None = None,
link_settings: Literal["log_logit"] | None = None,
prior_settings: Literal["safe"] | None = "safe",
extra_namespace: dict[str, Any] | None = None,
missing_data: bool | float = False,
deadline: bool | str = False,
loglik_missing_data: str | PathLike | Callable | None = None,
process_initvals: bool = True,
initval_jitter: float = INITVAL_JITTER_SETTINGS["jitter_epsilon"],
**kwargs: Any,
)
Bases: HSSMBase
The basic Hierarchical Sequential Sampling Model (HSSM) class.
Parameters:
-
data(DataFrame) –A pandas DataFrame with the minimum requirements of containing the data with the columns "rt" and "response".
-
model(SupportedModels | str, default:'ddm') –The name of the model to use. Currently supported models are "ddm", "ddm_sdv", "full_ddm", "angle", "levy", "ornstein", "weibull", "race_no_bias_angle_4", "ddm_seq2_no_bias". If any other string is passed, the model will be considered custom, in which case all
model_config,loglik, andloglik_kindhave to be provided by the user. -
choices(optional, default:None) –When an
int, the number of choices that the participants can make. If2, the choices are [-1, 1] by default. If anything greater than2, the choices are [0, 1, ..., n_choices - 1] by default. If alistis provided, it should be the list of choices that the participants can make. Defaults to2. If any value other than the choices provided is found in the "response" column of the data, an error will be raised. -
include(optional, default:None) –A list of dictionaries specifying parameter specifications to include in the model. If left unspecified, defaults will be used for all parameter specifications. Defaults to None.
-
model_config(optional, default:None) –A
hssm.config.BaseModelConfig/hssm.config.Configinstance or adictwith model configuration information. The constructor accepts a typedModelConfigor a plaindict; when adictis provided the library will build a typedConfigvia the factory function. IfNoneis provided, defaults will be used where available. Fields for this config are usually:"list_params": a list of parameters indicating the parameters of the model. The order in which the parameters are specified in this list is important. Values for each parameter will be passed to the likelihood function in this order."backend": Only used whenloglik_kindisapprox_differentiableand an onnx file is supplied for the likelihood approximation network (LAN). Valid values are"jax"or"pytensor". It determines whether the LAN in ONNX should be converted to"jax"or"pytensor". If not provided,jaxwill be used for maximum performance."default_priors": Adictindicating the default priors for each parameter."bounds": Adictindicating the boundaries for each parameter. In the case of LAN, these bounds are training boundaries."rv": Optional. Can be aRandomVariableclass containing the user's ownrng_fnfunction for sampling from the distribution that the user is supplying. If not supplied, HSSM will automatically generate aRandomVariableusing the simulator identified bymodelfrom thessm_simulatorspackage. Ifmodelis not supported inssm_simulators, a warning will be raised letting the user know that sampling from theRandomVariablewill result in errors."extra_fields": Optional. A list of strings indicating the additional columns indatathat will be passed to the likelihood function for calculation. This is helpful if the likelihood function depends on data other than the observed data and the parameter values.
-
loglik(optional, default:None) –A likelihood function. Defaults to None. Requirements are:
- if
loglik_kindis"analytical"or"blackbox", a pm.Distribution, a pytensor Op, or a Python callable can be used. Signatures are:pm.Distribution: needs to have parameters specified exactly as listed inlist_paramspytensor.graph.OpandCallable: needs to accept the parameters specified exactly as listed inlist_params
- If
loglik_kindis"approx_differentiable", then in addition to the specifications above, astrorPathlikecan also be used to specify a path to anonnxfile. If astris provided, HSSM will first look locally for anonnxfile. If that is not successful, HSSM will try to download thatonnxfile from Hugging Face hub. - It can also be
None, in which case a default likelihood function will be used
- if
-
loglik_kind(optional, default:None) –A string that specifies the kind of log-likelihood function specified with
loglik. Defaults toNone. Can be one of the following:"analytical": an analytical (approximation) likelihood function. It is differentiable and can be used with samplers that requires differentiation."approx_differentiable": a likelihood approximation network (LAN) likelihood function. It is differentiable and can be used with samplers that requires differentiation."blackbox": a black box likelihood function. It is typically NOT differentiable.None, in which a default will be used. Forddmtype of models, the default will beanalytical. For other models supported, it will beapprox_differentiable. If the model is a custom one, a ValueError will be raised.
-
p_outlier(optional, default:0.05) –The fixed lapse probability or the prior distribution of the lapse probability. Defaults to a fixed value of 0.05. When
None, the lapse probability will not be included in estimation. -
lapse(optional, default:None) –The lapse distribution. This argument is required only if
p_outlieris notNone. Defaults to Uniform(0.0, 10.0). -
global_formula(optional, default:None) –A string that specifies a regressions formula which will be used for all model parameters. If you specify parameter-wise regressions in addition, these will override the global regression for the respective parameter.
-
link_settings(optional, default:None) –An optional string literal that indicates the link functions to use for each parameter. Helpful for hierarchical models where sampling might get stuck/ very slow. Can be one of the following:
"log_logit": applies log link functions to positive parameters and generalized logit link functions to parameters that have explicit bounds.None: unless otherwise specified, the"identity"link functions will be used. The default value isNone.
-
prior_settings(optional, default:'safe') –An optional string literal that indicates the prior distributions to use for each parameter. Helpful for hierarchical models where sampling might get stuck/ very slow. Can be one of the following:
"safe": HSSM will scan all parameters in the model and apply safe priors to all parameters that do not have explicit bounds.- None: HSSM will use bambi to provide default priors for all parameters. Not
recommended when you are using hierarchical models.
The default value is
"safe".
-
extra_namespace(optional, default:None) –Additional user supplied variables with transformations or data to include in the environment where the formula is evaluated. Defaults to
None. -
missing_data(optional, default:False) –Specifies whether the model should handle missing data. Can be a
boolor afloat. IfFalse, and if thertcolumn contains in the data -999.0, the model will drop these rows and produce a warning. IfTrue, the model will treat code -999.0 as missing data. If afloatis provided, the model will treat this value as the missing data value. Defaults toFalse. -
deadline(optional, default:False) –Specifies whether the model should handle deadline data. Can be a
boolor astr. IfFalse, the model will not do nothing even if a deadline column is provided. IfTrue, the model will treat thedeadlinecolumn as deadline data. If astris provided, the model will treat this value as the name of the deadline column. Defaults toFalse. -
loglik_missing_data(optional, default:None) –A likelihood function for missing data. Please see the
loglikparameter to see how to specify the likelihood function this parameter. If nothing is provided, a default likelihood function will be used. This parameter is required only if eithermissing_dataordeadlineis notFalse. Defaults toNone. -
process_initvals(optional, default:True) –If
True, the model will process the initial values. Defaults toTrue. -
initval_jitter(optional, default:INITVAL_JITTER_SETTINGS['jitter_epsilon']) –The jitter value for the initial values. Defaults to
0.01. -
noncentered(optional) –Controls the centered vs. non-centered parameterization of group-specific (hierarchical) terms.
True(bambi's default) uses the non-centered parameterization everywhere,Falseuses centered. Adictkeyed by HSSM parameter name (e.g.{"v": False, "a": True}) sets it per parameter; an unknown key raises at construction. A per-priornoncenteredfield (inside a priordictor on anhssm.Prior) overrides the model-level value for that term (precedence: per-prior > model-level dict > defaultTrue). Only affects parameters that have a group-specific term (e.g.... + (1|participant_id)); setting it for a non-hierarchical parameter is a silent no-op. Passed tobmb.Model. -
**kwargs(Any, default:{}) –Additional arguments passed to the
bmb.Modelobject.