3 testMultistart <- function(N, n, K, p, beta, b, link, nstart, ncores)
6 list(n=n,p=p,beta=beta,b=b,optargs=list(K=K,link=link,nstart=nstart)),
12 op <- optimParams(K, fargs$optargs$link, fargs$optargs)
13 x_init <- list(p=rep(1/K,K-1), beta=fargs$mu, b=rep(0,K))
16 res <- do.call(rbind, op$run(x_init))
17 }, error = function(e) {
26 op <- optimParams(K, fargs$optargs$link, fargs$optargs)
29 for (i in 1:fargs$optargs$nstart)
31 #x_init <- list(p=rep(1/K,K-1), beta=i*fargs$mu, b=rep(0,K))
32 M <- matrix(rnorm(d*K), nrow=d, ncol=K)
33 M <- t(t(M) / sqrt(colSums(M^2)))
34 x_init <- list(p=rep(1/K,K-1), beta=M, b=rep(0,K))
37 }, error = function(e) {
42 val <- op$f( op$linArgs(par) )
50 # Bet that at least one run succeded:
51 do.call(rbind,best_par)
54 prepareArgs = function(fargs, index) {
56 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$optargs$link)
57 fargs$optargs$M <- computeMoments(io$X, io$Y)
58 mu <- computeMu(io$X, io$Y, fargs$optargs)
61 }, N=N, ncores=ncores, verbose=TRUE)
63 ms[[i]] <- alignMatrices(ms[[i]], ref=rbind(p,beta,b), ls_mode="exact")
77 nstart <- 3 #nstart-1 random starting points for each MC run
79 cmd_args <- commandArgs()
82 if (substr(arg,1,1)!='-')
84 spl <- strsplit(arg,'=')[[1]]
86 ncores <- as.integer(spl[2])
87 } else if (spl[1] == "N") {
88 N <- as.integer(spl[2])
89 } else if (spl[1] == "n") {
90 n <- as.integer(spl[2])
91 } else if (spl[1] == "d") {
92 d <- as.integer(spl[2])
93 } else if (spl[1] == "link") {
95 } else if (spl[1] == "nstart") {
101 matrix( c(1,-2, 3,1), ncol=K ), #d=2
102 matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=K ), #d=5
103 matrix( c(1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0), ncol=K ) ) #d=10
104 beta <- betas[[ ifelse( d==2, 1, ifelse(d==5,2,3) ) ]]
106 ms <- testMultistart(N, n, K, p, beta, b, link, nstart, ncores)
107 ms_params <- list("N"=N, "nc"=ncores, "n"=n, "K"=K, "d"=d, "link"=link,
108 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b, "nstart"=nstart)
110 save("ms", "ms_params", file="multistart.RData")