1 optimBeta <- function(N, n, K, p, beta, b, link, ncores)
5 list(n=n, p=p, beta=beta, b=b, optargs=list(K=K, link=link)),
11 M <- computeMoments(fargs$X, fargs$Y)
13 mu <- computeMu(fargs$X, fargs$Y, fargs$optargs)
16 op <- optimParams(K,link,fargs$optargs)
17 x_init <- list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
18 res2 <- do.call(rbind, op$run(x_init))
19 }, error = function(e) {
28 # source("../patch_Bettina/FLXMRglm.R")
29 # K <- fargs$optargs$K
30 # dat <- as.data.frame( cbind(fargs$Y,fargs$X) )
33 # fm <- flexmix( cbind(V1, 1-V1) ~ .-V1, data=dat, k=K,
34 # model = FLXMRglm(family = binomial(link = link)) )
35 # p <- mean(fm@posterior[["scaled"]][,1])
37 # beta_b <- sapply( seq_len(K), function(i) {
38 # as.double( out@components[[1]][[i]][,1] )
40 # res2 <- rbind(p, beta_b[2:nrow(beta_b),], beta_b[1,])
41 # }, error = function(e) {
47 prepareArgs = function(fargs, index) {
49 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$optargs$link)
52 fargs$optargs$K = ncol(fargs$beta)
53 fargs$optargs$M = computeMoments(io$X,io$Y)
55 }, N=N, ncores=ncores, verbose=TRUE)
57 for (i in 1:length(res)) {
59 if (is.null(res[[i]][[j]]) || is.na(res[[i]][[j]]))
62 print(paste("Count valid runs for ",i," = ",length(res[[i]]),sep=""))
63 res[[i]] <- alignMatrices(res[[i]], ref=rbind(p,beta,b), ls_mode="exact")
68 #model = binomial; default values:
75 cmd_args <- commandArgs()
78 if (substr(arg,1,1)!='-') {
79 spl <- strsplit(arg,'=')[[1]]
81 ncores <- as.integer(spl[2])
82 } else if (spl[1] == "N") {
83 N <- as.integer(spl[2])
84 } else if (spl[1] == "n") {
85 n <- as.integer(spl[2])
86 } else if (spl[1] == "d") {
87 d <- as.integer(spl[2])
88 } else if (spl[1] == "link") {
98 beta <- matrix( c(1,-2, 3,1), ncol=K )
103 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=K )
104 } else if (d == 10) {
108 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=K )
109 } else if (d == 20) {
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,1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0,1,1,2,2,-2,-2,3,1,0,0), ncol=K )
116 mr <- optimBeta(N, n, K, p, beta, b, link, ncores)
117 mr_params <- list("N"=N, "n"=n, "K"=K, "d"=d, "link"=link,
118 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b)
120 save("mr", "mr_params", file=paste("multirun_",n,"_",d,"_",link,".RData",sep=""))