Skip to content

remeta.modelspec.Parameter

Definition of ReMeta parameter

Usage

The Parameter class should only be used in the context of a Configuration instance. This ensures that sensible defaults are used for unspecified attributes of the parameter.

cfg = remeta.Configuration()

Disable parameter: cfg.param_type1_bias.enable = False

Enable parameter: cfg.param_type1_thresh.enable = True

Change the initial guess: cfg.param_type1_noise.guess = 0.8

Change parameter bounds: cfg.param_type1_noise.bounds = (1e-2, 2)

Change values visited during grid search: cfg.param_type1_noise.grid_range = np.arange(0.1, 0.5, 0.05)

Make a parameter a group-level (e.g. random-effects) parameter: cfg.param_type1_thresh.group = 'random'

Create a parameter prior with (mean, SD): cfg.param_type1_bias.prior = (0, 0.1)

Change the noise distribution: cfg.param_type1_noise.model = 'logistic'

Parameters:

Name Type Description Default
enable bool

Enable or disable a parameter.

False: disabled;

True: enabled;

None
asym bool

Enable or disable asymmetric fit. For type 1 parameters this creates stimulus-specific parameters. ToDo (not yet implemented): for type 2 parameters this should create response-specific parameters.

False: disabled;

True: enabled;

False
guess float

Initial guess for parameter optimization

None
bounds list[float]

Parameter bounds of the form [lower bound, upper bound].

None
grid_range list[float] | NDArray[float]

1-d grid for initial gridsearch in the parameter optimization procedure.

None
group None | str

None: no group-level estimate for the parameter

'fixed': fit parameter as a group fixed effect (i.e., single value for the group)

'random': fit parameter as a random effect (enforces shrinkage towards a group mean)

None
prior None | tuple[float, float]

None: no prior for the parameter (group_mean, group_sd): apply a Normal prior defined by mean and standard deviation

None
preset None | float

(not yet supported) Instead of fitting a parameter, set it to a fixed value. Note that this automatically disables the parameter, i.e. parameter.enable will be set to False.

None
default None | float

This an internal attribute, that should typically not be touched. It specifies a default value for a parameter that may be used if the parameter is not fitted.

None
model None | str

For noise parameters, specifies an appropriate sampling distribution. For other parameters, it may specify a function that is parameterized.

None
Source code in remeta/modelspec.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class Parameter(ReprMixin):
    """Definition of ReMeta parameter

    Usage:
        The Parameter class should only be used in the context of a
        [`Configuration`][remeta.configuration.Configuration] instance. This ensures that sensible defaults are used
        for unspecified attributes of the parameter.

        ```
        cfg = remeta.Configuration()
        ```

        Disable parameter: `cfg.param_type1_bias.enable = False`

        Enable parameter: `cfg.param_type1_thresh.enable = True`

        Change the initial guess: `cfg.param_type1_noise.guess = 0.8`

        Change parameter bounds: `cfg.param_type1_noise.bounds = (1e-2, 2)`

        Change values visited during grid search: `cfg.param_type1_noise.grid_range = np.arange(0.1, 0.5, 0.05)`

        Make a parameter a group-level (e.g. random-effects) parameter: `cfg.param_type1_thresh.group = 'random'`

        Create a parameter prior with (mean, SD): `cfg.param_type1_bias.prior = (0, 0.1)`

        Change the noise distribution: `cfg.param_type1_noise.model = 'logistic'`


    Args:
        enable:
            Enable or disable a parameter.

            `False`: disabled;

            `True`: enabled;
        asym:
            Enable or disable asymmetric fit. For type 1 parameters this creates stimulus-specific parameters.
            ToDo (not yet implemented): for type 2 parameters this should create response-specific parameters.

            `False`: disabled;

            `True`: enabled;
        guess:
            Initial guess for parameter optimization
        bounds:
            Parameter bounds of the form [lower bound, upper bound].
        grid_range:
            1-d grid for initial gridsearch in the parameter optimization procedure.
        group:
            `None`: no group-level estimate for the parameter

            `'fixed'`: fit parameter as a group fixed effect (i.e., single value for the group)

            `'random'`: fit parameter as a random effect (enforces shrinkage towards a group mean)
        prior:
            `None`: no prior for the parameter
            (group_mean, group_sd): apply a Normal prior defined by mean and standard deviation
        preset:
            (not yet supported) Instead of fitting a parameter, set it to a fixed value. Note that this
            automatically disables the parameter, i.e. parameter.enable will be set to False.
        default:
            This an internal attribute, that should typically not be touched. It specifies a default value
            for a parameter that may be used if the parameter is not fitted.
        model:
            For noise parameters, specifies an appropriate sampling distribution.
            For other parameters, it may specify a function that is parameterized.
    """
    def __init__(
        self,
        enable: bool = None,
        asym: bool = False,
        guess: float  = None,
        bounds: list[float] = None,
        grid_range: list[float] | np.typing.NDArray[float] = None,
        group: None | str = None,
        prior: None | tuple[float, float] = None,
        preset: None | float = None,
        default: None | float = None,
        model: None | str = None
    ):

        self.enable = enable if preset is None else False
        self.asym = asym
        self.guess = guess
        self.bounds = bounds
        self.grid_range = np.linspace(bounds[0], bounds[1], 4) if grid_range is None else grid_range
        self.group = group
        self.prior = prior
        self.preset = preset
        self.default = default
        self.model = model
        self._definition_changed = False

    def copy(self):
        new = self.__class__.__new__(self.__class__)
        new.__dict__ = {
            k: v.copy() if isinstance(v, (dict, np.ndarray))
            else v[:] if isinstance(v, list)
            else v
            for k, v in self.__dict__.items()
        }
        new._definition_changed = False
        return new

    def __copy__(self):
        return self.copy()

    def __setattr__(self, name, value):
        if name not in ('_definition_changed', 'enable', 'preset') and hasattr(self, name):
            old_value = getattr(self, name)
            if isinstance(old_value, np.ndarray) and isinstance(value, np.ndarray):
                changed = not np.array_equal(old_value, value)
            else:
                changed = old_value != value
            if changed:
                super().__setattr__("_definition_changed", True)

        super().__setattr__(name, value)