Parameter-transform API¶
ParameterTransform is the canonical abstract interface for sampling- and
simulation-time parameter transforms. ParameterAdaptation is its
backward-compatible public alias under
ssms.basic_simulators.parameter_adapters.
Use Write a custom parameter transform for the implementation and testing workflow.
ssms.transforms.base.ParameterTransform ¶
Bases: ABC
Abstract base class for all parameter transforms.
A parameter transform is a single, focused operation that modifies theta parameters. Transforms can be composed into pipelines and are used at two phases:
-
Sampling phase: Applied after parameter sampling to enforce constraints (e.g., ensure a > z by swapping values)
-
Simulation phase: Applied before calling the simulator to prepare parameters for the expected format (e.g., stack v0, v1 → v)
Subclasses must implement the apply method. The method signature
includes optional model_config and n_trials arguments to support
both simple constraints (which only need theta) and complex adapters
(which may need additional context).
Examples:
Create a custom transform:
>>> class ScaleParameter(ParameterTransform):
... def __init__(self, param_name: str, scale: float):
... self.param_name = param_name
... self.scale = scale
...
... def apply(self, theta, model_config=None, n_trials=None):
... if self.param_name in theta:
... theta[self.param_name] = theta[self.param_name] * self.scale
... return theta
Use in model config:
>>> model_config = {
... "name": "my_model",
... "parameter_transforms": {
... "sampling": [SwapIfLessConstraint("a", "z")],
... "simulation": [ColumnStackParameters(["v0", "v1"], "v")],
... }
... }
Methods:
-
apply–Apply transform to theta parameters.
ssms.transforms.base.ParameterTransform.apply
abstractmethod
¶
apply(theta: dict[str, Any], model_config: dict[str, Any] | None = None, n_trials: int | None = None) -> dict[str, Any]
Apply transform to theta parameters.
This method should modify the theta dictionary in place and return it. It may add new parameters, modify existing parameters, or remove parameters as needed.
Parameters:
-
theta(dict[str, Any]) –Dictionary of model parameters. Values are typically numpy arrays.
-
model_config(dict[str, Any] or None, default:None) –Model configuration dictionary. Available for transforms that need additional context (e.g., looking up simulator_fixed_params). Sampling-time transforms typically ignore this.
-
n_trials(int or None, default:None) –Number of trials. Available for transforms that need to create arrays of a specific size. Sampling-time transforms typically ignore this.
Returns:
Notes
- Transforms should be pure when possible (no side effects)
- If creating new arrays, use dtype=np.float32 for consistency
- Document any parameters that are added, modified, or removed
Adapter registry¶
The compatibility namespace also exports ParameterAdapterRegistry,
register_adapter_to_model, register_adapter_to_model_family, and
get_adapter_registry. Their generated reference remains on the
basic simulators API; this page owns the canonical
transform interface and alias relationship without rendering those objects a
second time.