@@ -149,7 +149,8 @@ VectorDistribution <- R6Class("VectorDistribution",
149
149
stop(" Either distlist or distribution and params must be provided." )
150
150
}
151
151
152
- distribution <- match.arg(distribution , listDistributions(simplify = TRUE ))
152
+ distribution <- match.arg(distribution , c(listDistributions(simplify = TRUE ),
153
+ listKernels(simplify = TRUE )))
153
154
154
155
if (grepl(" Empirical" , distribution )) {
155
156
stop(" Empirical and EmpiricalMV not currently available for `distribution/params`
@@ -183,36 +184,44 @@ or `distlist` should be used.")
183
184
}
184
185
185
186
# create wrapper parameters by cloning distribution parameters and setting by given params
187
+ # skip if no parameters
186
188
pdist <- get(distribution )
187
- p <- do.call(paste0(" getParameterSet." , distribution ), c(params [[1 ]], shared_params ))
188
-
189
- paramlst <- vector(" list" , length(params ))
190
- for (i in seq_along(params )) {
191
- paramlst [[i ]] <- p $ clone(deep = TRUE )
192
- }
193
-
194
- names(paramlst ) <- makeUniqueNames(rep(pdist $ public_fields $ short_name , length(params )))
195
- names(params ) <- names(paramlst )
196
- params <- unlist(params , recursive = FALSE )
197
- names(params ) <- gsub(" ." , " _" , names(params ), fixed = TRUE )
198
- if (! is.null(shared_params )) {
199
- if (distribution == " Geometric" ) {
200
- shared_params <- shared_params [! (names(shared_params ) %in% " trials" )]
189
+ p <- try(do.call(paste0(" getParameterSet." , distribution ), c(params [[1 ]], shared_params )),
190
+ silent = TRUE )
191
+ if (class(p )[[1 ]] != " try-error" ) {
192
+ paramlst <- vector(" list" , length(params ))
193
+ for (i in seq_along(params )) {
194
+ paramlst [[i ]] <- p $ clone(deep = TRUE )
201
195
}
202
- if (distribution == " NegativeBinomial" ) {
203
- shared_params <- shared_params [! (names(shared_params ) %in% " form" )]
196
+
197
+ names(paramlst ) <- makeUniqueNames(rep(pdist $ public_fields $ short_name , length(params )))
198
+ names(params ) <- names(paramlst )
199
+ params <- unlist(params , recursive = FALSE )
200
+ names(params ) <- gsub(" ." , " _" , names(params ), fixed = TRUE )
201
+ if (! is.null(shared_params )) {
202
+ if (distribution == " Geometric" ) {
203
+ shared_params <- shared_params [! (names(shared_params ) %in% " trials" )]
204
+ }
205
+ if (distribution == " NegativeBinomial" ) {
206
+ shared_params <- shared_params [! (names(shared_params ) %in% " form" )]
207
+ }
208
+ shared_params <- rep(list (shared_params ), length(params ))
209
+ names(shared_params ) <- names(paramlst )
210
+ shared_params <- unlist(shared_params , recursive = FALSE )
211
+ names(shared_params ) <- gsub(" ." , " _" , names(shared_params ), fixed = TRUE )
212
+ params <- c(params , shared_params )
204
213
}
205
- shared_params <- rep(list (shared_params ), length(params ))
206
- names(shared_params ) <- names(paramlst )
207
- shared_params <- unlist(shared_params , recursive = FALSE )
208
- names(shared_params ) <- gsub(" ." , " _" , names(shared_params ), fixed = TRUE )
209
- params <- c(params , shared_params )
214
+
215
+ support <- subset(as.data.table(p ), select = c(id , support ))
216
+ support [, support : = sapply(support , set6 :: setpower , power = length(paramlst ))]
217
+ parameters <- ParameterSetCollection $ new(lst = paramlst , .checks = p $ checks ,
218
+ .supports = support )$ setParameterValue(lst = params )
219
+ } else {
220
+ paramlst <- vector(" list" , length(params ))
221
+ names(paramlst ) <- makeUniqueNames(rep(pdist $ public_fields $ short_name , length(params )))
222
+ parameters <- ParameterSetCollection $ new()
210
223
}
211
224
212
- support <- subset(as.data.table(p ), select = c(id , support ))
213
- support [, support : = sapply(support , set6 :: setpower , power = length(paramlst ))]
214
- parameters <- ParameterSetCollection $ new(lst = paramlst , .checks = p $ checks ,
215
- .supports = support )$ setParameterValue(lst = params )
216
225
shortname <- get(distribution )$ public_fields $ short_name
217
226
218
227
# modelTable is for reference and later
@@ -223,8 +232,16 @@ or `distlist` should be used.")
223
232
224
233
# set univariate flag for calling d/p/q/r
225
234
private $ .univariate <- pdist $ private_fields $ .traits $ variateForm == " univariate"
235
+ # inheritance catch
236
+ if (! length(private $ .univariate )) {
237
+ private $ .univariate <- pdist $ get_inherit()$ private_fields $ .trait $ variateForm == " univariate"
238
+ }
226
239
# set valueSupport
227
240
valueSupport <- pdist $ private_fields $ .traits $ valueSupport
241
+ # inheritance catch
242
+ if (! length(valueSupport )) {
243
+ valueSupport <- pdist $ get_inherit()$ private_fields $ .trait $ valueSupport
244
+ }
228
245
229
246
# set d/p/q/r if non-NULL
230
247
pdist_pri <- pdist [[" private_methods" ]]
@@ -369,16 +386,22 @@ or `distlist` should be used.")
369
386
stopifnot(distlist [[i ]]$ traits $ variateForm == vf )
370
387
shortname <- c(shortname , distlist [[i ]]$ short_name )
371
388
distribution <- c(distribution , distlist [[i ]]$ name )
372
- paramlst [[i ]] <- distlist [[i ]]$ parameters()
389
+ if (! is.null(distlist [[i ]]$ parameters()))
390
+ paramlst [[i ]] <- distlist [[i ]]$ parameters()
373
391
vs <- c(vs , distlist [[i ]]$ traits $ valueSupport )
374
392
}
375
393
valueSupport <- if (length(unique(vs )) == 1 ) vs [[1 ]] else " mixture"
376
394
shortname <- makeUniqueNames(shortname )
377
- names(paramlst ) <- shortname
378
- names(distlist ) <- shortname
379
395
380
- # create parameterset
381
- parameters <- ParameterSetCollection $ new(lst = paramlst )
396
+ if (is.null(unlist(paramlst ))) {
397
+ parameters <- ParameterSetCollection $ new()
398
+ paramlst <- NULL
399
+ } else {
400
+ names(paramlst ) <- shortname
401
+ parameters <- ParameterSetCollection $ new(lst = paramlst )
402
+ }
403
+
404
+ names(distlist ) <- shortname
382
405
383
406
private $ .univariate <- vf == " univariate"
384
407
@@ -451,7 +474,8 @@ or `distlist` should be used.")
451
474
452
475
# create name, short_name, description, type, support
453
476
dst <- unique(self $ modelTable $ Distribution )
454
- if (length(dst ) == 1 & dst [[1 ]] %in% listDistributions(simplify = TRUE )) {
477
+ if (length(dst ) == 1 & dst [[1 ]] %in% c(listDistributions(simplify = TRUE ),
478
+ listKernels(simplify = TRUE ))) {
455
479
distribution <- get(as.character(unlist(self $ modelTable [1 , 1 ])))
456
480
if (is.null(name )) {
457
481
name <- paste0(
@@ -498,6 +522,7 @@ or `distlist` should be used.")
498
522
parameters = parameters ,
499
523
...
500
524
)
525
+
501
526
}
502
527
},
503
528
@@ -566,8 +591,18 @@ or `distlist` should be used.")
566
591
})
567
592
} else {
568
593
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ mean
594
+ if (is.null(f )) {
595
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
596
+ public_methods $ mean
597
+ }
598
+ if (is.null(f )) {
599
+ stop(" Not implemented for this distribution." )
600
+ }
569
601
formals(f ) <- c(list (self = self ), alist(... = ))
570
602
ret <- f()
603
+ if (length(ret ) == 1 ) {
604
+ ret <- rep(ret , nrow(self $ modelTable ))
605
+ }
571
606
}
572
607
573
608
if (is.null(dim(ret ))) {
@@ -589,8 +624,18 @@ or `distlist` should be used.")
589
624
})
590
625
} else {
591
626
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ mode
627
+ if (is.null(f )) {
628
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
629
+ public_methods $ mode
630
+ }
631
+ if (is.null(f )) {
632
+ stop(" Not implemented for this distribution." )
633
+ }
592
634
formals(f ) <- list (self = self , which = which )
593
635
ret <- f()
636
+ if (length(ret ) == 1 ) {
637
+ ret <- rep(ret , nrow(self $ modelTable ))
638
+ }
594
639
}
595
640
596
641
if (is.null(dim(ret ))) {
@@ -624,8 +669,18 @@ or `distlist` should be used.")
624
669
})
625
670
} else {
626
671
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ variance
672
+ if (is.null(f )) {
673
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
674
+ public_methods $ variance
675
+ }
676
+ if (is.null(f )) {
677
+ stop(" Not implemented for this distribution." )
678
+ }
627
679
formals(f ) <- c(list (self = self ), alist(... = ))
628
680
ret <- f()
681
+ if (length(ret ) == 1 ) {
682
+ ret <- rep(ret , nrow(self $ modelTable ))
683
+ }
629
684
}
630
685
631
686
if (is.null(dim(ret ))) {
@@ -648,8 +703,18 @@ or `distlist` should be used.")
648
703
})
649
704
} else {
650
705
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ skewness
706
+ if (is.null(f )) {
707
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
708
+ public_methods $ skewness
709
+ }
710
+ if (is.null(f )) {
711
+ stop(" Not implemented for this distribution." )
712
+ }
651
713
formals(f ) <- c(list (self = self ), alist(... = ))
652
714
ret <- f()
715
+ if (length(ret ) == 1 ) {
716
+ ret <- rep(ret , nrow(self $ modelTable ))
717
+ }
653
718
}
654
719
655
720
names(ret ) <- as.character(unlist(private $ .modelTable [, " shortname" ]))
@@ -668,8 +733,18 @@ or `distlist` should be used.")
668
733
})
669
734
} else {
670
735
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ kurtosis
736
+ if (is.null(f )) {
737
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
738
+ public_methods $ kurtosis
739
+ }
740
+ if (is.null(f )) {
741
+ stop(" Not implemented for this distribution." )
742
+ }
671
743
formals(f ) <- c(list (self = self , excess = excess ), alist(... = ))
672
744
ret <- f()
745
+ if (length(ret ) == 1 ) {
746
+ ret <- rep(ret , nrow(self $ modelTable ))
747
+ }
673
748
}
674
749
675
750
names(ret ) <- as.character(unlist(private $ .modelTable [, " shortname" ]))
@@ -687,8 +762,15 @@ or `distlist` should be used.")
687
762
})
688
763
} else {
689
764
f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ public_methods $ entropy
765
+ if (is.null(f )) {
766
+ f <- get(as.character(unlist(self $ modelTable $ Distribution [[1 ]])))$ get_inherit()$
767
+ public_methods $ entropy
768
+ }
690
769
formals(f ) <- c(list (self = self , base = base ), alist(... = ))
691
770
ret <- f()
771
+ if (length(ret ) == 1 ) {
772
+ ret <- rep(ret , nrow(self $ modelTable ))
773
+ }
692
774
}
693
775
694
776
names(ret ) <- as.character(unlist(private $ .modelTable [, " shortname" ]))
0 commit comments