3 testMultistart <- function(N, n, p, beta, b, link, nstart, ncores)
6 list(n=n, p=p, beta=beta, b=b, link=link, nstart=nstart),
12 mu <- computeMu(fargs$X, fargs$Y, list(K=K, M=fargs$M))
13 op <- optimParams(fargs$X, fargs$Y, K, fargs$link, fargs$M, 1)
14 x_init <- list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
17 res2 <- do.call(rbind, op$run(x_init))
18 }, error = function(e) {})
26 op <- optimParams(fargs$X, fargs$Y, K, fargs$link, fargs$M)
29 for (i in 1:fargs$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))
38 }, error = function(e) {})
41 val <- op$f( op$linArgs(par) )
49 do.call(rbind,best_par) #return NULL on empty list
52 prepareArgs = function(fargs, index) {
54 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$link)
55 fargs$M <- computeMoments(io$X, io$Y)
59 }, N=N, ncores=ncores, verbose=TRUE)
61 for (i in 1:length(res)) {
63 if (is.null(res[[i]][[j]]) || is.na(res[[i]][[j]]))
66 print(paste("Count valid runs for ",i," = ",length(res[[i]]),sep=""))
67 res[[i]] <- alignMatrices(res[[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") {
104 beta <- matrix( c(1,-2, 3,1), ncol=2 )
108 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=2 )
109 } else if (d == 10) {
112 beta <- matrix( c(1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0, -1,1,3,-1,0,0,2,0,1,-2), ncol=3 )
115 mr <- testMultistart(N, n, p, beta, b, link, nstart, ncores)
116 mr_params <- list("N"=N, "nc"=ncores, "n"=n, "link"=link,
117 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b, "nstart"=nstart)
119 save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,"_",nstart,".RData",sep=""))