Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions R/getFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ getBoundariesV4 <- function(coco.object, lower.bound = 2, upper.bound = 2){
mod_DM <- tmp_values$std.covs
}

coefs_lm <- stats::coef(stats::lm(term_labels,cbind.data.frame('z' = coco.object@z,mod_DM)))
if(is.formula(coco.object@model.list$mean)){
coefs_lm <- stats::coef(stats::lm(term_labels,cbind.data.frame('z' = coco.object@z,mod_DM)))
} else{
coefs_lm <- c()
}

boundaries_B <- getBoundariesV2(coco.object = coco.object,
mean.limits = c(-Inf, 0, Inf),
Expand All @@ -655,7 +659,9 @@ getBoundariesV4 <- function(coco.object, lower.bound = 2, upper.bound = 2){
smooth.limits = c(-lower.bound, 0, upper.bound),
nugget.limits = c(-lower.bound, 0, upper.bound))

boundaries_B$theta_init[1:length(coefs_lm)] <- coefs_lm
if(is.formula(coco.object@model.list$mean)){
boundaries_B$theta_init[1:length(coefs_lm)] <- coefs_lm
}

first_sd <- which(names(boundaries_B$theta_init) == "std.dev.limits")[1]
n_var <- length(which(names(boundaries_B$theta_init) == "std.dev.limits")) - 1
Expand Down
21 changes: 11 additions & 10 deletions R/optim.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' optim.type, optim.control)
#'
#' @param coco.object (\code{S4}) A \link{coco} object.
#' @param boundaries (\code{list}) If provided, a list containing lower, initial, and upper values for the parameters, as defined by \link{getBoundaries}. If not provided, these values are automatically computed with global lower and upper bounds set to -2 and 2.
#' @param boundaries (\code{list}) If provided, a list containing lower, initial, and upper values for the parameters, as defined by \link{getBoundaries}. If not provided, these values are automatically computed via getBoundariesV4 with global lower and upper bounds set to -3 and 3.
#' @param ncores (\code{character} or \code{integer}) The number of threads to use for the optimization. If set to `"auto"`, the number of threads is chosen based on system capabilities or a fraction of the available cores.
#' @param optim.type (\code{character}) The optimization approach. Options include:
#' @param safe (\code{logical}) If `TRUE`, the function avoids Cholesky decomposition errors due to ill-posed covariance matrices by returning a pre-defined large value. Defaults to `TRUE`.
Expand Down Expand Up @@ -37,15 +37,16 @@
#' 'smooth' = 3/2,
#' 'nugget' = -Inf)
#'
#' sample_index <- sample(1:dim(holes[[1]])[1],100)
#'
#' coco_object <- coco(type = 'dense',
#' data = holes[[1]][1:100,],
#' locs = as.matrix(holes[[1]][1:100,1:2]),
#' z = holes[[1]][1:100,]$z,
#' data = holes[[1]][sample_index, ],
#' locs = as.matrix(holes[[1]][sample_index,1:2]),
#' z = holes[[1]][sample_index, ]$z,
#' model.list = model.list)
#'
#' optim_coco <- cocoOptim(coco_object,
#' boundaries = getBoundaries(coco_object,
#' lower.value = -3, 3))
#' boundaries = getBoundaries(coco_object)
#'
#' plotOptimInfo(optim_coco)
#'
Expand Down Expand Up @@ -91,10 +92,10 @@ cocoOptim <- function(coco.object, boundaries = list(),

# Check boundaries
if(length(boundaries) == 0){
boundaries <- cocons::getBoundaries(
x = coco.object,
lower.value = -2,
upper.value = 2)
boundaries <- cocons::getBoundariesV4(
coco.object = coco.object,
lower.bound = -3,
upper.bound = 3)
} else{
.cocons.check.boundaries(coco.object, boundaries)
}
Expand Down
13 changes: 7 additions & 6 deletions man/cocoOptim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading