Commit fb02591d authored by Martin Maechler's avatar Martin Maechler

more output; checking on 32 bit platform reveals +-1 difference (!)

parent 05e8dd75
require(CLA)
b64 <- .Machine$sizeof.pointer == 8
cat(if(b64) "64" else "32", "bit platform\n")
data(muS.sp500)
if(requireNamespace("FRAPO")) {
......@@ -12,40 +16,72 @@ system.time(# ~ 9 sec
CLs5c.0.120 <- CLA(muS.sp500$mu, muS.sp500$covar, lB=0, uB=1/20)
)
if(require(Matrix)) { ## visualize how weights change "along turning points"
op <- options(width = max(500, getOption("width"))) # then it actually fits
if(require(Matrix)) withAutoprint({
## visualize how weights change "along turning points"
spWts <- Matrix(CLs5c.0.120$weights_set, sparse=TRUE)
image(spWts, xlab = "turning point", ylab = "asset number")
##
print(dim(spWts.non0 <- spWts[rowSums(spWts) > 0 , ]))
dim(spWts.non0 <- spWts[rowSums(spWts) > 0 , ])
round(1000 * spWts.non0)
##
image(spWts.non0, xlab = "turning point", ylab = "asset number")
wts.non0 <- as(spWts.non0, "matrix")
} else {
}) else {
warning("'Matrix' package not available -- should not happen!")
wts.non0 <- CLs5c.0.120$weights_set[rowSums(CLs5c.0.120$weights_set) > 0 , ]
if(is.null(colnames(wts.non0))) ## empty column names for nice printing:
colnames(wts.non0) <- rep("", ncol(wts.non0))
print.table(round(1000 * wts.non0), zero.print=".")
}
options(op)
stopifnot(nrow(wts.non0) == 79)
non.0.assets <- Filter(function(.) . > 0, apply(wts.non0, 1, function(c) sum(c > 0)))
## Unfortunately, currently the results are slighly *platform dependent* :
b32.n0 <- c(AAPL = 136L, ADSK = 66L, AET = 146L, AMGN = 3L, ATI = 76L,
AYE = 56L, AZO = 27L, BAX = 96L, BCR = 34L, BDX = 36L, BIIB = 118L,
BNI = 86L, BRL = 23L, BTU = 28L, BUD = 7L, CCE = 54L, CELG = 129L,
CI = 68L, CL = 82L, CLX = 54L, CME = 141L, CNX = 17L, COST = 41L,
CTL = 5L, CVS = 102L, DF = 36L, DGX = 34L, DVN = 15L, ED = 31L,
EIX = 127L, ESRX = 49L, FCX = 55L, FE = 60L, GILD = 38L, HAL = 30L,
HES = 41L, HST = 108L, HUM = 71L, INTU = 48L, JNJ = 34L, K = 61L,
LH = 80L, LLL = 96L, LMT = 84L, LUK = 72L, MCD = 60L, MDT = 43L,
MMC = 7L, MON = 54L, MRO = 137L, MTW = 67L, MUR = 98L, NEM = 45L,
NOC = 74L, NUE = 31L, NVDA = 14L, PBG = 72L, PCP = 103L, PDCO = 71L,
PEP = 70L, PG = 87L, RAI = 110L, RIG = 122L, RRC = 106L, RTN = 90L,
SII = 26L, SSP = 14L, SYK = 18L, SYMC = 14L, TEX = 37L, TIE = 85L,
TSO = 116L, TYC = 60L, UST = 128L, WAG = 17L, WFR = 6L, WMT = 6L,
X = 44L, XTO = 102L)
b64.n0 <- c(AAPL = 136L, ADSK = 66L, AET = 147L, AMGN = 3L, ATI = 76L,
AYE = 56L, AZO = 26L, BAX = 95L, BCR = 35L, BDX = 36L, BIIB = 118L,
BNI = 86L, BRL = 23L, BTU = 28L, BUD = 7L, CCE = 54L, CELG = 129L,
CI = 69L, CL = 83L, CLX = 53L, CME = 141L, CNX = 17L, COST = 40L,
CTL = 5L, CVS = 102L, DF = 36L, DGX = 33L, DVN = 14L, ED = 32L,
EIX = 127L, ESRX = 48L, FCX = 55L, FE = 61L, GILD = 38L, HAL = 31L,
HES = 41L, HST = 108L, HUM = 71L, INTU = 48L, JNJ = 34L, K = 61L,
LH = 80L, LLL = 96L, LMT = 83L, LUK = 72L, MCD = 61L, MDT = 43L,
MMC = 7L, MON = 54L, MRO = 137L, MTW = 67L, MUR = 97L, NEM = 45L,
NOC = 74L, NUE = 31L, NVDA = 14L, PBG = 72L, PCP = 103L, PDCO = 71L,
PEP = 69L, PG = 87L, RAI = 110L, RIG = 121L, RRC = 106L, RTN = 90L,
SII = 27L, SSP = 14L, SYK = 19L, SYMC = 13L, TEX = 37L, TIE = 85L,
TSO = 116L, TYC = 59L, UST = 127L, WAG = 17L, WFR = 6L, WMT = 6L,
X = 44L, XTO = 102L)
## They have the same names and only differ by +/- 1:
stopifnot(
identical(non.0.assets,
c(AAPL = 136L, ADSK = 66L, AET = 147L, AMGN = 3L, ATI = 76L,
AYE = 56L, AZO = 26L, BAX = 95L, BCR = 35L, BDX = 36L, BIIB = 118L,
BNI = 86L, BRL = 23L, BTU = 28L, BUD = 7L, CCE = 54L, CELG = 129L,
CI = 69L, CL = 83L, CLX = 53L, CME = 141L, CNX = 17L, COST = 40L,
CTL = 5L, CVS = 102L, DF = 36L, DGX = 33L, DVN = 14L, ED = 32L,
EIX = 127L, ESRX = 48L, FCX = 55L, FE = 61L, GILD = 38L, HAL = 31L,
HES = 41L, HST = 108L, HUM = 71L, INTU = 48L, JNJ = 34L, K = 61L,
LH = 80L, LLL = 96L, LMT = 83L, LUK = 72L, MCD = 61L, MDT = 43L,
MMC = 7L, MON = 54L, MRO = 137L, MTW = 67L, MUR = 97L, NEM = 45L,
NOC = 74L, NUE = 31L, NVDA = 14L, PBG = 72L, PCP = 103L, PDCO = 71L,
PEP = 69L, PG = 87L, RAI = 110L, RIG = 121L, RRC = 106L, RTN = 90L,
SII = 27L, SSP = 14L, SYK = 19L, SYMC = 13L, TEX = 37L, TIE = 85L,
TSO = 116L, TYC = 59L, UST = 127L, WAG = 17L, WFR = 6L, WMT = 6L,
X = 44L, XTO = 102L))
, identical(head(CLs5c.0.120$free_indices, 12),
list(295L, c(295L, 453L), 453L, c(453L, 472L), c(19L, 453L, 472L),
c(19L, 453L), 453L, c(15L, 453L), 15L, c(15L, 320L),
c(15L, 105L, 320L), c(105L, 320L)))
identical(names(b64.n0), names(b32.n0))
, identical(c(table(b64.n0 - b32.n0)),
c("-1" = 14L, "0" = 55L, "1" = 10L))
## ______ ______
, identical(non.0.assets, if(b64) b64.n0 else b32.n0)
, identical(head(CLs5c.0.120$free_indices, 12),
list(295L, c(295L, 453L), 453L, c(453L, 472L), c(19L, 453L, 472L),
c(19L, 453L), 453L, c(15L, 453L), 15L, c(15L, 320L),
c(15L, 105L, 320L), c(105L, 320L)))
)
## Check some of the 'Env<n>' versions:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment