# NOT RUN {
# not run to save time
# }
# NOT RUN {
vecDist <- VectorDistribution$new(list(Binomial$new(prob = 0.5,
size = 10), Normal$new(mean = 15)))
vecDist$pdf(x1 = 2, x2 =3)
# Equivalently
vecDist[1]$pdf(2); vecDist[2]$pdf(3)
# Or to evaluate every distribution at the same point
vecDist$pdf(1)
# Same wrapping for statistical functions
vecDist$mean()
c(vecDist[1]$mean(), vecDist[2]$mean())
vecDist$entropy()
c(vecDist[1]$entropy(), vecDist[2]$entropy())
vecDist$cdf(1:5, 12:16)
vecDist$rand(10)
vecBin = VectorDistribution$new(distribution = "Binomial",
params = list(list(prob = 0.1, size = 2),
list(prob = 0.6, size = 4),
list(prob = 0.2, size = 6)))
vecBin$pdf(x1=1,x2=2,x3=3)
vecBin$cdf(x1=1,x2=2,x3=3)
vecBin$rand(10)
#Equivalently
vecBin = VectorDistribution$new(distribution = "Binomial",
params = data.table::data.table(prob = c(0.1,0.6,0.2), size = c(2,4,6)))
vecBin$pdf(x1=1,x2=2,x3=3)
vecBin$cdf(x1=1,x2=2,x3=3)
vecBin$rand(10)
# sharedparams is very useful for vectorized custom distributions
shared_params = list(name = "A Distribution", short_name = "Dist", type = Reals$new())
params = list(list(pdf = function(x) return(1)), list(pdf = function(x) return(2)))
vecdist = VectorDistribution$new(distribution = "Distribution", params = params,
shared_params = shared_params)
vecdist$pdf(1)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab