R Under development (unstable) (2024-09-01 r87083 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(RandVar) Loading required package: distr Loading required package: startupmsg :startupmsg> Utilities for Start-Up Messages (version 0.9.7) :startupmsg> :startupmsg> For more information see ?"startupmsg", :startupmsg> NEWS("startupmsg") Loading required package: sfsmisc :distr> Object Oriented Implementation of Distributions (version :distr> 2.9.5) :distr> :distr> Attention: Arithmetics on distribution objects are :distr> understood as operations on corresponding random variables :distr> (r.v.s); see distrARITH(). :distr> :distr> Some functions from package 'stats' are intentionally masked :distr> ---see distrMASK(). :distr> :distr> Note that global options are controlled by distroptions() :distr> ---c.f. ?"distroptions". :distr> :distr> For more information see ?"distr", NEWS("distr"), as well as :distr> http://distr.r-forge.r-project.org/ :distr> Package "distrDoc" provides a vignette to this package as :distr> well as to several extension packages; try :distr> vignette("distr"). Attaching package: 'distr' The following objects are masked from 'package:stats': df, qqplot, sd Loading required package: distrEx :distrEx> Extensions of Package 'distr' (version 2.9.5) :distrEx> :distrEx> Note: Packages "e1071", "moments", "fBasics" should be :distrEx> attached /before/ package "distrEx". See :distrEx> distrExMASK().Note: Extreme value distribution :distrEx> functionality has been moved to :distrEx> :distrEx> package "RobExtremes". See distrExMOVED(). :distrEx> :distrEx> For more information see ?"distrEx", NEWS("distrEx"), as :distrEx> well as :distrEx> http://distr.r-forge.r-project.org/ :distrEx> Package "distrDoc" provides a vignette to this package :distrEx> as well as to several related packages; try :distrEx> vignette("distr"). Attaching package: 'distrEx' The following objects are masked from 'package:stats': IQR, mad, median, var :RandVar> Implementation of Random Variables (version 1.2.4) :RandVar> :RandVar> For more information see ?"RandVar", NEWS("RandVar"), as :RandVar> well as :RandVar> https://r-forge.r-project.org/projects/robast/ :RandVar> This package also includes a vignette; try :RandVar> vignette("RandVar"). > set.seed(123) > > ############################################################################### > ## start of tests > ############################################################################### > > ## RandVariable > (R1 <- new("RandVariable")) An object of class "RandVariable" length of Map: 1 Domain: NULL Range: NULL > (R1 <- RandVariable()) An object of class "RandVariable" length of Map: 1 Domain: NULL Range: NULL > ## IGNORE_RDIFF_BEGIN > Map(R1) [[1]] function (x) { } > ## IGNORE_RDIFF_END > Domain(R1) NULL > Range(R1) NULL > Map(R1) <- list(function(x){ceiling(x)}, function(x){floor(x)}) > Domain(R1) <- Reals() > Range(R1) <- Naturals() > R1 An object of class "RandVariable" length of Map: 2 Domain: Real Space with dimension 1 Range: Grid of Naturals with dimension 1 > Map(R1) [[1]] function (x) { ceiling(x) } [[2]] function (x) { floor(x) } > length(R1) [1] 2 > > R2 <- R1 > Domain(R2) <- Naturals() > compatibleDomains(R1, R2) [1] TRUE > Domain(R2) <- NULL > compatibleDomains(R1, R2) [1] FALSE > Domain(R2) <- EuclideanSpace(dimension = 1) > compatibleDomains(R1, R2) [1] TRUE > Domain(R2) <- EuclideanSpace(dimension = 2) > compatibleDomains(R1, R2) [1] FALSE > > > ## list of functions > L1 <- list(function(x){x}, function(x){x^2}, function(x){x^3}, function(x){x^4}) > L2 <- list(function(x){x}, function(x){x^2}, function(x){x^3}, function(x){x^4}, + function(x){x^5}, function(x){x^6}) > L3 <- list(function(x){x}, function(x){x^2}, function(x){x^3}, function(x){x^4}, + function(x){x^5}, function(x){x^6}, function(x){x^7}, function(x){x^8}) > L4 <- list(function(x){exp(x)}, function(x){abs(x)}, + function(x){sin(x)}, function(x){floor(x)}) > > ## EuclRandVariable > (R3 <- new("EuclRandVariable", Map = L4, Domain = Reals(), Range = Reals())) An object of class "EuclRandVariable" length of Map: 4 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > (R3 <- EuclRandVariable(L1, Domain = Reals(), dimension = 1)) An object of class "EuclRandVariable" length of Map: 4 Domain: Real Space with dimension 1 Range: Euclidean Space with dimension 1 > Map(R3) [[1]] function (x) { x } [[2]] function (x) { x^2 } [[3]] function (x) { x^3 } [[4]] function (x) { x^4 } > Range(R3) <- Reals() > R3[2] An object of class "EuclRandVariable" length of Map: 1 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > Map(R3[3]) [[1]] function (x) { x^3 } > Map(R3[c(1,2,4)]) [[1]] function (x) { x } [[2]] function (x) { x^2 } [[3]] function (x) { x^4 } > Map(R3[2:4]) [[1]] function (x) { x^2 } [[2]] function (x) { x^3 } [[3]] function (x) { x^4 } > evalRandVar(R3, rnorm(1)) [,1] [1,] -0.56047565 [2,] 0.31413295 [3,] -0.17606387 [4,] 0.09867951 > x <- as.matrix(rnorm(10)) > res.R3 <- evalRandVar(R3, x) > res.R3[2,,] # results for Map(R3)[[2]](x) [1] 0.052981677 2.429571609 0.004971433 0.016715318 2.941447909 0.212443749 [7] 1.600379927 0.471766840 0.198614592 1.498376247 > res.R3[2,1,] # results for Map(R3)[[2]](x[1,]) [1] 0.05298168 > # assuming a probability space with > # distribution Exp() > res.R31 <- evalRandVar(R3, x, Gammad()) > res.R31[2,,] # results for Map(R3)[[2]](x) [1] NA 2.429571609 0.004971433 0.016715318 2.941447909 0.212443749 [7] NA NA NA 1.498376247 > res.R31[2,1,] # results for Map(R3)[[2]](x[1,]) [1] NA > dimension(R3) [1] 4 > > R4 <- EuclRandVariable(L4, Domain = Reals(), dimension = 1) > DL1 <- imageDistr(R4, Norm()) > plot(DL1) > > Domain(R4) <- EuclideanSpace(dimension = 2) > Range(R4) <- EuclideanSpace(dimension = 2) > (X <- matrix(c(x, rnorm(10)), ncol = 2)) [,1] [,2] [1,] -0.23017749 0.3598138 [2,] 1.55870831 0.4007715 [3,] 0.07050839 0.1106827 [4,] 0.12928774 -0.5558411 [5,] 1.71506499 1.7869131 [6,] 0.46091621 0.4978505 [7,] -1.26506123 -1.9666172 [8,] -0.68685285 0.7013559 [9,] -0.44566197 -0.4727914 [10,] 1.22408180 -1.0678237 > res2.R4 <- evalRandVar(R4, X) > res2.R4[3,,1] # results for Map(R4)[[3]](X[,1]) [1] -0.22815034 0.99992694 0.07044998 0.12892786 0.98961131 0.44476889 [7] -0.95362595 -0.63410681 -0.43105529 0.94049422 > dimension(R4) [1] 8 > > > ## EuclRandMatrix > (R5 <- as(R4, "EuclRandMatrix")) An object of class "EuclRandMatrix" Dim of Map: 4 1 Domain: Euclidean Space with dimension 2 Range: Euclidean Space with dimension 2 > dimension(R5) [1] 8 > Domain(R5) <- Reals() > Range(R5) <- Reals() > (DL2 <- imageDistr(R5, Norm())) # list of distributions An object of class "DistrList" [[1]] Distribution Object of Class: AbscontDistribution [[2]] Distribution Object of Class: AbscontDistribution [[3]] Distribution Object of Class: AbscontDistribution [[4]] Distribution Object of Class: AbscontDistribution Warning messages: 1: In (new("standardGeneric", .Data = function (object) : arithmetics on distributions are understood as operations on r.v.'s see 'distrARITH()'; for switching off this warning see '?distroptions' 2: In (new("standardGeneric", .Data = function (object) : slots d,p,q have been filled using simulations; for switching off this warning see '?distroptions' > plot(DL2) # vgl. DL1 > > Domain(R5) <- EuclideanSpace(dimension = 2) > Range(R5) <- EuclideanSpace(dimension = 2) > #res1.R5 <- evalRandVar(R5, rnorm(2)) > #res1.R5[1,1,] # result for map of R5[1,1] > > res2.R5 <- evalRandVar(R5, X) > res2.R5[,,1,2] [1] 1.4330626 0.3598138 0.3521000 0.0000000 > res2.R5[,1,2,1:2] [,1] [,2] [1,] 4.7526783 1.4929760 [2,] 1.5587083 0.4007715 [3,] 0.9999269 0.3901288 [4,] 1.0000000 0.0000000 > res2.R5[1,1,1:2,2] [1] 1.433063 1.492976 > > new("EuclRandMatrix", Map = L2, Dim = as.integer(c(3,2)), Domain = Reals(), Range = Reals()) An object of class "EuclRandMatrix" Dim of Map: 3 2 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > (R6 <- EuclRandMatrix(Map = L2, ncol = 2, Domain = Reals(), Range = Reals())) An object of class "EuclRandMatrix" Dim of Map: 3 2 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > R6[1:2, 2] An object of class "EuclRandVariable" length of Map: 2 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > R6[1:2, 1:2] An object of class "EuclRandMatrix" Dim of Map: 2 2 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > Map(R6[1,2]) [[1]] function (x) { x^4 } > Map(t(R6)[2,1]) [[1]] function (x) { f <- function (x) { x^4 } t(f(x)) } > dimension(R6) [1] 6 > > R7 <- EuclRandMatrix(Map = L4, ncol = 2, Domain = Reals(), dimension = 1) > dimension(R7) [1] 4 > (DL3 <- imageDistr(R7, Norm())) An object of class "DistrList" [[1]] Distribution Object of Class: AbscontDistribution [[2]] Distribution Object of Class: AbscontDistribution [[3]] Distribution Object of Class: AbscontDistribution [[4]] Distribution Object of Class: AbscontDistribution Warning messages: 1: In (new("standardGeneric", .Data = function (object) : arithmetics on distributions are understood as operations on r.v.'s see 'distrARITH()'; for switching off this warning see '?distroptions' 2: In (new("standardGeneric", .Data = function (object) : slots d,p,q have been filled using simulations; for switching off this warning see '?distroptions' > plot(DL3) # vgl. DL1, DL2 > > > ## EuclRandVarList > new("EuclRandVarList") An object of class "EuclRandVarList" Domain: NULL [[1]] length of Map: 1 Range: Euclidean Space with dimension 1 > (RL1 <- EuclRandVarList(R3, R6, R7)) An object of class "EuclRandVarList" Domain: Real Space with dimension 1 [[1]] length of Map: 4 Range: Real Space with dimension 1 [[2]] Dim of Map: 3 2 Range: Real Space with dimension 1 [[3]] Dim of Map: 2 2 Range: Euclidean Space with dimension 1 > dimension(RL1) [1] 14 > as(R4, "EuclRandVarList") An object of class "EuclRandVarList" Domain: Euclidean Space with dimension 2 [[1]] length of Map: 4 Range: Euclidean Space with dimension 2 > as(R6, "EuclRandVarList") An object of class "EuclRandVarList" Domain: Real Space with dimension 1 [[1]] Dim of Map: 3 2 Range: Real Space with dimension 1 > Domain(R5) <- Reals() > Range(R5) <- Reals() > (RL2 <- EuclRandVarList(R5, R7)) An object of class "EuclRandVarList" Domain: Real Space with dimension 1 [[1]] Dim of Map: 4 1 Range: Real Space with dimension 1 [[2]] Dim of Map: 2 2 Range: Euclidean Space with dimension 1 > (DL4 <- imageDistr(RL2, Norm())) An object of class "DistrList" [[1]] Distribution Object of Class: AbscontDistribution [[2]] Distribution Object of Class: AbscontDistribution [[3]] Distribution Object of Class: AbscontDistribution [[4]] Distribution Object of Class: AbscontDistribution [[5]] Distribution Object of Class: AbscontDistribution [[6]] Distribution Object of Class: AbscontDistribution [[7]] Distribution Object of Class: AbscontDistribution [[8]] Distribution Object of Class: AbscontDistribution Warning messages: 1: In (new("standardGeneric", .Data = function (object) : arithmetics on distributions are understood as operations on r.v.'s see 'distrARITH()'; for switching off this warning see '?distroptions' 2: In (new("standardGeneric", .Data = function (object) : slots d,p,q have been filled using simulations; for switching off this warning see '?distroptions' > plot(DL4) > > > ## "Math" group > Map(log(abs(R4))) [[1]] function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } abs(f1(x)) } log(f1(x)) } [[2]] function (x) { f1 <- function (x) { f1 <- function (x) { abs(x) } abs(f1(x)) } log(f1(x)) } [[3]] function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } abs(f1(x)) } log(f1(x)) } [[4]] function (x) { f1 <- function (x) { f1 <- function (x) { floor(x) } abs(f1(x)) } log(f1(x)) } > Map(gamma(R7)) [[1]] function (x) { f1 <- function (x) { exp(x) } gamma(f1(x)) } [[2]] function (x) { f1 <- function (x) { abs(x) } gamma(f1(x)) } [[3]] function (x) { f1 <- function (x) { sin(x) } gamma(f1(x)) } [[4]] function (x) { f1 <- function (x) { floor(x) } gamma(f1(x)) } > Map(exp(RL1)[[1]]) [[1]] function (x) { f1 <- function (x) { x } exp(f1(x)) } [[2]] function (x) { f1 <- function (x) { x^2 } exp(f1(x)) } [[3]] function (x) { f1 <- function (x) { x^3 } exp(f1(x)) } [[4]] function (x) { f1 <- function (x) { x^4 } exp(f1(x)) } > > > ## "Arith" group > Map(3 + R3) [[1]] function (x) { f2 <- function (x) { x } 3 + f2(x) } [[2]] function (x) { f2 <- function (x) { x^2 } 3 + f2(x) } [[3]] function (x) { f2 <- function (x) { x^3 } 3 + f2(x) } [[4]] function (x) { f2 <- function (x) { x^4 } 3 + f2(x) } > Map(c(1,3,5) * R3) [[1]] function (x) { f2 <- function (x) { x } 1 * f2(x) } [[2]] function (x) { f2 <- function (x) { x^2 } 3 * f2(x) } [[3]] function (x) { f2 <- function (x) { x^3 } 5 * f2(x) } [[4]] function (x) { f2 <- function (x) { x^4 } 1 * f2(x) } Warning message: In c(1, 3, 5) * R3 : longer object length is not a multiple of shorter object length > try(1:5 * R3) # error Error in 1:5 * R3 : length of 'numeric' has to be less or equal dimension of 'EuclRandVariable' > Map(1:2 * R4) [[1]] function (x) { f2 <- function (x) { exp(x) } 1:2 * f2(x) } [[2]] function (x) { f2 <- function (x) { abs(x) } 1:2 * f2(x) } [[3]] function (x) { f2 <- function (x) { sin(x) } 1:2 * f2(x) } [[4]] function (x) { f2 <- function (x) { floor(x) } 1:2 * f2(x) } > Map(2/R6) [[1]] function (x) { f2 <- function (x) { x } 2/f2(x) } [[2]] function (x) { f2 <- function (x) { x^2 } 2/f2(x) } [[3]] function (x) { f2 <- function (x) { x^3 } 2/f2(x) } [[4]] function (x) { f2 <- function (x) { x^4 } 2/f2(x) } [[5]] function (x) { f2 <- function (x) { x^5 } 2/f2(x) } [[6]] function (x) { f2 <- function (x) { x^6 } 2/f2(x) } > Map(c(1,3,5) %% R6) [[1]] function (x) { f2 <- function (x) { x } 1%%f2(x) } [[2]] function (x) { f2 <- function (x) { x^2 } 3%%f2(x) } [[3]] function (x) { f2 <- function (x) { x^3 } 5%%f2(x) } [[4]] function (x) { f2 <- function (x) { x^4 } 1%%f2(x) } [[5]] function (x) { f2 <- function (x) { x^5 } 3%%f2(x) } [[6]] function (x) { f2 <- function (x) { x^6 } 5%%f2(x) } > Map(R4 - 5) [[1]] function (x) { f1 <- function (x) { exp(x) } f1(x) - c(5, 5) } [[2]] function (x) { f1 <- function (x) { abs(x) } f1(x) - c(5, 5) } [[3]] function (x) { f1 <- function (x) { sin(x) } f1(x) - c(5, 5) } [[4]] function (x) { f1 <- function (x) { floor(x) } f1(x) - c(5, 5) } > Map(R6 %/% 2) [[1]] function (x) { f1 <- function (x) { x } f1(x)%/%2 } [[2]] function (x) { f1 <- function (x) { x^2 } f1(x)%/%2 } [[3]] function (x) { f1 <- function (x) { x^3 } f1(x)%/%2 } [[4]] function (x) { f1 <- function (x) { x^4 } f1(x)%/%2 } [[5]] function (x) { f1 <- function (x) { x^5 } f1(x)%/%2 } [[6]] function (x) { f1 <- function (x) { x^6 } f1(x)%/%2 } > Map(R3 ^ R3) [[1]] function (x) { f1 <- function (x) { x } f2 <- function (x) { x } f1(x)^f2(x) } [[2]] function (x) { f1 <- function (x) { x^2 } f2 <- function (x) { x^2 } f1(x)^f2(x) } [[3]] function (x) { f1 <- function (x) { x^3 } f2 <- function (x) { x^3 } f1(x)^f2(x) } [[4]] function (x) { f1 <- function (x) { x^4 } f2 <- function (x) { x^4 } f1(x)^f2(x) } > Map(R7 * R7) [[1]] function (x) { f1 <- function (x) { exp(x) } f2 <- function (x) { exp(x) } f1(x) * f2(x) } [[2]] function (x) { f1 <- function (x) { abs(x) } f2 <- function (x) { abs(x) } f1(x) * f2(x) } [[3]] function (x) { f1 <- function (x) { sin(x) } f2 <- function (x) { sin(x) } f1(x) * f2(x) } [[4]] function (x) { f1 <- function (x) { floor(x) } f2 <- function (x) { floor(x) } f1(x) * f2(x) } > Map((1 + RL1)[[1]]) [[1]] function (x) { f2 <- function (x) { x } 1 + f2(x) } [[2]] function (x) { f2 <- function (x) { x^2 } 1 + f2(x) } [[3]] function (x) { f2 <- function (x) { x^3 } 1 + f2(x) } [[4]] function (x) { f2 <- function (x) { x^4 } 1 + f2(x) } > Map((RL1 * 2)[[2]]) [[1]] function (x) { f1 <- function (x) { x } f1(x) * 2 } [[2]] function (x) { f1 <- function (x) { x^2 } f1(x) * 2 } [[3]] function (x) { f1 <- function (x) { x^3 } f1(x) * 2 } [[4]] function (x) { f1 <- function (x) { x^4 } f1(x) * 2 } [[5]] function (x) { f1 <- function (x) { x^5 } f1(x) * 2 } [[6]] function (x) { f1 <- function (x) { x^6 } f1(x) * 2 } > Map((RL1 %% RL1)[[3]]) [[1]] function (x) { f1 <- function (x) { exp(x) } f2 <- function (x) { exp(x) } f1(x)%%f2(x) } [[2]] function (x) { f1 <- function (x) { abs(x) } f2 <- function (x) { abs(x) } f1(x)%%f2(x) } [[3]] function (x) { f1 <- function (x) { sin(x) } f2 <- function (x) { sin(x) } f1(x)%%f2(x) } [[4]] function (x) { f1 <- function (x) { floor(x) } f2 <- function (x) { floor(x) } f1(x)%%f2(x) } > > > ## "%*%" > M1 <- matrix(1:16, ncol = 8) > (R8 <- M1 %*% R4) An object of class "EuclRandMatrix" Dim of Map: 2 1 Domain: Euclidean Space with dimension 2 Range: Real Space with dimension 1 > Map(R4) [[1]] function (x) { exp(x) } [[2]] function (x) { abs(x) } [[3]] function (x) { sin(x) } [[4]] function (x) { floor(x) } > M1[1,] [1] 1 3 5 7 9 11 13 15 > Map(R8)[[1]] function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } c(1L, 3L) %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + c(5L, 7L) %*% f2(x) } f2 <- function (x) { sin(x) } f1(x) + c(9L, 11L) %*% f2(x) } f2 <- function (x) { floor(x) } f1(x) + c(13L, 15L) %*% f2(x) } > M1[2,] [1] 2 4 6 8 10 12 14 16 > Map(R8)[[2]] function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } c(2L, 4L) %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + c(6L, 8L) %*% f2(x) } f2 <- function (x) { sin(x) } f1(x) + c(10L, 12L) %*% f2(x) } f2 <- function (x) { floor(x) } f1(x) + c(14L, 16L) %*% f2(x) } > M2 <- matrix(1:2, ncol = 2) > (R9 <- M2 %*% R7) An object of class "EuclRandMatrix" Dim of Map: 1 2 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > Map(R7) [[1]] function (x) { exp(x) } [[2]] function (x) { abs(x) } [[3]] function (x) { sin(x) } [[4]] function (x) { floor(x) } > Map(R9) [[1]] function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } 1L %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + 2L %*% f2(x) } [[2]] function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } 1L %*% f1(x) } f2 <- function (x) { floor(x) } f1(x) + 2L %*% f2(x) } > Map(1:4 %*% R3) # inner product [[1]] function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { x } 1L %*% f1(x) } f2 <- function (x) { x^2 } f1(x) + 2L %*% f2(x) } f2 <- function (x) { x^3 } f1(x) + 3L %*% f2(x) } f2 <- function (x) { x^4 } f1(x) + 4L %*% f2(x) } > Map(1:2 %*% R7) # corresponds to Map(t(1:2) %*% R7) [[1]] function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } 1L %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + 2L %*% f2(x) } [[2]] function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } 1L %*% f1(x) } f2 <- function (x) { floor(x) } f1(x) + 2L %*% f2(x) } > Map(R4 %*% 1:8) # inner product [[1]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f <- function (x) { f <- function (x) { exp(x) } t(f(x)) } t(f(x)) } 1:2 %*% f1(x) } f2 <- function (x) { f <- function (x) { f <- function (x) { abs(x) } t(f(x)) } t(f(x)) } f1(x) + 3:4 %*% f2(x) } f2 <- function (x) { f <- function (x) { f <- function (x) { sin(x) } t(f(x)) } t(f(x)) } f1(x) + 5:6 %*% f2(x) } f2 <- function (x) { f <- function (x) { f <- function (x) { floor(x) } t(f(x)) } t(f(x)) } f1(x) + 7:8 %*% f2(x) } t(f(x)) } > Map(R9 %*% 3:4) [[1]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } 1L %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } 3L %*% f1(x) } f2 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } 1L %*% f1(x) } f2 <- function (x) { floor(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } f1(x) + 4L %*% f2(x) } t(f(x)) } > Map(R9 %*% matrix(1:4, nrow = 2)) [[1]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } 1L %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } 1L %*% f1(x) } f2 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } 1L %*% f1(x) } f2 <- function (x) { floor(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } f1(x) + 2L %*% f2(x) } t(f(x)) } [[2]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { exp(x) } 1L %*% f1(x) } f2 <- function (x) { abs(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } 3L %*% f1(x) } f2 <- function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { sin(x) } 1L %*% f1(x) } f2 <- function (x) { floor(x) } f1(x) + 2L %*% f2(x) } t(f(x)) } f1(x) + 4L %*% f2(x) } t(f(x)) } > (R10 <- R3 %*% matrix(1:16, ncol = 4)) An object of class "EuclRandMatrix" Dim of Map: 1 4 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > Map(R10) [[1]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { x } 1L %*% f1(x) } f2 <- function (x) { x^2 } f1(x) + 5L %*% f2(x) } f2 <- function (x) { x^3 } f1(x) + 9L %*% f2(x) } f2 <- function (x) { x^4 } f1(x) + 13L %*% f2(x) } t(f(x)) } [[2]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { x } 2L %*% f1(x) } f2 <- function (x) { x^2 } f1(x) + 6L %*% f2(x) } f2 <- function (x) { x^3 } f1(x) + 10L %*% f2(x) } f2 <- function (x) { x^4 } f1(x) + 14L %*% f2(x) } t(f(x)) } [[3]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { x } 3L %*% f1(x) } f2 <- function (x) { x^2 } f1(x) + 7L %*% f2(x) } f2 <- function (x) { x^3 } f1(x) + 11L %*% f2(x) } f2 <- function (x) { x^4 } f1(x) + 15L %*% f2(x) } t(f(x)) } [[4]] function (x) { f <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { f1 <- function (x) { x } 4L %*% f1(x) } f2 <- function (x) { x^2 } f1(x) + 8L %*% f2(x) } f2 <- function (x) { x^3 } f1(x) + 12L %*% f2(x) } f2 <- function (x) { x^4 } f1(x) + 16L %*% f2(x) } t(f(x)) } > R3 %*% R3 # inner product An object of class "EuclRandMatrix" Dim of Map: 1 1 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > R3 %*% R10 An object of class "EuclRandMatrix" Dim of Map: 4 4 Domain: Real Space with dimension 1 Range: Euclidean Space with dimension 1 > R9 %*% R7 An object of class "EuclRandMatrix" Dim of Map: 1 2 Domain: Real Space with dimension 1 Range: Euclidean Space with dimension 1 > (RL3 <- diag(dimension(RL1)) %*% RL1) An object of class "EuclRandMatrix" Dim of Map: 14 1 Domain: Real Space with dimension 1 Range: Real Space with dimension 1 > > > ## %m% "matrix multiplication" for 'EuclRandVarList' > RL4 <- EuclRandVarList(t(R3[1:2]), R7) %m% EuclRandVarList(R6, R9) > > ## integration > MVD <- DiscreteMVDistribution(supp = matrix(c(r(Pois(5))(10), r(Pois(5))(10)), ncol = 2)) Warning message: In DiscreteMVDistribution(supp = matrix(c(r(Pois(5))(10), r(Pois(5))(10)), : collapsing to unique support values > support(MVD) [,1] [,2] [1,] 4 7 [2,] 4 2 [3,] 3 5 [4,] 3 3 [5,] 5 6 [6,] 4 8 [7,] 7 4 [8,] 2 6 [9,] 5 2 > E(MVD) [1] 4.0 4.6 > E(as(MVD, "MultivariateDistribution")) [1] 3.99729 4.59816 > E(MVD, function(x){x}) [1] 4.0 4.6 > E(MVD, function(x){x}, useApply = FALSE) [1] 4.0 4.6 > E(as(MVD, "MultivariateDistribution"), function(x){x}) [1] 3.99545 4.59789 > E(as(MVD, "MultivariateDistribution"), function(x){x}, useApply = FALSE) [1] 3.99748 4.60623 > E(MVD, function(x){x^2}) [1] 17.8 25.2 > E(as(MVD, "MultivariateDistribution"), function(x){x^2}, useApply = FALSE) [1] 17.79446 25.17427 > E(MVD, function(x){x %*% t(x)}) [,1] [,2] [1,] 17.8 18.1 [2,] 18.1 25.2 > E(as(MVD, "MultivariateDistribution"), function(x){x %*% t(x)}) [,1] [,2] [1,] 17.82483 18.11391 [2,] 18.11391 25.21390 > > R1 <- RealRandVariable(list(function(x){x}, function(x){x^2}), Domain = Reals()) > R2 <- EuclRandMatrix(list(function(x){x}, function(x){x^2}), ncol = 1, Domain = Reals(), dimension = 1) > E(Norm(), R1) [1] 0.0000000 0.9999942 > E(Norm(), R1, useApply = FALSE) [1] 0.0000000 0.9999942 > E(Norm(), R2) [,1] [1,] 0.0000000 [2,] 0.9999942 > E(Norm(), R2, useApply = FALSE) [,1] [1,] 0.0000000 [2,] 0.9999942 > R3 <- EuclRandVarList(R1, R2) > E(Norm(), R3) [[1]] [1] 0.0000000 0.9999942 [[2]] [,1] [1,] 0.0000000 [2,] 0.9999942 > E(Norm(), R3, useApply = FALSE) [[1]] [1] 0.0000000 0.9999942 [[2]] [,1] [1,] 0.0000000 [2,] 0.9999942 > > R1 <- EuclRandVariable(list(function(x){x}, function(x){x^2}), Domain = EuclideanSpace(2), dimension = 2) > R2 <- EuclRandMatrix(list(function(x){x}, function(x){x^2}), ncol = 1, Domain = EuclideanSpace(2), dimension = 2) > E(MVD, R1) [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > E(MVD, R1, useApply = FALSE) [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > E(MVD, R2)[1:2,,] [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > E(MVD, R2, useApply = FALSE)[1:2,,] [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > R3 <- EuclRandVarList(R1, R2) > E1 <- E(MVD, R3) > E1[[1]] [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > E1[[2]][1:2,,] [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 > E(MVD, R3, useApply = FALSE) [[1]] [,1] [,2] [1,] 4.0 4.6 [2,] 17.8 25.2 [[2]] , , 1 [,1] [1,] 4.0 [2,] 17.8 , , 2 [,1] [1,] 4.6 [2,] 25.2 > > CD <- LMCondDistribution(theta = 1) > E(CD, cond = 2) [1] 2 > E(CD, cond = 2, useApply = FALSE) [1] 2 > E(CD, function(x){x}, cond = 2) [1] 2 > E(CD, function(x){x}, cond = 2, useApply = FALSE) [1] 2 > E(CD, function(x, cond){2*x}, cond = 2, withCond = FALSE) [1] 3.999999 > E(CD, function(x, cond){2*x}, cond = 2, withCond = TRUE, useApply = FALSE) [1] 3.999999 > E(CD, function(x){x^2}, cond = 2) [1] 4.999993 > E(CD, function(x){x^2}, cond = 2, useApply = FALSE) [1] 4.999993 > E(CD, function(x, cond){x^2*cond}, cond = 2, withCond = TRUE) [1] 9.999987 > E(CD, function(x, cond){x^2*cond}, cond = 2, withCond = TRUE, useApply = FALSE) [1] 9.999987 > Range(R1) <- Reals() > Domain(R1) <- Reals() > E(CD, R1, cond = 2) [1] 2.000000 4.999993 > E(CD, R1, cond = 2, useApply = FALSE) [1] 2.000000 4.999993 > R3 <- EuclRandVariable(list(function(x){x[2]*x[1]}, function(x){x[2]*x[1]^2}), + Domain = EuclideanSpace(2), dimension = 1) > E(CD, R3, cond = 2, withCond = TRUE) [1] 3.999999 9.999987 > Range(R2) <- Reals() > Domain(R2) <- Reals() > E(CD, R2, cond = 2) [,1] [1,] 2.000000 [2,] 4.999993 > E(CD, R2, cond = 2, useApply = FALSE) [,1] [1,] 2.000000 [2,] 4.999993 > R4 <- EuclRandMatrix(list(function(x){x[2]*x[1]}, function(x){x[2]*x[1]^2}), + ncol = 1, Domain = EuclideanSpace(2), dimension = 1) > E(CD, R4, cond = 2, withCond = TRUE) [,1] [1,] 3.999999 [2,] 9.999987 > R5 <- EuclRandVarList(R1, R2) > E(CD, R5, cond = 2) [[1]] [1] 2.000000 4.999993 [[2]] [,1] [1,] 2.000000 [2,] 4.999993 > E(CD, R5, cond = 2, useApply = FALSE) [[1]] [1] 2.000000 4.999993 [[2]] [,1] [1,] 2.000000 [2,] 4.999993 > R6 <- EuclRandVarList(R3, R4) > E(CD, R6, cond = 2, withCond = TRUE) [[1]] [1] 3.999999 9.999987 [[2]] [,1] [1,] 3.999999 [2,] 9.999987 > > > ############################################################################### > ## end of tests > ############################################################################### > > q("no") > proc.time() user system elapsed 7.07 0.57 7.67