Commit 74098c55 authored by Martin Maechler's avatar Martin Maechler

+ all.equal() comparison with saved 64-bit weights

Acked-by: default avatarMartin Maechler <maechler@r-project.org>
parent a5ccc60c
......@@ -12,13 +12,13 @@ if(requireNamespace("FRAPO")) {
}
(n <- length(muS.sp500$mu)) # 476
system.time(# ~ 9 sec
system.time(# ~ 9 sec (64-bit); 13.8 sec (32-b florence); seen 27.44 sec on Winb.32
CLs5c.0.120 <- CLA(muS.sp500$mu, muS.sp500$covar, lB=0, uB=1/20)
)
op <- options(width = max(500, getOption("width"))) # then it actually fits
if(require(Matrix)) withAutoprint({
if(require(Matrix)) withAutoprint(local = FALSE, {
## visualize how weights change "along turning points"
spWts <- Matrix(CLs5c.0.120$weights_set, sparse=TRUE)
image(spWts, xlab = "turning point", ylab = "asset number")
......@@ -36,10 +36,18 @@ if(require(Matrix)) withAutoprint({
print.table(round(1000 * wts.non0), zero.print=".")
}
options(op)
stopifnot(nrow(wts.non0) == 79)
if(FALSE) # once, manually (into tests/ directory
saveRDS(wts.non0, "wtsn0.rds")
file.info("wtsn0.rds")$size # 27049
wtsn0.ref <- readRDS("wtsn0.rds")
non.0.assets <- Filter(function(.) . > 0, apply(wts.non0, 1, function(c) sum(c > 0)))
## see on all platforms what we get
all.equal(target = wtsn0.ref, current = wts.non0, tol=0) # expect TRUE only on 64bit (Lnx)
## 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,
......@@ -71,25 +79,31 @@ b64.n0 <- c(AAPL = 136L, ADSK = 66L, AET = 147L, AMGN = 3L, ATI = 76L,
TSO = 116L, TYC = 59L, UST = 127L, WAG = 17L, WFR = 6L, WMT = 6L,
X = 44L, XTO = 102L)
## see on all platforms what we get:
all.equal(non.0.assets, if(b64) b64.n0 else b32.n0, tol=0)
## They have the same names and only differ by +/- 1:
stopifnot(
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)
, if(b64) identical(non.0.assets, b64.n0)
else all.equal(non.0.assets, b32.n0, tol = 1e-10) # <- tol may need adaption
, 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:
## Check some of the 'Env<n>' versions: ---------
##' Transform CLA() result to old style (= Env8 / Env9 results):
claStrip <- function(res) {
## transform to old style
class(res) <- NULL
res$call <- NULL
res$weights_set <- unname(res$weights_set)
names(res)[[5]] <- "MS_weight" # new is "MS_weights" w/ final "s"
names(res)[[match("MS_weights", names(res))]] <- "MS_weight" # "MS_weights" w/ final "s"
res
}
......
File added
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