3 testMultistart <- function(N, n, d, K, p, beta, b, link, nstart, ncores)
6 list(n=n,p=p,beta=beta,b=b,optargs=list(K=K,d=d,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 res2 <- do.call(rbind, op$run(x_init))
17 }, error = function(e) {})
25 op <- optimParams(K, fargs$optargs$link, fargs$optargs)
28 for (i in 1:fargs$optargs$nstart)
30 #x_init <- list(p=rep(1/K,K-1), beta=i*fargs$mu, b=rep(0,K))
31 M <- matrix(rnorm(d*K), nrow=d, ncol=K)
32 M <- t(t(M) / sqrt(colSums(M^2)))
33 x_init <- list(p=rep(1/K,K-1), beta=M, b=rep(0,K))
37 }, error = function(e) {})
40 val <- op$f( op$linArgs(par) )
48 # Bet that at least one run succeded:
49 do.call(rbind,best_par)
52 prepareArgs = function(fargs, index) {
54 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$optargs$link)
55 fargs$optargs$M <- computeMoments(io$X, io$Y)
56 mu <- computeMu(io$X, io$Y, fargs$optargs)
59 }, N=N, ncores=ncores, verbose=TRUE)
61 res[[i]] <- alignMatrices(ms[[i]], ref=rbind(p,beta,b), ls_mode="exact")
75 nstart <- 3 #nstart-1 random starting points for each MC run
77 cmd_args <- commandArgs()
80 if (substr(arg,1,1)!='-')
82 spl <- strsplit(arg,'=')[[1]]
84 ncores <- as.integer(spl[2])
85 } else if (spl[1] == "N") {
86 N <- as.integer(spl[2])
87 } else if (spl[1] == "n") {
88 n <- as.integer(spl[2])
89 } else if (spl[1] == "d") {
90 d <- as.integer(spl[2])
91 } else if (spl[1] == "link") {
93 } else if (spl[1] == "nstart") {
99 matrix( c(1,-2, 3,1), ncol=K ), #d=2
100 matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=K ), #d=5
101 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
102 beta <- betas[[ ifelse( d==2, 1, ifelse(d==5,2,3) ) ]]
104 mr <- testMultistart(N, n, d, K, p, beta, b, link, nstart, ncores)
105 mr_params <- list("N"=N, "nc"=ncores, "n"=n, "K"=K, "d"=d, "link"=link,
106 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b, "nstart"=nstart)
108 save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,"_",nstart,".RData",sep=""))