@@ -155,51 +155,35 @@ predict_flexsurvreg <- function(object, task, ...) {
155
155
# parameters above.
156
156
pdf = function (x ) {} # nolint
157
157
body(pdf ) = substitute({
158
- fn = func
159
- args = as.list(subset(data.table :: as.data.table(self $ parameters()), select = " value" ))$ value
160
- names(args ) = unname(unlist(data.table :: as.data.table(self $ parameters())[, 1 ]))
161
- do.call(fn , c(list (x = x ), args ))
158
+ do.call(func , c(list (x = x ), self $ parameters()$ values ))
162
159
}, list (func = object $ dfns $ d ))
163
160
164
161
cdf = function (x ) {} # nolint
165
162
body(cdf ) = substitute({
166
- fn = func
167
- args = as.list(subset(data.table :: as.data.table(self $ parameters()), select = " value" ))$ value
168
- names(args ) = unname(unlist(data.table :: as.data.table(self $ parameters())[, 1 ]))
169
- do.call(fn , c(list (q = x ), args ))
163
+ do.call(func , c(list (q = x ), self $ parameters()$ values ))
170
164
}, list (func = object $ dfns $ p ))
171
165
172
166
quantile = function (p ) {} # nolint
173
167
body(quantile ) = substitute({
174
- fn = func
175
- args = as.list(subset(data.table :: as.data.table(self $ parameters()), select = " value" ))$ value
176
- names(args ) = unname(unlist(data.table :: as.data.table(self $ parameters())[, 1 ]))
177
- do.call(fn , c(list (p = p ), args ))
168
+ do.call(func , c(list (p = p ), self $ parameters()$ values ))
178
169
}, list (func = object $ dfns $ q ))
179
170
180
171
rand = function (n ) {} # nolint
181
172
body(rand ) = substitute({
182
- fn = func
183
- args = as.list(subset(data.table :: as.data.table(self $ parameters()), select = " value" ))$ value
184
- names(args ) = unname(unlist(data.table :: as.data.table(self $ parameters())[, 1 ]))
185
- do.call(fn , c(list (n = n ), args ))
173
+ do.call(func , c(list (n = n ), self $ parameters()$ values ))
186
174
}, list (func = object $ dfns $ r ))
187
175
188
176
# The parameter set combines the auxiliary parameters with the fitted gamma coefficients.
189
- # Whilst the
190
- # user can set these after fitting, this is generally ill-advised.
191
- parameters = distr6 :: ParameterSet $ new(
192
- id = c(names(args ), object $ dlist $ pars ),
193
- value = c(list (
194
- numeric (length(object $ knots )),
195
- " hazard" , " log" ), rep(list (0 ), length(object $ dlist $ pars ))),
196
- settable = rep(TRUE , length(args ) + length(object $ dlist $ pars )),
197
- support = c(
198
- list (set6 :: Reals $ new()^ length(object $ knots )),
199
- set6 :: Set $ new(" hazard" , " odds" , " normal" ),
200
- set6 :: Set $ new(" log" , " identity" ),
201
- rep(list (set6 :: Reals $ new()), length(object $ dlist $ pars )))
202
- )
177
+ # Whilst the user can set these after fitting, this is generally ill-advised.
178
+ parameters = param6 :: ParameterSet $ new(c(list (
179
+ param6 :: prm(
180
+ " knots" , set6 :: Reals $ new()^ length(object $ knots ),
181
+ numeric (length(object $ knots ))
182
+ ),
183
+ param6 :: prm(" scale" , set6 :: Set $ new(" hazard" , " odds" , " normal" ), " hazard" ),
184
+ param6 :: prm(" timescale" , set6 :: Set $ new(" log" , " identity" ), " log" )),
185
+ lapply(object $ dlist $ pars , function (x ) param6 :: prm(x , " reals" , 0 ))
186
+ ))
203
187
204
188
pars = data.table :: data.table(t(pars ))
205
189
pargs = data.table :: data.table(matrix (args , ncol = ncol(pars ), nrow = length(args )))
@@ -217,18 +201,16 @@ predict_flexsurvreg <- function(object, task, ...) {
217
201
pdf = pdf , cdf = cdf , quantile = quantile , rand = rand
218
202
)
219
203
204
+ # # FIXME - This is bad and needs speeding up
220
205
distlist = lapply(pars , function (x ) {
221
- x = as.list(x )
222
- names(x ) = c(object $ dlist $ pars , names(args ))
223
206
yparams = parameters $ clone(deep = TRUE )
224
- ind = match(yparams $ .__enclos_env__ $ private $ .parameters $ id , names(x ))
225
- yparams $ .__enclos_env__ $ private $ .parameters $ value = x [ind ]
207
+ yparams $ values = setNames(as.list(x ), c(object $ dlist $ pars , names(args )))
226
208
227
209
do.call(distr6 :: Distribution $ new , c(list (parameters = yparams ), shared_params ))
228
210
})
229
211
230
- distr = distr6 :: VectorDistribution $ new(distlist ,
231
- decorators = c(" CoreStatistics" , " ExoticStatistics" ))
212
+ distr = distr6 :: VectorDistribution $ new(
213
+ distlist , decorators = c(" CoreStatistics" , " ExoticStatistics" ))
232
214
233
215
return (list (distr = distr , lp = lp ))
234
216
}
0 commit comments