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 op <- optimParams(fargs$X, fargs$Y, K, fargs$link, fargs$M)
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(fargs$X, fargs$Y, K, fargs$link, fargs$M)
28 for (i in 1:fargs$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 do.call(rbind,best_par) #return NULL on empty list
51 prepareArgs = function(fargs, index) {
53 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$link)
54 fargs$M <- computeMoments(io$X, io$Y)
55 mu <- computeMu(io$X, io$Y, list(M=fargs$M))
60 }, N=N, ncores=ncores, verbose=TRUE)
62 for (i in 1:length(res)) {
64 if (is.null(res[[i]][[j]]) || is.na(res[[i]][[j]]))
67 print(paste("Count valid runs for ",i," = ",length(res[[i]]),sep=""))
68 res[[i]] <- alignMatrices(res[[i]], ref=rbind(p,beta,b), ls_mode="exact")
78 nstart <- 3 #nstart-1 random starting points for each MC run
80 cmd_args <- commandArgs()
83 if (substr(arg,1,1)!='-')
85 spl <- strsplit(arg,'=')[[1]]
87 ncores <- as.integer(spl[2])
88 } else if (spl[1] == "N") {
89 N <- as.integer(spl[2])
90 } else if (spl[1] == "n") {
91 n <- as.integer(spl[2])
92 } else if (spl[1] == "d") {
93 d <- as.integer(spl[2])
94 } else if (spl[1] == "link") {
96 } else if (spl[1] == "nstart") {
105 beta <- matrix( c(1,-2, 3,1), ncol=2 )
109 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=2 )
110 } else if (d == 10) {
113 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 )
116 mr <- testMultistart(N, n, p, beta, b, link, nstart, ncores)
117 mr_params <- list("N"=N, "nc"=ncores, "n"=n, "link"=link,
118 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b, "nstart"=nstart)
120 save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,"_",nstart,".RData",sep=""))