optimizers
optimizers
¶
Optimizers for continual learning.
Implements LMS (fixed step-size baseline), IDBD (meta-learned step-sizes), and Autostep (tuning-free step-size adaptation) for Step 1 of the Alberta Plan.
References: - Sutton 1992, "Adapting Bias by Gradient Descent: An Incremental Version of Delta-Bar-Delta" - Mahmood et al. 2012, "Tuning-free step-size adaptation"
OptimizerUpdate
¶
Result of an optimizer update step.
Attributes: weight_delta: Change to apply to weights bias_delta: Change to apply to bias new_state: Updated optimizer state metrics: Dictionary of metrics for logging (values are JAX arrays for scan compatibility)
Optimizer
¶
Bases: ABC
Base class for optimizers.
init(feature_dim)
abstractmethod
¶
Initialize optimizer state.
Args: feature_dim: Dimension of weight vector
Returns: Initial optimizer state
update(state, error, observation)
abstractmethod
¶
Compute weight updates given prediction error.
Args: state: Current optimizer state error: Prediction error (target - prediction) observation: Current observation/feature vector
Returns: OptimizerUpdate with deltas and new state
Source code in src/alberta_framework/core/optimizers.py
LMS(step_size=0.01)
¶
Least Mean Square optimizer with fixed step-size.
The simplest gradient-based optimizer: w_{t+1} = w_t + alpha * delta * x_t
This serves as a baseline. The challenge is that the optimal step-size depends on the problem and changes as the task becomes non-stationary.
Attributes: step_size: Fixed learning rate alpha
Args: step_size: Fixed learning rate
Source code in src/alberta_framework/core/optimizers.py
init(feature_dim)
¶
Initialize LMS state.
Args: feature_dim: Dimension of weight vector (unused for LMS)
Returns: LMS state containing the step-size
Source code in src/alberta_framework/core/optimizers.py
update(state, error, observation)
¶
Compute LMS weight update.
Update rule: delta_w = alpha * error * x
Args: state: Current LMS state error: Prediction error (scalar) observation: Feature vector
Returns: OptimizerUpdate with weight and bias deltas
Source code in src/alberta_framework/core/optimizers.py
IDBD(initial_step_size=0.01, meta_step_size=0.01)
¶
Incremental Delta-Bar-Delta optimizer.
IDBD maintains per-weight adaptive step-sizes that are meta-learned based on gradient correlation. When successive gradients agree in sign, the step-size for that weight increases. When they disagree, it decreases.
This implements Sutton's 1992 algorithm for adapting step-sizes online without requiring manual tuning.
Reference: Sutton, R.S. (1992). "Adapting Bias by Gradient Descent: An Incremental Version of Delta-Bar-Delta"
Attributes: initial_step_size: Initial per-weight step-size meta_step_size: Meta learning rate beta for adapting step-sizes
Args: initial_step_size: Initial value for per-weight step-sizes meta_step_size: Meta learning rate beta for adapting step-sizes
Source code in src/alberta_framework/core/optimizers.py
init(feature_dim)
¶
Initialize IDBD state.
Args: feature_dim: Dimension of weight vector
Returns: IDBD state with per-weight step-sizes and traces
Source code in src/alberta_framework/core/optimizers.py
update(state, error, observation)
¶
Compute IDBD weight update with adaptive step-sizes.
The IDBD algorithm:
- Compute step-sizes:
alpha_i = exp(log_alpha_i) - Update weights:
w_i += alpha_i * error * x_i - Update log step-sizes:
log_alpha_i += beta * error * x_i * h_i - Update traces:
h_i = h_i * max(0, 1 - alpha_i * x_i^2) + alpha_i * error * x_i
The trace h_i tracks the correlation between current and past gradients. When gradients consistently point the same direction, h_i grows, leading to larger step-sizes.
Args: state: Current IDBD state error: Prediction error (scalar) observation: Feature vector
Returns: OptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
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 | |
Autostep(initial_step_size=0.01, meta_step_size=0.01, normalizer_decay=0.99)
¶
Bases: Optimizer[AutostepState]
Autostep optimizer with tuning-free step-size adaptation.
Autostep normalizes gradients to prevent large updates and adapts per-weight step-sizes based on gradient correlation. The key innovation is automatic normalization that makes the algorithm robust to different feature scales.
The algorithm maintains: - Per-weight step-sizes that adapt based on gradient correlation - Running max of absolute gradients for normalization - Traces for detecting consistent gradient directions
Reference: Mahmood, A.R., Sutton, R.S., Degris, T., & Pilarski, P.M. (2012). "Tuning-free step-size adaptation"
Attributes: initial_step_size: Initial per-weight step-size meta_step_size: Meta learning rate mu for adapting step-sizes normalizer_decay: Decay factor tau for gradient normalizers
Args: initial_step_size: Initial value for per-weight step-sizes meta_step_size: Meta learning rate for adapting step-sizes normalizer_decay: Decay factor for gradient normalizers (higher = slower decay)
Source code in src/alberta_framework/core/optimizers.py
init(feature_dim)
¶
Initialize Autostep state.
Args: feature_dim: Dimension of weight vector
Returns: Autostep state with per-weight step-sizes, traces, and normalizers
Source code in src/alberta_framework/core/optimizers.py
update(state, error, observation)
¶
Compute Autostep weight update with normalized gradients.
The Autostep algorithm:
- Compute gradient:
g_i = error * x_i - Normalize gradient:
g_i' = g_i / max(|g_i|, v_i) - Update weights:
w_i += alpha_i * g_i' - Update step-sizes:
alpha_i *= exp(mu * g_i' * h_i) - Update traces:
h_i = h_i * (1 - alpha_i) + alpha_i * g_i' - Update normalizers:
v_i = max(|g_i|, v_i * tau)
Args: state: Current Autostep state error: Prediction error (scalar) observation: Feature vector
Returns: OptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
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 | |
TDOptimizerUpdate
¶
Result of a TD optimizer update step.
Attributes: weight_delta: Change to apply to weights bias_delta: Change to apply to bias new_state: Updated optimizer state metrics: Dictionary of metrics for logging
TDOptimizer
¶
Bases: ABC
Base class for TD optimizers.
TD optimizers handle temporal-difference learning with eligibility traces. They take TD error and both current and next observations as input.
init(feature_dim)
abstractmethod
¶
Initialize optimizer state.
Args: feature_dim: Dimension of weight vector
Returns: Initial optimizer state
update(state, td_error, observation, next_observation, gamma)
abstractmethod
¶
Compute weight updates given TD error.
Args: state: Current optimizer state td_error: TD error δ = R + γV(s') - V(s) observation: Current observation φ(s) next_observation: Next observation φ(s') gamma: Discount factor γ (0 at terminal)
Returns: TDOptimizerUpdate with deltas and new state
Source code in src/alberta_framework/core/optimizers.py
TDIDBD(initial_step_size=0.01, meta_step_size=0.01, trace_decay=0.0, use_semi_gradient=True)
¶
Bases: TDOptimizer[TDIDBDState]
TD-IDBD optimizer for temporal-difference learning.
Extends IDBD to TD learning with eligibility traces. Maintains per-weight adaptive step-sizes that are meta-learned based on gradient correlation in the TD setting.
Two variants are supported: - Semi-gradient (default): Uses only φ(s) in meta-update, more stable - Ordinary gradient: Uses both φ(s) and φ(s'), more accurate but sensitive
Reference: Kearney et al. 2019, "Learning Feature Relevance Through Step Size Adaptation in Temporal-Difference Learning"
The semi-gradient TD-IDBD algorithm (Algorithm 3 in paper):
1. Compute TD error: δ = R + γ*w^T*φ(s') - w^T*φ(s)
2. Update meta-weights: β_i += θ*δ*φ_i(s)*h_i
3. Compute step-sizes: α_i = exp(β_i)
4. Update eligibility traces: z_i = γ*λ*z_i + φ_i(s)
5. Update weights: w_i += α_i*δ*z_i
6. Update h traces: h_i = h_i*[1 - α_i*φ_i(s)*z_i]^+ + α_i*δ*z_i
Attributes: initial_step_size: Initial per-weight step-size meta_step_size: Meta learning rate theta trace_decay: Eligibility trace decay lambda use_semi_gradient: If True, use semi-gradient variant (default)
Args: initial_step_size: Initial value for per-weight step-sizes meta_step_size: Meta learning rate theta for adapting step-sizes trace_decay: Eligibility trace decay lambda (0 = TD(0)) use_semi_gradient: If True, use semi-gradient variant (recommended)
Source code in src/alberta_framework/core/optimizers.py
init(feature_dim)
¶
Initialize TD-IDBD state.
Args: feature_dim: Dimension of weight vector
Returns: TD-IDBD state with per-weight step-sizes, traces, and h traces
Source code in src/alberta_framework/core/optimizers.py
update(state, td_error, observation, next_observation, gamma)
¶
Compute TD-IDBD weight update with adaptive step-sizes.
Implements Algorithm 3 (semi-gradient) or Algorithm 4 (ordinary gradient) from Kearney et al. 2019.
Args: state: Current TD-IDBD state td_error: TD error δ = R + γV(s') - V(s) observation: Current observation φ(s) next_observation: Next observation φ(s') gamma: Discount factor γ (0 at terminal)
Returns: TDOptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
AutoTDIDBD(initial_step_size=0.01, meta_step_size=0.01, trace_decay=0.0, normalizer_decay=10000.0)
¶
Bases: TDOptimizer[AutoTDIDBDState]
AutoStep-style normalized TD-IDBD optimizer.
Adds AutoStep-style normalization to TDIDBD for improved stability and reduced sensitivity to the meta step-size theta. Includes: 1. Normalization of the meta-weight update by a running trace of recent updates 2. Effective step-size normalization to prevent overshooting
Reference: Kearney et al. 2019, Algorithm 6 "AutoStep Style Normalized TIDBD(λ)"
The AutoTDIDBD algorithm:
1. Compute TD error: δ = R + γ*w^T*φ(s') - w^T*φ(s)
2. Update normalizers: η_i = max(|δ*[γφ_i(s')-φ_i(s)]*h_i|,
η_i - (1/τ)*α_i*[γφ_i(s')-φ_i(s)]*z_i*(|δ*φ_i(s)*h_i| - η_i))
3. Normalized meta-update: β_i -= θ*(1/η_i)*δ*[γφ_i(s')-φ_i(s)]*h_i
4. Effective step-size normalization: M = max(-exp(β)*[γφ(s')-φ(s)]^T*z, 1)
then β_i -= log(M)
5. Update weights and traces as in TIDBD
Attributes: initial_step_size: Initial per-weight step-size meta_step_size: Meta learning rate theta trace_decay: Eligibility trace decay lambda normalizer_decay: Decay parameter tau for normalizers
Args: initial_step_size: Initial value for per-weight step-sizes meta_step_size: Meta learning rate theta for adapting step-sizes trace_decay: Eligibility trace decay lambda (0 = TD(0)) normalizer_decay: Decay parameter tau for normalizers (default: 10000)
Source code in src/alberta_framework/core/optimizers.py
init(feature_dim)
¶
Initialize AutoTDIDBD state.
Args: feature_dim: Dimension of weight vector
Returns: AutoTDIDBD state with per-weight step-sizes, traces, h traces, and normalizers
Source code in src/alberta_framework/core/optimizers.py
update(state, td_error, observation, next_observation, gamma)
¶
Compute AutoTDIDBD weight update with normalized adaptive step-sizes.
Implements Algorithm 6 from Kearney et al. 2019.
Args: state: Current AutoTDIDBD state td_error: TD error δ = R + γV(s') - V(s) observation: Current observation φ(s) next_observation: Next observation φ(s') gamma: Discount factor γ (0 at terminal)
Returns: TDOptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |