R Under development (unstable) (2023-11-06 r85483 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 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(kappalab) Loading required package: lpSolve Loading required package: quadprog Loading required package: kernlab > > ## some alternatives > a <- c(18,11,18,11,11) > b <- c(18,18,11,11,11) > c <- c(11,11,18,18,11) > d <- c(18,11,11,11,18) > e <- c(11,11,18,11,18) > > ## preference threshold relative > ## to the preorder of the alternatives > delta.C <- 1 > > ## corresponding Choquet preorder constraint matrix > Acp <- rbind(c(d,a,delta.C), + c(a,e,delta.C), + c(e,b,delta.C), + c(b,c,delta.C) + ) > > ## a Shapley preorder constraint matrix > ## Sh(1) - Sh(2) >= -delta.S > ## Sh(2) - Sh(1) >= -delta.S > ## Sh(3) - Sh(4) >= -delta.S > ## Sh(4) - Sh(3) >= -delta.S > ## i.e. criteria 1,2 and criteria 3,4 > ## should have the same global importances > delta.S <- 0.01 > Asp <- rbind(c(1,2,-delta.S), + c(2,1,-delta.S), + c(3,4,-delta.S), + c(4,3,-delta.S) + ) > > ## a Shapley interval constraint matrix > ## 0.3 <= Sh(1) <= 0.9 > Asi <- rbind(c(1,0.3,0.9)) > > > ## an interaction preorder constraint matrix > ## such that I(12) = I(34) > delta.I <- 0.01 > Aip <- rbind(c(1,2,3,4,-delta.I), + c(3,4,1,2,-delta.I)) > > ## an interaction interval constraint matrix > ## i.e. -0.20 <= I(12) <= -0.15 > delta.I <- 0.01 > Aii <- rbind(c(1,2,-0.2,-0.15)) > > ## the capacity that we want to approach > x <- runif(31) > for (i in 2:31) + x[i] <- x[i] + x[i-1] > mu <- normalize(capacity(c(0,x))) > ## and its Mobius transform > a.mu <- Mobius(mu) > > ## some basic checks > mini.dist.capa.ident(a.mu,5) Distance used: Choquet.coefficients $solution Mobius.capacity {} 0.000000 {1} 0.055342 {2} 0.063938 {3} 0.079113 {4} 0.097020 {5} 0.145004 {1,2} 0.044110 {1,3} 0.063852 {1,4} 0.079085 {1,5} 0.072544 {2,3} 0.189393 {2,4} 0.183361 {2,5} 0.168287 {3,4} 0.201114 {3,5} 0.178744 {4,5} 0.184426 {1,2,3} -0.011451 {1,2,4} 0.009589 {1,2,5} 0.042316 {1,3,4} 0.071664 {1,3,5} 0.062276 {1,4,5} 0.076514 {2,3,4} -0.085626 {2,3,5} -0.075071 {2,4,5} -0.050022 {3,4,5} -0.090779 {1,2,3,4} -0.202157 {1,2,3,5} -0.191898 {1,2,4,5} -0.228444 {1,3,4,5} -0.330815 {2,3,4,5} -0.242649 {1,2,3,4,5} 0.441219 $value [1] -0.137454 $iterations [1] 1 0 $iact [1] 0 > mini.dist.capa.ident(a.mu,5,"binary.alternatives") Distance used: binary.alternatives $solution Mobius.capacity {} 0.000000 {1} 0.055342 {2} 0.063938 {3} 0.079113 {4} 0.097020 {5} 0.145004 {1,2} 0.044110 {1,3} 0.063852 {1,4} 0.079085 {1,5} 0.072544 {2,3} 0.189393 {2,4} 0.183361 {2,5} 0.168287 {3,4} 0.201114 {3,5} 0.178744 {4,5} 0.184426 {1,2,3} -0.011451 {1,2,4} 0.009589 {1,2,5} 0.042316 {1,3,4} 0.071664 {1,3,5} 0.062276 {1,4,5} 0.076514 {2,3,4} -0.085626 {2,3,5} -0.075071 {2,4,5} -0.050022 {3,4,5} -0.090779 {1,2,3,4} -0.202157 {1,2,3,5} -0.191898 {1,2,4,5} -0.228444 {1,3,4,5} -0.330815 {2,3,4,5} -0.242649 {1,2,3,4,5} 0.441219 $value [1] -5.417779 $iterations [1] 1 0 $iact [1] 0 > mini.dist.capa.ident(a.mu,5,"global.scores") Distance used: global.scores $solution Mobius.capacity {} 0.000000 {1} 0.055342 {2} 0.063938 {3} 0.079113 {4} 0.097020 {5} 0.145004 {1,2} 0.044110 {1,3} 0.063852 {1,4} 0.079085 {1,5} 0.072544 {2,3} 0.189393 {2,4} 0.183361 {2,5} 0.168287 {3,4} 0.201114 {3,5} 0.178744 {4,5} 0.184426 {1,2,3} -0.011451 {1,2,4} 0.009589 {1,2,5} 0.042316 {1,3,4} 0.071664 {1,3,5} 0.062276 {1,4,5} 0.076514 {2,3,4} -0.085626 {2,3,5} -0.075071 {2,4,5} -0.050022 {3,4,5} -0.090779 {1,2,3,4} -0.202157 {1,2,3,5} -0.191898 {1,2,4,5} -0.228444 {1,3,4,5} -0.330815 {2,3,4,5} -0.242649 {1,2,3,4,5} 0.441219 $value [1] -0.1349528 $iterations [1] 2 0 $iact [1] 1 > mini.dist.capa.ident(a.mu,3) Distance used: Choquet.coefficients $solution Mobius.capacity {} 0.000000 {1} 0.045495 {2} 0.058500 {3} 0.068556 {4} 0.084636 {5} 0.133132 {1,2} 0.067760 {1,3} 0.107976 {1,4} 0.130519 {1,5} 0.121925 {2,3} 0.215884 {2,4} 0.217161 {2,5} 0.200034 {3,4} 0.255388 {3,5} 0.230966 {4,5} 0.243957 {1,2,3} -0.082416 {1,2,4} -0.079649 {1,2,5} -0.041792 {1,3,4} -0.068760 {1,3,5} -0.073018 {1,4,5} -0.077052 {2,3,4} -0.181967 {2,3,5} -0.166281 {2,4,5} -0.159506 {3,4,5} -0.251448 $value [1] -0.1357366 $iterations [1] 1 0 $iact [1] 0 > mini.dist.capa.ident(a.mu,3,"binary.alternatives") Distance used: binary.alternatives $solution Mobius.capacity {} 0.000000 {1} 0.035998 {2} 0.055616 {3} 0.057994 {4} 0.071333 {5} 0.120599 {1,2} 0.076288 {1,3} 0.121623 {1,4} 0.145992 {1,5} 0.136886 {2,3} 0.225122 {2,4} 0.228227 {2,5} 0.210587 {3,4} 0.271572 {3,5} 0.246637 {4,5} 0.261456 {1,2,3} -0.090820 {1,2,4} -0.088053 {1,2,5} -0.050196 {1,3,4} -0.077164 {1,3,5} -0.081422 {1,4,5} -0.085456 {2,3,4} -0.190371 {2,3,5} -0.174686 {2,4,5} -0.167910 {3,4,5} -0.259852 $value [1] -5.41362 $iterations [1] 2 0 $iact [1] 1 > mini.dist.capa.ident(a.mu,3,"global.scores") Distance used: global.scores $solution Mobius.capacity {} 0.000000 {1} 0.042930 {2} 0.057824 {3} 0.065686 {4} 0.080983 {5} 0.129699 {1,2} 0.070243 {1,3} 0.111921 {1,4} 0.134986 {1,5} 0.126245 {2,3} 0.218570 {2,4} 0.220369 {2,5} 0.203096 {3,4} 0.260058 {3,5} 0.235490 {4,5} 0.249003 {1,2,3} -0.084937 {1,2,4} -0.082170 {1,2,5} -0.044313 {1,3,4} -0.071281 {1,3,5} -0.075539 {1,4,5} -0.079573 {2,3,4} -0.184488 {2,3,5} -0.168803 {2,4,5} -0.162027 {3,4,5} -0.253969 $value [1] -0.1349403 $iterations [1] 2 0 $iact [1] 1 > > ## a minimum distance 2-additive solution > min.dist <- mini.dist.capa.ident(a.mu,2,"binary.alternatives",A.Choquet.preorder = Acp) Distance used: binary.alternatives > m <- min.dist$solution > m Mobius.capacity {} 0.000000 {1} 0.251923 {2} 0.247885 {3} 0.109066 {4} 0.000001 {5} 0.394780 {1,2} -0.247884 {1,3} 0.176649 {1,4} 0.000000 {1,5} 0.033792 {2,3} 0.000000 {2,4} 0.133939 {2,5} 0.000000 {3,4} 0.000000 {3,5} -0.109065 {4,5} 0.008913 > > ## a minimum distance 3-additive more constrained solution > min.dist2 <- mini.dist.capa.ident(a.mu,3,"global.scores", + A.Choquet.preorder = Acp, + A.Shapley.preorder = Asp) Distance used: global.scores > m <- min.dist2$solution > m Mobius.capacity {} 0.000000 {1} 0.086199 {2} 0.098042 {3} 0.020438 {4} 0.020438 {5} 0.168892 {1,2} -0.020944 {1,3} 0.342373 {1,4} 0.046691 {1,5} 0.336777 {2,3} 0.282617 {2,4} 0.318979 {2,5} 0.052665 {3,4} -0.020437 {3,5} 0.116823 {4,5} 0.320860 {1,2,3} -0.287362 {1,2,4} 0.009913 {1,2,5} 0.007873 {1,3,4} 0.138990 {1,3,5} -0.384513 {1,4,5} -0.275996 {2,3,4} -0.141218 {2,3,5} -0.005600 {2,4,5} -0.298466 {3,4,5} 0.065966 > rbind(c(a,mean(a),Choquet.integral(m,a)), + c(b,mean(b),Choquet.integral(m,b)), + c(c,mean(c),Choquet.integral(m,c)), + c(d,mean(d),Choquet.integral(m,d)), + c(e,mean(e),Choquet.integral(m,e))) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 18 11 18 11 11 13.8 14.14308 [2,] 18 18 11 11 11 13.8 12.14308 [3,] 11 11 18 18 11 13.8 11.14308 [4,] 18 11 11 11 18 13.8 15.14308 [5,] 11 11 18 11 18 13.8 13.14308 > Shapley.value(m) 1 2 3 4 5 0.1749493 0.1764129 0.1765477 0.1865477 0.2855424 > > ## a minimum distance 5-additive more constrained solution > min.dist3 <- mini.dist.capa.ident(a.mu,5, + A.Choquet.preorder = Acp, + A.Shapley.preorder = Asp, + A.Shapley.interval = Asi, + A.interaction.preorder = Aip, + A.interaction.interval = Aii) Distance used: Choquet.coefficients > > m <- min.dist3$solution > m Mobius.capacity {} 0.000000 {1} 0.175233 {2} 0.175233 {3} 0.000001 {4} 0.009941 {5} 0.045067 {1,2} -0.175232 {1,3} 0.285714 {1,4} 0.152062 {1,5} 0.383506 {2,3} 0.234150 {2,4} 0.248535 {2,5} 0.181052 {3,4} 0.022436 {3,5} 0.273024 {4,5} 0.152487 {1,2,3} 0.036418 {1,2,4} 0.177214 {1,2,5} -0.045745 {1,3,4} -0.067413 {1,3,5} -0.456008 {1,4,5} -0.199818 {2,3,4} -0.065360 {2,3,5} -0.192016 {2,4,5} -0.079045 {3,4,5} -0.141797 {1,2,3,4} -0.255352 {1,2,3,5} 0.079602 {1,2,4,5} -0.200490 {1,3,4,5} 0.110230 {2,3,4,5} -0.130436 {1,2,3,4,5} 0.266809 > rbind(c(a,mean(a),Choquet.integral(m,a)), + c(b,mean(b),Choquet.integral(m,b)), + c(c,mean(c),Choquet.integral(m,c)), + c(d,mean(d),Choquet.integral(m,d)), + c(e,mean(e),Choquet.integral(m,e))) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 18 11 18 11 11 13.8 14.22664 [2,] 18 18 11 11 11 13.8 12.22664 [3,] 11 11 18 18 11 13.8 11.22664 [4,] 18 11 11 11 18 13.8 15.22664 [5,] 11 11 18 11 18 13.8 13.22664 > summary(m) Shapley value : 1 2 3 4 5 0.3000000 0.2900000 0.1166434 0.1066434 0.1867131 Shapley interaction indices : 1 2 3 4 5 1 NA -0.150000000 0.08707493 0.0585512 0.095870141 2 -0.15000000 NA 0.08831090 0.1362151 0.005576357 3 0.08707493 0.088310899 NA -0.1400000 -0.035385829 4 0.05855120 0.136215076 -0.14000000 NA -0.064705805 5 0.09587014 0.005576357 -0.03538583 -0.0647058 NA Orness : 0.493152 Veto indices : 1 2 3 4 5 0.5749499 0.5700200 0.4500915 0.4457237 0.4934547 Favor indices : 1 2 3 4 5 0.5500501 0.5424800 0.4457128 0.4375806 0.4899367 Normalized variance : 0.1573271 Normalized entropy : 0.7631456 > > proc.time() user system elapsed 0.54 0.07 0.60