drvec 0.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.
- drvec/__init__.py +22 -0
- drvec/_gsl.py +83 -0
- drvec/api.py +942 -0
- drvec/c_engine.py +391 -0
- drvec/cast.py +196 -0
- drvec/cli.py +592 -0
- drvec/data.py +295 -0
- drvec/diagnose.py +439 -0
- drvec/fdhess.py +130 -0
- drvec/fit.py +528 -0
- drvec/forecast.py +314 -0
- drvec/irfboot.py +216 -0
- drvec/levels.py +158 -0
- drvec/loglik.py +45 -0
- drvec/nla.py +266 -0
- drvec/parallel.py +86 -0
- drvec/params.py +311 -0
- drvec/rank.py +401 -0
- drvec/report.py +1712 -0
- drvec/results.py +167 -0
- drvec/rng.py +51 -0
- drvec/rungtable.py +82 -0
- drvec/start.py +317 -0
- drvec/stderr.py +33 -0
- drvec/xlink.py +226 -0
- drvec-0.1.0.dist-info/METADATA +205 -0
- drvec-0.1.0.dist-info/RECORD +31 -0
- drvec-0.1.0.dist-info/WHEEL +5 -0
- drvec-0.1.0.dist-info/entry_points.txt +2 -0
- drvec-0.1.0.dist-info/licenses/COPYING +339 -0
- drvec-0.1.0.dist-info/top_level.txt +1 -0
drvec/xlink.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"""-xpre X.pre / -xlink FILE: exogenous transfer-function inputs on the LEVELS
|
|
2
|
+
of the system's series (drvec.c:520-640, xl_load 7003, xl_compute 592).
|
|
3
|
+
|
|
4
|
+
N_t = Y_t - sum_k nu_k(B) X_{k,t}, nu_k(B) = omega_k(B)/delta_k(B) B^b,
|
|
5
|
+
omega(B) = w0 - w1 B - ..., delta(B) = 1 - d1 B - ...
|
|
6
|
+
|
|
7
|
+
N is the VEC process; by linearity nabla Y2 receives nu(B) nabla X and W
|
|
8
|
+
receives (nu_1 + B2' nu_2)(B) X in levels (the cast "by subtraction"). X's own
|
|
9
|
+
model is frozen at its .pre and used only for the presample: observations of X
|
|
10
|
+
before the system's sample first, then a backcast. The parameters go last in
|
|
11
|
+
x, after B2 (par_blocks' tail).
|
|
12
|
+
|
|
13
|
+
Each input is read and cast by fue, as the system's series are
|
|
14
|
+
(data.levels_cast): w = refactor * BoxCox(z) minus its own deterministic
|
|
15
|
+
component on the input's own sample (drvec.c:7041-7051; fue's regressor and
|
|
16
|
+
rule, nu(B) truncated at 40 lags for a rational term, as in the C 0.13; the
|
|
17
|
+
link's own nu_k(B) above is the exact filter, untruncated, as in the C); inputs at
|
|
18
|
+
most I(1) at frequency zero with no seasonal unit roots. The presample the
|
|
19
|
+
sample does not cover is backcast with the input's ARMA from its .pre, fue's
|
|
20
|
+
factors multiplied out (the phi and theta of fue's cast, `_unscramble` with
|
|
21
|
+
the fixed-frequency AR(2)/MA(2)) and its mean's VALUE whatever the flag
|
|
22
|
+
(BUG-38): xl_backcast, on the levels (d = 0) or on the differences, cumulated
|
|
23
|
+
backwards (d = 1).
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
from dataclasses import dataclass
|
|
29
|
+
|
|
30
|
+
import numpy as np
|
|
31
|
+
|
|
32
|
+
from .data import abs_period, levels_cast, load_model
|
|
33
|
+
|
|
34
|
+
XL_MAXORD = 12
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True)
|
|
38
|
+
class Link:
|
|
39
|
+
out: int # 0-based series of the system
|
|
40
|
+
inp: int # 0-based input
|
|
41
|
+
b: int
|
|
42
|
+
r: int
|
|
43
|
+
s: int
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class Inputs:
|
|
48
|
+
names: list
|
|
49
|
+
X: np.ndarray # (nin, xl_len): row t = npre + raw row
|
|
50
|
+
npre: int
|
|
51
|
+
nreal: list
|
|
52
|
+
nbc: list
|
|
53
|
+
d: list
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _parse_net(path, names, innames):
|
|
57
|
+
links = []
|
|
58
|
+
for raw in open(path):
|
|
59
|
+
line = raw.split("#", 1)[0]
|
|
60
|
+
tok = line.split()
|
|
61
|
+
if not tok:
|
|
62
|
+
continue
|
|
63
|
+
if len(tok) < 6 or tok[1] != "<-":
|
|
64
|
+
raise ValueError(f"{path}: a link is `OUTPUT <- INPUT b r s', got: {raw}")
|
|
65
|
+
o, _a, i, b, r, s = tok[:6]
|
|
66
|
+
b, r, s = int(b), int(r), int(s)
|
|
67
|
+
if b < 0 or r < 0 or s < 0 or r > 2 or s > XL_MAXORD:
|
|
68
|
+
raise ValueError(f"{path}: b, r, s must be >= 0, r <= 2 and s <= {XL_MAXORD}")
|
|
69
|
+
if o not in names or i not in innames:
|
|
70
|
+
raise ValueError(f"{path}: `{o} <- {i}': the output must be a series of the "
|
|
71
|
+
"system\n and the input the name of an -xpre file.")
|
|
72
|
+
links.append(Link(names.index(o), innames.index(i), b, r, s))
|
|
73
|
+
if not links:
|
|
74
|
+
raise ValueError(f"{path} declares no link")
|
|
75
|
+
return tuple(links)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def backcast(w, ph, th, mu, L):
|
|
79
|
+
"""xl_backcast (drvec.c:6965): drtran's backcast_arma. The ARMA in elf's
|
|
80
|
+
sign convention is symmetric under time reversal, so backcasting is
|
|
81
|
+
forecasting the reversed series with the same phi and theta. -> out[0..L-1],
|
|
82
|
+
out[k-1] the value k periods before w[0]."""
|
|
83
|
+
n, p, q = len(w), len(ph), len(th)
|
|
84
|
+
if L <= 0 or n <= 0:
|
|
85
|
+
return []
|
|
86
|
+
u = [0.0] * (n + 1)
|
|
87
|
+
e = [0.0] * (n + 1)
|
|
88
|
+
for t in range(1, n + 1):
|
|
89
|
+
u[t] = w[n - t] - mu
|
|
90
|
+
for t in range(1, n + 1):
|
|
91
|
+
acc = u[t]
|
|
92
|
+
for i in range(1, p + 1):
|
|
93
|
+
if i >= t:
|
|
94
|
+
break
|
|
95
|
+
acc -= ph[i - 1] * u[t - i]
|
|
96
|
+
for j in range(1, q + 1):
|
|
97
|
+
if j >= t:
|
|
98
|
+
break
|
|
99
|
+
acc += th[j - 1] * e[t - j]
|
|
100
|
+
e[t] = acc
|
|
101
|
+
out = [0.0] * (L + 1)
|
|
102
|
+
for k in range(1, L + 1):
|
|
103
|
+
acc = 0.0
|
|
104
|
+
for i in range(1, p + 1):
|
|
105
|
+
ix = k - i
|
|
106
|
+
acc += ph[i - 1] * (out[ix] - mu if ix >= 1 else u[n + ix])
|
|
107
|
+
for j in range(1, q + 1):
|
|
108
|
+
ix = n + k - j
|
|
109
|
+
if ix <= n:
|
|
110
|
+
acc -= th[j - 1] * e[ix]
|
|
111
|
+
out[k] = acc + mu
|
|
112
|
+
return out[1:]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def load(data, xpre, xnet):
|
|
116
|
+
"""xl_load: -> (links, Inputs)."""
|
|
117
|
+
from fue.forecast import _nonsop_coefs
|
|
118
|
+
first = abs_period(data.start[0], data.start[1], data.freq)
|
|
119
|
+
nobs_raw = data.nobs_raw
|
|
120
|
+
ws, sts, innames, ds, mus, phs, ths = [], [], [], [], [], [], []
|
|
121
|
+
for f in xpre:
|
|
122
|
+
ts, m = load_model(f, "ERROR: cannot read the input")
|
|
123
|
+
freq = int(ts.freq) if ts.freq else 1
|
|
124
|
+
if freq != data.freq:
|
|
125
|
+
raise ValueError(f"the input {f} has frequency {freq} and the system {data.freq}")
|
|
126
|
+
d, D = int(m.d or 0), int(m.D or 0)
|
|
127
|
+
ornsop = len(_nonsop_coefs(d, D, freq, ifadf=(m.ifadf or None)))
|
|
128
|
+
if D != 0 or d > 1 or ornsop != d:
|
|
129
|
+
raise ValueError(f"the input {f} is not at most I(1) at frequency zero with no\n"
|
|
130
|
+
f" seasonal unit roots (d={d}, D={D}). Its level would "
|
|
131
|
+
"not be\n a transfer input W could stay stationary with.")
|
|
132
|
+
lam = float(m.boxlam)
|
|
133
|
+
for z in ts.data:
|
|
134
|
+
if abs(lam - 1.0) > 1.0e-12 and float(z) <= 0.0:
|
|
135
|
+
raise ValueError(f"{f}: Box-Cox with lambda {lam:g} at a value {float(z):g}")
|
|
136
|
+
phi, theta, mu, z = levels_cast(m)
|
|
137
|
+
w = [float(v) for v in z]
|
|
138
|
+
st = abs_period(ts.start[0], ts.start[1], freq)
|
|
139
|
+
if st + len(w) - 1 < first + nobs_raw - 1:
|
|
140
|
+
raise ValueError(f"the input {f} ends before the system's sample does. An\n"
|
|
141
|
+
" exogenous input must be observed over the whole sample.")
|
|
142
|
+
ws.append(w); sts.append(st); innames.append(ts.name or str(f)); ds.append(d)
|
|
143
|
+
mus.append(mu)
|
|
144
|
+
phs.append(phi)
|
|
145
|
+
ths.append(theta)
|
|
146
|
+
links = _parse_net(xnet, list(data.names), innames)
|
|
147
|
+
maxbs = max(L.b + L.s for L in links)
|
|
148
|
+
anyr = any(L.r > 0 for L in links)
|
|
149
|
+
npre = nobs_raw + maxbs if anyr else maxbs
|
|
150
|
+
xlen = npre + nobs_raw
|
|
151
|
+
X = np.zeros((len(xpre), xlen))
|
|
152
|
+
nreal, nbc = [], []
|
|
153
|
+
for i, w in enumerate(ws):
|
|
154
|
+
k0 = 0
|
|
155
|
+
for k in range(1, xlen + 1):
|
|
156
|
+
per = first + (k - npre - 1)
|
|
157
|
+
ix = per - sts[i] + 1
|
|
158
|
+
if 1 <= ix <= len(w):
|
|
159
|
+
X[i, k - 1] = w[ix - 1]
|
|
160
|
+
if not k0:
|
|
161
|
+
k0 = k
|
|
162
|
+
L = k0 - 1
|
|
163
|
+
nreal.append(npre - L)
|
|
164
|
+
nbc.append(L)
|
|
165
|
+
if L > 0:
|
|
166
|
+
if ds[i] == 0:
|
|
167
|
+
out = backcast(w, phs[i], ths[i], mus[i], L)
|
|
168
|
+
for k in range(1, L + 1):
|
|
169
|
+
X[i, k0 - k - 1] = out[k - 1]
|
|
170
|
+
else:
|
|
171
|
+
u = [w[t + 1] - w[t] for t in range(len(w) - 1)]
|
|
172
|
+
out = backcast(u, phs[i], ths[i], mus[i], L)
|
|
173
|
+
for k in range(1, L + 1):
|
|
174
|
+
X[i, k0 - k - 1] = X[i, k0 - k] - out[k - 1]
|
|
175
|
+
return links, Inputs(innames, X, npre, nreal, nbc, ds)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def npar(links):
|
|
179
|
+
return sum(L.s + 1 + L.r for L in links)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def compute(links, inp, xp, nobs_raw, M):
|
|
183
|
+
"""xl_compute: T (nobs_raw, M) = sum over links of nu(B) X, or None when a
|
|
184
|
+
denominator is not stable. The convolution keeps the C's order of
|
|
185
|
+
additions, vectorised over the rows."""
|
|
186
|
+
T = np.zeros((nobs_raw, M))
|
|
187
|
+
xlen = inp.X.shape[1]
|
|
188
|
+
c = 0
|
|
189
|
+
for L in links:
|
|
190
|
+
om = [xp[c + j] for j in range(L.s + 1)]
|
|
191
|
+
c += L.s + 1
|
|
192
|
+
de = [0.0] + [xp[c + j] for j in range(L.r)]
|
|
193
|
+
c += L.r
|
|
194
|
+
if (L.r == 1 and abs(de[1]) >= 1.0) or (L.r == 2 and not (
|
|
195
|
+
de[1] + de[2] < 1.0 and de[2] - de[1] < 1.0 and abs(de[2]) < 1.0)):
|
|
196
|
+
return None
|
|
197
|
+
nu = [0.0] * (xlen + 1)
|
|
198
|
+
for t in range(1, xlen + 1):
|
|
199
|
+
acc = 0.0
|
|
200
|
+
lag = t - 1 - L.b
|
|
201
|
+
if 0 <= lag <= L.s:
|
|
202
|
+
acc = om[0] if lag == 0 else -om[lag]
|
|
203
|
+
for j in range(1, L.r + 1):
|
|
204
|
+
if t > j:
|
|
205
|
+
acc += de[j] * nu[t - j]
|
|
206
|
+
nu[t] = acc
|
|
207
|
+
Xi = inp.X[L.inp]
|
|
208
|
+
kk = inp.npre + np.arange(1, nobs_raw + 1) # 1-based
|
|
209
|
+
acc = np.zeros(nobs_raw)
|
|
210
|
+
for m in range(1, int(kk.max()) + 1):
|
|
211
|
+
ok = kk >= m
|
|
212
|
+
acc[ok] += nu[m] * Xi[kk[ok] - m]
|
|
213
|
+
T[:, L.out] += acc
|
|
214
|
+
return T
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def labels(links, names, innames):
|
|
218
|
+
out = []
|
|
219
|
+
for L in links:
|
|
220
|
+
out += [(f"{names[L.out]} <- {innames[L.inp]} w{j}", "xlink", 1) for j in range(L.s + 1)]
|
|
221
|
+
out += [(f"{names[L.out]} <- {innames[L.inp]} d{j}", "xlink", 1)
|
|
222
|
+
for j in range(1, L.r + 1)]
|
|
223
|
+
return out
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
_ = re
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: drvec
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: VARMA-VEC cointegration models by exact maximum likelihood (Mauricio 2006): rank tests with a parametric bootstrap, restrictions, forecasts and impulse responses. The Python port of the ATSW suite's drvec, on drvarma's exact VARMA likelihood and fue's univariate models
|
|
5
|
+
Author-email: "David E. Guerrero" <davidesg@ucm.es>
|
|
6
|
+
License-Expression: GPL-2.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/davidesg/drvec-python
|
|
8
|
+
Project-URL: Repository, https://github.com/davidesg/drvec-python
|
|
9
|
+
Project-URL: Issues, https://github.com/davidesg/drvec-python/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/davidesg/drvec-python/blob/main/docs/PORT.md
|
|
11
|
+
Project-URL: Changelog, https://github.com/davidesg/drvec-python/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: cointegration,VECM,VARMA,VARMA-VEC,error correction,Johansen,rank test,bootstrap,exact maximum likelihood,time series,econometrics,Box-Jenkins,forecasting
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: COPYING
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Requires-Dist: scipy>=1.10
|
|
29
|
+
Requires-Dist: fue>=0.1.18
|
|
30
|
+
Requires-Dist: drvarma>=0.3.0
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# drvec
|
|
36
|
+
|
|
37
|
+
**VARMA-VEC cointegration models by exact maximum likelihood** (Mauricio
|
|
38
|
+
2006): a vector error-correction model whose short-run part is a full VARMA,
|
|
39
|
+
not only a VAR, estimated by the exact Gaussian likelihood. drvec fits the
|
|
40
|
+
model at a given cointegrating rank, tests the rank (the sequential LR test,
|
|
41
|
+
with a parametric bootstrap), and writes the C program's reports: estimates
|
|
42
|
+
and standard errors, the long run (alpha, beta, Pi), restrictions on alpha and
|
|
43
|
+
beta with their LR tests, diagnostics, forecasts and impulse responses.
|
|
44
|
+
|
|
45
|
+
It is the Python port of the C program **drvec** of the ATSW suite
|
|
46
|
+
([atsw-gui](https://github.com/davidesg/atsw-gui), `engines/drvec`), and the
|
|
47
|
+
engine of its cointegrated systems: [fue](https://pypi.org/project/fue/) and
|
|
48
|
+
[art](https://pypi.org/project/art-tseries/) build each series' univariate
|
|
49
|
+
model, drtran the transfer functions, drvarma and sima the stationary VARMA,
|
|
50
|
+
and drvec the cointegrated system. The assistant that drives it is **sima**
|
|
51
|
+
([sima-tseries](https://pypi.org/project/sima-tseries/)).
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pip install drvec
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
drvec's code is Python. What must be fast comes with binary wheels:
|
|
60
|
+
[drvarma](https://pypi.org/project/drvarma/) (>= 0.3.0) brings the compiled
|
|
61
|
+
exact VARMA likelihood (AS 311), its optimiser and GSL's eigensolvers,
|
|
62
|
+
[fue](https://pypi.org/project/fue/) (>= 0.1.18) the reader and cast of the
|
|
63
|
+
`.pre` files, and drvec's own wheels carry **drvec C 0.13**, the program the
|
|
64
|
+
port mirrors, for the long bootstraps (below): Linux x86_64 and aarch64,
|
|
65
|
+
macOS arm64 and Windows AMD64, with GSL linked in. Nothing to compile, and
|
|
66
|
+
no system GSL needed. Python 3.10 or later. Elsewhere pip takes the
|
|
67
|
+
pure-Python wheel, and the bootstraps run in Python.
|
|
68
|
+
|
|
69
|
+
Check that the compiled engine is in use:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
python -c "import drvarma._engine as E, drvec._gsl as G; print(E.engine_backend(), G.backend())"
|
|
73
|
+
# c gsl
|
|
74
|
+
python -c "from drvec import c_engine; print(c_engine.find())"
|
|
75
|
+
# CBinary(path='.../site-packages/drvec/_bin/drvec', version='0.13', source='bundled')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## A minimal example
|
|
79
|
+
|
|
80
|
+
drvec reads one fue `.pre` file per series: each series' univariate model
|
|
81
|
+
(its Box-Cox, deterministic terms and ARMA), from which it takes the series
|
|
82
|
+
in levels. Jenkins and Alavi's muskrat and mink (62 annual observations from
|
|
83
|
+
1850), with the files of the test suite:
|
|
84
|
+
[mmpre.muskrat.pre](https://raw.githubusercontent.com/davidesg/drvec-python/main/tests/data/fixtures/mmpre.muskrat.pre)
|
|
85
|
+
and
|
|
86
|
+
[mmpre.mink.pre](https://raw.githubusercontent.com/davidesg/drvec-python/main/tests/data/fixtures/mmpre.mink.pre).
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import drvec
|
|
90
|
+
|
|
91
|
+
pre = ["mmpre.muskrat.pre", "mmpre.mink.pre"]
|
|
92
|
+
|
|
93
|
+
# the rank: sequential LR tests (add bootstrap=200 for the bootstrap p-values)
|
|
94
|
+
rt = drvec.rank_test(pre, p=1, q=0, case=2)
|
|
95
|
+
open("mmrank.out", "w").write(rt.out_text("mmrank")) # the C program's .out
|
|
96
|
+
|
|
97
|
+
# a VAR(1)-VEC with one cointegrating relation, Johansen's case 2
|
|
98
|
+
r = drvec.fit(pre, p=1, q=0, r=1, case=2)
|
|
99
|
+
print(r.loglik) # -18.980152265473677
|
|
100
|
+
for p in r.params:
|
|
101
|
+
print(f"{p.label:24s} {p.value:9.4f} {p.se:8.4f}")
|
|
102
|
+
open("mm.out", "w").write(r.out_text("mm"))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The same from the command line, with the C program's syntax and files:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
drvec-py mmpre.muskrat.pre mmpre.mink.pre 1 0 1 -case 2 -name mm
|
|
109
|
+
drvec-py mmpre.muskrat.pre mmpre.mink.pre 2 0 1 -case 2 -lrtest -bootstrap 200
|
|
110
|
+
drvec-py -h
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
It is `drvec-py` and not `drvec` because `drvec` is the C program's name on a
|
|
114
|
+
system with the ATSW suite.
|
|
115
|
+
|
|
116
|
+
## The results as numbers
|
|
117
|
+
|
|
118
|
+
Everything the `.out` prints is also there as arrays, computed by the same
|
|
119
|
+
routine that prints it (the suite checks that each equals the printed number):
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
r.alpha, r.beta, r.Pi, r.gamma, r.theta, r.Sigma # in the files' order
|
|
123
|
+
r.residuals, r.stationary # Ybar's innovations and VARMA
|
|
124
|
+
r.level_irf(), r.fevd(), r.long_run() # the responses in levels
|
|
125
|
+
r.diagnostics().hosking_p, r.diagnostics().jb_p # the residual tests
|
|
126
|
+
r.forecasts(8).level # (H, M), in each series' units
|
|
127
|
+
r.restriction_lr # an LR with its df, when restricted
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The list, with the conventions, is in
|
|
131
|
+
[docs/API.md](https://github.com/davidesg/drvec-python/blob/main/docs/API.md).
|
|
132
|
+
|
|
133
|
+
## Long bootstraps: workers, and drvec C as the engine
|
|
134
|
+
|
|
135
|
+
A rank test with B = 999 on three series is hours of Python on one core.
|
|
136
|
+
Two things make it affordable, and neither changes a number:
|
|
137
|
+
|
|
138
|
+
- **`workers=`**: the replications are drawn in sequence, in the C's order,
|
|
139
|
+
and refitted in a process pool. The default is `DRVEC_WORKERS`, else the
|
|
140
|
+
cores less one; `workers=1` runs in-process. The output is byte-identical
|
|
141
|
+
whatever the number.
|
|
142
|
+
- **`engine=`**: `"auto"` (the default) runs the bootstrap on **drvec C 0.13**
|
|
143
|
+
when it finds the binary -- `DRVEC_BIN`, then the one bundled in the
|
|
144
|
+
wheel (`drvec/_bin/drvec`), then `drvec` on the `PATH`, then the ATSW
|
|
145
|
+
install directory -- and on the parallel Python otherwise. The C's replications are read back into
|
|
146
|
+
the same result objects; on Linux x86_64 the files are the same bytes.
|
|
147
|
+
`"python"` and `"c"` force one or the other.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
rt = drvec.rank_test(pre, p=2, q=0, case=2, bootstrap=999, boot_path="mm.boot",
|
|
151
|
+
progress=lambda b, rep: print(rep.h0, b, rep.status))
|
|
152
|
+
print(rt.provenance.engine, rt.provenance.version) # c 0.13, or python 0.1.0
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`seed=` gives another stream for a Monte Carlo check (always in Python: the
|
|
156
|
+
C's generator is fixed at its seed); the default is the C's.
|
|
157
|
+
|
|
158
|
+
## The C oracle and the platform convention
|
|
159
|
+
|
|
160
|
+
The port is homologated, case by case, against its oracle: the C program
|
|
161
|
+
**drvec 0.13** ([atsw-gui](https://github.com/davidesg/atsw-gui) commit
|
|
162
|
+
`ae95446`; the bundled build is `800a540`, with BUG-61 to BUG-64 fixed,
|
|
163
|
+
`-gzero` and the I(1, r) check before the rank bootstrap, and the oracle files
|
|
164
|
+
are that build's where it moves them (`tests/data/oracle/SOURCE`); its
|
|
165
|
+
tag `drvec-v0.13` comes with the suite's release). On these
|
|
166
|
+
cases it is not "within tolerance" of the C: it is the same computation.
|
|
167
|
+
|
|
168
|
+
- **Exact on Linux x86_64**, the oracle's platform: every number and every
|
|
169
|
+
line of the `.out`, `.boot`, `.forecast` and `.irfboot` files is byte for
|
|
170
|
+
byte the C's.
|
|
171
|
+
- **A tolerance tier elsewhere** (Linux aarch64, macOS, Windows): the
|
|
172
|
+
compiled likelihood and libm round the last bits differently, and the
|
|
173
|
+
optimiser can amplify them on a flat likelihood. There the log-likelihood
|
|
174
|
+
agrees to 1e-5 and the estimates to 1e-4, and every *decision* -- the
|
|
175
|
+
winning start, the rank test's verdicts, the bootstrap's statuses and
|
|
176
|
+
p-values -- must still be the C's.
|
|
177
|
+
- **Ill-defined fits** (a search that stops on a flat ridge, a gate verdict
|
|
178
|
+
that rounding can flip) are compared off that platform on what they
|
|
179
|
+
declare, not on the point.
|
|
180
|
+
|
|
181
|
+
The details, decision by decision, are in
|
|
182
|
+
[docs/PORT.md](https://github.com/davidesg/drvec-python/blob/main/docs/PORT.md);
|
|
183
|
+
the rules of the convention in
|
|
184
|
+
[tests/conftest.py](https://github.com/davidesg/drvec-python/blob/main/tests/conftest.py).
|
|
185
|
+
|
|
186
|
+
Not ported in this version, and refused by name when asked for (exit 2, with
|
|
187
|
+
the C's words): the options starred in `drvec-py -h` -- `-specs`, `-warma`,
|
|
188
|
+
`-mawarma`, `-matest`, `-artest`, `-rankadm`, `-eval`, the seed options
|
|
189
|
+
(`-seed`, `-seedybar`, `-seedgate`, `-noladder`, `-seedjoh`, `-seedb2`) and
|
|
190
|
+
the writers (`-writeres`, `-writeinp`) --, `-m 2`, the `.inp` route, and the
|
|
191
|
+
rank test's and `-rungs`' combinations that the C has and the port does not
|
|
192
|
+
yet (docs/PORT.md §10).
|
|
193
|
+
|
|
194
|
+
## Documentation and changes
|
|
195
|
+
|
|
196
|
+
- [CHANGELOG.md](https://github.com/davidesg/drvec-python/blob/main/CHANGELOG.md)
|
|
197
|
+
- [docs/API.md](https://github.com/davidesg/drvec-python/blob/main/docs/API.md): the API, the accessors, the engines
|
|
198
|
+
- [docs/PORT.md](https://github.com/davidesg/drvec-python/blob/main/docs/PORT.md): how the C was ported
|
|
199
|
+
- [TODO.md](https://github.com/davidesg/drvec-python/blob/main/TODO.md): the milestones and the open risks
|
|
200
|
+
- [bugs/](https://github.com/davidesg/drvec-python/tree/main/bugs): the C defects found by the port, each with its repro
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
GPL-2.0-or-later (see
|
|
205
|
+
[COPYING](https://github.com/davidesg/drvec-python/blob/main/COPYING)).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
drvec/__init__.py,sha256=NSIfc2WcJ3voVVkcEe21wHUG4Lk-4luVhTPZLyzn2AA,1200
|
|
2
|
+
drvec/_gsl.py,sha256=8_yzw-WyG5-7VqPdsN6rHRZBpSSBwnHNiIOVbBbR5mU,3488
|
|
3
|
+
drvec/api.py,sha256=BW9sr8EVpts1xs6YDQAGo6jd6FlENlX_4iEaggWiIdI,43175
|
|
4
|
+
drvec/c_engine.py,sha256=RBRNPcT4HiY4XVgotQXHyAS0jFxfi4ObjzksmSTQ5Qs,15159
|
|
5
|
+
drvec/cast.py,sha256=gv2RM4EfDHRoDL6UBDcAAwpnHBelmA1r_uo71fi7WBM,7003
|
|
6
|
+
drvec/cli.py,sha256=H1ScUZ0zRMjigSxQEXqP3MilZGD31E7lmnsbve-Cv4g,25463
|
|
7
|
+
drvec/data.py,sha256=99x55HbkQi6XXCB8xnMIKuEEvhZQu_4w-usZGDZvEm4,12978
|
|
8
|
+
drvec/diagnose.py,sha256=5u7xv5OKg9RqwDyBfZTU3v4rIfXoKWfRnfn_VKWPTZM,15795
|
|
9
|
+
drvec/fdhess.py,sha256=_Eagiy0E4q_NZoBzueAmzhRb8C-KhxMcANESf5sSb7g,5209
|
|
10
|
+
drvec/fit.py,sha256=cS07Sabm_cptiCR5W-QTIFKxZpN-wow3ngNvaaBdmT0,20444
|
|
11
|
+
drvec/forecast.py,sha256=899J3nZJ7yosJCnpcRTk4u38-GAup-HLBpFQU0uzS20,13374
|
|
12
|
+
drvec/irfboot.py,sha256=exuY21W4FRbXJpD8lO7kPR3I9YL2ppqeJ-z44gKOaCU,8513
|
|
13
|
+
drvec/levels.py,sha256=xycg0o8iX2GcPtgGt2z2wM3zgJq0FeYIx9yKs_cQtGM,6803
|
|
14
|
+
drvec/loglik.py,sha256=lodoAIAcxxBVGRckwq38o40CWPA_QfBDLS7vLAdU2Rw,1547
|
|
15
|
+
drvec/nla.py,sha256=7i2UaM17vFm3LAmkan6li088fOJyVt3CxGTAF6tb3nM,8183
|
|
16
|
+
drvec/parallel.py,sha256=sN4ST5Ryq0Xg284yaGIxwyap5dkiirEI1nHw5Mp1x6Y,3321
|
|
17
|
+
drvec/params.py,sha256=9xjGtRynqlgjqyAl7Ynu0sYP6HCrhMabyAztNPZXc3w,12173
|
|
18
|
+
drvec/rank.py,sha256=jpYMDYN1Etz_hpIAnT0KLJEJu4iuBNzbwvJOeQSVrjs,16180
|
|
19
|
+
drvec/report.py,sha256=pu28Oxko9KvEXtzbM2kez8D5pFKA7z9U52WPbc5A2yM,77969
|
|
20
|
+
drvec/results.py,sha256=IRnVXWipEl9Sxf2njMNyglBoAGTf9xE0edgz2RwRnEE,5368
|
|
21
|
+
drvec/rng.py,sha256=oURb5YLTpMh_8tlFLgkMx04feG8puOlWiECphlSvnR0,1708
|
|
22
|
+
drvec/rungtable.py,sha256=HTwTk8QqxsbjLoMYd6x2abFBxm-oaTK-6n_HxUOPN_g,3752
|
|
23
|
+
drvec/start.py,sha256=Ibm1-YlCd5FwWBFpSqyoC2K43QrDAAzxGdTokFvX328,11172
|
|
24
|
+
drvec/stderr.py,sha256=Wuvh_R3eF-gzE_BHrEGBpVI4_FJOUoBOuXgisY2ntWE,1047
|
|
25
|
+
drvec/xlink.py,sha256=Al7u_KXV04jfCLvEOBl2NSybAOpS_SLSPnRv_yVujMo,8502
|
|
26
|
+
drvec-0.1.0.dist-info/licenses/COPYING,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
|
|
27
|
+
drvec-0.1.0.dist-info/METADATA,sha256=zdF2FpNCQrZnXQ9keqn9D544S_ow4AxA80-vA2LUJdA,10043
|
|
28
|
+
drvec-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
29
|
+
drvec-0.1.0.dist-info/entry_points.txt,sha256=uTZYIZwSU_wKLzcS7-8rZBTU6xElg-wdTSQNc4u605U,44
|
|
30
|
+
drvec-0.1.0.dist-info/top_level.txt,sha256=zvJx8fQBJTWqDc5nqNCaU952Btba0UFmt-toZ5NzVio,6
|
|
31
|
+
drvec-0.1.0.dist-info/RECORD,,
|