Optimization
collimator.optimization
AutoTuner
PID autotuning (without a measurement filter) with constraints in the frequency domain.
Supports only SISO systems.
Supports only continuous-time plants (TODO: extend to discrete-time systems)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
LeafSystem or a Diagram. If plant is not an LTISystem, operating points x_op and u_op must be provided for linearization. |
required | |
n
|
int, optional Filter coefficient for the continuous-time PID controller |
100
|
|
sim_time
|
float, optional Simulation time for computation of the error metric |
2.0
|
|
metric
|
str, optional Error metric to be minimized. Options are "IAE" and "IE" "IAE": Integral of the absolute error "IE": Integral of the error |
'IAE'
|
|
x_op
|
np.ndarray, optional Operating point of state vector for linearization |
None
|
|
u_op
|
np.ndarray, optional Operating point of control vector for linearization |
None
|
|
pid_gains_0
|
list or Array, optional Initial guess for PID gains [kp, ki, kd] |
[1.0, 10.0, 0.1]
|
|
pid_gains_upper_bounds
|
list or Array, optional Upper bounds for PID gains [kp, ki, kd]. Lower bounds are set to 0 |
None
|
|
Ms
|
float, optional Maximum sensitivity |
100.0
|
|
Mt
|
float, optional Maximum complementary sensitivity |
100.0
|
|
add_filter
|
bool, optional Add measurement filter (currently not implemented) |
False
|
|
method
|
str, optional The method for optimization. Available options are: - "scipy-slsqp" - "scipy-cobyla" - "scipy-trust-constr" - "ipopt" - "nlopt-slsqp" - "nlopt-cobyla" - "nlopt-ld_mma" - "nlopt-isres" - "nlopt-ags" - "nlopt-direct" |
'scipy-slsqp'
|
Notes:
The utilities plot_freq_response
, plot_time_response
, and
plot_freq_and_time_responses
can be used to visualize the frequency and time
responses of the closed-loop system.
Post initialization the tune
method should be called to obtain the optimal PID
gains. See notebooks/opt_framework/pid_autotuning.ipynb
for an example.
Source code in collimator/optimization/pid_autotuning.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
circle_constraint_(kp, ki, kd, omega, c, r)
Deprecated: this is needed for self.constraints_
which is deprecated
and replaced by self.constraints
.
Source code in collimator/optimization/pid_autotuning.py
270 271 272 273 274 275 276 277 |
|
constraints_(pid_params)
Deprecated: replaced by self.constraints
Source code in collimator/optimization/pid_autotuning.py
279 280 281 282 283 284 285 286 287 288 289 290 |
|
CompositeTransform
Bases: Transform
A composite transformation that applies a list of transformations in sequence.
Source code in collimator/optimization/framework/base/transformations.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
DistributionConfig
dataclass
Structure of attributes for specifying distributions for stochastic variables
Source code in collimator/optimization/framework/base/optimizable.py
59 60 61 62 63 64 65 66 67 68 |
|
Evosax
Bases: Optimizer
Population based global optimizers from Evosax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizable
|
Optimizable
|
The optimizable object. |
required |
opt_method
|
str
|
The optimization method to use. See |
'CMA_ES'
|
opt_method_config
|
dict
|
Configuration for the optimization method. |
None
|
pop_size
|
int
|
The population size. |
10
|
num_generations
|
int
|
The number of generations. |
100
|
print_every
|
int
|
Print progress every |
1
|
metrics_writer
|
MetricsWriter | None
|
Optional CSV file to write metrics to. |
None
|
seed
|
int
|
The random seed. |
None
|
Source code in collimator/optimization/framework/optimizers_evosax.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_evosax.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
IPOPT
Bases: Optimizer
Interior Point Optimizer (IPOPT) for optimization of the objective function with constraints.
Prameters
optimizable (Optimizable): The optimizable object. options (dict): Options for the IPOPT solver. See https://coin-or.github.io/Ipopt/OPTIONS.html
Source code in collimator/optimization/framework/optimizers_ipopt.py
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 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_ipopt.py
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 |
|
IdentityTransform
Bases: Transform
A transformation that does nothing: y = x
.
Source code in collimator/optimization/framework/base/transformations.py
48 49 50 51 52 53 54 55 56 57 |
|
LogTransform
Bases: Transform
A transformation that applies the natural logarithm to the values of the parameters.
y = log(x)
.
Source code in collimator/optimization/framework/base/transformations.py
60 61 62 63 64 65 66 67 68 69 70 |
|
LogitTransform
Bases: Transform
The logit transformation, defined as:
y = log(x / (1 - x))
Source code in collimator/optimization/framework/base/transformations.py
113 114 115 116 117 118 119 120 121 122 123 |
|
NLopt
Bases: Optimizer
Optimizers using the NLopt library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizable
|
Optimizable
|
The optimizable object. |
required |
opt_method
|
str
|
The optimization method to use. |
required |
ftol_rel
|
float
|
Relative tolerance on function value. |
1e-06
|
ftol_abs
|
float
|
Absolute tolerance on function value. |
1e-06
|
xtol_rel
|
float
|
Relative tolerance on optimization parameters. |
1e-06
|
xtol_abs
|
float
|
Absolute tolerance on optimization parameters. |
1e-06
|
cons_tol
|
float
|
Tolerance on constraints. |
1e-06
|
maxeval
|
int
|
Maximum number of function evaluations. |
500
|
maxtime
|
float
|
Maximum time in seconds. |
0
|
Source code in collimator/optimization/framework/optimizers_nlopt.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_nlopt.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
NegativeNegativeLogTransform
Bases: Transform
A transformation that applies the negative of the natural logarithm of the negative
of the values of the parameters.
y = -log(-x)
Source code in collimator/optimization/framework/base/transformations.py
73 74 75 76 77 78 79 80 81 82 83 84 |
|
NormalizeTransform
Bases: Transform
A transformation that normalizes the values of the parameters to the range [0, 1].
y = (x - min) / (max - min)
Paramteters:
- params_min: dict with the minimum values for each parameter.
- params_max: dict with the maximum values for each parameter.
Source code in collimator/optimization/framework/base/transformations.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
Optax
Bases: Optimizer
Optax optimizer without support for stochastic variables.
Paramters
optimizable (Optimizable):
The optimizable object.
opt_method (str):
The optimization method to use.
learning_rate (float):
The learning rate.
opt_method_config (dict):
Configuration for the optimization method.
num_epochs (int):
The number of epochs.
clip_range (tuple):
The range to clip the gradients.
print_every (int):
Print progress every print_every
epochs.
metrics_writer (MetricsWriter|None):
Optional CSV file to write metrics to.
Source code in collimator/optimization/framework/optimizers_optax.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_optax.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
step(params, opt_state)
Take a single optimization step
Source code in collimator/optimization/framework/optimizers_optax.py
299 300 301 302 303 304 305 306 |
|
OptaxWithStochasticVars
Bases: Optimizer
Optax optimizer with support for stochastic variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizable
|
OptimizableWithStochasticVars
|
The optimizable object. |
required |
opt_method
|
str
|
The optimization method to use. |
required |
learning_rate
|
float
|
The learning rate. |
required |
opt_method_config
|
dict
|
Configuration for the optimization method. |
required |
num_epochs
|
int
|
The number of epochs. |
100
|
batch_size
|
int
|
The batch size. |
1
|
num_batches
|
int
|
The number of batches. |
1
|
clip_range
|
tuple
|
The range to clip the gradients. |
None
|
print_every
|
int
|
Print progress every |
None
|
metrics_writer
|
MetricsWriter | None
|
Optional CSV file to write metrics to. |
None
|
Source code in collimator/optimization/framework/optimizers_optax.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 |
|
batched_objective_flat(params, stochastic_vars_batch_flat)
Mean of the objective function over a batch
Source code in collimator/optimization/framework/optimizers_optax.py
141 142 143 144 145 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_optax.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 |
|
step(params, opt_state, stochastic_vars_batch)
Take a single optimization step over one batch
Source code in collimator/optimization/framework/optimizers_optax.py
147 148 149 150 151 152 153 154 155 156 157 158 |
|
Optimizable
Bases: OptimizableBase
Base class for all optimizables with no stochastic variables.
For parameters, see OptimizableBase
.
The abstract method prepare_context
should update the context to incorporate the
optimization parameters.
This classs creates methods for evaluation of the objective and constraints from the concrete implementation of the abstract methods. This class also creates methods for batched evaluation of the objective and constraints, which are useful for optimizers that can work with batches (eg. Optax), and population-based optimizers.
Source code in collimator/optimization/framework/base/optimizable.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
constraints(params)
Constraints function for optimization with dict parameters input
Source code in collimator/optimization/framework/base/optimizable.py
329 330 331 332 333 334 |
|
constraints_flat(params)
Constraints function for optimization with flattened parameters input
Source code in collimator/optimization/framework/base/optimizable.py
325 326 327 |
|
objective(params)
Objective function for optimization with dict parameters input
Source code in collimator/optimization/framework/base/optimizable.py
318 319 320 321 322 323 |
|
objective_flat(params)
Objective function for optimization with flattened parameters input
Source code in collimator/optimization/framework/base/optimizable.py
314 315 316 |
|
prepare_context(context, params)
abstractmethod
Model-specific updates to incorporate the sample data and parameters. Return the updated context.
Source code in collimator/optimization/framework/base/optimizable.py
297 298 299 300 301 302 303 |
|
run_simulation(params)
Run simulation and return final results context.
Source code in collimator/optimization/framework/base/optimizable.py
305 306 307 308 309 310 311 312 |
|
OptimizableWithStochasticVars
Bases: OptimizableBase
Base class for all optimizables with stochastic variables. This is designed only for Optax optimizers and without constraints. Other optimizers are unlikely to work well with stochastic variables.
This class is similar to Optimizable
with the key difference that both params
and vars
(stochastic variables) need to be updated as opposed to params
alone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vars_0
|
dict
Initial stochastic variable values. If not provided, the
|
None
|
|
distribution_config_vars
|
DistributionConfig Configuration for stochastic variables. If not provided, standard normal distribution is used. |
None
|
Source code in collimator/optimization/framework/base/optimizable.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
generate_batches(data, num_batches, batch_size)
Given all samples data
, generate num_batches
random batches of size
batch_size
each
Source code in collimator/optimization/framework/base/optimizable.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
objective(params, vars)
Objective function for optimization with dict parameters and vars input
Source code in collimator/optimization/framework/base/optimizable.py
439 440 441 442 443 444 |
|
objective_flat(params, vars)
Objective function for optimization with flattened parameters and vars input
Source code in collimator/optimization/framework/base/optimizable.py
431 432 433 434 435 436 437 |
|
prepare_context(context, params, vars)
abstractmethod
Model-specific updates to incorporate the parameters and stochastic vars. Return the updated context.
Source code in collimator/optimization/framework/base/optimizable.py
408 409 410 411 412 413 414 |
|
run_simulation(params, vars)
Run simulation and return final results context.
Source code in collimator/optimization/framework/base/optimizable.py
424 425 426 427 428 429 |
|
sample_random_vars(num_samples)
Generate random samples of the stochastic variables
Source code in collimator/optimization/framework/base/optimizable.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
stochastic_vars(context)
abstractmethod
Extract stochastic vars
from the context.
These should be in the form of a dict of Pytrees.
Source code in collimator/optimization/framework/base/optimizable.py
416 417 418 419 420 421 422 |
|
RLEnv
Bases: Env
Base class for reinforcement learning environments in Collimator.
Source code in collimator/optimization/rl_env.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
get_done(pipeline_state, obs)
Return a boolean indicating whether the episode is done.
Source code in collimator/optimization/rl_env.py
144 145 146 |
|
get_reward(pipeline_state, obs, act)
abstractmethod
Return the reward for the current state and observation.
Source code in collimator/optimization/rl_env.py
137 138 139 140 141 142 |
|
randomize(pipeline_state, rng)
Randomize the initial states, parameters, etc.
Source code in collimator/optimization/rl_env.py
148 149 150 |
|
render(trajectory, height=240, width=320, camera=None)
Render the trajectory
Source code in collimator/optimization/rl_env.py
152 153 154 155 156 157 158 159 160 161 162 |
|
Scipy
Bases: Optimizer
Scipy/JAX-scipy optimizers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizable
|
Optimizable
|
The optimizable object. |
required |
opt_method
|
str
|
The optimization method to use. |
required |
tol
|
float
|
Tolerance for termination. For detailed control, use |
None
|
opt_method_config
|
dict
|
Configuration for the optimization method. |
None
|
use_autodiff_grad
|
bool
|
Whether to use autodiff for gradient computation. |
True
|
use_jax_scipy
|
bool
|
Whether to use JAX's version of |
False
|
Source code in collimator/optimization/framework/optimizers_scipy.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
optimize()
Run optimization
Source code in collimator/optimization/framework/optimizers_scipy.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 |
|
Trainer
Base class for optimizing model parameters via simulation.
Should probably get a more descriptive name once we're doing other kinds of training...
Source code in collimator/optimization/training.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
evaluate_cost(context)
abstractmethod
Model-specific cost function, evaluated on final context
Source code in collimator/optimization/training.py
89 90 91 92 |
|
make_forward(start_time, stop_time)
Create a generic forward pass through the simulation, returning loss
Source code in collimator/optimization/training.py
94 95 96 97 98 99 100 101 102 103 104 |
|
make_loss_fn(forward, params)
Create a loss function based on a forward pass of the simulation
params
here can be any PyTree - it will get flattened to a single array
Source code in collimator/optimization/training.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
optimizable_parameters(context)
abstractmethod
Extract optimizable model-specific parameters from the context.
These should be in the form of a PyTree (e.g. tuple, dict, array, etc)
and should be the first arguments to prepare_context
.
Source code in collimator/optimization/training.py
70 71 72 73 74 75 76 77 |
|
prepare_context(context, *data, key=None)
abstractmethod
Model-specific updates to incorporate the sample data and parameters.
data
should be the combination of the output of optimizable_parameters
along with all the per-simulation "training data". Parameters will
update once per epoch, and training data will update once per sample.
Source code in collimator/optimization/training.py
79 80 81 82 83 84 85 86 87 |
|
train(training_data, sim_start_time, sim_stop_time, epochs=100, key=None, params=None, opt_state=None)
Run the optimization loop over the training data
Source code in collimator/optimization/training.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
Transform
Bases: ABC
Base class for transformations.
Source code in collimator/optimization/framework/base/transformations.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
inverse_transform(params)
abstractmethod
Take transformed parameters dict {key:value} and output a dict with identical
keys but inverse-transformed values
.
Source code in collimator/optimization/framework/base/transformations.py
20 21 22 23 24 25 26 |
|
transform(params)
abstractmethod
Take original parameters dict {key:value} and output a dict with identical keys
but transformed values
.
Source code in collimator/optimization/framework/base/transformations.py
12 13 14 15 16 17 18 |
|