Command-line reference¶
fxtensor-bayesnet [--config PATH] [options]
python -m fxtensor_bayesnet accepts the same arguments.
--help prints the usage text in Japanese. --version prints the package version.
Option |
Meaning |
|---|---|
|
Config file. Default: |
|
Validate only. Every config error is printed. Exit code 2 on error, 0 when the file is valid. Does not write results. |
|
Do not write |
|
Print Markdown instead of JSON. |
|
Language of Markdown and of figure titles and legends. Default |
|
Language of keys in |
|
Save the config and the results (Japanese keys) to |
|
Allow |
|
Diff against a snapshot, then exit. Does not write |
|
Rewrite the config in place, one kernel row per line, then continue with the rest of the command. |
|
Where results and figures go. Default: the config file’s directory. |
|
Where snapshots go. Default: |
|
Write figures to |
|
|
|
PNG resolution. Default 150. |
Exit codes¶
Code |
When |
|---|---|
0 |
Success. Also |
1 |
|
2 |
The config is missing, is not JSON, or fails validation (including duplicate effect keys). Also a |
3 |
|
>>> import json, subprocess, sys, tempfile
>>> from pathlib import Path
>>> from fxtensor_bayesnet import __version__
>>> d = Path(tempfile.mkdtemp())
>>> cfg = {
... "as_of": "2026-10-18",
... "variables": {
... "A": {"name": "Cloud", "labels": ["Clear", "Cloudy"]},
... "B": {"name": "Rain", "labels": ["None", "Some"]},
... },
... "priors": {"A": {"p": [0.5, 0.5]}},
... "kernels": {"B": {"parents": ["A"], "cpt": {"Clear": [0.8, 0.2], "Cloudy": [0.4, 0.6]}}},
... }
>>> p = d / "config.json"
>>> _ = p.write_text(json.dumps(cfg), encoding="utf-8")
>>> ok = subprocess.run([sys.executable, "-m", "fxtensor_bayesnet", "--config", str(p), "--check"],
... capture_output=True, text=True)
>>> ok.returncode
0
>>> "設定OK" in ok.stdout
True
>>> cfg["effects"] = [
... {"treatment": "A", "outcome": "B", "name": "dup"},
... {"treatment": "A", "outcome": "B", "name": "dup"},
... ]
>>> _ = p.write_text(json.dumps(cfg), encoding="utf-8")
>>> bad = subprocess.run([sys.executable, "-m", "fxtensor_bayesnet", "--config", str(p), "--check"],
... capture_output=True, text=True)
>>> bad.returncode
2
>>> "重なる" in bad.stderr
True
>>> missing = subprocess.run(
... [sys.executable, "-m", "fxtensor_bayesnet", "--config", str(d / "missing.json"), "--check"],
... capture_output=True, text=True)
>>> missing.returncode
2
>>> ver = subprocess.run([sys.executable, "-m", "fxtensor_bayesnet", "--version"],
... capture_output=True, text=True)
>>> __version__ in (ver.stdout + ver.stderr)
True
--diff¶
PATH may be a snapshot directory (its config.json and results.json are used)
or a config.json file. A missing path exits with code 2.
Without PATH, the latest directory under --history-dir whose name matches
YYYY-MM-DD, contains config.json, and is strictly before as_of is used.
A snapshot with the same date as as_of is never picked automatically.
Pass it explicitly, for example --diff history/2026-10-18.
The diff lists config changes: added and removed variables, label and display-name edits,
prior changes, prior reason changes, kernel parent changes (with every old and new row),
added and removed CPT rows, kernel reason changes, and changes to scenarios, observations,
interventions, effects, sensitivity, and outputs.
When the previous results.json is present, the tool reruns inference and lists result
changes of 0.1 points or more: scenario marginals, intervention marginals, and ACEs.
It does not diff observation posteriors or sensitivity rows.
Config and result messages are Japanese.
--diff returns before the normal write. Combine it with --plot to write diff.png.
If there is no previous results.json, a message is printed and that figure is skipped.
Output files¶
On a normal run (not --check or --diff), unless --no-write:
results.json— priors, marginals per scenario, Bayesian updates, interventions, effects, sensitivity, and checks. Key language follows--json-keys.results.md— tables and a summary. Heading language follows--lang.model.mmd— mermaidgraph TD. Roots, intermediate variables, and outputs are coloured. Labels come from the config, not from--lang.
Figures¶
--plot needs matplotlib. SVGs store text as paths, so they do not depend on the viewer’s fonts.
File |
Contents |
When |
|---|---|---|
|
Layered network. Roots blue, intermediate grey, outputs orange. No Graphviz. |
Normal run |
|
Bar charts of each output marginal, scenarios side by side. |
Normal run |
|
Prior vs posterior of the focus variables, with total variation. Impossible observations are omitted. |
When at least one possible observation was updated |
|
Observed P(Y | X=x) next to P(Y | do(X=x)), annotated with the observational difference and the ACE. A level with probability 0 is marked undefined instead of drawn as 0. Stratum ACEs get their own panels: one bar per stratum, the value inside a negative bar (just above 0 if the bar is too short), and the overall ACE as a dashed line named in that panel’s legend. If the result key is not the plain |
When |
|
Tornado chart. |
When |
|
Change in marginals, in points, since the previous snapshot. |
|
Quickstart shows these files for the weather, maintenance, and ecology examples.
A font that can display Japanese is chosen from this list, in order:
Noto Sans CJK JP, Noto Sans JP, Source Han Sans JP, IPAexGothic, IPAGothic,
Hiragino Sans, Hiragino Kaku Gothic ProN, Yu Gothic, Meiryo, MS Gothic,
TakaoGothic, VL Gothic, Noto Sans CJK SC, Noto Sans Mono CJK JP, Noto Serif CJK JP.
If none is installed, a warning is issued and the default font is used.
Set FXTENSOR_BAYESNET_FONT to a font name to override the search.
Daily workflow¶
cd my-model
fxtensor-bayesnet --check
fxtensor-bayesnet --diff
fxtensor-bayesnet --snapshot --md
fxtensor-bayesnet --plot --no-write