@@ -106,26 +106,29 @@ ResamplingFcstCV = R6Class("ResamplingFcstCV",
106
106
setnames(tab , c(" row_id" , " order" ))
107
107
setorderv(tab , " order" )
108
108
train_end = tab [.N - horizon , row_id ]
109
- train_end = rev( seq.int(
109
+ train_end = seq.int(
110
110
from = train_end ,
111
111
by = - pars $ step_size ,
112
112
length.out = pars $ folds
113
- ))
113
+ )
114
114
if (! pars $ fixed_window ) {
115
115
train_ids = map(train_end , function (x ) ids [1L ]: x )
116
116
} else {
117
117
train_ids = map(train_end , function (x ) (x - window_size + 1L ): x )
118
118
}
119
- test_ids = map(train_ids , function (x ) (x [length(x )] + 1L ): (x [length(x )] + horizon ))
119
+ test_ids = map(train_ids , function (x ) {
120
+ n = length(x )
121
+ (x [n ] + 1L ): (x [n ] + horizon )
122
+ })
120
123
} else {
121
124
setnames(tab , " ..row_id" , " row_id" )
122
125
setorderv(tab , c(key_cols , order_cols ))
123
126
ids = tab [, {
124
- train_end = rev( seq.int(
127
+ train_end = seq.int(
125
128
from = .N - horizon ,
126
129
by = - pars $ step_size ,
127
130
length.out = pars $ folds
128
- ))
131
+ )
129
132
if (pars $ fixed_window ) {
130
133
train_ids = map(train_end , function (x ) .SD [(x - window_size + 1L ): x , row_id ])
131
134
} else {
@@ -137,9 +140,10 @@ ResamplingFcstCV = R6Class("ResamplingFcstCV",
137
140
})
138
141
list (train_ids = train_ids , test_ids = test_ids )
139
142
}, by = key_cols ][, .(train_ids , test_ids )]
140
-
143
+ train_ids = ids $ train_ids
144
+ test_ids = ids $ test_ids
141
145
}
142
- list (train = ids $ train_ids , test = ids $ test_ids )
146
+ list (train = train_ids , test = test_ids )
143
147
},
144
148
145
149
.sample_ids = function (ids , ... ) {
@@ -149,11 +153,11 @@ ResamplingFcstCV = R6Class("ResamplingFcstCV",
149
153
150
154
ids = sort(ids )
151
155
train_end = ids [ids < = (max(ids ) - horizon ) & ids > = window_size ]
152
- train_end = rev( seq.int(
156
+ train_end = seq.int(
153
157
from = train_end [length(train_end )],
154
158
by = - pars $ step_size ,
155
159
length.out = pars $ folds
156
- ))
160
+ )
157
161
if (pars $ fixed_window ) {
158
162
train_ids = map(train_end , function (x ) (x - window_size + 1L ): x )
159
163
} else {
0 commit comments