markov-ts 0.4.0__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.
Files changed (51) hide show
  1. markov_ts-0.4.0/.gitignore +35 -0
  2. markov_ts-0.4.0/CHANGELOG.md +200 -0
  3. markov_ts-0.4.0/CITATION.cff +51 -0
  4. markov_ts-0.4.0/LICENSE +661 -0
  5. markov_ts-0.4.0/PKG-INFO +292 -0
  6. markov_ts-0.4.0/README.md +239 -0
  7. markov_ts-0.4.0/corpus_sources.example.toml +16 -0
  8. markov_ts-0.4.0/evals/README.md +56 -0
  9. markov_ts-0.4.0/evals/aggregate.py +62 -0
  10. markov_ts-0.4.0/evals/data/hmm_strict_xy.csv +2001 -0
  11. markov_ts-0.4.0/evals/data/pmc_observations.csv +3001 -0
  12. markov_ts-0.4.0/evals/data/pmc_verite.csv +3001 -0
  13. markov_ts-0.4.0/evals/data/pmm_article_xy.csv +2001 -0
  14. markov_ts-0.4.0/evals/data/pmm_modere_xy.csv +5001 -0
  15. markov_ts-0.4.0/evals/data/serie_queues_lourdes.csv +2001 -0
  16. markov_ts-0.4.0/evals/data/serie_trous.csv +401 -0
  17. markov_ts-0.4.0/evals/grade.py +243 -0
  18. markov_ts-0.4.0/evals/make_data.py +66 -0
  19. markov_ts-0.4.0/evals/questions.toml +293 -0
  20. markov_ts-0.4.0/evals/questions_en.toml +102 -0
  21. markov_ts-0.4.0/evals/questions_intl.toml +87 -0
  22. markov_ts-0.4.0/evals/references.json +8 -0
  23. markov_ts-0.4.0/evals/run_evals.py +114 -0
  24. markov_ts-0.4.0/pyproject.toml +94 -0
  25. markov_ts-0.4.0/src/markov_ts/__init__.py +6 -0
  26. markov_ts-0.4.0/src/markov_ts/backends/__init__.py +62 -0
  27. markov_ts-0.4.0/src/markov_ts/backends/pkf/__init__.py +247 -0
  28. markov_ts-0.4.0/src/markov_ts/backends/pkf/core.py +916 -0
  29. markov_ts-0.4.0/src/markov_ts/backends/pkf/spl.py +468 -0
  30. markov_ts-0.4.0/src/markov_ts/backends/pkf/tsp.py +208 -0
  31. markov_ts-0.4.0/src/markov_ts/backends/pmc/__init__.py +152 -0
  32. markov_ts-0.4.0/src/markov_ts/backends/pmc/core.py +349 -0
  33. markov_ts-0.4.0/src/markov_ts/backends/pmm/__init__.py +285 -0
  34. markov_ts-0.4.0/src/markov_ts/backends/pmm/core.py +599 -0
  35. markov_ts-0.4.0/src/markov_ts/backends/tmc/__init__.py +166 -0
  36. markov_ts-0.4.0/src/markov_ts/backends/tmc/core.py +451 -0
  37. markov_ts-0.4.0/src/markov_ts/common.py +255 -0
  38. markov_ts-0.4.0/src/markov_ts/documents/__init__.py +175 -0
  39. markov_ts-0.4.0/src/markov_ts/documents/build.py +284 -0
  40. markov_ts-0.4.0/src/markov_ts/figures.py +184 -0
  41. markov_ts-0.4.0/src/markov_ts/server.py +175 -0
  42. markov_ts-0.4.0/src/markov_ts/tooling.py +82 -0
  43. markov_ts-0.4.0/tests/conftest.py +39 -0
  44. markov_ts-0.4.0/tests/test_core.py +213 -0
  45. markov_ts-0.4.0/tests/test_documents.py +101 -0
  46. markov_ts-0.4.0/tests/test_eval_grader.py +133 -0
  47. markov_ts-0.4.0/tests/test_figures.py +127 -0
  48. markov_ts-0.4.0/tests/test_pkf_backend.py +204 -0
  49. markov_ts-0.4.0/tests/test_pmc_backend.py +93 -0
  50. markov_ts-0.4.0/tests/test_pmm_backend.py +271 -0
  51. markov_ts-0.4.0/tests/test_tmc_backend.py +124 -0
@@ -0,0 +1,35 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ venv/
7
+ build/
8
+ dist/
9
+
10
+ # Tools
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .mypy_cache/
14
+ .coverage
15
+ htmlcov/
16
+
17
+ # Outputs written by the server
18
+ markov_ts_outputs/
19
+ outputs/
20
+
21
+ # OS / editors
22
+ .DS_Store
23
+ .vscode/
24
+ .idea/
25
+ .claude/settings.local.json
26
+
27
+ # Evaluation runs (transcripts, outputs)
28
+ evals/results/
29
+
30
+ # Research corpus built from local manuscripts (not for publication) and its source list
31
+ corpus/
32
+ corpus_sources.toml
33
+
34
+ # Lock file of the local development environment (the package pins nothing)
35
+ uv.lock
@@ -0,0 +1,200 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.4.0] — 2026-12-05
8
+
9
+ ### Added
10
+ - **`codemeta.json`** (CodeMeta 3.0), as in the four libraries: HAL pre-fills the software record from it.
11
+ `server.json` declares `MARKOV_TS_BACKENDS` and `MARKOV_TS_CORPUS`. A test keeps the version of
12
+ `CITATION.cff`, `server.json` and `codemeta.json` in step with `markov_ts.__version__`.
13
+ - **Guided prompts for awesomePKF, awesomePMC and awesomeTMC** (pmmforecast already had two):
14
+ `pkf_choisir_filtre` (filter or smoother for a pairwise model, compared over several seeds),
15
+ `pkf_reproduire_tsp`, `pkf_reproduire_spl`, `pmc_classer_serie` (unsupervised classification with copulas),
16
+ `tmc_choisir_filtre` (AB constraint, exactness of IMM / GPB2, comparison) and `tmc_reproduire_tac`. Each
17
+ checks the scope first and routes to the right library, and the reproduction prompts compare with the
18
+ manuscript through `doc_read`.
19
+ - **`MARKOV_TS_BACKENDS`** restricts the active libraries (`pmm`, `pkf`, `pmc`, `tmc` or library names,
20
+ comma- or space-separated; unset = every installed library). An excluded library is not imported and
21
+ declares no tools, which lightens clients that send every tool description at each turn; `markov://ecosysteme`
22
+ lists it as disabled, so the agent can still route to it.
23
+
24
+ ### Changed
25
+ - **Development status Beta** (was Alpha) on PyPI.
26
+ - **Lighter tool descriptions.** Shorter docstrings and parameter descriptions, no description repeated on
27
+ every parameter of the same kind, no manuscript values in the reproduction tools (the agent reads them with
28
+ `doc_read`), and the auto-generated `title` of every parameter dropped from all input schemas (arguments are
29
+ still validated by the tools' pydantic models). Characters of tool descriptions: `pmm_*` 16 510 → 11 050,
30
+ `pkf_*` 12 840 → 9 720, `pmc_*` 7 090 → 5 600, `tmc_*` 6 490 → 5 300; whole server ~44 700 → ~33 300
31
+ (~11 200 → ~8 300 tokens). Bench on the questions that use these tools: pmmforecast 10 / 10, awesomePKF
32
+ 14 / 14 (French, English, Spanish, Arabic), awesomePMC and awesomeTMC 8 / 8.
33
+ - **Agent instructions fit Claude Code's limit.** Claude Code passes only the first ~4 000 characters of a
34
+ server's instructions to the model; markov-ts's were ~12 000, so the per-library rules never reached it.
35
+ The mandatory rules are now a compact block of under 3 800 characters (checked by a test), first; the
36
+ details follow and are also served as the new resource `markov://consignes`. The English header names the
37
+ topics that belong to markov-ts even when no library is named (pairwise Kalman filters, triplet and jump
38
+ systems, the TSP, SPL and TAC manuscripts and their `*_reproduce_*` tools).
39
+ - Rules: state explicitly that an answer is not financial advice; never present an integral recursion or an
40
+ approximation as a closed-form formula (no closed form for the general non-linear filter or smoother).
41
+ - Tested against the libraries as published on PyPI: pmmforecast 0.25.1, awesomepkf 2.18.0, awesomepmc
42
+ 1.7.1, awesometmc 3.5.0.
43
+
44
+ ### Added
45
+ - [`examples/CLAUDE.md`](examples/CLAUDE.md), recommended to Claude Code users: it sends questions on the
46
+ papers to markov-ts instead of local files or the web (reproduction questions: 4/9 → 9/9 in the bench).
47
+ - Evaluation bench: `run_evals.py --claude-md FILE` puts a `CLAUDE.md` in each question's work folder; the
48
+ grader ignores Markdown bold inside phrases.
49
+
50
+ ### Bench (3 campaigns per set; awesomepkf 2.18.1, awesometmc 3.6.0)
51
+ - French: 95 / 99 answers (96 %), 31 / 33 questions passed every time (before: 94 / 99, 30 / 33). Misses:
52
+ QS2 (one value of the classical family, 1 / 3) and Q43 (the trap answer does not say plainly that the
53
+ reference cannot be found, 1 / 3).
54
+ - English: 29 / 30, 9 / 10 every time (E14, 2 / 3). Spanish / Arabic: 24 / 24, 8 / 8 (before: 16 / 24).
55
+ - With three campaigns in parallel, the server sometimes did not start in time while the reproduction
56
+ questions of the other campaigns loaded the machine (19 answers of 153, QT1 every time as it starts last):
57
+ the agent then searched the web. Those questions were run again (QT1 on its own); the figures above count
58
+ the reruns. With `examples/CLAUDE.md`, the reproduction questions pass 9 / 9.
59
+ - Evaluation bench: the grader reports a server that did not start (« serveur markov-ts failed au démarrage »)
60
+ instead of blaming the agent, and `run_evals.py` gives Claude Code 120 s to connect (`MCP_TIMEOUT`); that was not enough for QT1
61
+ under the heaviest load, hence the reruns.
62
+
63
+ ## [0.3.0] — 2026-12-01
64
+
65
+ First public version. Figures, an evaluation bench for the agent, optional access to local research documents,
66
+ and the fixes found by the evaluation campaigns.
67
+
68
+ ### Added
69
+ - **Figures.** Simulation, filtering, smoothing, forecasting, classification, estimation and filter-comparison
70
+ tools of the four backends draw a PNG and return its path (`figure`) and caption (`figure_legende`).
71
+ `MARKOV_TS_FIGURES` = `fichier` (default), `image` (the PNG is also attached to the tool result) or `non`.
72
+ A failed plot never fails the tool (`figure_erreur`). New agent rule: show the figure, and describe what it
73
+ shows only if the image was received.
74
+ - **Evaluation bench** (`evals/`): 33 questions (plus 10 in English and 8 in Spanish and Arabic) asked to Claude with only this server connected
75
+ (`claude -p`), graded by explicit rules (tools, numbers with tolerance, required and forbidden claims, figure
76
+ shown). Reports `rapport.md`, `reponses.md`, `resultats.json`.
77
+ - **Research documents** (optional, local): `doc_list`, `doc_search`, `doc_read` over a corpus of LaTeX
78
+ manuscripts converted section by section (`python -m markov_ts.documents.build`, needs pandoc): equations and
79
+ statements numbered as in the compiled document, citations resolved, author notes and e-mails removed,
80
+ publication status returned with every read. The source list (`corpus_sources.toml`) and the corpus stay
81
+ out of git and of the package; `corpus_sources.example.toml` shows the format.
82
+ - `markov://<library>/readme` resources for the four libraries; agent rule 7: explain notions from these
83
+ resources and the tools' `hypotheses`, and tell an article DOI from a software (Zenodo) DOI.
84
+ - `markov-ts --status` also reports the document corpus.
85
+ - `pkf_smooth_nonlinear`: awesomePKF's nonlinear smoothers (EPKS, UPKS, particle smoother PPS; UKS on
86
+ non-pairwise models), with filtering and smoothing MSE, smoothing gain, run time and a figure. A smoother
87
+ that degrades the filtered estimate is flagged (`alerte`), a numerical failure reported (`echec`).
88
+ - `evals/aggregate.py`: stability report over several campaigns.
89
+ - `tmc_reproduce_tac`: reproduces Sections V-A to V-C (Fig. 4) of the awesomeTMC paper submitted to IEEE TAC
90
+ (`awesometmc.experiments.tac_stationary`): exact mean square errors of the CGOMSM1, CGOMSM2 and CGOMSM1
91
+ without autoregression approximations, 100Δ and its regression / weight / interaction decomposition, figure;
92
+ the 18 quadratures run in parallel (≈ 15 s). The manuscript's values are not stored in the package: the agent
93
+ compares with the manuscript through the local document corpus. Section V-D (river data) is not covered.
94
+ - `pkf_reproduce_spl`: reproduces the experiment of the awesomePKF letter submitted to IEEE SPL (six smoothers
95
+ against an exact reference): a faithful rewrite of the authors' experiment script restricted to the random
96
+ model families (same generators, seeds and metrics; 60-digit lifted reference solved with mpmath), one stress
97
+ regime per call, run in parallel processes. Raw covariances are captured before the library's in-place
98
+ regularisation. Like `tmc_reproduce_tac`, it stores no manuscript value and asks the agent to compare through
99
+ the corpus; it states that round-off-level errors depend on numpy / BLAS (in this environment the counts match
100
+ the letter to within one model, the maxima within a factor of about 2). `famille="classique"` runs the same
101
+ study on the letter's textbook models y = Hx + v (generators T1, T2 of `conditioning_exact_classical.py`).
102
+ Condition numbers and the Joseph-form variant are not covered.
103
+ - `pkf_reproduce_tsp`: reproduces the simulation section of the awesomePKF paper submitted to IEEE TSP, rewritten
104
+ from the authors' scripts shipped with awesomePKF (`prg/run_paper_section4*.py`; same library models, seeds,
105
+ sigma-point set and metrics): illustration model (Tables III and V, MSE over 30 seeds), multiplicative
106
+ observation noise (Table IV, Fig. 2) and back-action against a misspecified Markov EKF (Fig. 3), run in
107
+ parallel processes, with figures. In this environment every tabulated value is found to the printed precision.
108
+ The S&P 500 experiment, the supplementary higher-dimensional models and the timing table are not covered.
109
+ - `n_seeds` (default 5) on `pkf_compare_filters`, `pkf_smooth_nonlinear` and `tmc_compare_filters`: results
110
+ averaged over several simulations, with the spread between seeds, the per-seed values and the number of
111
+ seeds where each method wins (not counted for the oracle, nor when the exact TMC filter is present). Seeds
112
+ whose *simulation* fails numerically are set aside and reported. Agent rule 9: a recommendation rests on
113
+ the mean and the spread; a single seed is only indicative.
114
+
115
+ ### Changed
116
+ - The `tmc` extra requires `awesometmc>=3.5` with no Python condition: awesomeTMC 3.5 supports Python 3.11
117
+ to 3.14 (3.4 required 3.14), so `markov-ts[all]` brings the four backends on every supported Python.
118
+ - The awesomePKF backend imports `awesomepkf` (its import package since awesomepkf 2.18, formerly `prg`) and the
119
+ `pkf` extra requires `awesomepkf>=2.18`.
120
+ - pmmforecast is now public (GitHub, and PyPI 0.25.0): new `pmm` extra (`pmmforecast>=0.25`), included in
121
+ `all`, so CI also runs the pmmforecast tests. Its notation and changelog resources, which are not
122
+ installed with the package, point to the GitHub files when the sources are not available.
123
+ - The agent answers in the language of the question. Checked with two new bench sets,
124
+ `evals/questions_en.toml` (10 English questions) and `evals/questions_intl.toml` (4 Spanish, 4 Arabic),
125
+ graded with a language criterion (`langue`). With French-only instructions the agent sometimes answered in
126
+ French, copied French result fields, sent forecasting to awesomePMC, and in Arabic or Spanish searched the web
127
+ or local files instead of its own tools. The server instructions now open with a short English header (use
128
+ this server's tools, load them by name; answer in the user's language; insert every figure) and gain a
129
+ language rule, an explicit library-routing rule and a stricter figure rule (opening the PNG does not show it
130
+ to the user). Last campaigns: English 27/30, Spanish/Arabic 19/24 then 9/9 on the three questions that
131
+ had failed, French unchanged (6/6 on a sample).
132
+ - The `pmc` extra requires `awesomepmc>=1.7.0`, the first release under the AGPL, so every installed
133
+ backend library is under the same licence as markov-ts.
134
+ - Project renamed from `markov-mcp` to **markov-ts** before any public release: distribution, command
135
+ and MCP server `markov-ts`, import package `markov_ts`, output variable `MARKOV_TS_OUTPUT`. The
136
+ resource URIs keep the `markov://` scheme.
137
+ - Paper references carry their real status: the awesomeTMC paper is submitted to IEEE TAC, the awesomePKF
138
+ nonlinear paper to IEEE TSP (HAL preprint), the six-smoothers letter to IEEE SPL; papers in preparation
139
+ are labelled as such. `pkf_smooth` now cites the six-smoothers letter. Software (Zenodo) DOIs are in
140
+ a separate `logiciel` field, so that the agent no longer gives one as the article's DOI.
141
+ - awesomeTMC outputs include the exact definition of the AB constraint.
142
+ - `pmc_estimate` names the initial model and warns that the result depends on it.
143
+ - Document corpus: formulas in figure captions are kept as LaTeX instead of MathML.
144
+ - Agent rule 3: bibliographic questions start from `markov://ecosysteme` and the `citation` resources (the
145
+ agent used to search the documents for 12–15 turns), and the DOI is always given.
146
+ - `matplotlib` is a dependency.
147
+
148
+ ### Fixed
149
+ - Loading a one-column CSV: the separator is now read from the header line (pandas' guess split numbers on
150
+ `.` or `-`); a missing column gives an explicit error listing the available ones.
151
+ - `pmm_fit` on Y alone no longer reports whether the model is an HMM, which Y alone cannot determine.
152
+
153
+ ## [0.2.0] — 2026-12-01
154
+
155
+ Phase 2: the four Markov libraries are connected.
156
+
157
+ ### Added
158
+ - **awesomepkf** backend (extra `pkf`): `pkf_list_models`, `pkf_simulate`, `pkf_compare_filters`
159
+ (EPKF / UPKF / PPF / UKF / PF: MSE, NEES, time; a filter's numerical failure is reported, not raised),
160
+ `pkf_smooth` (the six linear smoothers and their agreement), `pkf_backaction_test` (LRT of measurement
161
+ back-action by partial EM), `pkf_filter`; citation resource.
162
+ - **awesomepmc** backend (extra `pmc`): `pmc_list_models`, `pmc_get_model`, `pmc_simulate`, `pmc_classify`
163
+ (MPM, missing values), `pmc_estimate` (ICE / SEM, automatic copula and margin selection, fitted TOML),
164
+ `pmc_forecast`; citation resource.
165
+ - **awesometmc** backend (extra `tmc`, Python ≥ 3.14): `tmc_list_models`, `tmc_describe_model` (AB
166
+ constraint, exactness domains of IMM and GPB2), `tmc_simulate`, `tmc_compare_filters` (exact filter vs
167
+ GPB2, IMM, RBPF, Kalman, oracle; gap to the exact filter), `tmc_filter`; citation resource.
168
+ - Extras `pkf`, `pmc`, `tmc` and `all`; CI installs `all` so the published backends are tested.
169
+ - Evaluation tests for the new backends (questions Q4, Q5–Q7, Q9, Q10, Q13, Q14, Q17).
170
+
171
+ ### Changed
172
+ - The pmmforecast backend requires pmmforecast ≥ 0.25, whose import package is `pmmforecast` (it was `prg`,
173
+ which clashed with awesomepkf).
174
+ - Library warnings are captured from each backend's loggers and capped at 10 per call.
175
+
176
+ ### Fixed
177
+ - awesometmc reference filters (GPB2, IMM, …) now start from the stationary law, like the exact filter:
178
+ otherwise an exact filter showed a spurious gap during the initial transient.
179
+
180
+ ## [0.1.0] — 2026-12-01
181
+
182
+ First version: the pilot of the agent, with the pmmforecast backend.
183
+
184
+ ### Added
185
+ - MCP server `markov-ts` (stdio and Streamable HTTP), built on the MCP Python SDK 2.x.
186
+ - Optional backend architecture (`markov_ts.backends`): a backend's tools are registered only when its
187
+ library is installed; `markov-ts --status` lists them; the `markov://ecosysteme` resource describes the
188
+ four libraries and their state.
189
+ - **pmmforecast** backend: 11 tools (`pmm_check_model`, `pmm_simulate`, `pmm_fit`, `pmm_lrt_hmm_vs_pmm`,
190
+ `pmm_diagnostics`, `pmm_normality_check`, `pmm_filter`, `pmm_forecast`, `pmm_theoretical_mse`,
191
+ `pmm_reproduce_table1`, `pmm_reference_models`), 4 resources, 2 prompts.
192
+ - Agent safeguards in the server instructions: no mental arithmetic, stated assumptions, cited sources,
193
+ out-of-scope redirection, no financial or medical advice.
194
+ - Expected errors (invalid data, out-of-scope requests) reach the agent with their explanation (`ToolError`).
195
+ - Library warnings are filtered: only those about the returned model are passed on, not those about the
196
+ optimiser's intermediate models.
197
+ - `params_from_y_only` flag on `pmm_filter` / `pmm_forecast`: X is not returned when the parameters were
198
+ estimated from Y alone (weak identifiability).
199
+ - Evaluation tests numbered after the question set of the feasibility study, including the reproduction of
200
+ Table 1 of Escudier et al. (CMCSI 2023).
@@ -0,0 +1,51 @@
1
+ # Citation metadata for markov-ts — keep in step with .zenodo.json and codemeta.json (2026-12-05).
2
+ cff-version: 1.2.0
3
+ title: "markov-ts — an AI agent for hidden, pairwise and triplet Markov chains on signals and time series"
4
+ message: >-
5
+ If you use this software, please cite the papers of the Markov libraries you used
6
+ through it, and this software record.
7
+ type: software
8
+ authors:
9
+ - family-names: Derrode
10
+ given-names: Stéphane
11
+ affiliation: "École Centrale de Lyon, LIRIS UMR CNRS 5205"
12
+ orcid: "https://orcid.org/0000-0002-2865-2057"
13
+ repository-code: "https://github.com/SDerrode/markov-ts"
14
+ license: AGPL-3.0-or-later
15
+ version: "0.4.0"
16
+ date-released: "2026-12-05"
17
+ keywords:
18
+ - Model Context Protocol
19
+ - AI agent
20
+ - pairwise Markov chain
21
+ - triplet Markov chain
22
+ - hidden Markov model
23
+ - Kalman filter
24
+ - time series
25
+ references:
26
+ - type: article
27
+ title: "Pairwise Markov chains"
28
+ authors:
29
+ - family-names: Pieczynski
30
+ given-names: Wojciech
31
+ journal: "IEEE Transactions on Pattern Analysis and Machine Intelligence"
32
+ volume: 25
33
+ issue: 5
34
+ start: 634
35
+ end: 639
36
+ year: 2003
37
+ doi: "10.1109/TPAMI.2003.1195998"
38
+ - type: conference-paper
39
+ title: "Forecasting with Pairwise Gaussian Markov Models"
40
+ authors:
41
+ - family-names: Escudier
42
+ given-names: Marc
43
+ - family-names: Abdelkefi
44
+ given-names: Ikram
45
+ - family-names: Fernandes
46
+ given-names: Clément
47
+ - family-names: Pieczynski
48
+ given-names: Wojciech
49
+ collection-title: "8th IEEE International Conference on Mathematics and Computers in Sciences and Industry (CMCSI)"
50
+ year: 2023
51
+ doi: "10.1109/MCSI60294.2023.00009"