1 # flexmix optimization to get beta
2 fmOptim <- function(X, Y, K, link)
4 dat <- as.data.frame( cbind(Y,X) )
5 fm <- flexmix( cbind(Y, 1-Y) ~ .-Y, data=dat, k=K,
6 model = FLXMRglm(family = binomial(link = link)) )
7 p <- mean(fm@posterior[["scaled"]][,1])
9 beta_b <- sapply( seq_len(K), function(i) as.double( out@components[[1]][[i]][,1] ) )
10 list("p"=p, "beta"=beta_b[2:nrow(beta_b),], "b"=beta_b[1,])
14 # Our package optimization for beta (using mu as a starting point)
15 ourOptim <- function(X, Y, K, link)
17 M <- computeMoments(X, Y)
18 mu <- computeMu(X, Y, list(K=K,M=M))
19 x_init = list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
20 optimParams(X, Y, K, link, M, 1)$run(x_init)
24 # Get timings for both methods with the same beta matrix
25 getTimings <- function(link)
27 timings <- list('fm'=matrix(0,nrow=10,ncol=7),'our'=matrix(0,nrow=10,ncol=7))
31 beta <- matrix(runif(d*K,min=-5,max=5),ncol=K)
35 io <- generateSampleIO(n, rep(1/K,K-1), beta, runif(K), link)
36 timings[['fm']][d,logn] <- system.time(fmOptim(io$X,io$Y,K,link))[3]
37 timings[['our']][d,logn] <- system.time(ourOptim(io$X,io$Y,K,link))[3]
48 cmd_args <- commandArgs()
51 if (substr(arg,1,1)!='-')
53 spl <- strsplit(arg,'=')[[1]]
54 if (spl[1] == "link") {
56 } else if (spl[1] == "nc") {
57 ncores <- as.integer(spl[2])
58 } else if (spl[1] == "N") {
59 N <- as.integer(spl[2])
66 source("../patch_Bettina/FLXMRglm.R")
70 lapply(1:N, function(i) {
76 mclapply(1:N, function(i) {
80 mc.preschedule=FALSE, mc.cores=ncores)
82 tm_params <- list("link"=link, "N"=N, "nc"=ncores)
84 save("tm", "tm_params", file="timings.RData")