drift
drift
¶
Drift detection mixin for the global learning store.
This module contains the DriftMixin class that provides drift detection and pattern retirement functionality. Drift detection monitors how patterns change over time in both effectiveness and epistemic confidence.
Evolution v12: Goal Drift Detection - enables proactive pattern health monitoring. Evolution v21: Epistemic Drift Detection - complements effectiveness drift with belief-level monitoring. Evolution v14: Pattern Auto-Retirement - automated pattern lifecycle management.
Extracted from global_store.py as part of the modularization effort.
Classes¶
DriftMixin
¶
Mixin providing drift detection and pattern retirement functionality.
This mixin provides methods for detecting effectiveness drift and epistemic drift in patterns, as well as automatic retirement of drifting patterns.
Effectiveness drift tracks changes in success rates over time. Epistemic drift tracks changes in confidence/belief levels over time.
Requires the following from the composed class
- _get_connection() -> context manager yielding sqlite3.Connection
Functions¶
calculate_effectiveness_drift
¶
Calculate effectiveness drift for a pattern.
Compares the effectiveness of a pattern in its recent applications vs older applications to detect drift. Patterns that were once effective but are now declining may need investigation.
v12 Evolution: Goal Drift Detection - enables proactive pattern health monitoring.
Formula
drift = effectiveness_after - effectiveness_before drift_magnitude = |drift| weighted_drift = drift_magnitude / avg_grounding_confidence
A positive drift means the pattern is improving, negative means declining. The weighted drift amplifies the signal when grounding confidence is low.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_id
|
str
|
Pattern to analyze. |
required |
window_size
|
int
|
Number of applications per window (default 5). Total applications needed = 2 × window_size. |
5
|
drift_threshold
|
float
|
Threshold for flagging drift (default 0.2 = 20%). |
0.2
|
Returns:
| Type | Description |
|---|---|
DriftMetrics | None
|
DriftMetrics if enough data exists, None otherwise. |
Source code in src/marianne/learning/store/drift.py
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 | |
get_drifting_patterns
¶
Get all patterns with significant drift.
Scans all patterns with enough application history and returns those that exceed the drift threshold.
v12 Evolution: Goal Drift Detection - enables CLI display of drifting patterns for operator review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift_threshold
|
float
|
Minimum drift to include (default 0.2). |
0.2
|
window_size
|
int
|
Applications per window (default 5). |
5
|
limit
|
int
|
Maximum patterns to return. |
20
|
Returns:
| Type | Description |
|---|---|
list[DriftMetrics]
|
List of DriftMetrics for drifting patterns, sorted by |
list[DriftMetrics]
|
drift_magnitude descending. |
Source code in src/marianne/learning/store/drift.py
get_pattern_drift_summary
¶
Get a summary of pattern drift across all patterns.
Provides aggregate statistics for monitoring pattern health.
v12 Evolution: Goal Drift Detection - supports dashboard/reporting.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with drift statistics: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in src/marianne/learning/store/drift.py
calculate_epistemic_drift
¶
Calculate epistemic drift for a pattern - how belief/confidence changes over time.
Unlike effectiveness drift (which tracks outcome success rates), epistemic drift tracks how our CONFIDENCE in the pattern changes. This enables detecting belief degradation before effectiveness actually declines.
v21 Evolution: Epistemic Drift Detection - complements effectiveness drift with belief-level monitoring.
Formula
belief_change = avg_confidence_after - avg_confidence_before belief_entropy = std_dev(all_confidence_values) / mean(all_confidence_values) weighted_change = |belief_change| × (1 + belief_entropy)
A positive belief_change means growing confidence, negative means declining. High entropy indicates unstable beliefs (variance in confidence).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_id
|
str
|
Pattern to analyze. |
required |
window_size
|
int
|
Number of applications per window (default 5). Total applications needed = 2 × window_size. |
5
|
drift_threshold
|
float
|
Threshold for flagging epistemic drift (default 0.15 = 15%). |
0.15
|
Returns:
| Type | Description |
|---|---|
EpistemicDriftMetrics | None
|
EpistemicDriftMetrics if enough data exists, None otherwise. |
Source code in src/marianne/learning/store/drift.py
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 | |
get_epistemic_drifting_patterns
¶
Get all patterns with significant epistemic drift.
Scans all patterns with enough application history and returns those that exceed the epistemic drift threshold.
v21 Evolution: Epistemic Drift Detection - enables CLI display of patterns with changing beliefs for operator review.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift_threshold
|
float
|
Minimum epistemic drift to include (default 0.15). |
0.15
|
window_size
|
int
|
Applications per window (default 5). |
5
|
limit
|
int
|
Maximum patterns to return. |
20
|
Returns:
| Type | Description |
|---|---|
list[EpistemicDriftMetrics]
|
List of EpistemicDriftMetrics for drifting patterns, sorted by |
list[EpistemicDriftMetrics]
|
belief_change magnitude descending. |
Source code in src/marianne/learning/store/drift.py
get_epistemic_drift_summary
¶
Get a summary of epistemic drift across all patterns.
Provides aggregate statistics for monitoring belief/confidence health.
v21 Evolution: Epistemic Drift Detection - supports dashboard/reporting.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with epistemic drift statistics: |
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/drift.py
retire_drifting_patterns
¶
Retire patterns that are drifting negatively.
Connects the drift detection infrastructure (DriftMetrics) to action. Patterns that have drifted significantly AND in a negative direction are retired by setting their priority_score to 0.
v14 Evolution: Pattern Auto-Retirement - enables automated pattern lifecycle management based on empirical effectiveness drift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift_threshold
|
float
|
Minimum drift magnitude to consider (default 0.2). |
0.2
|
window_size
|
int
|
Applications per window for drift calculation. |
5
|
require_negative_drift
|
bool
|
If True, only retire patterns with negative drift (getting worse). If False, also retire patterns with positive anomalous drift. |
True
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, str, float]]
|
List of (pattern_id, pattern_name, drift_magnitude) tuples for |
list[tuple[str, str, float]]
|
patterns that were retired. |
Source code in src/marianne/learning/store/drift.py
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 | |
get_retired_patterns
¶
Get patterns that have been retired (priority_score = 0).
Returns patterns that were retired through auto-retirement or manual deprecation, useful for review and potential recovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of patterns to return. |
50
|
Returns:
| Type | Description |
|---|---|
list[PatternRecord]
|
List of PatternRecord objects with priority_score = 0. |
Source code in src/marianne/learning/store/drift.py
record_evolution_entry
¶
record_evolution_entry(cycle=None, evolutions_completed=None, evolutions_deferred=None, issue_classes=None, cv_avg=None, implementation_loc=None, test_loc=None, loc_accuracy=None, research_candidates_resolved=0, research_candidates_created=0, notes='', *, entry=None)
Record an evolution cycle entry to the trajectory.
v16 Evolution: Evolution Trajectory Tracking - enables Marianne to track its own evolution history for recursive self-improvement analysis.
Accepts either individual keyword args (backward compatible) or
a bundled EvolutionEntryInput dataclass via the entry kwarg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
int | None
|
Evolution cycle number (e.g., 16 for v16). |
None
|
evolutions_completed
|
int | None
|
Number of evolutions completed in this cycle. |
None
|
evolutions_deferred
|
int | None
|
Number of evolutions deferred in this cycle. |
None
|
issue_classes
|
list[str] | None
|
Issue classes addressed (e.g., ['infrastructure_activation']). |
None
|
cv_avg
|
float | None
|
Average Consciousness Volume of selected evolutions. |
None
|
implementation_loc
|
int | None
|
Total implementation LOC for this cycle. |
None
|
test_loc
|
int | None
|
Total test LOC for this cycle. |
None
|
loc_accuracy
|
float | None
|
LOC estimation accuracy (actual/estimated as ratio). |
None
|
research_candidates_resolved
|
int
|
Number of research candidates resolved. |
0
|
research_candidates_created
|
int
|
Number of new research candidates created. |
0
|
notes
|
str
|
Optional notes about this evolution cycle. |
''
|
entry
|
EvolutionEntryInput | None
|
Bundled input parameters (overrides individual args if provided). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The ID of the created trajectory entry. |
Raises:
| Type | Description |
|---|---|
IntegrityError
|
If an entry for this cycle already exists. |
Source code in src/marianne/learning/store/drift.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 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 | |
get_trajectory
¶
Retrieve evolution trajectory history.
v16 Evolution: Evolution Trajectory Tracking - enables analysis of Marianne's evolution history over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_cycle
|
int | None
|
Optional minimum cycle number to include. |
None
|
end_cycle
|
int | None
|
Optional maximum cycle number to include. |
None
|
limit
|
int
|
Maximum number of entries to return (default: 50). |
50
|
Returns:
| Type | Description |
|---|---|
list[EvolutionTrajectoryEntry]
|
List of EvolutionTrajectoryEntry objects, ordered by cycle descending. |
Source code in src/marianne/learning/store/drift.py
get_recurring_issues
¶
Identify recurring issue classes across evolution cycles.
v16 Evolution: Evolution Trajectory Tracking - enables identification of patterns in what types of issues Marianne addresses repeatedly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_occurrences
|
int
|
Minimum number of occurrences to consider recurring. |
2
|
window_cycles
|
int | None
|
Optional limit to analyze only recent N cycles. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[int]]
|
Dict mapping issue class names to list of cycles where they appeared. |
dict[str, list[int]]
|
Only includes issue classes that meet the min_occurrences threshold. |
Source code in src/marianne/learning/store/drift.py
record_evolution_cycle
¶
record_evolution_cycle(cycle_number, candidates_generated, candidates_applied, changes_summary, outcome, learning_snapshot)
Record evolution cycle metadata to trajectory table.
v25 Evolution: Simplified wrapper for recording evolution cycles with essential metadata. Maps to the more detailed record_evolution_entry() internal method.
This method provides a simpler interface focused on what evolution cycles need to record: how many candidates were generated/applied, what changed, and the outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle_number
|
int
|
Evolution cycle number (e.g., 25 for v25). |
required |
candidates_generated
|
int
|
Number of evolution candidates generated. |
required |
candidates_applied
|
int
|
Number of candidates successfully applied. |
required |
changes_summary
|
str
|
Git diff summary or description of changes. |
required |
outcome
|
Literal['SUCCESS', 'PARTIAL', 'DEFERRED']
|
Evolution outcome - SUCCESS, PARTIAL, or DEFERRED. |
required |
learning_snapshot
|
dict[str, Any]
|
Dict containing learning metrics at time of cycle. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ID of the created trajectory entry. |
Raises:
| Type | Description |
|---|---|
IntegrityError
|
If an entry for this cycle already exists. |
Example
store = GlobalLearningStore() entry_id = store.record_evolution_cycle( ... cycle_number=25, ... candidates_generated=5, ... candidates_applied=3, ... changes_summary="Fixed learning export, wired pattern lifecycle", ... outcome="SUCCESS", ... learning_snapshot={ ... "patterns": 6, ... "entropy": 0.000, ... "recovery_rate": 0.0 ... } ... )
Source code in src/marianne/learning/store/drift.py
get_evolution_history
¶
Retrieve last N evolution cycles for context.
v25 Evolution: Simplified wrapper for retrieving evolution history. Maps to the more detailed get_trajectory() method.
This provides a simpler interface focused on getting recent evolution history for context in future cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_n
|
int
|
Number of recent cycles to retrieve (default: 10). |
10
|
Returns:
| Type | Description |
|---|---|
list[EvolutionTrajectoryEntry]
|
List of EvolutionTrajectoryEntry objects, ordered by cycle descending |
list[EvolutionTrajectoryEntry]
|
(most recent first). |
Example
store = GlobalLearningStore() recent_cycles = store.get_evolution_history(last_n=5) for entry in recent_cycles: ... print(f"Cycle {entry.cycle}: {entry.evolutions_completed} completed")