hsmmkit 0.5.0__py3-none-any.whl
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.
- hsmmkit/__init__.py +13 -0
- hsmmkit/cli/__init__.py +1 -0
- hsmmkit/cli/app.py +513 -0
- hsmmkit/cli/stream.py +194 -0
- hsmmkit/config/__init__.py +1 -0
- hsmmkit/config/defaults.py +13 -0
- hsmmkit/config/gates.py +39 -0
- hsmmkit/config/migrate.py +53 -0
- hsmmkit/config/schema.py +996 -0
- hsmmkit/config/yaml_io.py +67 -0
- hsmmkit/data/__init__.py +1 -0
- hsmmkit/data/batch.py +311 -0
- hsmmkit/data/calendar.py +314 -0
- hsmmkit/data/clocks.py +165 -0
- hsmmkit/data/contracts.py +543 -0
- hsmmkit/data/labels.py +150 -0
- hsmmkit/data/prepare.py +706 -0
- hsmmkit/data/provenance.py +34 -0
- hsmmkit/data/quality.py +112 -0
- hsmmkit/data/sources/__init__.py +92 -0
- hsmmkit/data/sources/base.py +247 -0
- hsmmkit/data/sources/csv.py +36 -0
- hsmmkit/data/sources/numpy.py +143 -0
- hsmmkit/data/sources/pandas.py +33 -0
- hsmmkit/data/sources/parquet.py +37 -0
- hsmmkit/data/sources/xarray.py +62 -0
- hsmmkit/data/transforms.py +129 -0
- hsmmkit/engine/__init__.py +1 -0
- hsmmkit/engine/approx.py +51 -0
- hsmmkit/engine/augmented.py +93 -0
- hsmmkit/engine/base.py +134 -0
- hsmmkit/engine/batch.py +414 -0
- hsmmkit/engine/constraints.py +173 -0
- hsmmkit/engine/criteria.py +67 -0
- hsmmkit/engine/estep.py +314 -0
- hsmmkit/engine/estep_explicit.py +260 -0
- hsmmkit/engine/expanded_hmm.py +336 -0
- hsmmkit/engine/explicit_dd.py +114 -0
- hsmmkit/engine/explicit_duration.py +721 -0
- hsmmkit/engine/ffbs.py +229 -0
- hsmmkit/engine/parallel.py +98 -0
- hsmmkit/engine/viterbi.py +85 -0
- hsmmkit/estimation/__init__.py +36 -0
- hsmmkit/estimation/compare.py +154 -0
- hsmmkit/estimation/ecm.py +106 -0
- hsmmkit/estimation/em.py +460 -0
- hsmmkit/estimation/gem.py +467 -0
- hsmmkit/estimation/gibbs.py +136 -0
- hsmmkit/estimation/init.py +578 -0
- hsmmkit/estimation/map.py +287 -0
- hsmmkit/estimation/mcmc.py +370 -0
- hsmmkit/estimation/mstep.py +304 -0
- hsmmkit/estimation/newton.py +104 -0
- hsmmkit/estimation/objective.py +232 -0
- hsmmkit/estimation/optimizers.py +195 -0
- hsmmkit/estimation/recovery.py +748 -0
- hsmmkit/estimation/recovery_ext.py +557 -0
- hsmmkit/estimation/relabel.py +85 -0
- hsmmkit/estimation/report.py +167 -0
- hsmmkit/estimation/results.py +53 -0
- hsmmkit/estimation/selftest.py +154 -0
- hsmmkit/estimation/vb.py +508 -0
- hsmmkit/evaluation/__init__.py +1 -0
- hsmmkit/evaluation/backtest.py +616 -0
- hsmmkit/evaluation/compare.py +172 -0
- hsmmkit/evaluation/metrics/__init__.py +1 -0
- hsmmkit/evaluation/metrics/clustering.py +111 -0
- hsmmkit/evaluation/metrics/labels.py +40 -0
- hsmmkit/evaluation/metrics/matching.py +103 -0
- hsmmkit/evaluation/metrics/model.py +53 -0
- hsmmkit/evaluation/metrics/predictive.py +337 -0
- hsmmkit/evaluation/metrics/registry.py +154 -0
- hsmmkit/evaluation/metrics/segmentation.py +182 -0
- hsmmkit/evaluation/padding.py +72 -0
- hsmmkit/evaluation/report.py +170 -0
- hsmmkit/evaluation/results.py +28 -0
- hsmmkit/inference/__init__.py +1 -0
- hsmmkit/inference/covariate_forecasters.py +344 -0
- hsmmkit/inference/decode.py +185 -0
- hsmmkit/inference/forecast.py +475 -0
- hsmmkit/inference/results.py +97 -0
- hsmmkit/inference/simulate.py +342 -0
- hsmmkit/interop/__init__.py +1 -0
- hsmmkit/interop/arviz.py +114 -0
- hsmmkit/interop/hmmlearn.py +163 -0
- hsmmkit/interop/pandas.py +116 -0
- hsmmkit/interop/sklearn.py +505 -0
- hsmmkit/interop/xarray.py +296 -0
- hsmmkit/model/__init__.py +1 -0
- hsmmkit/model/build.py +404 -0
- hsmmkit/model/conjugate.py +260 -0
- hsmmkit/model/dists.py +244 -0
- hsmmkit/model/duration/__init__.py +23 -0
- hsmmkit/model/duration/base.py +215 -0
- hsmmkit/model/duration/explicit.py +205 -0
- hsmmkit/model/duration/gamma.py +53 -0
- hsmmkit/model/duration/geometric.py +106 -0
- hsmmkit/model/duration/hazard.py +23 -0
- hsmmkit/model/duration/lognormal.py +56 -0
- hsmmkit/model/duration/negbin.py +115 -0
- hsmmkit/model/duration/nonparametric.py +120 -0
- hsmmkit/model/duration/per_state.py +107 -0
- hsmmkit/model/duration/poisson.py +56 -0
- hsmmkit/model/duration/weibull.py +61 -0
- hsmmkit/model/emission/__init__.py +24 -0
- hsmmkit/model/emission/_discrete.py +104 -0
- hsmmkit/model/emission/base.py +105 -0
- hsmmkit/model/emission/bernoulli.py +131 -0
- hsmmkit/model/emission/categorical.py +158 -0
- hsmmkit/model/emission/gaussian.py +754 -0
- hsmmkit/model/emission/mixture.py +387 -0
- hsmmkit/model/emission/msar.py +545 -0
- hsmmkit/model/emission/poisson.py +144 -0
- hsmmkit/model/emission/product.py +390 -0
- hsmmkit/model/emission/student_t.py +454 -0
- hsmmkit/model/lattice.py +246 -0
- hsmmkit/model/params/__init__.py +45 -0
- hsmmkit/model/params/bijectors.py +238 -0
- hsmmkit/model/params/manager.py +307 -0
- hsmmkit/model/params/priors.py +84 -0
- hsmmkit/model/params/spec.py +65 -0
- hsmmkit/model/spec.py +43 -0
- hsmmkit/model/topology.py +97 -0
- hsmmkit/model/transition.py +419 -0
- hsmmkit/online/__init__.py +24 -0
- hsmmkit/online/alerts.py +181 -0
- hsmmkit/online/buffer.py +203 -0
- hsmmkit/online/covariates.py +162 -0
- hsmmkit/online/em.py +304 -0
- hsmmkit/online/filter.py +682 -0
- hsmmkit/online/session.py +364 -0
- hsmmkit/online/state.py +240 -0
- hsmmkit/persistence/__init__.py +1 -0
- hsmmkit/persistence/results.py +495 -0
- hsmmkit/persistence/store.py +394 -0
- hsmmkit/plot/__init__.py +13 -0
- hsmmkit/plot/_common.py +56 -0
- hsmmkit/plot/diagnostics.py +176 -0
- hsmmkit/plot/durations.py +74 -0
- hsmmkit/plot/forecast.py +55 -0
- hsmmkit/plot/regimes.py +146 -0
- hsmmkit/plugins.py +311 -0
- hsmmkit/presets/__init__.py +116 -0
- hsmmkit/presets/core/counts_poisson_hazard.yaml +61 -0
- hsmmkit/presets/core/msar2_hamilton.yaml +59 -0
- hsmmkit/presets/core/segmentation_gaussian_ltr.yaml +82 -0
- hsmmkit/presets/core/two_regime_gaussian.yaml +60 -0
- hsmmkit/presets/fixtures.py +330 -0
- hsmmkit/project.py +1106 -0
- hsmmkit/py.typed +0 -0
- hsmmkit/scaffold.py +80 -0
- hsmmkit/selection/__init__.py +30 -0
- hsmmkit/selection/bootstrap.py +388 -0
- hsmmkit/selection/cv.py +301 -0
- hsmmkit/selection/grid.py +412 -0
- hsmmkit/selection/ppc.py +199 -0
- hsmmkit/selection/pseudo_residuals.py +265 -0
- hsmmkit/selection/replicate.py +57 -0
- hsmmkit/selection/splitters.py +213 -0
- hsmmkit/statespace/__init__.py +1 -0
- hsmmkit/statespace/builders.py +317 -0
- hsmmkit/statespace/factorial.py +249 -0
- hsmmkit/statespace/index.py +85 -0
- hsmmkit/statespace/transitions.py +143 -0
- hsmmkit/templates/family-plugin/common/README.md.tmpl +9 -0
- hsmmkit/templates/family-plugin/common/pyproject.toml.tmpl +19 -0
- hsmmkit/templates/family-plugin/common/src/__pkg__/__init__.py.tmpl +7 -0
- hsmmkit/templates/family-plugin/common/src/__pkg__/tests/__init__.py.tmpl +0 -0
- hsmmkit/templates/family-plugin/duration/family.py.tmpl +19 -0
- hsmmkit/templates/family-plugin/duration/test_contract.py.tmpl +14 -0
- hsmmkit/templates/family-plugin/emission/family.py.tmpl +95 -0
- hsmmkit/templates/family-plugin/emission/test_contract.py.tmpl +48 -0
- hsmmkit/testing/__init__.py +6 -0
- hsmmkit/testing/clock_contract.py +53 -0
- hsmmkit/testing/duration_contract.py +218 -0
- hsmmkit/testing/family_contract.py +339 -0
- hsmmkit/testing/metric_contract.py +157 -0
- hsmmkit/testing/source_contract.py +196 -0
- hsmmkit/utils/__init__.py +1 -0
- hsmmkit/utils/clock.py +109 -0
- hsmmkit/utils/deprecation.py +125 -0
- hsmmkit/utils/errors.py +56 -0
- hsmmkit/utils/jax_setup.py +48 -0
- hsmmkit/utils/logging.py +30 -0
- hsmmkit/utils/optional.py +25 -0
- hsmmkit/utils/rng.py +49 -0
- hsmmkit/utils/typing.py +32 -0
- hsmmkit-0.5.0.dist-info/METADATA +84 -0
- hsmmkit-0.5.0.dist-info/RECORD +192 -0
- hsmmkit-0.5.0.dist-info/WHEEL +4 -0
- hsmmkit-0.5.0.dist-info/entry_points.txt +2 -0
- hsmmkit-0.5.0.dist-info/licenses/LICENSE +190 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""Preset registry (E10-T10): validated YAML configurations with a synthetic fixture generator.
|
|
2
|
+
|
|
3
|
+
A preset is a registered object (kind `preset`) with a name, a description, the YAML text and an optional
|
|
4
|
+
`fixture(seed)` that returns the synthetic data files the YAML refers to (relative path -> DataFrame).
|
|
5
|
+
Applications register their own presets through `register("preset", name)`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from importlib import resources
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import pandas as pd
|
|
16
|
+
|
|
17
|
+
from hsmmkit.plugins import REGISTRY, register
|
|
18
|
+
from hsmmkit.presets import fixtures
|
|
19
|
+
from hsmmkit.utils.errors import ConfigError
|
|
20
|
+
|
|
21
|
+
__all__ = ["Preset", "get_preset", "list_presets", "register_preset", "write_preset"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class Preset:
|
|
26
|
+
"""A named configuration with its synthetic data generator."""
|
|
27
|
+
|
|
28
|
+
name: str
|
|
29
|
+
description: str
|
|
30
|
+
yaml: str
|
|
31
|
+
fixture: Callable[[int], dict[str, pd.DataFrame]] | None = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def register_preset(preset: Preset) -> Preset:
|
|
35
|
+
"""Register `preset` under `preset.name` (kind `preset`) and return it."""
|
|
36
|
+
register("preset", preset.name)(preset)
|
|
37
|
+
return preset
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _core_yaml(name: str) -> str:
|
|
41
|
+
return resources.files("hsmmkit.presets").joinpath("core", f"{name}.yaml").read_text(encoding="utf-8")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _register_core() -> None:
|
|
45
|
+
core = (
|
|
46
|
+
(
|
|
47
|
+
"segmentation_gaussian_ltr",
|
|
48
|
+
"Left-to-right 4-regime segmentation of 50 labelled 3-dim sessions (Part II Appendix H).",
|
|
49
|
+
fixtures.segmentation_gaussian_ltr,
|
|
50
|
+
),
|
|
51
|
+
(
|
|
52
|
+
"two_regime_gaussian",
|
|
53
|
+
"Two-regime Gaussian sanity example on a daily calendar grid (Part I Appendix E, Gaussian form).",
|
|
54
|
+
fixtures.two_regime_gaussian,
|
|
55
|
+
),
|
|
56
|
+
(
|
|
57
|
+
"counts_poisson_hazard",
|
|
58
|
+
"Reliability counts: normal / degraded / absorbing failed state, Poisson counts, gamma sojourns.",
|
|
59
|
+
fixtures.counts_poisson_hazard,
|
|
60
|
+
),
|
|
61
|
+
(
|
|
62
|
+
"msar2_hamilton",
|
|
63
|
+
"Two-regime mean-adjusted MS-AR(2) with Hamilton-type magnitudes, 1000 steps.",
|
|
64
|
+
fixtures.msar2_hamilton,
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
for short, description, fixture in core:
|
|
68
|
+
name = f"core/{short}"
|
|
69
|
+
if not REGISTRY.is_registered("preset", name):
|
|
70
|
+
register_preset(Preset(name, description, _core_yaml(short), fixture))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
_register_core()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def list_presets() -> list[Preset]:
|
|
77
|
+
"""All registered presets, sorted by name."""
|
|
78
|
+
return sorted(
|
|
79
|
+
(e.obj for e in REGISTRY.entries("preset") if isinstance(e.obj, Preset)), key=lambda p: p.name
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def get_preset(name: str) -> Preset:
|
|
84
|
+
"""The preset `name`.
|
|
85
|
+
|
|
86
|
+
Raises:
|
|
87
|
+
ConfigError: unknown name; the message lists the registered presets.
|
|
88
|
+
"""
|
|
89
|
+
for preset in list_presets():
|
|
90
|
+
if preset.name == name:
|
|
91
|
+
return preset
|
|
92
|
+
names = ", ".join(p.name for p in list_presets()) or "<none>"
|
|
93
|
+
raise ConfigError(f"unknown preset '{name}'; registered: {names}", path="preset")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def write_preset(name: str, directory: str | Path, *, seed: int = 0) -> list[Path]:
|
|
97
|
+
"""Write the YAML of preset `name` and its synthetic data files into `directory`; return the paths.
|
|
98
|
+
|
|
99
|
+
The YAML is `<directory>/<short name>.yaml`; the data files go where the YAML's relative paths point,
|
|
100
|
+
below `directory`.
|
|
101
|
+
"""
|
|
102
|
+
preset = get_preset(name)
|
|
103
|
+
out = Path(directory)
|
|
104
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
105
|
+
written = [out / f"{name.rpartition('/')[2]}.yaml"]
|
|
106
|
+
written[0].write_text(preset.yaml, encoding="utf-8")
|
|
107
|
+
if preset.fixture is not None:
|
|
108
|
+
for rel, frame in preset.fixture(seed).items():
|
|
109
|
+
target = out / rel
|
|
110
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
111
|
+
if target.suffix == ".parquet":
|
|
112
|
+
frame.to_parquet(target, index=False)
|
|
113
|
+
else:
|
|
114
|
+
frame.to_csv(target, index=False)
|
|
115
|
+
written.append(target)
|
|
116
|
+
return written
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Reliability counts: 30 units observed daily, three states (normal -> degraded -> failed), Poisson error counts
|
|
2
|
+
# with the exposure of a calendar step, gamma sojourns, the failed state absorbing (topology matrix, right-censored).
|
|
3
|
+
# Rates are per year (exposure = the step length in years under the calendar clock): 1, 4 and 12 events per day.
|
|
4
|
+
schema_version: 1
|
|
5
|
+
project:
|
|
6
|
+
name: counts_poisson_hazard
|
|
7
|
+
seed: 7
|
|
8
|
+
output_dir: runs/counts_poisson_hazard
|
|
9
|
+
log_level: INFO
|
|
10
|
+
|
|
11
|
+
data:
|
|
12
|
+
source:
|
|
13
|
+
kind: csv
|
|
14
|
+
path: data/unit_counts.csv
|
|
15
|
+
observation_columns: [count]
|
|
16
|
+
sequence_column: unit_id
|
|
17
|
+
time_column: date
|
|
18
|
+
clock: calendar
|
|
19
|
+
sequences:
|
|
20
|
+
group_by: null
|
|
21
|
+
bucket_edges: [128, 256]
|
|
22
|
+
preparation:
|
|
23
|
+
missing_observations: mask
|
|
24
|
+
|
|
25
|
+
model:
|
|
26
|
+
n_states: 3
|
|
27
|
+
engine: explicit
|
|
28
|
+
d_max: 150 # >= the 150 observed days: the explicit posterior of an absorbing regime needs d_max >= T
|
|
29
|
+
topology:
|
|
30
|
+
matrix: [[0, 1, 1], [0, 0, 1], [0, 0, 0]] # normal -> degraded | failed, degraded -> failed, failed absorbs
|
|
31
|
+
initial_state: free
|
|
32
|
+
emission:
|
|
33
|
+
family: poisson
|
|
34
|
+
params:
|
|
35
|
+
rate: {mode: free, init: [300.0, 1500.0, 4000.0]} # events per year
|
|
36
|
+
duration:
|
|
37
|
+
family: gamma
|
|
38
|
+
params:
|
|
39
|
+
shape: {mode: free, init: 3.0}
|
|
40
|
+
scale: {mode: free, init_mean_sojourn_steps: [40.0, 20.0, 60.0]}
|
|
41
|
+
transition:
|
|
42
|
+
order: 1
|
|
43
|
+
covariates: []
|
|
44
|
+
|
|
45
|
+
estimation:
|
|
46
|
+
method: map
|
|
47
|
+
restarts: 2
|
|
48
|
+
max_iter: 200
|
|
49
|
+
init: [rolling_kmeans, random]
|
|
50
|
+
device: cpu
|
|
51
|
+
|
|
52
|
+
forecast:
|
|
53
|
+
horizon: 14
|
|
54
|
+
n_sim: 500
|
|
55
|
+
quantiles: [0.1, 0.5, 0.9]
|
|
56
|
+
|
|
57
|
+
evaluation:
|
|
58
|
+
metrics: [bic, icl]
|
|
59
|
+
|
|
60
|
+
output:
|
|
61
|
+
write: [posterior, report]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Two-regime mean-adjusted Markov-switching AR(2) (Hamilton 1989 magnitudes: a long expansion regime with a
|
|
2
|
+
# positive mean and a short contraction regime with a negative one), geometric sojourns, one series of 1000 steps.
|
|
3
|
+
schema_version: 1
|
|
4
|
+
project:
|
|
5
|
+
name: msar2_hamilton
|
|
6
|
+
seed: 7
|
|
7
|
+
output_dir: runs/msar2_hamilton
|
|
8
|
+
log_level: INFO
|
|
9
|
+
|
|
10
|
+
data:
|
|
11
|
+
source:
|
|
12
|
+
kind: csv
|
|
13
|
+
path: data/msar2_series.csv
|
|
14
|
+
observation_columns: [y]
|
|
15
|
+
time_column: null
|
|
16
|
+
clock: steps
|
|
17
|
+
preparation:
|
|
18
|
+
missing_observations: mask
|
|
19
|
+
|
|
20
|
+
model:
|
|
21
|
+
n_states: 2
|
|
22
|
+
engine: expanded
|
|
23
|
+
initial_state: uniform
|
|
24
|
+
emission:
|
|
25
|
+
family: msar
|
|
26
|
+
ar: {p: 2, form: mean_adjusted}
|
|
27
|
+
params:
|
|
28
|
+
mean: {mode: free, init: [-0.3, 0.8], constraint: increasing}
|
|
29
|
+
scale: {mode: free, init: [1.0, 1.0]}
|
|
30
|
+
duration:
|
|
31
|
+
family: geometric
|
|
32
|
+
params:
|
|
33
|
+
rate: {mode: free, init_mean_sojourn_steps: [12.0, 15.0]}
|
|
34
|
+
transition:
|
|
35
|
+
mode: jump
|
|
36
|
+
order: 1
|
|
37
|
+
|
|
38
|
+
estimation:
|
|
39
|
+
method: map
|
|
40
|
+
restarts: 3
|
|
41
|
+
max_iter: 300
|
|
42
|
+
init: [rolling_kmeans]
|
|
43
|
+
device: cpu
|
|
44
|
+
|
|
45
|
+
forecast:
|
|
46
|
+
horizon: 5
|
|
47
|
+
n_sim: 500
|
|
48
|
+
quantiles: [0.05, 0.5, 0.95]
|
|
49
|
+
|
|
50
|
+
evaluation:
|
|
51
|
+
metrics: [log_score, bic, icl]
|
|
52
|
+
backtest:
|
|
53
|
+
scheme: expanding
|
|
54
|
+
initial_train_steps: 700
|
|
55
|
+
refit_every_steps: 100
|
|
56
|
+
horizons: [1]
|
|
57
|
+
|
|
58
|
+
output:
|
|
59
|
+
write: [posterior, forecast, report]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
schema_version: 1
|
|
2
|
+
project:
|
|
3
|
+
name: segmentation_gaussian_ltr
|
|
4
|
+
seed: 7
|
|
5
|
+
output_dir: runs/segmentation_gaussian_ltr
|
|
6
|
+
log_level: INFO
|
|
7
|
+
|
|
8
|
+
data:
|
|
9
|
+
source:
|
|
10
|
+
kind: parquet
|
|
11
|
+
path: data/sensor_windows.parquet
|
|
12
|
+
observation_columns: [acc_x, acc_y, acc_z]
|
|
13
|
+
sequence_column: session_id
|
|
14
|
+
time_column: null
|
|
15
|
+
clock: steps
|
|
16
|
+
sequences:
|
|
17
|
+
group_by: null
|
|
18
|
+
bucket_edges: [256, 512, 1024, 2048]
|
|
19
|
+
labels:
|
|
20
|
+
source: column
|
|
21
|
+
column: activity
|
|
22
|
+
allowed_sets: false # exact labels where present, NaN = unlabelled
|
|
23
|
+
boundaries: null
|
|
24
|
+
preparation:
|
|
25
|
+
observation_transform: null
|
|
26
|
+
standardize_observations: true
|
|
27
|
+
missing_observations: mask
|
|
28
|
+
|
|
29
|
+
model:
|
|
30
|
+
n_states: 4
|
|
31
|
+
engine: explicit
|
|
32
|
+
d_max: 400
|
|
33
|
+
topology: left_to_right
|
|
34
|
+
left_censored: true
|
|
35
|
+
initial_state: free
|
|
36
|
+
emission:
|
|
37
|
+
family: gaussian
|
|
38
|
+
covariance: full
|
|
39
|
+
scale_by_dt: false
|
|
40
|
+
params:
|
|
41
|
+
mean: {mode: free, init: labels}
|
|
42
|
+
chol: {mode: free, init: labels, prior: {type: lognormal, sd: 1.0}}
|
|
43
|
+
duration:
|
|
44
|
+
per_state:
|
|
45
|
+
- {family: gamma, params: {shape: {mode: free, init: 2.0}, scale: {mode: free, init: 20}}}
|
|
46
|
+
- {family: gamma, params: {shape: {mode: free, init: 2.0}, scale: {mode: free, init: 40}}}
|
|
47
|
+
- {family: geometric, params: {rate: {mode: free, init_mean_sojourn_steps: 15}}}
|
|
48
|
+
- {family: nonparametric, params: {logits: {mode: free, init_mean_sojourn_steps: 20, prior: {type: dirichlet, alpha: 0.5}}}}
|
|
49
|
+
duration_dependent_jumps: false
|
|
50
|
+
transition:
|
|
51
|
+
order: 1
|
|
52
|
+
covariates: []
|
|
53
|
+
prior: {type: dirichlet, alpha: 1.0}
|
|
54
|
+
|
|
55
|
+
estimation:
|
|
56
|
+
method: gem
|
|
57
|
+
max_iter: 300
|
|
58
|
+
tol_f: 1.0e-7
|
|
59
|
+
restarts: 4
|
|
60
|
+
init: [labels, random]
|
|
61
|
+
use_priors: true
|
|
62
|
+
|
|
63
|
+
forecast:
|
|
64
|
+
horizon: 10
|
|
65
|
+
n_sim: 2000
|
|
66
|
+
quantiles: [0.1, 0.5, 0.9]
|
|
67
|
+
|
|
68
|
+
online:
|
|
69
|
+
lag: 20
|
|
70
|
+
alerts:
|
|
71
|
+
- {regime: 3, p_on: 0.8, p_off: 0.5}
|
|
72
|
+
|
|
73
|
+
evaluation:
|
|
74
|
+
metrics: [log_score, bic, icl, boundary_f1, hausdorff, covering, hamming_matched, ari, nmi]
|
|
75
|
+
boundary_tolerance: 5
|
|
76
|
+
cv:
|
|
77
|
+
splitter: sequence_kfold
|
|
78
|
+
folds: 5
|
|
79
|
+
seed: 7
|
|
80
|
+
|
|
81
|
+
output:
|
|
82
|
+
write: [posterior, forecast, cv, report]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Two-regime sanity example (Part I concept, Appendix E) in Gaussian form: calm and turbulent regimes,
|
|
2
|
+
# per-step parameters on a daily calendar grid (calm 0.03 % / 0.756 %, turbulent -0.064 % / 2.205 % per step).
|
|
3
|
+
schema_version: 1
|
|
4
|
+
project:
|
|
5
|
+
name: two_regime_gaussian
|
|
6
|
+
seed: 7
|
|
7
|
+
output_dir: runs/two_regime_gaussian
|
|
8
|
+
log_level: INFO
|
|
9
|
+
|
|
10
|
+
data:
|
|
11
|
+
source:
|
|
12
|
+
kind: csv
|
|
13
|
+
path: data/two_regime.csv
|
|
14
|
+
observation_columns: [x]
|
|
15
|
+
time_column: date
|
|
16
|
+
clock: calendar
|
|
17
|
+
preparation:
|
|
18
|
+
missing_observations: mask
|
|
19
|
+
|
|
20
|
+
model:
|
|
21
|
+
n_states: 2
|
|
22
|
+
engine: expanded
|
|
23
|
+
initial_state: uniform
|
|
24
|
+
emission:
|
|
25
|
+
family: gaussian
|
|
26
|
+
ito_correction: false
|
|
27
|
+
params:
|
|
28
|
+
mean: {mode: free, init: [0.0003, -0.0006]}
|
|
29
|
+
scale: {mode: free, init: [0.0076, 0.022], constraint: increasing}
|
|
30
|
+
duration:
|
|
31
|
+
family: geometric
|
|
32
|
+
params:
|
|
33
|
+
rate: {mode: free, init_mean_sojourn_steps: [100.0, 40.0]}
|
|
34
|
+
transition:
|
|
35
|
+
mode: jump
|
|
36
|
+
order: 1
|
|
37
|
+
|
|
38
|
+
estimation:
|
|
39
|
+
method: map
|
|
40
|
+
restarts: 4
|
|
41
|
+
max_iter: 500
|
|
42
|
+
init: [rolling_kmeans, random]
|
|
43
|
+
device: auto
|
|
44
|
+
|
|
45
|
+
forecast:
|
|
46
|
+
horizon: 10
|
|
47
|
+
n_sim: 1000
|
|
48
|
+
covariate_forecaster: {type: freeze}
|
|
49
|
+
quantiles: [0.05, 0.5, 0.95]
|
|
50
|
+
|
|
51
|
+
evaluation:
|
|
52
|
+
metrics: [log_score, bic, icl]
|
|
53
|
+
backtest:
|
|
54
|
+
scheme: expanding
|
|
55
|
+
initial_train_steps: 500
|
|
56
|
+
refit_every_steps: 60
|
|
57
|
+
horizons: [1, 5]
|
|
58
|
+
|
|
59
|
+
output:
|
|
60
|
+
write: [posterior, forecast, backtest, report]
|