feat: kOREInference — Algorithm 4 iDRegEx with MDL scoring + ensemble integration #1

Merged
tobi merged 17 commits from feature/kore-inference into main 2026-07-01 14:08:19 +00:00
Owner

What

Implements kOREInference following arXiv 1004.2372 Algorithm 4 (iDRegEx) exactly:

  1. For k = 1..kmax, N random trials:
    • iKoa (Algorithm 1) → deterministic k-OA
    • rwr² (Algorithm 3) → k-ORE expression
    • Validate determinism + k-occurrence
  2. Score all candidates by MDL (model cost + data cost)
  3. Return the best (KOA, expression, k)

Changes

File Change
bex/kore.py Rewrote. Removed broken PTA→Shrink→Repair→StateElimination approach. Replaced with proper Algorithm 4 pipeline wrapping ikoa + rwr_sq + MDL
bex/ensemble.py Added kOREInference as 3rd algorithm in infer_ensemble alongside CRX and iDRegEx. Refactored prefer logic into a clean dispatch table
bex/__init__.py Export kOREInference and validate_k_ore
tests/test_kore.py 32 tests — core inference, edge cases (empty, single, 20×identical), validate_k_ore, MDL scoring, paper-faithful assertions
tests/test_ensemble.py 19 tests — ensemble runs all three, prefer=crx/idregex/koreinference, edge cases, stochastic stability

Test count: 79 total (28 existing + 32 kORE + 19 ensemble), all passing.

Key finding

Applied to 3,926 real opencode step-boundary tool sequences, kOREInference returns None — rwr0 cannot handle the interconnectivity. The tool graph (read→bash, read→grep, read→glob, bash→read, etc.) is not SORE (Single Occurrence Regular Expression). This is a genuine empirical result: the agent's behavior within steps is probabilistic, not grammatically structured.

Next steps

  • Merge when ready
  • The examples/ directory (untracked) has exploratory scripts for the session-data analysis
## What Implements `kOREInference` following **arXiv 1004.2372 Algorithm 4** (iDRegEx) exactly: 1. For k = 1..kmax, N random trials: - iKoa (Algorithm 1) → deterministic k-OA - rwr² (Algorithm 3) → k-ORE expression - Validate determinism + k-occurrence 2. Score all candidates by **MDL** (model cost + data cost) 3. Return the best (KOA, expression, k) ## Changes | File | Change | |------|--------| | `bex/kore.py` | **Rewrote.** Removed broken PTA→Shrink→Repair→StateElimination approach. Replaced with proper Algorithm 4 pipeline wrapping `ikoa` + `rwr_sq` + MDL | | `bex/ensemble.py` | Added kOREInference as 3rd algorithm in `infer_ensemble` alongside CRX and iDRegEx. Refactored prefer logic into a clean dispatch table | | `bex/__init__.py` | Export `kOREInference` and `validate_k_ore` | | `tests/test_kore.py` | **32 tests** — core inference, edge cases (empty, single, 20×identical), validate_k_ore, MDL scoring, paper-faithful assertions | | `tests/test_ensemble.py` | **19 tests** — ensemble runs all three, prefer=crx/idregex/koreinference, edge cases, stochastic stability | Test count: **79 total** (28 existing + 32 kORE + 19 ensemble), all passing. ## Key finding Applied to 3,926 real opencode step-boundary tool sequences, `kOREInference` returns `None` — rwr0 cannot handle the interconnectivity. The tool graph (read→bash, read→grep, read→glob, bash→read, etc.) is **not SORE** (Single Occurrence Regular Expression). This is a genuine empirical result: the agent's behavior within steps is probabilistic, not grammatically structured. ## Next steps - Merge when ready - The `examples/` directory (untracked) has exploratory scripts for the session-data analysis
tobi added 1 commit 2026-07-01 12:50:24 +00:00
feat: implement kOREInference (Algorithm 4) with MDL scoring, add to ensemble, 79 tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
edd6d9d4dd
tobi added 1 commit 2026-07-01 13:09:17 +00:00
feat: core+outlier analysis via min_coverage parameter, 6 new tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
9045769d57
Author
Owner

Neu: min_coverage Core + Outlier Analyse

infer_ensemble(sequences, min_coverage=0.8) findet jetzt zusätzlich den engsten Kern per iterativem CRX + Outlier-Removal:

  • Outlier werden nach Symbol-Seltenheit identifiziert (Sequenzen mit seltenen Symbolen zuerst entfernt)
  • Bis genau min_coverage (default 1.0 = kein Filter) der Sequenzen übrig ist
  • Rückgabe enthält result['core'] mit {grammar, coverage, outlier_count, outliers}

Beispiel: 15 Ansible-Rollen

min_coverage=1.0: fail.include_vars.set_fact.package.file.template.service?.npm?.pip?.lineinfile?  (alle 15)
min_coverage=0.9: fail.include_vars.set_fact.package.file.template.service?.(lineinfile+npm)?       (13/15, outliers: mysql, docker)
min_coverage=0.8: fail.include_vars.set_fact.package.file.template.service?.npm?                    (12/15, + nginx)
min_coverage=0.7: fail.include_vars.set_fact.package.file.template.service?                         (10/15, + phpmyadmin, apache)

Die Outlier sind Rollen mit den seltensten Symbolen (npm, pip, lineinfile). Ein LLM sieht: "10/15 Rollen folgen dem Kern. Nur wer spezifische Tools braucht, fügt extras hinzu."

Tests

85 Tests insgesamt (+6 neue für min_coverage), alle grün.

## Neu: `min_coverage` Core + Outlier Analyse `infer_ensemble(sequences, min_coverage=0.8)` findet jetzt zusätzlich den **engsten Kern** per iterativem CRX + Outlier-Removal: - Outlier werden nach **Symbol-Seltenheit** identifiziert (Sequenzen mit seltenen Symbolen zuerst entfernt) - Bis genau `min_coverage` (default 1.0 = kein Filter) der Sequenzen übrig ist - Rückgabe enthält `result['core']` mit `{grammar, coverage, outlier_count, outliers}` ### Beispiel: 15 Ansible-Rollen ``` min_coverage=1.0: fail.include_vars.set_fact.package.file.template.service?.npm?.pip?.lineinfile? (alle 15) min_coverage=0.9: fail.include_vars.set_fact.package.file.template.service?.(lineinfile+npm)? (13/15, outliers: mysql, docker) min_coverage=0.8: fail.include_vars.set_fact.package.file.template.service?.npm? (12/15, + nginx) min_coverage=0.7: fail.include_vars.set_fact.package.file.template.service? (10/15, + phpmyadmin, apache) ``` Die Outlier sind Rollen mit den seltensten Symbolen (`npm`, `pip`, `lineinfile`). Ein LLM sieht: "10/15 Rollen folgen dem Kern. Nur wer spezifische Tools braucht, fügt extras hinzu." ### Tests 85 Tests insgesamt (+6 neue für min_coverage), alle grün.
tobi added 1 commit 2026-07-01 13:16:31 +00:00
docs: add min_coverage to MCP tool + README, include core in output
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
036a84cc76
Author
Owner

Letzter Commit: MCP-Tool + README aktualisiert.

  • infer_best_grammar hat jetzt min_coverage Parameter (default 1.0 = deaktiviert)
  • Nur wenn Agent explizit setzt (min_coverage=0.8), kommt Core+Outlier-Analyse in der Antwort
  • README dokumentiert den Parameter und die Algorithm Selection Guide
Letzter Commit: MCP-Tool + README aktualisiert. - `infer_best_grammar` hat jetzt `min_coverage` Parameter (default 1.0 = deaktiviert) - Nur wenn Agent explizit setzt (`min_coverage=0.8`), kommt Core+Outlier-Analyse in der Antwort - README dokumentiert den Parameter und die Algorithm Selection Guide
tobi added 1 commit 2026-07-01 13:18:34 +00:00
docs: update README and SHOWCASE for kOREInference + core/outlier analysis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
0886e5f3bc
tobi added 1 commit 2026-07-01 13:21:57 +00:00
docs: fix Go lint description (both optional), format outliers in SHOWCASE usage
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
5e0674bf77
tobi added 1 commit 2026-07-01 13:24:03 +00:00
docs: badges row, nav links, language tags on code blocks
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
0be1a7fd79
tobi added 1 commit 2026-07-01 13:37:12 +00:00
docs: add Buy Me a Coffee button
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
929a50c95d
tobi added 1 commit 2026-07-01 13:40:05 +00:00
chore: ignore examples/
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
a70024397f
tobi added 1 commit 2026-07-01 13:41:39 +00:00
docs: center logo, move coffee button below nav links
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
4969819dbb
tobi added 1 commit 2026-07-01 13:41:58 +00:00
docs: bump logo 180→216px
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
bb193d000f
tobi added 1 commit 2026-07-01 13:42:17 +00:00
docs: extra blank line above coffee button
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
bc81bbdce1
tobi added 1 commit 2026-07-01 13:48:38 +00:00
docs: syntax highlighting tags in SHOWCASE.md
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
fbdb39bf7c
tobi added 1 commit 2026-07-01 14:00:08 +00:00
feat: replace single-chart Helm with cross-project convention (15 charts, 6 publishers)
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
b34e39d4b9
tobi added 1 commit 2026-07-01 14:02:17 +00:00
docs: xkcd-style chart
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
d96e99d84f
tobi added 1 commit 2026-07-01 14:03:22 +00:00
fix: chart bars use Dervish purple #853E91
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ce4088e705
tobi added 1 commit 2026-07-01 14:04:57 +00:00
fix: grouped bar chart with Without Dervish vs With Dervish
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
2562519718
tobi added 1 commit 2026-07-01 14:05:53 +00:00
fix: broken y-axis bar chart for readability
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
90d8c69aa7
tobi merged commit d2d57bc431 into main 2026-07-01 14:08:19 +00:00
tobi deleted branch feature/kore-inference 2026-07-01 14:08:19 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: tobi/grammar-inference-engine#1
No description provided.