timegym 1.1.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.
- timegym/__init__.py +37 -0
- timegym/_internal.py +94 -0
- timegym/_process_common.py +655 -0
- timegym/checks.py +68 -0
- timegym/contracts.py +578 -0
- timegym/data/real.py +121 -0
- timegym/data/synthetic.py +27 -0
- timegym/diagnostics.py +457 -0
- timegym/evaluation.py +75 -0
- timegym/features.py +223 -0
- timegym/joint_processes.py +439 -0
- timegym/metrics.py +201 -0
- timegym/models.py +419 -0
- timegym/mutations.py +180 -0
- timegym/pipeline.py +428 -0
- timegym/plotting.py +434 -0
- timegym/processes.py +536 -0
- timegym/provenance.py +241 -0
- timegym/reporting.py +330 -0
- timegym/scenarios.py +304 -0
- timegym/smoothing.py +75 -0
- timegym/statistics.py +46 -0
- timegym/target.py +531 -0
- timegym-1.1.0.dist-info/METADATA +262 -0
- timegym-1.1.0.dist-info/RECORD +27 -0
- timegym-1.1.0.dist-info/WHEEL +4 -0
- timegym-1.1.0.dist-info/licenses/LICENSE +21 -0
timegym/__init__.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/12_package.ipynb.
|
|
2
|
+
|
|
3
|
+
from .contracts import Forecast, ForecastTask, Reference, SimulationReference
|
|
4
|
+
from .scenarios import Scenario, Case
|
|
5
|
+
from .pipeline import Pipeline
|
|
6
|
+
from .models import NaiveForecaster, GaussianAR1Forecaster
|
|
7
|
+
from .reporting import (
|
|
8
|
+
TestReport,
|
|
9
|
+
DiagnosticStatus,
|
|
10
|
+
DiagnosticCategory,
|
|
11
|
+
DiagnosticResult,
|
|
12
|
+
CaseResult,
|
|
13
|
+
)
|
|
14
|
+
from .evaluation import ForecastRun, EvaluatedCase
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Case",
|
|
18
|
+
"Forecast",
|
|
19
|
+
"ForecastTask",
|
|
20
|
+
"Reference",
|
|
21
|
+
"SimulationReference",
|
|
22
|
+
"Scenario",
|
|
23
|
+
"Pipeline",
|
|
24
|
+
"NaiveForecaster",
|
|
25
|
+
"GaussianAR1Forecaster",
|
|
26
|
+
"TestReport",
|
|
27
|
+
"ForecastRun",
|
|
28
|
+
"EvaluatedCase",
|
|
29
|
+
"DiagnosticStatus",
|
|
30
|
+
"DiagnosticCategory",
|
|
31
|
+
"DiagnosticResult",
|
|
32
|
+
"CaseResult",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# %% ../notebooks/12_package.ipynb #12_package-05
|
|
36
|
+
|
|
37
|
+
__version__ = "1.1.0"
|
timegym/_internal.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../notebooks/12_package.ipynb.
|
|
2
|
+
|
|
3
|
+
from dataclasses import fields, is_dataclass
|
|
4
|
+
from enum import Enum
|
|
5
|
+
import math
|
|
6
|
+
import traceback
|
|
7
|
+
from typing import Any
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
__all__ = ["positive_int", "nonnegative_int"]
|
|
11
|
+
|
|
12
|
+
# %% ../notebooks/12_package.ipynb #shared-integer-validation
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _integer(value: Any, name: str, *, minimum: int) -> int:
|
|
16
|
+
if (
|
|
17
|
+
isinstance(value, (bool, np.bool_))
|
|
18
|
+
or not isinstance(value, (int, np.integer))
|
|
19
|
+
or value < minimum
|
|
20
|
+
):
|
|
21
|
+
qualifier = "positive" if minimum else "nonnegative"
|
|
22
|
+
raise ValueError(f"{name} must be a {qualifier} integer")
|
|
23
|
+
return int(value)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def positive_int(value: Any, name: str) -> int:
|
|
27
|
+
return _integer(value, name, minimum=1)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def nonnegative_int(value: Any, name: str) -> int:
|
|
31
|
+
return _integer(value, name, minimum=0)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# %% ../notebooks/12_package.ipynb #08_forecast_contract-07
|
|
35
|
+
def _has_complex_values(array: np.ndarray) -> bool:
|
|
36
|
+
"""Detect complex scalars even when an object array hides their dtype."""
|
|
37
|
+
return np.iscomplexobj(array) or (
|
|
38
|
+
array.dtype.kind == "O" and any(np.iscomplexobj(value) for value in array.flat)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# %% ../notebooks/12_package.ipynb #08_forecast_contract-09
|
|
43
|
+
def _real_array(value: Any, name: str) -> np.ndarray:
|
|
44
|
+
"""Convert real numeric data without discarding an imaginary component."""
|
|
45
|
+
array = np.asarray(value)
|
|
46
|
+
if _has_complex_values(array):
|
|
47
|
+
raise ValueError(f"{name} must contain real-valued numbers")
|
|
48
|
+
return np.asarray(array, dtype=float)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# %% ../notebooks/12_package.ipynb #10_reports_and_repla-09
|
|
52
|
+
def _exception_evidence(exc: BaseException) -> dict:
|
|
53
|
+
"""Format the supplied exception even outside its handling block."""
|
|
54
|
+
return {
|
|
55
|
+
"exception_type": type(exc).__name__,
|
|
56
|
+
"exception_message": str(exc),
|
|
57
|
+
"traceback": "".join(traceback.format_exception(exc)),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _json_safe(value):
|
|
62
|
+
"""Canonicalize evidence to JSON values, rejecting nonfinite numbers."""
|
|
63
|
+
if isinstance(value, Enum):
|
|
64
|
+
return _json_safe(value.value)
|
|
65
|
+
if value is None:
|
|
66
|
+
return None
|
|
67
|
+
if isinstance(value, str):
|
|
68
|
+
return str(value)
|
|
69
|
+
if isinstance(value, (bool, np.bool_)):
|
|
70
|
+
return bool(value)
|
|
71
|
+
if isinstance(value, (int, np.integer)):
|
|
72
|
+
return int(value)
|
|
73
|
+
if isinstance(value, (float, np.floating)):
|
|
74
|
+
value = float(value)
|
|
75
|
+
if not math.isfinite(value):
|
|
76
|
+
raise ValueError("JSON evidence contains a nonfinite number")
|
|
77
|
+
return float(value)
|
|
78
|
+
if isinstance(value, np.generic):
|
|
79
|
+
return _json_safe(value.item())
|
|
80
|
+
if isinstance(value, np.ndarray):
|
|
81
|
+
return _json_safe(value.tolist())
|
|
82
|
+
if isinstance(value, BaseException):
|
|
83
|
+
return _exception_evidence(value)
|
|
84
|
+
if is_dataclass(value):
|
|
85
|
+
return {
|
|
86
|
+
item.name: _json_safe(getattr(value, item.name)) for item in fields(value)
|
|
87
|
+
}
|
|
88
|
+
if isinstance(value, dict):
|
|
89
|
+
return {str(key): _json_safe(item) for key, item in value.items()}
|
|
90
|
+
if isinstance(value, (tuple, list)):
|
|
91
|
+
return [_json_safe(item) for item in value]
|
|
92
|
+
if hasattr(value, "isoformat"):
|
|
93
|
+
return str(value.isoformat())
|
|
94
|
+
return repr(value)
|