From: Benjamin Auder Date: Mon, 16 Dec 2019 14:50:03 +0000 (+0100) Subject: Avoid computing an extra W in optimParams X-Git-Url: https://git.auder.net/variants/current/doc/scripts/pieces/css/%3C?a=commitdiff_plain;h=ef0d907c50abe7c4dc0d3c0e94645b5bf6ef3626;p=morpheus.git Avoid computing an extra W in optimParams --- diff --git a/pkg/R/optimParams.R b/pkg/R/optimParams.R index 13aec83..f06581e 100644 --- a/pkg/R/optimParams.R +++ b/pkg/R/optimParams.R @@ -257,14 +257,16 @@ setRefClass( else if (!is.numeric(θ0$b) || length(θ0$b) != K || any(is.na(θ0$b))) stop("θ0$b: length K, no NA") # TODO: stopping condition? N iterations? Delta <= epsilon ? - for (loop in 1:2) + loopMax <- 2 + for (loop in 1:loopMax) { op_res = constrOptim( linArgs(θ0), .self$f, .self$grad_f, ui=cbind( rbind( rep(-1,K-1), diag(K-1) ), matrix(0, nrow=K, ncol=(d+1)*K) ), ci=c(-1,rep(0,K-1)) ) - W <<- computeW(expArgs(op_res$par)) + if (loop < loopMax) #avoid computing an extra W + W <<- computeW(expArgs(op_res$par)) print(op_res$value) #debug print(expArgs(op_res$par)) #debug }