Optimization
TypeOptimizer
¶
optax
wrapper which allows different argument values for different params.
Source code in jaxley/optimize/optimizer.py
9 10 11 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 |
|
__init__(optimizer, optimizer_args, opt_params)
¶
Create the optimizers.
This requires access to opt_params
in order to know how many optimizers
should be created. It creates len(opt_params)
optimizers.
Example usage:
lrs = {"HH_gNa": 0.01, "radius": 1.0}
optimizer = TypeOptimizer(lambda lr: optax.adam(lr), lrs, opt_params)
opt_state = optimizer.init(opt_params)
optimizer_args = {"HH_gNa": [0.01, 0.4], "radius": [1.0, 0.8]}
optimizer = TypeOptimizer(
lambda args: optax.sgd(args[0], momentum=args[1]),
optimizer_args,
opt_params
)
opt_state = optimizer.init(opt_params)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer
|
Callable
|
A Callable that takes the learning rate and returns the
|
required |
optimizer_args
|
Dict[str, Any]
|
The arguments for different kinds of parameters.
Each item of the dictionary will be passed to the |
required |
opt_params
|
List[Dict[str, ndarray]]
|
The parameters to be optimized. The exact values are not used, only the number of elements in the list and the key of each dict. |
required |
Source code in jaxley/optimize/optimizer.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 |
|
init(opt_params)
¶
Initialize the optimizers. Equivalent to optax.optimizers.init()
.
Source code in jaxley/optimize/optimizer.py
59 60 61 62 63 64 65 66 |
|
update(gradient, opt_state)
¶
Update the optimizers. Equivalent to optax.optimizers.update()
.
Source code in jaxley/optimize/optimizer.py
68 69 70 71 72 73 74 75 76 77 |
|
AffineTransform
¶
Bases: Transform
Source code in jaxley/optimize/transforms.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
__init__(scale, shift)
¶
This transform rescales and shifts the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
ArrayLike
|
Scaling factor. |
required |
shift
|
ArrayLike
|
Additive shift. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Scale needs to be larger than 0 |
Source code in jaxley/optimize/transforms.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
ChainTransform
¶
Bases: Transform
Chaining together multiple transformations
Source code in jaxley/optimize/transforms.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
__init__(transforms)
¶
A chain of transformations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transforms
|
Sequence[Transform]
|
Transforms to apply |
required |
Source code in jaxley/optimize/transforms.py
115 116 117 118 119 120 121 122 |
|
CustomTransform
¶
Bases: Transform
Custom transformation
Source code in jaxley/optimize/transforms.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
__init__(forward_fn, inverse_fn)
¶
A custom transformation using a user-defined froward and inverse function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forward_fn
|
Callable
|
Forward transformation |
required |
inverse_fn
|
Callable
|
Inverse transformation |
required |
Source code in jaxley/optimize/transforms.py
157 158 159 160 161 162 163 164 165 166 167 |
|
MaskedTransform
¶
Bases: Transform
Source code in jaxley/optimize/transforms.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
__init__(mask, transform)
¶
A masked transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ArrayLike
|
Which elements to transform |
required |
transform
|
Transform
|
Transformation to apply |
required |
Source code in jaxley/optimize/transforms.py
136 137 138 139 140 141 142 143 144 145 |
|
NegSoftplusTransform
¶
Bases: SoftplusTransform
Negative softplus transformation.
Source code in jaxley/optimize/transforms.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
__init__(upper)
¶
This transform maps any value bijectively to the interval (-inf, upper].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
upper
|
ArrayLike
|
Upper bound of the interval. |
required |
Source code in jaxley/optimize/transforms.py
74 75 76 77 78 79 80 |
|
ParamTransform
¶
Parameter transformation utility.
This class is used to transform parameters usually from an unconstrained space to a constrained space and back (bacause most biophysical parameter are bounded). The user can specify a PyTree of transforms that are applied to the parameters.
Attributes:
Name | Type | Description |
---|---|---|
tf_dict |
A PyTree of transforms for each parameter. |
Source code in jaxley/optimize/transforms.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
__init__(tf_dict)
¶
Creates a new ParamTransform object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tf_dict
|
List[Dict[str, Transform]] | Transform
|
A PyTree of transforms for each parameter. |
required |
Source code in jaxley/optimize/transforms.py
188 189 190 191 192 193 194 195 |
|
forward(params)
¶
Pushes unconstrained parameters through a tf such that they fit the interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
List[Dict[str, ArrayLike]] | ArrayLike
|
A list of dictionaries (or any PyTree) with unconstrained parameters. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Array]
|
A list of dictionaries (or any PyTree) with transformed parameters. |
Source code in jaxley/optimize/transforms.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
inverse(params)
¶
Takes parameters from within the interval and makes them unconstrained.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
List[Dict[str, ArrayLike]] | ArrayLike
|
A list of dictionaries (or any PyTree) with transformed parameters. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Array]
|
A list of dictionaries (or any PyTree) with unconstrained parameters. |
Source code in jaxley/optimize/transforms.py
212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
SigmoidTransform
¶
Bases: Transform
Sigmoid transformation.
Source code in jaxley/optimize/transforms.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
__init__(lower, upper)
¶
This transform maps any value bijectively to the interval [lower, upper].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower
|
ArrayLike
|
Lower bound of the interval. |
required |
upper
|
ArrayLike
|
Upper bound of the interval. |
required |
Source code in jaxley/optimize/transforms.py
31 32 33 34 35 36 37 38 39 40 |
|
SoftplusTransform
¶
Bases: Transform
Softplus transformation.
Source code in jaxley/optimize/transforms.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
__init__(lower)
¶
This transform maps any value bijectively to the interval [lower, inf).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower
|
ArrayLike
|
Lower bound of the interval. |
required |
Source code in jaxley/optimize/transforms.py
55 56 57 58 59 60 61 62 |
|