core
core
¶
Core components for the Alberta Framework.
BatchedHordeResult
¶
Result from batched Horde learning loop.
Attributes:
states: Batched multi-head MLP learner states
per_demon_metrics: Per-demon metrics,
shape (n_seeds, num_steps, n_demons, 3)
td_errors: TD errors, shape (n_seeds, num_steps, n_demons)
HordeLearner(horde_spec, hidden_sizes=(128, 128), optimizer=None, step_size=1.0, bounder=None, normalizer=None, sparsity=0.9, leaky_relu_slope=0.01, use_layer_norm=True, head_optimizer=None)
¶
Horde: GVF demons sharing a trunk (Sutton et al. 2011).
Wraps MultiHeadMLPLearner. Adds:
- Per-demon gamma/lambda from HordeSpec
- TD target computation for temporal demons (gamma > 0)
- GVF metadata
The trunk uses gamma=0, lamda=0 (no temporal trace decay on shared
features). Each head uses its own gamma * lambda product for
trace decay, set via per_head_gamma_lamda on the inner learner.
For all-gamma=0 Hordes (e.g. rlsecd's 5 prediction heads), this
produces identical results to MultiHeadMLPLearner since the
TD target reduces to just the cumulant.
Single-Step (Daemon) Usage
Both predict() and update() work with single unbatched
observations (1D arrays). JIT-compiled automatically.
Attributes: horde_spec: The HordeSpec defining all demons n_demons: Number of demons (heads)
Args: horde_spec: Specification of all GVF demons hidden_sizes: Tuple of hidden layer sizes (default: two layers of 128) optimizer: Optimizer for weight updates. Defaults to LMS(step_size). step_size: Base learning rate (used only when optimizer is None) bounder: Optional update bounder (e.g. ObGDBounding) normalizer: Optional feature normalizer sparsity: Fraction of weights zeroed out per neuron (default: 0.9) leaky_relu_slope: Negative slope for LeakyReLU (default: 0.01) use_layer_norm: Whether to apply parameterless layer normalization head_optimizer: Optional separate optimizer for heads
Source code in src/alberta_framework/core/horde.py
horde_spec
property
¶
The HordeSpec defining all demons.
n_demons
property
¶
Number of demons (heads).
learner
property
¶
The underlying MultiHeadMLPLearner.
to_config()
¶
Serialize learner configuration to dict.
Returns: Dict with horde_spec and all MultiHeadMLPLearner constructor args.
Source code in src/alberta_framework/core/horde.py
from_config(config)
classmethod
¶
Reconstruct from config dict.
Args:
config: Dict as produced by to_config()
Returns: Reconstructed HordeLearner
Source code in src/alberta_framework/core/horde.py
init(feature_dim, key)
¶
Initialize Horde learner state.
Args: feature_dim: Dimension of the input feature vector key: JAX random key for weight initialization
Returns: Initial MultiHeadMLPState
Source code in src/alberta_framework/core/horde.py
predict(state, observation)
¶
Compute predictions from all demons.
Args: state: Current learner state observation: Input feature vector
Returns:
Array of shape (n_demons,) with one prediction per demon
Source code in src/alberta_framework/core/horde.py
update(state, observation, cumulants, next_observation)
¶
Update Horde given observation, cumulants, and next observation.
Computes TD targets r + gamma * V(s') for each demon, then
delegates to MultiHeadMLPLearner.update(). For gamma=0 demons,
the target equals the cumulant.
Args:
state: Current state
observation: Input feature vector, shape (feature_dim,)
cumulants: Per-demon pseudo-rewards, shape (n_demons,).
NaN = inactive demon.
next_observation: Next feature vector, shape (feature_dim,).
Used for V(s') bootstrapping. For all-gamma=0 Hordes,
this is required but doesn't affect results.
Returns: HordeUpdateResult with updated state, predictions, TD errors, TD targets, and per-demon metrics
Source code in src/alberta_framework/core/horde.py
HordeLearningResult
¶
Result from a Horde scan-based learning loop.
Attributes:
state: Final multi-head MLP learner state
per_demon_metrics: Per-demon metrics over time,
shape (num_steps, n_demons, 3)
td_errors: TD errors over time, shape (num_steps, n_demons)
HordeUpdateResult
¶
Result of a single Horde update step.
Attributes:
state: Updated multi-head MLP learner state
predictions: Predictions from all demons, shape (n_demons,)
td_errors: TD errors (target - prediction), shape (n_demons,).
NaN for inactive demons.
td_targets: Computed TD targets r + gamma * V(s'),
shape (n_demons,). NaN for inactive demons.
per_demon_metrics: Per-demon metrics, shape (n_demons, 3).
Columns: [squared_error, raw_error, mean_step_size].
NaN for inactive demons.
trunk_bounding_metric: Scalar trunk bounding metric
LinearLearner(optimizer=None, normalizer=None)
¶
Linear function approximator with pluggable optimizer and optional normalizer.
Computes predictions as: y = w @ x + b
The learner maintains weights and bias, delegating the adaptation of learning rates to the optimizer (e.g., LMS or IDBD).
This follows the Alberta Plan philosophy of temporal uniformity: every component updates at every time step.
Attributes: optimizer: The optimizer to use for weight updates normalizer: Optional online feature normalizer
Args: optimizer: Optimizer for weight updates. Defaults to LMS(0.01) normalizer: Optional feature normalizer (e.g. EMANormalizer, WelfordNormalizer)
Source code in src/alberta_framework/core/learners.py
normalizer
property
¶
The feature normalizer, or None if normalization is disabled.
init(feature_dim)
¶
Initialize learner state.
Args: feature_dim: Dimension of the input feature vector
Returns: Initial learner state with zero weights and bias
Source code in src/alberta_framework/core/learners.py
predict(state, observation)
¶
Compute prediction for an observation.
Args: state: Current learner state observation: Input feature vector
Returns:
Scalar prediction y = w @ x + b
Source code in src/alberta_framework/core/learners.py
update(state, observation, target)
¶
Update learner given observation and target.
Performs one step of the learning algorithm: 1. Optionally normalize observation 2. Compute prediction 3. Compute error 4. Get weight updates from optimizer 5. Apply updates to weights and bias
Args: state: Current learner state observation: Input feature vector target: Desired output
Returns: UpdateResult with new state, prediction, error, and metrics
Source code in src/alberta_framework/core/learners.py
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 | |
TDLinearLearner(optimizer=None)
¶
Linear function approximator for TD learning.
Computes value predictions as: V(s) = w @ phi(s) + b
The learner maintains weights, bias, and eligibility traces, delegating the adaptation of learning rates to the TD optimizer (e.g., TDIDBD).
This follows the Alberta Plan philosophy of temporal uniformity: every component updates at every time step.
Reference: Kearney et al. 2019, "Learning Feature Relevance Through Step Size Adaptation in Temporal-Difference Learning"
Attributes: optimizer: The TD optimizer to use for weight updates
Args: optimizer: TD optimizer for weight updates. Defaults to TDIDBD()
Source code in src/alberta_framework/core/learners.py
init(feature_dim)
¶
Initialize TD learner state.
Args: feature_dim: Dimension of the input feature vector
Returns: Initial TD learner state with zero weights and bias
Source code in src/alberta_framework/core/learners.py
predict(state, observation)
¶
Compute value prediction for an observation.
Args: state: Current TD learner state observation: Input feature vector phi(s)
Returns:
Scalar value prediction V(s) = w @ phi(s) + b
Source code in src/alberta_framework/core/learners.py
update(state, observation, reward, next_observation, gamma)
¶
Update learner given a TD transition.
Performs one step of TD learning: 1. Compute V(s) and V(s') 2. Compute TD error delta = R + gamma*V(s') - V(s) 3. Get weight updates from TD optimizer 4. Apply updates to weights and bias
Args: state: Current TD learner state observation: Current observation phi(s) reward: Reward R received next_observation: Next observation phi(s') gamma: Discount factor gamma (0 at terminal states)
Returns: TDUpdateResult with new state, prediction, TD error, and metrics
Source code in src/alberta_framework/core/learners.py
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 | |
TDUpdateResult
¶
Result of a TD learner update step.
Attributes: state: Updated TD learner state prediction: Value prediction V(s) before update td_error: TD error delta = R + gamma*V(s') - V(s) metrics: Array of metrics [squared_td_error, td_error, mean_step_size, ...]
IDBD(initial_step_size=0.01, meta_step_size=0.01, h_decay_mode='prediction_grads')
¶
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
h_decay_mode: Mode for computing the h-decay term in MLP path.
"prediction_grads": h_decay = z^2 (squared prediction
gradients). This is the principled generalization — for
linear models, z = x so z^2 = x^2, recovering Sutton 1992.
"loss_grads": h_decay = (error * z)^2 (Fisher
approximation of the Hessian diagonal).
Only affects the MLP path (update_from_gradient);
the linear update() method always uses x^2.
Raises:
ValueError: If h_decay_mode is not one of the valid modes
Source code in src/alberta_framework/core/optimizers.py
to_config()
¶
Serialize configuration to dict.
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
init_for_shape(shape)
¶
Initialize IDBD state for arbitrary-shape parameters.
Args: shape: Shape of the parameter array
Returns: IDBDParamState with arrays matching the given shape
Source code in src/alberta_framework/core/optimizers.py
update_from_gradient(state, gradient, error=None)
¶
Compute IDBD update from pre-computed gradient (MLP path).
Implements Meyer's adaptation of IDBD to nonlinear models. The key
insight: replace x^2 in the h-decay term with (dy/dw)^2
(squared prediction gradients), which generalizes IDBD to arbitrary
architectures.
This follows Meyer's implementation, which differs from the linear IDBD (Sutton 1992) in two ways to better handle deep networks:
- The meta-update uses
z * h(prediction gradient times trace) without the current error, rather thanerror * z * h. - The h-trace accumulates loss gradients (
-error * z) rather than error-scaled prediction gradients (error * z).
These changes address problems with IDBD in deep networks where the step-size being factored into both h and beta updates causes compounding effects.
Reference: Meyer, https://github.com/ejmejm/phd_research
Operation order (meta-update first, then new alpha for trace):
- Compute h_decay based on mode:
z^2or(error * z)^2 - Meta-update with OLD traces:
log_alpha += beta * z * h - Clip log step-sizes to
[-10.0, 2.0] - New step-sizes:
alpha = exp(log_alpha) - Step:
alpha * z(error applied externally by caller) - Trace update:
h = h * max(0, 1 - alpha * h_decay) + alpha * gwhereg = -error * z(loss gradient direction)
When error is None (trunk path in multi-head), the gradient
is already in loss gradient direction (accumulated cotangents),
so the trace uses alpha * z directly.
Args: state: Current IDBD param state gradient: Pre-computed prediction gradient / eligibility trace (same shape as state arrays) error: Optional prediction error scalar. When provided, used for h_decay (loss_grads mode) and h-trace sign.
Returns:
(step, new_state) where step has the same shape as gradient
Source code in src/alberta_framework/core/optimizers.py
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 569 570 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 | |
update(state, error, observation)
¶
Compute IDBD weight update with adaptive step-sizes.
Following Sutton 1992, Figure 2, the operation ordering is:
- Meta-update:
log_alpha_i += beta * error * x_i * h_i(using OLD traces) - Compute NEW step-sizes:
alpha_i = exp(log_alpha_i) - Update weights:
w_i += alpha_i * error * x_i(using NEW alpha) - Update traces:
h_i = h_i * max(0, 1 - alpha_i * x_i^2) + alpha_i * error * x_i(using NEW alpha)
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
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 | |
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
to_config()
¶
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
init_for_shape(shape)
¶
Initialize LMS state for arbitrary-shape parameters.
LMS state is shape-independent (single scalar), so this returns the same state regardless of shape.
Source code in src/alberta_framework/core/optimizers.py
update_from_gradient(state, gradient, error=None)
¶
Compute step from gradient: step = alpha * gradient.
Args: state: Current LMS state gradient: Pre-computed gradient (any shape) error: Unused by LMS (accepted for interface compatibility)
Returns:
(step, state) -- state is unchanged for LMS
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
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 phi(s) in meta-update, more stable - Ordinary gradient: Uses both phi(s) and phi(s'), more accurate but sensitive
Reference: Kearney et al. 2019, "Learning Feature Relevance Through Step Size Adaptation in Temporal-Difference Learning"
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 delta = R + gamma*V(s') - V(s) observation: Current observation phi(s) next_observation: Next observation phi(s') gamma: Discount factor gamma (0 at terminal)
Returns: TDOptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 | |
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.
Reference: Kearney et al. 2019, Algorithm 6 "AutoStep Style Normalized TIDBD(lambda)"
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 delta = R + gamma*V(s') - V(s) observation: Current observation phi(s) next_observation: Next observation phi(s') gamma: Discount factor gamma (0 at terminal)
Returns: TDOptimizerUpdate with weight deltas and updated state
Source code in src/alberta_framework/core/optimizers.py
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 | |
Optimizer
¶
Bases: ABC
Base class for optimizers.
to_config()
abstractmethod
¶
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
init_for_shape(shape)
¶
Initialize optimizer state for parameters of arbitrary shape.
Used by MLP learners where parameters are matrices/vectors of varying shapes. Not all optimizers support this.
The return type varies by subclass (e.g. LMSState for LMS,
AutostepParamState for Autostep) so the base signature uses
Any.
Args: shape: Shape of the parameter array
Returns: Initial optimizer state with arrays matching the given shape
Raises: NotImplementedError: If the optimizer does not support this
Source code in src/alberta_framework/core/optimizers.py
update_from_gradient(state, gradient, error=None)
¶
Compute step delta from pre-computed gradient.
The returned delta does NOT include the error -- the caller is
responsible for multiplying error * delta before applying.
The state type varies by subclass (e.g. LMSState for LMS,
AutostepParamState for Autostep) so the base signature uses
Any.
Args: state: Current optimizer state gradient: Pre-computed gradient (e.g. eligibility trace) error: Optional prediction error scalar. Optimizers with meta-learning (e.g. Autostep) use this for meta-gradient computation. LMS ignores it.
Returns:
(step, new_state) where step has the same shape as gradient
Raises: NotImplementedError: If the optimizer does not support this
Source code in src/alberta_framework/core/optimizers.py
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 delta = R + gamma*V(s') - V(s) observation: Current observation phi(s) next_observation: Next observation phi(s') gamma: Discount factor gamma (0 at terminal)
Returns: TDOptimizerUpdate with deltas and new state
Source code in src/alberta_framework/core/optimizers.py
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
AutoTDIDBDState
¶
State for the AutoTDIDBD optimizer.
AutoTDIDBD adds AutoStep-style normalization to TDIDBD for improved stability. Includes normalizers for the meta-weight updates and effective step-size normalization to prevent overshooting.
Reference: Kearney et al. 2019, Algorithm 6
Attributes: log_step_sizes: Log of per-weight step-sizes (log alpha_i) eligibility_traces: Eligibility traces z_i h_traces: Per-weight h traces for gradient correlation normalizers: Running max of absolute gradient correlations (eta_i) meta_step_size: Meta learning rate theta trace_decay: Eligibility trace decay parameter lambda normalizer_decay: Decay parameter tau for normalizers bias_log_step_size: Log step-size for the bias term bias_eligibility_trace: Eligibility trace for the bias bias_h_trace: h trace for the bias term bias_normalizer: Normalizer for the bias gradient correlation
DemonType
¶
Bases: Enum
Type of GVF demon.
A prediction demon has a fixed policy and learns to predict. A control demon learns a policy (e.g. via SARSA) — Step 4.
GVFSpec
¶
One GVF demon's question functions (Sutton et al. 2011).
Declarative, not callable — JAX pytree-compatible. Cumulant values are computed externally and passed as arrays.
Attributes: name: Human-readable name for this demon demon_type: Whether this is a prediction or control demon gamma: Pseudo-termination discount (0.0 = single-step prediction) lamda: Trace decay parameter (0.0 = no eligibility traces) cumulant_index: Index into targets array, or -1 for external cumulant terminal_reward: Terminal pseudo-reward z (default 0.0)
to_config()
¶
Serialize to dict.
Returns: Dict with all fields needed to recreate the GVFSpec.
Source code in src/alberta_framework/core/types.py
from_config(config)
classmethod
¶
Reconstruct from config dict.
Args:
config: Dict as produced by to_config()
Returns: Reconstructed GVFSpec
Source code in src/alberta_framework/core/types.py
HordeSpec
¶
Collection of GVF demons, one per head.
Attributes:
demons: Tuple of GVFSpec, one per demon/head
gammas: Pre-computed gamma array for JIT, shape (n_demons,)
lamdas: Pre-computed lambda array for JIT, shape (n_demons,)
to_config()
¶
Serialize to dict.
Returns:
Dict with demons list, each serialized via GVFSpec.to_config().
from_config(config)
classmethod
¶
Reconstruct from config dict.
Args:
config: Dict as produced by to_config()
Returns:
Reconstructed HordeSpec via create_horde_spec
Source code in src/alberta_framework/core/types.py
IDBDState
¶
State for the IDBD (Incremental Delta-Bar-Delta) optimizer.
IDBD maintains per-weight adaptive step-sizes that are meta-learned based on the correlation of successive gradients.
Reference: Sutton 1992, "Adapting Bias by Gradient Descent"
Attributes: log_step_sizes: Log of per-weight step-sizes (log alpha_i) traces: Per-weight traces h_i for gradient correlation meta_step_size: Meta learning rate beta for adapting step-sizes bias_step_size: Step-size for the bias term bias_trace: Trace for the bias term
LearnerState
¶
State for a linear learner.
Attributes: weights: Weight vector for linear prediction bias: Bias term optimizer_state: State maintained by the optimizer normalizer_state: Optional state for online feature normalization
LMSState
¶
State for the LMS (Least Mean Square) optimizer.
LMS uses a fixed step-size, so state only tracks the step-size parameter.
Attributes: step_size: Fixed learning rate alpha
TDIDBDState
¶
State for the TD-IDBD (Temporal-Difference IDBD) optimizer.
TD-IDBD extends IDBD to temporal-difference learning with eligibility traces. Maintains per-weight adaptive step-sizes that are meta-learned based on gradient correlation in the TD setting.
Reference: Kearney et al. 2019, "Learning Feature Relevance Through Step Size Adaptation in Temporal-Difference Learning"
Attributes: log_step_sizes: Log of per-weight step-sizes (log alpha_i) eligibility_traces: Eligibility traces z_i for temporal credit assignment h_traces: Per-weight h traces for gradient correlation meta_step_size: Meta learning rate theta for adapting step-sizes trace_decay: Eligibility trace decay parameter lambda bias_log_step_size: Log step-size for the bias term bias_eligibility_trace: Eligibility trace for the bias bias_h_trace: h trace for the bias term
TDLearnerState
¶
State for a TD linear learner.
Attributes: weights: Weight vector for linear value function approximation bias: Bias term optimizer_state: State maintained by the TD optimizer
TDTimeStep
¶
Single experience from a TD stream.
Represents a transition (s, r, s', gamma) for temporal-difference learning.
Attributes: observation: Feature vector phi(s) reward: Reward R received next_observation: Feature vector phi(s') gamma: Discount factor gamma_t (0 at terminal states)
TimeStep
¶
Single experience from an experience stream.
Attributes: observation: Feature vector x_t target: Desired output y*_t (for supervised learning)
run_horde_learning_loop(horde, state, observations, cumulants, next_observations)
¶
Run Horde learning loop using jax.lax.scan.
Scans over (obs, cumulants, next_obs) triples.
Args:
horde: Horde learner
state: Initial learner state
observations: Input observations, shape (num_steps, feature_dim)
cumulants: Per-demon cumulants, shape (num_steps, n_demons).
NaN = inactive demon for that step.
next_observations: Next observations, shape (num_steps, feature_dim)
Returns: HordeLearningResult with final state, per-demon metrics, and TD errors
Source code in src/alberta_framework/core/horde.py
run_horde_learning_loop_batched(horde, observations, cumulants, next_observations, keys)
¶
Run Horde learning loop across seeds using jax.vmap.
Each seed produces an independently initialized state. All seeds share the same observations, cumulants, and next observations.
Args:
horde: Horde learner
observations: Shared observations, shape (num_steps, feature_dim)
cumulants: Shared cumulants, shape (num_steps, n_demons)
next_observations: Shared next observations,
shape (num_steps, feature_dim)
keys: JAX random keys, shape (n_seeds,) or (n_seeds, 2)
Returns: BatchedHordeResult with batched states, per-demon metrics, and TD errors
Source code in src/alberta_framework/core/horde.py
create_horde_spec(demons)
¶
Create a HordeSpec from a sequence of GVFSpec demons.
Pre-computes gamma and lambda arrays for efficient JIT usage.
Args: demons: Sequence of GVFSpec, one per demon/head
Returns: HordeSpec with pre-computed arrays