Skip to content

Commit

Permalink
Cleaning point estimation file
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonSimonot committed Jan 6, 2025
1 parent bbea7bb commit 554d84c
Showing 1 changed file with 26 additions and 52 deletions.
78 changes: 26 additions & 52 deletions R/point-estimation.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,12 @@ compute_point_estimate <- function(pf,
nparams <- pf$nparams

if (!is.null(guess)) {
#if (ncores == 1) {
# opt <- stats::optim(
# par = guess,
# fn = pf$get_value,
# method = "L-BFGS-B",
# control = list(fnscale = -1)
# )
#} else {
# parallel_opts <- list(
# cl = parallel::makeCluster(ncores),
# forward = FALSE,
# loginfo = FALSE
# )

opt <- optimParallel::optimParallel(
par = guess,
fn = pf$get_value,
control = list(fnscale = -1)#,
#parallel = parallel_opts #here, will use default cluster
)
#parallel::stopCluster(parallel_opts$cl)
#}
# uses user default cluster
opt <- optimParallel::optimParallel(
par = guess,
fn = pf$get_value,
control = list(fnscale = -1)

Check warning on line 13 in R/point-estimation.R

View check run for this annotation

Codecov / codecov/patch

R/point-estimation.R#L10-L13

Added lines #L10 - L13 were not covered by tests
)
x0 <- opt$par
fval <- opt$value
} else {
Expand All @@ -37,36 +21,26 @@ compute_point_estimate <- function(pf,
if (length(upper_bound) != nparams)
abort("The number of provided upper bounds does not match the number of parameters.")

# if (nparams == 1 && ncores == 1) {
# opt <- stats::optimise(
# f = pf$get_value,
# interval = c(lower_bound, upper_bound),
# maximum = TRUE
# )
# x0 <- opt$maximum
# fval <- opt$objective
# } else {
opt <- rgenoud::genoud(
fn = pf$get_value,
nvars = nparams,
Domains = cbind(lower_bound, upper_bound),
max = TRUE,
pop.size = 20 * nparams,
max.generations = 10 * nparams,
wait.generations = 2 * nparams + 1,
BFGSburnin = 2 * nparams + 1,
print.level = 0,
cluster = parallel::getDefaultCluster(),
balance = nparams > 2
)
opt <- compute_point_estimate(
pf = pf,
guess = opt$par,
verbose = FALSE
)
x0 <- opt$par
fval <- opt$value
#}
opt <- rgenoud::genoud(
fn = pf$get_value,
nvars = nparams,
Domains = cbind(lower_bound, upper_bound),
max = TRUE,
pop.size = 20 * nparams,
max.generations = 10 * nparams,
wait.generations = 2 * nparams + 1,
BFGSburnin = 2 * nparams + 1,
print.level = 0,
cluster = parallel::getDefaultCluster(),
balance = nparams > 2

Check warning on line 35 in R/point-estimation.R

View check run for this annotation

Codecov / codecov/patch

R/point-estimation.R#L24-L35

Added lines #L24 - L35 were not covered by tests
)
opt <- compute_point_estimate(
pf = pf,
guess = opt$par,
verbose = FALSE

Check warning on line 40 in R/point-estimation.R

View check run for this annotation

Codecov / codecov/patch

R/point-estimation.R#L37-L40

Added lines #L37 - L40 were not covered by tests
)
x0 <- opt$par
fval <- opt$value

Check warning on line 43 in R/point-estimation.R

View check run for this annotation

Codecov / codecov/patch

R/point-estimation.R#L42-L43

Added lines #L42 - L43 were not covered by tests
}

if (verbose) {
Expand Down

0 comments on commit 554d84c

Please sign in to comment.