Repository avatar
AI Tools
v0.4.0
active

markov-ts

io.github.SDerrode/markov-ts

Hidden, pairwise and triplet Markov chains for time series: filtering, forecasting, estimation.

Documentation

markov-ts

CI License: AGPL v3+ MCP PyPI DOI

An AI agent for hidden, pairwise and triplet Markov chains on signals and time series.

markov-ts is a Model Context Protocol server. It exposes the reference implementations of the Markov library family (Pieczynski, Derrode and co-authors) as tools that an AI assistant such as Claude can call. You ask in plain language, for example "Is a classical HMM enough for my series, or do I need a pairwise chain?". The agent then runs the published algorithms on your data and answers with numbers it computed, never guessed, together with the model assumptions and the paper to cite.

The tools, results and agent instructions are written in French. The agent answers in the user's language.


Why an agent?

The Markov libraries are mature research code: on PyPI, tested, documented, each the companion of a paper. Using them still takes time: choosing the right model, the right estimator, and checking the hypotheses. The agent connects a question to the right algorithm and follows a few rules:

  • No mental arithmetic. Every number comes from a library call.
  • Assumptions are stated (Gaussianity, stationarity, identifiability…).
  • Sources are cited (DOI, BibTeX).
  • Out of scope? It says so and points to the right library.
  • No financial or medical advice. It provides a statistical analysis only.

Libraries (backends)

Each library is an optional backend. The server activates only the ones installed in its environment.

LibraryModelToolsInstall
awesomepkfPairwise Kalman filters (PKF, EPKF, UPKF, PPF), linear and nonlinear smoothers, back-action test9 pkf_*markov-ts[pkf]
awesomepmcCopula-based pairwise / hidden Markov chains, discrete states6 pmc_*markov-ts[pmc]
awesometmcTriplet Markov chains: exact fast filtering in switching systems6 tmc_*markov-ts[tmc]
pmmforecastGaussian pairwise Markov model, 1-D (PMM)11 pmm_*markov-ts[pmm]

Run markov-ts --status to see which backends are active.

awesomepkf — pairwise Kalman filtering

ToolWhat it does
pkf_list_modelsLinear and nonlinear pairwise models, filters, sigma-point sets
pkf_simulateSimulate (X, Y) from a library model or a custom linear model {A, Q, dim_x, dim_y}
pkf_compare_filtersEPKF / UPKF / PPF (/ UKF / PF) on simulated data, averaged over n_seeds simulations (default 5): MSE and its spread, wins per seed, NEES, run time; numerical failures reported
pkf_smoothThe six linear smoothers (RTS, BF, MBF, MF, DWY, VAR): smoothing gain and agreement between them
pkf_smooth_nonlinearNonlinear smoothers EPKS, UPKS, particle smoother PPS (and UKS on non-pairwise models), over n_seeds simulations: filtering vs smoothing MSE, gain, time; a smoother that degrades the estimate is flagged
pkf_reproduce_tspReproduces the simulation section of the paper submitted to IEEE TSP: the illustration model (Tables III and V, then the MSE over 30 seeds), the multiplicative-noise experiment (Table IV, Fig. 2) and the back-action experiment against a misspecified Markov EKF (Fig. 3); one experiment per call, ≈ 30–50 s
pkf_reproduce_splReproduces the experiment of the letter submitted to IEEE SPL: the six linear smoothers against an exact 60-digit reference on 80 random pairwise models, one stress regime per call (broad prior, vanishing state noise, correlated noise, poles near the unit circle), on the pairwise models or on the textbook models y = Hx + v (famille="classique"): aborts, indefinite covariances, covariance and mean errors, figure (≈ 30 s per parameter value)
pkf_backaction_testLikelihood-ratio test of measurement back-action (A_xy = 0), partial EM
pkf_filterFilter a real 1-D observation series

awesomepmc — copula-based pairwise Markov chains

ToolWhat it does
pmc_list_models, pmc_get_modelBundled TOML models (HMC-IN … general PMC with copulas)
pmc_simulateSimulate classes and observations
pmc_classifyBayesian MPM classification, exact handling of missing values, error rate if labels are known
pmc_estimateUnsupervised ICE / SEM with automatic copula (and margin) selection; returns the fitted TOML
pmc_forecasth-step forecasts and future class probabilities

awesometmc — triplet Markov chains / switching systems

ToolWhat it does
tmc_list_modelsPaper models M1–M3 and library presets
tmc_describe_modelAB constraint (exact fast filter available?), exactness domains of IMM and GPB2
tmc_simulateSimulate regimes, states and observations
tmc_compare_filtersExact filter vs GPB2, IMM, RBPF, single Kalman, oracle, over n_seeds simulations: MSE, regime error, time, maximal gap to the exact filter
tmc_filterFilter real observations (exact filter when the model allows it)
tmc_reproduce_tacReproduces Sections V-A to V-C (Fig. 4) of the paper submitted to IEEE TAC: exact errors of the CGOMSM1 and CGOMSM2 approximations along the two families, 100Δ and its decomposition (≈ 15 s, no simulation)

pmmforecast — 1-D Gaussian pairwise Markov model

ToolWhat it does
pmm_reference_modelsCanonical (a, b, c, d, e) models of the library
pmm_check_modelValidity, transition matrix, spectral radius, HMM projection
pmm_simulateSimulate (X, Y) → CSV
pmm_normality_checkNormality and autocorrelation of a single series
pmm_fitEstimation: moments, joint MLE with standard errors, Y-only Kalman likelihood
pmm_lrt_hmm_vs_pmmLikelihood-ratio test HMM vs PMM (χ²(3), optional bootstrap), AIC/BIC
pmm_diagnosticsLjung-Box and Jarque-Bera tests on whitened innovations
pmm_filter`E[X
pmm_forecasth-step forecasts with prediction intervals
pmm_theoretical_mseExact closed-form MSE, excess MSE of a mismatched HMM filter
pmm_reproduce_table1Reproduces Table 1 of the CMCSI 2023 paper

Every backend also exposes markov://<library>/readme and markov://<library>/citation resources. The server exposes markov://ecosysteme and guided prompts: pmmforecast choisir_modele, reproduire_article; awesomePKF pkf_choisir_filtre, pkf_reproduire_tsp, pkf_reproduire_spl; awesomePMC pmc_classer_serie; awesomeTMC tmc_choisir_filtre, tmc_reproduire_tac.

Figures

Simulation, filtering, smoothing, forecasting, classification, estimation and filter-comparison tools also draw a PNG and return its path in a figure field, with a caption in figure_legende. The agent shows the figure in its answer. MARKOV_TS_FIGURES controls them:

ValueEffect
fichier (default)PNG file only
imagethe PNG is also attached to the tool result, so the agent sees it and the client can display it (about a thousand tokens per figure)
nonno figures

Choosing the active libraries

By default every installed library is active. MARKOV_TS_BACKENDS restricts the list, for instance to keep a client that loads every tool description at each turn light (the 35 tools weigh about 11 000 tokens, pmm_* alone about 4 000):

ValueEffect
unset or emptyevery installed library
pmmpmmforecast only
pkf,tmcawesomePKF and awesomeTMC (extras pmm, pkf, pmc, tmc or library names, separated by commas or spaces)

An excluded library is not imported and declares no tools; markov://ecosysteme lists it as disabled, so the agent can still point to it. markov-ts --status shows the result. Names it does not know are reported on stderr and ignored.

Your own research documents (optional, local)

The agent can also read your unpublished manuscripts and reports to ground its explanations in your own text: doc_list, doc_search and doc_read (one section at a time, equations numbered as in the document, publication status always returned). The documents never enter the repository or the package:

cp corpus_sources.example.toml corpus_sources.toml   # list your LaTeX documents (ignored by git)
python -m markov_ts.documents.build                  # LaTeX -> Markdown sections in corpus/ (needs pandoc)
markov-ts --status                                   # "documents  active"

Author-to-author notes (remarque* boxes, \decide{}, \todo{}), comments and author e-mails are removed during the conversion. Without a corpus, the doc_* tools are not registered.


Installation

pip install "markov-ts[all]"     # server + pmmforecast, awesomepkf, awesomepmc, awesometmc
pip install "markov-ts[pmc]"     # or only the libraries you need
markov-ts --status

Use it with Claude

Claude Code

claude mcp add markov-ts -- markov-ts

or commit a project-level .mcp.json (see examples/mcp.json).

Claude Code is a coding agent: asked to reproduce a paper, it may first look at the files of the current folder, then the web, before the markov-ts tools. Put examples/CLAUDE.md (four lines) in the folder you work from, or add its content to your own CLAUDE.md: it sends these questions to markov-ts. In the evaluation bench it took the reproduction questions from 4/9 to 9/9 successes.

Claude Desktop: add the server to claude_desktop_config.json (see examples/claude_desktop_config.json), then restart Claude Desktop.

Any MCP client: markov-ts speaks stdio. markov-ts --http 8765 serves Streamable HTTP on 127.0.0.1.

Generated files (CSV tables and PNG figures) go to $MARKOV_TS_OUTPUT (default: ./markov_ts_outputs).

Things to ask

  • Reproduce Table 1 of the CMCSI 2023 paper and explain the gap to the published values.
  • Simulate 2,000 points of the paper's model, then tell me whether an HMM would be enough.
  • Here is a series with gaps: data.csv. Forecast the next 12 points with 95% intervals.
  • What should I cite for pairwise Markov chains? Give me the BibTeX.
  • Are IMM and GPB2 exact on model M1? Show me their gap to the exact filter.
  • Reproduce Section V of the CGOMSM2 paper and tell me whether you find the manuscript's values.
  • Segment this series into 2 classes without labels, and tell me which copulas were selected.
  • Is there measurement back-action in this pairwise linear model?

Development

git clone https://github.com/SDerrode/markov-ts.git
cd markov-ts
uv venv --python 3.14 && uv pip install -e ".[dev,all]"
uv pip install -e ../pmmforecast        # optional: work against local pmmforecast sources instead of PyPI
pytest                                   # fast tests; backend tests are skipped if the library is absent
pytest -m slow                           # Monte-Carlo reproduction of the paper (~12 s)
ruff check src tests

Backend tests are numbered after the evaluation questions (Q1, Q2, Q8, …) listed in evals/questions.toml. Each question has a reference answer taken from a published result. Adding a backend means adding a module in src/markov_ts/backends/. See CONTRIBUTING.md.

Evaluating the agent

Unit tests check the tools; evals/ checks the agent. It asks Claude the questions of evals/questions.toml (model choice, forecasting, exactness, bibliography, and traps: financial or medical advice, invented papers, impossible formulas), with only the markov-ts server connected, then grades each transcript with explicit rules: tools called, numbers within tolerance, required mentions, forbidden claims, figure shown.

python evals/run_evals.py                 # every question (uses your Claude account: about $4 for the set)
python evals/run_evals.py --only Q25 Q14  # a few questions
python evals/grade.py evals/results/<run> # re-grade without asking again
python evals/run_evals.py --claude-md examples/CLAUDE.md   # with the recommended CLAUDE.md in each work folder

Each run writes rapport.md (verdicts), reponses.md (full answers, to be read: the rules do not judge the quality of an explanation) and resultats.json. See evals/README.md.

Citation

If this agent helps your research, please cite the papers of the libraries you used (each backend exposes a citation resource) and this software: concept DOI 10.5281/zenodo.24853225 (all versions), or the DOI of the version you used (0.4.0: 10.5281/zenodo.24853226); see CITATION.cff.

The pairwise Markov chain model was introduced in: W. Pieczynski, Pairwise Markov chains, IEEE TPAMI 25(5), 2003, doi:10.1109/TPAMI.2003.1195998.

License

AGPL-3.0-or-later. The four libraries it drives, pmmforecast, awesomepkf, awesomepmc (since 1.7.0) and awesometmc, are under the AGPL too. If you run a modified version of this server as a network service, you must offer its source code to its users.

PYPI
markov-ts
Install Command
pip install markov-ts