margin 0.9.1__tar.gz → 0.9.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of margin might be problematic. Click here for more details.

Files changed (85) hide show
  1. {margin-0.9.1/margin.egg-info → margin-0.9.2}/PKG-INFO +1 -1
  2. {margin-0.9.1 → margin-0.9.2}/margin/health.py +8 -0
  3. {margin-0.9.1 → margin-0.9.2}/margin/loop.py +9 -0
  4. {margin-0.9.1 → margin-0.9.2}/margin/observation.py +12 -2
  5. {margin-0.9.1 → margin-0.9.2}/margin/persist.py +12 -7
  6. {margin-0.9.1 → margin-0.9.2}/margin/policy/core.py +3 -1
  7. {margin-0.9.1 → margin-0.9.2}/margin/policy/trace.py +15 -11
  8. {margin-0.9.1 → margin-0.9.2}/margin/streaming.py +46 -25
  9. {margin-0.9.1 → margin-0.9.2/margin.egg-info}/PKG-INFO +1 -1
  10. {margin-0.9.1 → margin-0.9.2}/pyproject.toml +1 -1
  11. {margin-0.9.1 → margin-0.9.2}/LICENSE +0 -0
  12. {margin-0.9.1 → margin-0.9.2}/NOTICE +0 -0
  13. {margin-0.9.1 → margin-0.9.2}/README.md +0 -0
  14. {margin-0.9.1 → margin-0.9.2}/margin/__init__.py +0 -0
  15. {margin-0.9.1 → margin-0.9.2}/margin/__main__.py +0 -0
  16. {margin-0.9.1 → margin-0.9.2}/margin/algebra.py +0 -0
  17. {margin-0.9.1 → margin-0.9.2}/margin/anomaly.py +0 -0
  18. {margin-0.9.1 → margin-0.9.2}/margin/bridge.py +0 -0
  19. {margin-0.9.1 → margin-0.9.2}/margin/calibrate.py +0 -0
  20. {margin-0.9.1 → margin-0.9.2}/margin/causal.py +0 -0
  21. {margin-0.9.1 → margin-0.9.2}/margin/composite.py +0 -0
  22. {margin-0.9.1 → margin-0.9.2}/margin/confidence.py +0 -0
  23. {margin-0.9.1 → margin-0.9.2}/margin/config.py +0 -0
  24. {margin-0.9.1 → margin-0.9.2}/margin/contract.py +0 -0
  25. {margin-0.9.1 → margin-0.9.2}/margin/correlate.py +0 -0
  26. {margin-0.9.1 → margin-0.9.2}/margin/diff.py +0 -0
  27. {margin-0.9.1 → margin-0.9.2}/margin/drift.py +0 -0
  28. {margin-0.9.1 → margin-0.9.2}/margin/events.py +0 -0
  29. {margin-0.9.1 → margin-0.9.2}/margin/forecast.py +0 -0
  30. {margin-0.9.1 → margin-0.9.2}/margin/intent.py +0 -0
  31. {margin-0.9.1 → margin-0.9.2}/margin/ledger.py +0 -0
  32. {margin-0.9.1 → margin-0.9.2}/margin/policy/__init__.py +0 -0
  33. {margin-0.9.1 → margin-0.9.2}/margin/policy/compose.py +0 -0
  34. {margin-0.9.1 → margin-0.9.2}/margin/policy/temporal.py +0 -0
  35. {margin-0.9.1 → margin-0.9.2}/margin/policy/tuning.py +0 -0
  36. {margin-0.9.1 → margin-0.9.2}/margin/policy/validate.py +0 -0
  37. {margin-0.9.1 → margin-0.9.2}/margin/predicates.py +0 -0
  38. {margin-0.9.1 → margin-0.9.2}/margin/provenance.py +0 -0
  39. {margin-0.9.1 → margin-0.9.2}/margin/transitions.py +0 -0
  40. {margin-0.9.1 → margin-0.9.2}/margin/uncertain.py +0 -0
  41. {margin-0.9.1 → margin-0.9.2}/margin/validity.py +0 -0
  42. {margin-0.9.1 → margin-0.9.2}/margin.egg-info/SOURCES.txt +0 -0
  43. {margin-0.9.1 → margin-0.9.2}/margin.egg-info/dependency_links.txt +0 -0
  44. {margin-0.9.1 → margin-0.9.2}/margin.egg-info/top_level.txt +0 -0
  45. {margin-0.9.1 → margin-0.9.2}/setup.cfg +0 -0
  46. {margin-0.9.1 → margin-0.9.2}/tests/test_algebra.py +0 -0
  47. {margin-0.9.1 → margin-0.9.2}/tests/test_anomaly.py +0 -0
  48. {margin-0.9.1 → margin-0.9.2}/tests/test_bridge.py +0 -0
  49. {margin-0.9.1 → margin-0.9.2}/tests/test_calibrate.py +0 -0
  50. {margin-0.9.1 → margin-0.9.2}/tests/test_causal.py +0 -0
  51. {margin-0.9.1 → margin-0.9.2}/tests/test_composite.py +0 -0
  52. {margin-0.9.1 → margin-0.9.2}/tests/test_confidence.py +0 -0
  53. {margin-0.9.1 → margin-0.9.2}/tests/test_config.py +0 -0
  54. {margin-0.9.1 → margin-0.9.2}/tests/test_contract.py +0 -0
  55. {margin-0.9.1 → margin-0.9.2}/tests/test_correlate.py +0 -0
  56. {margin-0.9.1 → margin-0.9.2}/tests/test_diff.py +0 -0
  57. {margin-0.9.1 → margin-0.9.2}/tests/test_drift.py +0 -0
  58. {margin-0.9.1 → margin-0.9.2}/tests/test_events.py +0 -0
  59. {margin-0.9.1 → margin-0.9.2}/tests/test_forecast.py +0 -0
  60. {margin-0.9.1 → margin-0.9.2}/tests/test_health.py +0 -0
  61. {margin-0.9.1 → margin-0.9.2}/tests/test_healthcare.py +0 -0
  62. {margin-0.9.1 → margin-0.9.2}/tests/test_intent.py +0 -0
  63. {margin-0.9.1 → margin-0.9.2}/tests/test_ledger.py +0 -0
  64. {margin-0.9.1 → margin-0.9.2}/tests/test_loop.py +0 -0
  65. {margin-0.9.1 → margin-0.9.2}/tests/test_neuro.py +0 -0
  66. {margin-0.9.1 → margin-0.9.2}/tests/test_observation.py +0 -0
  67. {margin-0.9.1 → margin-0.9.2}/tests/test_persist.py +0 -0
  68. {margin-0.9.1 → margin-0.9.2}/tests/test_policy.py +0 -0
  69. {margin-0.9.1 → margin-0.9.2}/tests/test_policy_compose.py +0 -0
  70. {margin-0.9.1 → margin-0.9.2}/tests/test_policy_temporal.py +0 -0
  71. {margin-0.9.1 → margin-0.9.2}/tests/test_policy_trace.py +0 -0
  72. {margin-0.9.1 → margin-0.9.2}/tests/test_policy_tuning.py +0 -0
  73. {margin-0.9.1 → margin-0.9.2}/tests/test_policy_validate.py +0 -0
  74. {margin-0.9.1 → margin-0.9.2}/tests/test_predicates.py +0 -0
  75. {margin-0.9.1 → margin-0.9.2}/tests/test_printer3d.py +0 -0
  76. {margin-0.9.1 → margin-0.9.2}/tests/test_provenance.py +0 -0
  77. {margin-0.9.1 → margin-0.9.2}/tests/test_reverse_bridge.py +0 -0
  78. {margin-0.9.1 → margin-0.9.2}/tests/test_ros2.py +0 -0
  79. {margin-0.9.1 → margin-0.9.2}/tests/test_staleness.py +0 -0
  80. {margin-0.9.1 → margin-0.9.2}/tests/test_streaming.py +0 -0
  81. {margin-0.9.1 → margin-0.9.2}/tests/test_transformer.py +0 -0
  82. {margin-0.9.1 → margin-0.9.2}/tests/test_transitions.py +0 -0
  83. {margin-0.9.1 → margin-0.9.2}/tests/test_uncertain.py +0 -0
  84. {margin-0.9.1 → margin-0.9.2}/tests/test_validity.py +0 -0
  85. {margin-0.9.1 → margin-0.9.2}/tests/test_windowing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: margin
3
- Version: 0.9.1
3
+ Version: 0.9.2
4
4
  Summary: Typed health classification, uncertainty algebra, and correction auditing for any system that measures things and needs to explain what happened.
5
5
  Author: Cope Labs LLC
6
6
  License: MIT
@@ -46,6 +46,7 @@ class Thresholds:
46
46
  (throughput, signal), False means lower values are
47
47
  healthier (error rate, latency)
48
48
  active_min: minimum correction magnitude to count as "active"
49
+ labels: optional display labels keyed by Health.value strings
49
50
 
50
51
  For higher_is_better=True: intact >= ablated, value >= intact → INTACT
51
52
  For higher_is_better=False: intact <= ablated, value <= intact → INTACT
@@ -54,6 +55,13 @@ class Thresholds:
54
55
  ablated: float
55
56
  higher_is_better: bool = True
56
57
  active_min: float = 0.05
58
+ labels: Optional[dict[str, str]] = None
59
+
60
+ def label_for(self, health: 'Health') -> str:
61
+ """Return the display label for a health state, or the state name if no label set."""
62
+ if self.labels:
63
+ return self.labels.get(health.value, health.value)
64
+ return health.value
57
65
 
58
66
  def __post_init__(self):
59
67
  if self.higher_is_better and self.ablated > self.intact:
@@ -45,6 +45,7 @@ class StepResult:
45
45
  correction: Optional[Correction] = None
46
46
  escalation: Optional[Escalation] = None
47
47
  contract: Optional[ContractResult] = None
48
+ corrections: list = field(default_factory=list) # all fired corrections (multi_rule)
48
49
 
49
50
  @property
50
51
  def acted(self) -> bool:
@@ -74,6 +75,8 @@ class StepResult:
74
75
  d["decision"] = self.decision.to_dict()
75
76
  if self.correction:
76
77
  d["correction"] = self.correction.to_dict()
78
+ if self.corrections:
79
+ d["corrections"] = [c.to_dict() for c in self.corrections]
77
80
  if self.escalation:
78
81
  d["escalation"] = self.escalation.to_dict()
79
82
  if self.contract:
@@ -140,6 +143,11 @@ def step(
140
143
  elif isinstance(decision.result, Escalation):
141
144
  escalation = decision.result
142
145
 
146
+ # Collect all corrections for multi_rule mode
147
+ all_corrections = []
148
+ if policy.multi_rule:
149
+ all_corrections = [r for r in decision.results if isinstance(r, Correction)]
150
+
143
151
  # 3. Evaluate contract
144
152
  contract_result = None
145
153
  if contract:
@@ -152,6 +160,7 @@ def step(
152
160
  correction=correction,
153
161
  escalation=escalation,
154
162
  contract=contract_result,
163
+ corrections=all_corrections,
155
164
  )
156
165
 
157
166
 
@@ -60,6 +60,7 @@ class Observation:
60
60
  higher_is_better: bool = True
61
61
  provenance: list[str] = field(default_factory=list)
62
62
  measured_at: Optional[datetime] = None
63
+ health_label: Optional[str] = None
63
64
 
64
65
  @property
65
66
  def sigma(self) -> float:
@@ -91,10 +92,11 @@ class Observation:
91
92
 
92
93
  def to_atom(self) -> str:
93
94
  """Compact string: NAME:HEALTH(±σ)"""
95
+ display = self.health_label or self.health.value
94
96
  if self.health == Health.OOD:
95
- return f"{self.name}:{self.health.value}"
97
+ return f"{self.name}:{display}"
96
98
  sign = "+" if self.sigma >= 0 else ""
97
- return f"{self.name}:{self.health.value}({sign}{self.sigma:.2f}σ)"
99
+ return f"{self.name}:{display}({sign}{self.sigma:.2f}σ)"
98
100
 
99
101
  def to_dict(self) -> dict:
100
102
  d = {
@@ -107,6 +109,8 @@ class Observation:
107
109
  "higher_is_better": self.higher_is_better,
108
110
  "provenance": self.provenance,
109
111
  }
112
+ if self.health_label is not None:
113
+ d["health_label"] = self.health_label
110
114
  if self.measured_at is not None:
111
115
  d["measured_at"] = self.measured_at.isoformat()
112
116
  return d
@@ -125,6 +129,7 @@ class Observation:
125
129
  higher_is_better=d.get("higher_is_better", True),
126
130
  provenance=d.get("provenance", []),
127
131
  measured_at=measured_at,
132
+ health_label=d.get("health_label"),
128
133
  )
129
134
 
130
135
 
@@ -311,6 +316,10 @@ class Parser:
311
316
  def _thresholds_for(self, name: str) -> Thresholds:
312
317
  return self.component_thresholds.get(name, self.thresholds)
313
318
 
319
+ def label_for(self, component: str, health: Health) -> str:
320
+ """Return the display label for a component's health state."""
321
+ return self._thresholds_for(component).label_for(health)
322
+
314
323
  def parse(
315
324
  self,
316
325
  values: dict[str, float],
@@ -343,6 +352,7 @@ class Parser:
343
352
  name=name, health=h, value=val, baseline=baseline,
344
353
  confidence=conf, higher_is_better=ct.higher_is_better,
345
354
  provenance=list(provenance),
355
+ health_label=ct.label_for(h) if ct.labels else None,
346
356
  ))
347
357
 
348
358
  corrections = []
@@ -33,13 +33,14 @@ def save_monitor(monitor: Monitor, path: str) -> None:
33
33
  "anomaly_window": monitor.anomaly_window,
34
34
  "correlation_window": monitor.correlation_window,
35
35
  "anomaly_min_reference": _anomaly_min_ref,
36
+ "features": sorted(monitor.features),
36
37
  "drift": {},
37
38
  "anomaly": {},
38
39
  "correlation": {
39
40
  "components": monitor._correlation_tracker.components,
40
41
  "series": {c: list(d) for c, d in monitor._correlation_tracker._series.items()},
41
42
  "n_updates": monitor._correlation_tracker.n_updates,
42
- },
43
+ } if monitor._correlation_tracker is not None else None,
43
44
  }
44
45
 
45
46
  for name, dt in monitor._drift_trackers.items():
@@ -71,12 +72,15 @@ def load_monitor(path: str, parser: Parser, **kwargs) -> Monitor:
71
72
  anomaly_window = data.get("anomaly_window", kwargs.pop("anomaly_window", None))
72
73
  correlation_window = data.get("correlation_window", kwargs.pop("correlation_window", None))
73
74
  anomaly_min_reference = data.get("anomaly_min_reference", kwargs.pop("anomaly_min_reference", 10))
75
+ features_data = data.get("features", None)
76
+ features = set(features_data) if features_data is not None else None
74
77
  monitor = Monitor(
75
78
  parser, window=window,
76
79
  drift_window=drift_window,
77
80
  anomaly_window=anomaly_window,
78
81
  correlation_window=correlation_window,
79
82
  anomaly_min_reference=anomaly_min_reference,
83
+ features=features,
80
84
  **kwargs,
81
85
  )
82
86
  monitor._step = data.get("step", 0)
@@ -101,12 +105,13 @@ def load_monitor(path: str, parser: Parser, **kwargs) -> Monitor:
101
105
  tracker._values.append(v)
102
106
 
103
107
  # Restore correlation series
104
- corr_data = data.get("correlation", {})
105
- for c in monitor._correlation_tracker.components:
106
- series = corr_data.get("series", {}).get(c, [])
107
- for v in series:
108
- monitor._correlation_tracker._series[c].append(v)
109
- monitor._correlation_tracker._n_updates = corr_data.get("n_updates", 0)
108
+ corr_data = data.get("correlation")
109
+ if corr_data is not None and monitor._correlation_tracker is not None:
110
+ for c in monitor._correlation_tracker.components:
111
+ series = corr_data.get("series", {}).get(c, [])
112
+ for v in series:
113
+ monitor._correlation_tracker._series[c].append(v)
114
+ monitor._correlation_tracker._n_updates = corr_data.get("n_updates", 0)
110
115
 
111
116
  return monitor
112
117
 
@@ -258,6 +258,7 @@ class Policy:
258
258
  rules: list[PolicyRule] = field(default_factory=list)
259
259
  default_constraint: Optional[Constraint] = None
260
260
  default_escalation: Optional[Escalation] = None
261
+ multi_rule: bool = False
261
262
 
262
263
  def evaluate(self, expr: Expression, ledger: Optional[Ledger] = None) -> list[Union[Correction, Escalation]]:
263
264
  matching = sorted([r for r in self.rules if r.matches(expr)],
@@ -305,7 +306,7 @@ class Policy:
305
306
  return results
306
307
 
307
308
  def to_dict(self) -> dict:
308
- d: dict = {"name": self.name, "rules": [r.to_dict() for r in self.rules]}
309
+ d: dict = {"name": self.name, "rules": [r.to_dict() for r in self.rules], "multi_rule": self.multi_rule}
309
310
  if self.default_constraint:
310
311
  d["default_constraint"] = self.default_constraint.to_dict()
311
312
  if self.default_escalation:
@@ -324,6 +325,7 @@ class Policy:
324
325
  name=d["name"], rules=rules,
325
326
  default_constraint=Constraint.from_dict(d["default_constraint"]) if "default_constraint" in d else None,
326
327
  default_escalation=Escalation.from_dict(d["default_escalation"]) if "default_escalation" in d else None,
328
+ multi_rule=d.get("multi_rule", False),
327
329
  )
328
330
 
329
331
  def __repr__(self) -> str:
@@ -59,6 +59,7 @@ class DecisionTrace:
59
59
  winner: Optional[str] = None
60
60
  result: Optional[Union[Correction, Escalation]] = None
61
61
  causal_context: Optional[dict] = None # from causal.explain_all() if available
62
+ results: list = field(default_factory=list) # all fired corrections/escalations (multi_rule)
62
63
 
63
64
  @property
64
65
  def rules_considered(self) -> int:
@@ -111,6 +112,11 @@ class DecisionTrace:
111
112
  d["result_type"] = None
112
113
  if self.causal_context:
113
114
  d["causal_context"] = self.causal_context
115
+ if self.results:
116
+ d["results"] = [
117
+ r.to_dict() if hasattr(r, 'to_dict') else str(r)
118
+ for r in self.results
119
+ ]
114
120
  return d
115
121
 
116
122
  def __repr__(self) -> str:
@@ -132,12 +138,12 @@ def trace_evaluate(
132
138
  attached to the trace for auditability.
133
139
  """
134
140
  dt = DecisionTrace(expression=expr, causal_context=causal_context)
135
- winner_result = None
136
- winner_name = None
137
141
 
138
142
  # Evaluate all rules in priority order
139
143
  sorted_rules = sorted(policy.rules, key=lambda r: r.priority, reverse=True)
140
144
 
145
+ all_results = []
146
+
141
147
  for rule in sorted_rules:
142
148
  matched = rule.matches(expr)
143
149
  ev = RuleEvaluation(
@@ -156,26 +162,24 @@ def trace_evaluate(
156
162
  ev.outcome = "escalation"
157
163
  ev.reason = f"{result.level.value}: {result.reason}"
158
164
  ev.result = result
159
-
160
- if winner_result is None:
161
- winner_result = result
162
- winner_name = rule.name
165
+ all_results.append((rule.name, result))
163
166
  else:
164
167
  ev.outcome = "suppressed"
165
168
  ev.reason = "evaluate returned None"
166
169
 
167
170
  dt.evaluations.append(ev)
168
171
 
169
- if winner_result is None and policy.default_escalation:
170
- winner_result = Escalation(
172
+ if not all_results and policy.default_escalation:
173
+ default_esc = Escalation(
171
174
  policy.default_escalation.level,
172
175
  policy.default_escalation.reason,
173
176
  "default",
174
177
  )
175
- winner_name = "default"
178
+ all_results.append(("default", default_esc))
176
179
 
177
- dt.winner = winner_name
178
- dt.result = winner_result
180
+ dt.results = [r for _, r in all_results]
181
+ dt.winner = all_results[0][0] if all_results else None
182
+ dt.result = all_results[0][1] if all_results else None
179
183
  return dt
180
184
 
181
185
 
@@ -364,6 +364,7 @@ class Monitor:
364
364
  window_config: Optional[WindowConfig] = None,
365
365
  min_correlation: float = 0.7,
366
366
  anomaly_min_reference: int = 10,
367
+ features: Optional[set] = None,
367
368
  ):
368
369
  self.parser = parser
369
370
  self.window = window
@@ -374,7 +375,10 @@ class Monitor:
374
375
  self.anomaly_window = cfg.anomaly or anomaly_window or window
375
376
  self.correlation_window = cfg.correlation or correlation_window or window
376
377
 
377
- if anomaly_min_reference > self.anomaly_window:
378
+ # Resolve feature flags: None means all enabled (backward compatible)
379
+ self.features = frozenset(features) if features is not None else frozenset({"drift", "anomaly", "correlation"})
380
+
381
+ if "anomaly" in self.features and anomaly_min_reference > self.anomaly_window:
378
382
  warnings.warn(
379
383
  f"Monitor: anomaly_min_reference={anomaly_min_reference} > "
380
384
  f"anomaly_window={self.anomaly_window} — AnomalyTrackers will never "
@@ -386,22 +390,28 @@ class Monitor:
386
390
  self._expression: Optional[Expression] = None
387
391
  self._step = 0
388
392
 
389
- # Create per-component trackers
393
+ # Create per-component trackers for enabled features only
390
394
  self._drift_trackers: dict[str, DriftTracker] = {}
391
395
  self._anomaly_trackers: dict[str, AnomalyTracker] = {}
392
396
 
393
- for name in parser.baselines:
394
- self._drift_trackers[name] = DriftTracker(name, window=self.drift_window)
395
- self._anomaly_trackers[name] = AnomalyTracker(
396
- name, window=self.anomaly_window, min_reference=anomaly_min_reference,
397
- )
397
+ if "drift" in self.features:
398
+ for name in parser.baselines:
399
+ self._drift_trackers[name] = DriftTracker(name, window=self.drift_window)
398
400
 
399
- # Correlation tracker across all components
400
- self._correlation_tracker = CorrelationTracker(
401
- list(parser.baselines.keys()),
402
- window=self.correlation_window,
403
- min_correlation=min_correlation,
404
- )
401
+ if "anomaly" in self.features:
402
+ for name in parser.baselines:
403
+ self._anomaly_trackers[name] = AnomalyTracker(
404
+ name, window=self.anomaly_window, min_reference=anomaly_min_reference,
405
+ )
406
+
407
+ if "correlation" in self.features:
408
+ self._correlation_tracker: Optional[CorrelationTracker] = CorrelationTracker(
409
+ list(parser.baselines.keys()),
410
+ window=self.correlation_window,
411
+ min_correlation=min_correlation,
412
+ )
413
+ else:
414
+ self._correlation_tracker = None
405
415
 
406
416
  def update(
407
417
  self,
@@ -440,7 +450,8 @@ class Monitor:
440
450
  self._anomaly_trackers[name].update(obs.value)
441
451
 
442
452
  # Correlation
443
- self._correlation_tracker.update(values)
453
+ if self._correlation_tracker is not None:
454
+ self._correlation_tracker.update(values)
444
455
 
445
456
  return self._expression
446
457
 
@@ -458,6 +469,8 @@ class Monitor:
458
469
 
459
470
  @property
460
471
  def correlations(self) -> Optional[CorrelationMatrix]:
472
+ if self._correlation_tracker is None:
473
+ return None
461
474
  return self._correlation_tracker.matrix
462
475
 
463
476
  @property
@@ -469,16 +482,18 @@ class Monitor:
469
482
  d: dict = {
470
483
  "step": self._step,
471
484
  "expression": self._expression.to_dict() if self._expression else None,
472
- "drift": {},
473
- "anomaly": {},
474
485
  }
475
- for name, tracker in self._drift_trackers.items():
476
- if tracker.classification:
477
- d["drift"][name] = tracker.classification.to_dict()
478
- for name, tracker in self._anomaly_trackers.items():
479
- if tracker.classification:
480
- d["anomaly"][name] = tracker.classification.to_dict()
481
- if self._correlation_tracker.matrix:
486
+ if "drift" in self.features:
487
+ d["drift"] = {}
488
+ for name, tracker in self._drift_trackers.items():
489
+ if tracker.classification:
490
+ d["drift"][name] = tracker.classification.to_dict()
491
+ if "anomaly" in self.features:
492
+ d["anomaly"] = {}
493
+ for name, tracker in self._anomaly_trackers.items():
494
+ if tracker.classification:
495
+ d["anomaly"][name] = tracker.classification.to_dict()
496
+ if self._correlation_tracker is not None and self._correlation_tracker.matrix:
482
497
  d["correlations"] = self._correlation_tracker.matrix.to_dict()
483
498
  return d
484
499
 
@@ -506,7 +521,8 @@ class Monitor:
506
521
  t.reset()
507
522
  for t in self._anomaly_trackers.values():
508
523
  t.reset()
509
- self._correlation_tracker.reset()
524
+ if self._correlation_tracker is not None:
525
+ self._correlation_tracker.reset()
510
526
 
511
527
  def __repr__(self) -> str:
512
528
  windows_uniform = (self.drift_window == self.anomaly_window == self.correlation_window)
@@ -514,4 +530,9 @@ class Monitor:
514
530
  w = f"window={self.drift_window}"
515
531
  else:
516
532
  w = f"drift={self.drift_window}, anomaly={self.anomaly_window}, corr={self.correlation_window}"
517
- return f"Monitor(step={self._step}, {len(self._drift_trackers)} components, {w})"
533
+ all_features = frozenset({"drift", "anomaly", "correlation"})
534
+ if self.features == all_features:
535
+ feat = ""
536
+ else:
537
+ feat = f", features={{{', '.join(sorted(self.features))}}}"
538
+ return f"Monitor(step={self._step}, {len(self._drift_trackers)} components, {w}{feat})"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: margin
3
- Version: 0.9.1
3
+ Version: 0.9.2
4
4
  Summary: Typed health classification, uncertainty algebra, and correction auditing for any system that measures things and needs to explain what happened.
5
5
  Author: Cope Labs LLC
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "margin"
7
- version = "0.9.1"
7
+ version = "0.9.2"
8
8
  description = "Typed health classification, uncertainty algebra, and correction auditing for any system that measures things and needs to explain what happened."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes