Skip to content

Commit 5dbae2a

Browse files
align with R's v0.8.1
1 parent 6cce109 commit 5dbae2a

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# version 0.8.1
2+
3+
- Align with R version (see [https://github.com/Techtonique/ahead/blob/main/NEWS.md#version-070](https://github.com/Techtonique/ahead/blob/main/NEWS.md#version-070) and [https://github.com/Techtonique/ahead/blob/main/NEWS.md#version-080](https://github.com/Techtonique/ahead/blob/main/NEWS.md#version-080)) as much as possible
4+
- moving block bootstrap in `ridge2f`, `basicf`, in addition to circular block bootstrap from 0.6.2
5+
- adjust R-Vine copulas on residuals for `ridge2f` simulation (with empirical and Gaussian marginals)
6+
17
# version 0.6.2
28

39
- Add Block Bootstrap to `ridge2f` and `basicf`

ahead/Basic/BasicForecaster.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ class BasicForecaster():
2020
2121
type_pi: a string;
2222
Type of prediction interval (currently "gaussian",
23-
or "bootstrap")
23+
"bootstrap" (independent), "blockbootstrap" (circular),
24+
"movingblockbootstrap")
2425
2526
block_length: an integer
26-
length of block for multivariate circular block bootstrap (`type_pi == blockbootstrap`)
27+
length of block for multivariate block bootstrap (`type_pi == blockbootstrap`
28+
or `type_pi == movingblockbootstrap`)
2729
2830
B: an integer;
29-
Number of bootstrap replications for `type_pi == bootstrap`
31+
Number of replications
3032
3133
date_formatting: a string;
3234
Currently:
3335
- "original": yyyy-mm-dd
3436
- "ms": milliseconds
3537
3638
seed: an integer;
37-
reproducibility seed for type_pi == 'bootstrap'
39+
reproducibility seed
3840
3941
Attributes:
4042
@@ -151,8 +153,8 @@ def forecast(self, df):
151153

152154
y = mv.compute_y_mts(self.input_df, frequency)
153155

154-
if self.type_pi is "blockbootstrap":
155-
assert self.block_length is not None, "For `type_pi == 'blockbootstrap'`, `block_length` must be not None"
156+
if self.type_pi in ("blockbootstrap", "movingblockbootstrap"):
157+
assert self.block_length is not None, "For `type_pi in ('blockbootstrap', 'movingblockbootstrap')`, `block_length` must be not None"
156158

157159
self.fcast_ = config.AHEAD_PACKAGE.basicf(
158160
y,
@@ -188,7 +190,8 @@ def forecast(self, df):
188190
for i in range(n_series)
189191
)
190192

191-
if self.type_pi == "bootstrap" or self.type_pi == "blockbootstrap":
193+
if self.type_pi in ("bootstrap", "blockbootstrap",
194+
"movingblockbootstrap"):
192195
self.sims_ = tuple(
193196
np.asarray(self.fcast_.rx2["sims"][i]) for i in range(self.B)
194197
)

ahead/Ridge2/Ridge2Regressor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ def __init__(
155155
date_formatting ="original",
156156
seed =123,
157157
):
158+
159+
if not config.R_IS_INSTALLED:
160+
raise ImportError("R is not installed! \n" + config.USAGE_MESSAGE)
161+
162+
if not config.RPY2_IS_INSTALLED:
163+
raise ImportError(config.RPY2_ERROR_MESSAGE + config.USAGE_MESSAGE)
158164

159165
self.h = h
160166
self.level = level

examples/basicforecaster.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,37 @@
122122
print(d4.mean_)
123123
print(d4.lower_)
124124
print(d4.upper_)
125+
126+
print("\n")
127+
print("Example 5 -----")
128+
129+
dataset = {
130+
'date' : ['2001-01-01', '2002-01-01', '2003-01-01',
131+
'2004-01-01', '2005-01-01', '2006-01-01',
132+
'2007-01-01'],
133+
'series1' : [34, 30, 35.6, 33.3, 38.1, 34.4, 33.9],
134+
'series2' : [4, 5.5, 5.6, 6.3, 5.1, 4.9, 4.7],
135+
'series3' : [100, 100.5, 100.6, 100.2, 100.1, 99.9, 101.0]}
136+
df = pd.DataFrame(dataset).set_index('date')
137+
138+
139+
d5 = BasicForecaster(h = 5, date_formatting = "original",
140+
type_pi="movingblockbootstrap", B=20, block_length=3)
141+
142+
start = time()
143+
d5.forecast(df)
144+
print(f"Elapsed: {time()-start} \n")
145+
146+
print("\n output_dates_: \n")
147+
print(d5.output_dates_)
148+
149+
print("\n mean, lower, upper as numpy arrays: \n")
150+
print(d5.mean_)
151+
print(d5.lower_)
152+
print(d5.upper_)
153+
154+
print("\n result_dfs_: \n")
155+
print(d5.result_dfs_)
156+
157+
print("\n sims_: \n")
158+
print(d5.sims_)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from codecs import open
33
from os import path
44

5-
__version__ = "0.6.2"
5+
__version__ = "0.8.1"
66

77
here = path.abspath(path.dirname(__file__))
88

0 commit comments

Comments
 (0)