From: Benjamin Auder Date: Wed, 30 Oct 2019 14:04:07 +0000 (+0100) Subject: Revert sample.R back to working code X-Git-Url: https://git.auder.net/doc/html/mini-custom.min.css?a=commitdiff_plain;h=778a955e6830f48306f2e35322440c5f9a0adaf3;p=morpheus.git Revert sample.R back to working code --- diff --git a/pkg/R/sampleIO.R b/pkg/R/sampleIO.R index 753e00d..6fa38ae 100644 --- a/pkg/R/sampleIO.R +++ b/pkg/R/sampleIO.R @@ -51,7 +51,7 @@ generateSampleIO = function(n, p, β, b, link) { index = c(index, rep(i, classes[i])) newXblock = cbind( MASS::mvrnorm(classes[i], zero_mean, id_sigma), 1 ) - arg_link = newXblock %*% β + arg_link = newXblock %*% β[,i] #β probas = if (link == "logit") { @@ -61,10 +61,10 @@ generateSampleIO = function(n, p, β, b, link) else #"probit" pnorm(arg_link) probas[is.nan(probas)] = 1 #overflow of exp(x) - probas = rowSums(p * probas) + #probas = rowSums(p * probas) X = rbind(X, newXblock) - Y = c( Y, vapply(probas, function(p) (ifelse(p >= .5, 1, 0)), 1) ) - #Y = c( Y, vapply(probas, function(p) (rbinom(1,1,p)), 1) ) + #Y = c( Y, vapply(probas, function(p) (ifelse(p >= .5, 1, 0)), 1) ) + Y = c( Y, vapply(probas, function(p) (rbinom(1,1,p)), 1) ) } shuffle = sample(n) # Returned X should not contain an intercept column (it's an argument of estimation diff --git a/reports/multistart.R b/reports/multistart.R index c5d9f51..252de91 100644 --- a/reports/multistart.R +++ b/reports/multistart.R @@ -2,7 +2,7 @@ library(morpheus) testMultistart <- function(N, n, d, K, p, beta, b, link, nstart, ncores) { - ms <- multiRun( + res <- multiRun( list(n=n,p=p,beta=beta,b=b,optargs=list(K=K,d=d,link=link,nstart=nstart)), list( function(fargs) { @@ -11,11 +11,11 @@ testMultistart <- function(N, n, d, K, p, beta, b, link, nstart, ncores) K <- fargs$optargs$K op <- optimParams(K, fargs$optargs$link, fargs$optargs) x_init <- list(p=rep(1/K,K-1), beta=fargs$mu, b=rep(0,K)) - res <- NULL + res2 <- NULL tryCatch({ - res <- do.call(rbind, op$run(x_init)) + res2 <- do.call(rbind, op$run(x_init)) }, error = function(e) {}) - res + res2 }, function(fargs) { # B starts @@ -58,8 +58,8 @@ testMultistart <- function(N, n, d, K, p, beta, b, link, nstart, ncores) fargs }, N=N, ncores=ncores, verbose=TRUE) for (i in 1:2) - ms[[i]] <- alignMatrices(ms[[i]], ref=rbind(p,beta,b), ls_mode="exact") - ms + res[[i]] <- alignMatrices(ms[[i]], ref=rbind(p,beta,b), ls_mode="exact") + res } #model = binomial @@ -101,8 +101,8 @@ betas <- list( matrix( c(1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0), ncol=K ) ) #d=10 beta <- betas[[ ifelse( d==2, 1, ifelse(d==5,2,3) ) ]] -ms <- testMultistart(N, n, d, K, p, beta, b, link, nstart, ncores) -ms_params <- list("N"=N, "nc"=ncores, "n"=n, "K"=K, "d"=d, "link"=link, +mr <- testMultistart(N, n, d, K, p, beta, b, link, nstart, ncores) +mr_params <- list("N"=N, "nc"=ncores, "n"=n, "K"=K, "d"=d, "link"=link, "p"=c(p,1-sum(p)), "beta"=beta, "b"=b, "nstart"=nstart) -save("ms", "ms_params", file=paste("res_",n,"_",d,"_",link,"_",nstart,".RData",sep="")) +save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,"_",nstart,".RData",sep=""))