1 optimBeta <- function(N, n, p, beta, b, link, ncores)
5 list(n=n, p=p, beta=beta, b=b, link=link),
11 M <- computeMoments(fargs$X, fargs$Y)
12 mu <- computeMu(fargs$X, fargs$Y, list(K=K, M=M))
13 op <- optimParams(fargs$X, fargs$Y, K, fargs$link, M)
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) {})
24 source("../patch_Bettina/FLXMRglm.R")
26 dat <- as.data.frame( cbind(fargs$Y,fargs$X) )
29 fm <- flexmix( cbind(V1, 1-V1) ~ .-V1, data=dat, k=K,
30 model = FLXMRglm(family = binomial(link = link)) )
31 p <- mean(fm@posterior[["scaled"]][,1])
33 beta_b <- sapply( seq_len(K), function(i) {
34 as.double( out@components[[1]][[i]][,1] )
36 res2 <- rbind(p, beta_b[2:nrow(beta_b),], beta_b[1,])
37 }, error = function(e) {
43 prepareArgs = function(fargs, index) {
45 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$link)
49 }, N=N, ncores=ncores, verbose=TRUE)
51 for (i in 1:length(res)) {
53 if (is.null(res[[i]][[j]]) || is.na(res[[i]][[j]]))
56 print(paste("Count valid runs for ",i," = ",length(res[[i]]),sep=""))
57 res[[i]] <- alignMatrices(res[[i]], ref=rbind(p,beta,b), ls_mode="exact")
69 cmd_args <- commandArgs()
72 if (substr(arg,1,1)!='-') {
73 spl <- strsplit(arg,'=')[[1]]
75 ncores <- as.integer(spl[2])
76 } else if (spl[1] == "N") {
77 N <- as.integer(spl[2])
78 } else if (spl[1] == "n") {
79 n <- as.integer(spl[2])
80 } else if (spl[1] == "d") {
81 d <- as.integer(spl[2])
82 } else if (spl[1] == "link") {
91 beta <- matrix( c(1,-2, 3,1), ncol=2 )
95 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=2 )
99 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 )
102 mr <- optimBeta(N, n, p, beta, b, link, ncores)
103 mr_params <- list("N"=N, "nc"=ncores, "n"=n, "link"=link,
104 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b)
106 save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,".RData",sep=""))