Repository navigation
Description
Task
T-073· Milestone M6 — Analysis + risk · Size S · Priority P1 · Epic #6Implements FR-ANA-004 · PR-15
Branch
feat/t-073-ruleextractor-depth-limited-decision-tree— one task = one branch = one PR (doc 32 §6)
Summary
Implement analysis/rules.py per doc 09 §4.3: balanced DecisionTreeClassifier(max_depth, min_samples_leaf=max(3, 0.02·n)); leaves with precision ≥ min_precision become rules (≤ 4 conditions) translated to physical units with support/precision/class; attach to the mode with the largest overlap.
Context / motivation
Rules like IF speed > 0.38 m/s AND light < 32 lux AND noise > 0.041 m THEN FAIL are the most actionable output for engineers.
Scope
In scope
Rulemodel with conditions list, precision, support, class, mode code.Condition,Rulevalue objects; text renderer separately unit-tested.
Implementation guidance
- Module
roboprobe/analysis/rules.py:class RuleExtractor: def extract(self, X: NDArray, y_fail: NDArray, names: list[str], space: ScenarioSpace, modes: Sequence[FailureModeSummary] = ()) -> list[Rule](doc 05 §7 signature plusspacefor unit translation). - Tree:
DecisionTreeClassifier(max_depth=analysis.rules.max_depth, min_samples_leaf=max(3, ceil(0.02*n)), class_weight="balanced", random_state=seed); the 0.02 factor becomesanalysis.rules.min_leaf_fraction(new). - Walk
tree_arrays to enumerate root→leaf paths; keep FAIL leaves with precision ≥analysis.rules.min_precision; merge conditions on the same feature to tightest bounds; cap at 4 conditions (drop least-informative by impurity decrease). Rule(frozen):conditions: tuple[Condition, ...](param,op∈ {<,≥},threshold_unit,threshold_physical,unit),precision,support,primary_class(majority class of covered failures),mode_code | None(largest Jaccard overlap with mode members),textrendered likeIF speed > 0.38 m/s AND light < 32 lux THEN FAIL.- Thresholds converted with
ParameterSpec.denormalize(log-scale aware) and rounded to the parameter's display precision (from the space, not inline). - Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
analysis.rules.max_depthanalysis.rules.min_precision- analysis.rules.min_leaf_fraction (new)
Acceptance criteria
- Planted thresholds recovered within ±0.05 (unit scale).
- Rule text format matches doc example.
- Rules sorted by (precision × support) desc.
- Log-scaled parameter thresholds render correctly in physical units.
- No rule exceeds 4 conditions.
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/unit/analysis/test_rules.py.- Table-driven test for condition merging.
- Planted-threshold recovery test (doc 18 §4.6).
Dependencies
Blocked by: #131 (T-072)
Blocks: #137 (T-075a)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/analysis/rules.py
Small.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-073 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 09 §4.3 · doc 18 §4.6 · doc 05 §7
Requirements: FR-ANA-004 · PR-15 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
report.jsonand analysis artefacts #137