budget
budget
¶
Budget and entropy response mixin for the global learning store.
This module contains the BudgetMixin class that provides exploration budget management and automatic entropy response functionality. The exploration budget prevents pattern selection from converging to zero diversity, while entropy responses automatically inject diversity when the system detects low entropy.
Evolution v23: Exploration Budget Maintenance - dynamic budget with floor/ceiling. Evolution v23: Automatic Entropy Response - automatic diversity injection.
Extracted from global_store.py as part of the modularization effort.
Classes¶
EntropyResponseConfig
dataclass
¶
EntropyResponseConfig(boost_budget=True, revisit_quarantine=True, max_quarantine_revisits=3, budget_floor=0.05, budget_ceiling=0.5, budget_boost_amount=0.1)
Configuration for entropy response actions.
Groups the tuneable parameters for trigger_entropy_response(),
reducing its parameter count and making configs reusable.
Attributes¶
boost_budget
class-attribute
instance-attribute
¶
Whether to boost exploration budget.
revisit_quarantine
class-attribute
instance-attribute
¶
Whether to revisit quarantined patterns.
max_quarantine_revisits
class-attribute
instance-attribute
¶
Maximum quarantined patterns to revisit per response.
budget_ceiling
class-attribute
instance-attribute
¶
Ceiling for budget enforcement.
budget_boost_amount
class-attribute
instance-attribute
¶
Amount to boost budget by.
EntropyTriggerContext
dataclass
¶
Runtime context for an entropy response trigger.
Bundles the positional parameters of trigger_entropy_response() into a
single typed object, keeping the method signature manageable when combined
with EntropyResponseConfig.
BudgetMixin
¶
Mixin providing exploration budget and entropy response functionality.
This mixin provides methods for managing the exploration budget (which controls how much the system explores vs exploits known patterns) and automatic entropy responses (which inject diversity when entropy drops).
The exploration budget uses a floor to ensure diversity never goes to zero, and a ceiling to prevent over-exploration. It adjusts dynamically based on measured entropy: low entropy triggers boosts, healthy entropy allows decay.
Requires the following from the composed class
- _get_connection() -> context manager yielding sqlite3.Connection
Functions¶
get_exploration_budget
¶
Get the most recent exploration budget record.
v23 Evolution: Exploration Budget Maintenance - returns the current exploration budget state for pattern selection modulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by specific job. |
None
|
Returns:
| Type | Description |
|---|---|
ExplorationBudgetRecord | None
|
The most recent ExplorationBudgetRecord, or None if no budget recorded. |
Source code in src/marianne/learning/store/budget.py
get_exploration_budget_history
¶
Get exploration budget history for analysis.
v23 Evolution: Exploration Budget Maintenance - returns historical budget records for visualization and trend analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by specific job. |
None
|
limit
|
int
|
Maximum number of records to return. |
50
|
Returns:
| Type | Description |
|---|---|
list[ExplorationBudgetRecord]
|
List of ExplorationBudgetRecord objects, most recent first. |
Source code in src/marianne/learning/store/budget.py
update_exploration_budget
¶
update_exploration_budget(job_hash, budget_value, adjustment_type, entropy_at_time=None, adjustment_reason=None, floor=0.05, ceiling=0.5)
Update the exploration budget with floor and ceiling enforcement.
v23 Evolution: Exploration Budget Maintenance - records budget adjustments while enforcing floor (never go to zero) and ceiling limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str
|
Hash of the job updating the budget. |
required |
budget_value
|
float
|
Proposed new budget value. |
required |
adjustment_type
|
str
|
Type: 'initial', 'decay', 'boost', 'floor_enforced'. |
required |
entropy_at_time
|
float | None
|
Optional entropy measurement at adjustment time. |
None
|
adjustment_reason
|
str | None
|
Human-readable reason for adjustment. |
None
|
floor
|
float
|
Minimum allowed budget (default 0.05 = 5%). |
0.05
|
ceiling
|
float
|
Maximum allowed budget (default 0.50 = 50%). |
0.5
|
Returns:
| Type | Description |
|---|---|
ExplorationBudgetRecord
|
The new ExplorationBudgetRecord. |
Source code in src/marianne/learning/store/budget.py
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 | |
calculate_budget_adjustment
¶
calculate_budget_adjustment(job_hash, current_entropy, floor=0.05, ceiling=0.5, decay_rate=0.95, boost_amount=0.1, entropy_threshold=0.3, initial_budget=0.15)
Calculate and record the next budget adjustment based on entropy.
v23 Evolution: Exploration Budget Maintenance - implements the core budget adjustment logic: - When entropy < threshold: boost budget by boost_amount - When entropy >= threshold: decay budget by decay_rate - Budget never drops below floor or exceeds ceiling
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str
|
Hash of the job. |
required |
current_entropy
|
float
|
Current pattern entropy (0.0-1.0). |
required |
floor
|
float
|
Minimum budget floor (default 0.05). |
0.05
|
ceiling
|
float
|
Maximum budget ceiling (default 0.50). |
0.5
|
decay_rate
|
float
|
Decay multiplier when entropy healthy (default 0.95). |
0.95
|
boost_amount
|
float
|
Amount to add when entropy low (default 0.10). |
0.1
|
entropy_threshold
|
float
|
Entropy level that triggers boost (default 0.3). |
0.3
|
initial_budget
|
float
|
Starting budget if no history (default 0.15). |
0.15
|
Returns:
| Type | Description |
|---|---|
ExplorationBudgetRecord
|
The new ExplorationBudgetRecord after adjustment. |
Source code in src/marianne/learning/store/budget.py
get_exploration_budget_statistics
¶
Get statistics about exploration budget usage.
v23 Evolution: Exploration Budget Maintenance - provides aggregate statistics for monitoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by specific job. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with budget statistics: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in src/marianne/learning/store/budget.py
check_entropy_response_needed
¶
Check if an entropy response is needed based on current conditions.
v23 Evolution: Automatic Entropy Response - evaluates whether the current entropy level warrants a diversity injection response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str
|
Hash of the job to check. |
required |
entropy_threshold
|
float
|
Entropy below this triggers response. |
0.3
|
cooldown_seconds
|
int
|
Minimum seconds since last response. |
3600
|
Returns:
| Type | Description |
|---|---|
bool
|
Tuple of (needs_response, current_entropy, reason): |
float | None
|
|
str
|
|
tuple[bool, float | None, str]
|
|
Source code in src/marianne/learning/store/budget.py
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 | |
trigger_entropy_response
¶
trigger_entropy_response(job_hash='', entropy_at_trigger=0.0, threshold_used=0.0, *, trigger=None, config=None, boost_budget=None, revisit_quarantine=None, max_quarantine_revisits=None, budget_floor=None, budget_ceiling=None, budget_boost_amount=None)
Execute an entropy response by boosting budget and/or revisiting quarantine.
v23 Evolution: Automatic Entropy Response - performs the actual response actions when entropy has dropped below threshold.
Supports two calling conventions
- Positional (legacy):
trigger_entropy_response(job_hash, entropy, threshold, ...) - Bundled (preferred):
trigger_entropy_response(trigger=ctx, config=cfg)
When trigger is supplied, its fields take precedence over positional arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str
|
Hash of the job triggering response (legacy positional). |
''
|
entropy_at_trigger
|
float
|
Entropy value that triggered this response (legacy positional). |
0.0
|
threshold_used
|
float
|
The threshold that was crossed (legacy positional). |
0.0
|
trigger
|
EntropyTriggerContext | None
|
Bundled trigger context (preferred over positional args). |
None
|
config
|
EntropyResponseConfig | None
|
Configuration object grouping all response tuning params. Individual keyword arguments override config values when both are provided. |
None
|
boost_budget
|
bool | None
|
Whether to boost exploration budget. |
None
|
revisit_quarantine
|
bool | None
|
Whether to revisit quarantined patterns. |
None
|
max_quarantine_revisits
|
int | None
|
Maximum patterns to revisit. |
None
|
budget_floor
|
float | None
|
Floor for budget enforcement. |
None
|
budget_ceiling
|
float | None
|
Ceiling for budget enforcement. |
None
|
budget_boost_amount
|
float | None
|
Amount to boost budget by. |
None
|
Returns:
| Type | Description |
|---|---|
EntropyResponseRecord
|
The EntropyResponseRecord documenting the response. |
Source code in src/marianne/learning/store/budget.py
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 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 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 | |
get_last_entropy_response
¶
Get the most recent entropy response record.
v23 Evolution: Automatic Entropy Response - used for cooldown checking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
EntropyResponseRecord | None
|
The most recent EntropyResponseRecord, or None if none found. |
Source code in src/marianne/learning/store/budget.py
get_entropy_response_history
¶
Get entropy response history for analysis.
v23 Evolution: Automatic Entropy Response - returns historical response records for visualization and trend analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by. |
None
|
limit
|
int
|
Maximum number of records to return. |
50
|
Returns:
| Type | Description |
|---|---|
list[EntropyResponseRecord]
|
List of EntropyResponseRecord objects, most recent first. |
Source code in src/marianne/learning/store/budget.py
get_entropy_response_statistics
¶
Get statistics about entropy responses.
v23 Evolution: Automatic Entropy Response - provides aggregate statistics for monitoring and reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_hash
|
str | None
|
Optional job hash to filter by. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with response statistics. |
Source code in src/marianne/learning/store/budget.py
calculate_pattern_entropy
¶
Calculate current Shannon entropy of the pattern population.
Queries all patterns with at least one application and computes
Shannon entropy over the application-count distribution. This
reuses the same algorithm as check_entropy_response_needed
but returns a structured result for CLI display and recording.
Returns:
| Type | Description |
|---|---|
PatternEntropyMetrics
|
PatternEntropyMetrics with the current entropy snapshot. |
Source code in src/marianne/learning/store/budget.py
record_pattern_entropy
¶
Persist a pattern entropy snapshot for historical trend analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
PatternEntropyMetrics
|
The entropy metrics to record. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The record ID of the persisted snapshot. |
Source code in src/marianne/learning/store/budget.py
get_pattern_entropy_history
¶
Retrieve historical entropy snapshots for trend analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of records to return. |
50
|
Returns:
| Type | Description |
|---|---|
list[PatternEntropyMetrics]
|
List of PatternEntropyMetrics, most recent first. |