Skip to content

Commit 634525f

Browse files
authored
Fix various issues in initializing nimOptim, plus use of Laplace updateSettings (#1581)
* Revise formatting of new addSampler allowData messaging. * Fix nimOptimDefaultControl default types. Ensure fnscale=-1 in inner Laplace when using updateSettings. Use `working_maxit` consistently in nimOptim solve.
1 parent b3c650a commit 634525f

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/nimble/R/Laplace.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ buildOneAGHQuad1D <- nimbleFunction(
323323
## transMethod <<- gridType
324324
## }
325325
if(replace_optimControl) {
326+
optimControl$fnscale <- -1
326327
optimControl_ <<- optimControl
327328
}
328329
},
@@ -1163,6 +1164,7 @@ buildOneAGHQuad <- nimbleFunction(
11631164
transMethod <<- gridType
11641165
}
11651166
if(replace_optimControl) {
1167+
optimControl$fnscale <- -1
11661168
optimControl_ <<- optimControl
11671169
}
11681170
},

packages/nimble/R/nimbleFunction_Rexecution.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,15 +1497,15 @@ nimOptimDefaultControl <- function() {
14971497
control <- optimControlNimbleList$new()
14981498
control$trace <- 0
14991499
control$fnscale <- 1
1500-
control$parscale <- NA # Must be filled in to length of par
1501-
control$ndeps <- NA # Ditto
1502-
control$maxit <- NA ## The default value depends on method.
1500+
control$parscale <- as.numeric(NA) # Must be filled in to length of par
1501+
control$ndeps <- as.numeric(NA) # Ditto
1502+
control$maxit <- as.integer(NA) ## The default value depends on method.
15031503
control$abstol = -Inf
15041504
control$reltol <- sqrt(.Machine$double.eps)
15051505
control$alpha <- 1.0
15061506
control$beta <- 0.5
15071507
control$gamma <- 2.0
1508-
control$REPORT <- NA # Method dependent and not used in compiled version
1508+
control$REPORT <- as.integer(NA) # Method dependent and not used in compiled version
15091509
control$type <- 1
15101510
control$lmm <- 5
15111511
control$factr <- 1e7

packages/nimble/inst/CppCode/nimOptim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ nimSmartPtr<OptimResultNimbleList> NimOptimProblem::solve(
185185
result->hessian.initialize(NA_REAL, true, n, n);
186186
}
187187

188+
188189
// Parameters common to all methods.
189190
double* dpar = par.getPtr();
190191
double* X = result->par.getPtr();
@@ -248,7 +249,7 @@ nimSmartPtr<OptimResultNimbleList> NimOptimProblem::solve(
248249
SEXP Scontrol = PROTECT(Rf_allocVector(VECSXP, 6));
249250
SET_VECTOR_ELT(Scontrol, 0, PROTECT(double_2_SEXP(control_->abstol)));
250251
SET_VECTOR_ELT(Scontrol, 1, PROTECT(double_2_SEXP(control_->reltol)));
251-
SET_VECTOR_ELT(Scontrol, 2, PROTECT(int_2_SEXP(control_->maxit)));
252+
SET_VECTOR_ELT(Scontrol, 2, PROTECT(int_2_SEXP(working_maxit)));
252253
SET_VECTOR_ELT(Scontrol, 3, PROTECT(NimArr_2_SEXP<1>(working_parscale)));
253254
SET_VECTOR_ELT(Scontrol, 4, PROTECT(double_2_SEXP(control_->fnscale)));
254255
SET_VECTOR_ELT(Scontrol, 5, PROTECT(int_2_SEXP(control_->trace)));
@@ -321,7 +322,6 @@ nimSmartPtr<OptimResultNimbleList> NimOptimProblem::solve(
321322
// NIMERROR("Unknown method_: %s", method_.c_str());
322323
//}
323324
result->value *= control_->fnscale;
324-
325325
// Compute Hessian.
326326
// Parameters are still on the optimization scale,
327327
// i.e. divided by parscale

0 commit comments

Comments
 (0)