Skip to content

Commit

Permalink
Many improvements to ablation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MLopez-Ibanez committed Jan 11, 2025
1 parent eac7fa2 commit 15c4c26
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 187 deletions.
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
* Now `blockSize` multiplies `elitistNewInstances`, which should ensure that
irace evaluates instances in blocks.

* Several improvements in `ablation()` may result in different ablation
results using this version of irace. Also, the log generated by `ablation()`
has some important changes to record more detailed information and it is
more consistent with the log generated by `irace()`.

## New features and improvements

* When `targetRunner` or `targetEvaluator` are implemented in R, using random
Expand All @@ -28,6 +33,14 @@
* `getConfigurationById()` now returns configurations in the same order
(including repeated values) of the IDs passed as argument.

* `ablation(type="full")` will evaluate all intermediate configurations on all
instances at once. This makes better use of parallel resources but will not
report any information about progress after each instance.

* `ablation()` now works better with dependent-domain parameters and with
complicated conditions. Ablation will not generate intermediate
configurations that are forbidden.

## Fixes

* Fix #76: Recovery (`--recover-file`) is working again with a completely new implementation.
Expand Down
296 changes: 155 additions & 141 deletions R/ablation.R

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions R/generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ repairConfigurations <- function(x, parameters, repair)
x
}

is_within_dependent_bound <- function(param, configuration, value)
{
domain <- unlist(lapply(param[["domain"]], eval, configuration))
# Value gets truncated (defined from robotics initial requirements)
if (param[["type"]] == "i")
domain <- as.integer(domain)
domain[[1L]] <= value && value <= domain[[2L]]
}

## Calculates the parameter bounds when parameters domain is dependent
getDependentBound <- function(param, configuration)
{
Expand Down Expand Up @@ -87,12 +96,12 @@ generate_sobol <- function(parameters, n, repair = NULL)
# FIXME: How to do this faster using data.table?
for (x in nodep_names)
set(confs, j = x, value = param_quantile(parameters$get(x), confs[[x]]))

for (x in parameters$names_fixed)
set(confs, j = x, value = parameters$domains[[x]])

setcolorder(confs, parameters$names)

max_level <- max(hierarchy)
if (max_level > 1L) {
.NEWVALUE <- .DOMAIN <- NULL # To silence CRAN warnings.
Expand Down Expand Up @@ -136,7 +145,7 @@ sampleSobol <- function(parameters, n, repair = NULL)
{
newConfigurations <- generate_sobol(parameters, n, repair)
newConfigurations <- unique(newConfigurations)
forbidden <- parameters$forbidden
forbidden <- parameters$forbidden
newConfigurations <- filter_forbidden(newConfigurations, forbidden)
have <- nrow(newConfigurations)
if (have < n) {
Expand Down Expand Up @@ -190,7 +199,7 @@ generate_uniform <- function(parameters, nbConfigurations, repair = NULL)
sampleUniform <- function(parameters, nbConfigurations, repair = NULL)
{
newConfigurations <- generate_uniform(parameters, nbConfigurations, repair)
forbidden <- parameters$forbidden
forbidden <- parameters$forbidden
if (!is.null(forbidden)) {
retries <- 100L
repeat {
Expand Down Expand Up @@ -219,7 +228,7 @@ sample_from_model <- function(parameters, eliteConfigurations, model,
print(utils::str(ids_elites))
print(utils::str(eliteConfigurations[[".ID."]]))
})

newConfigurations <- configurations_alloc(parameters$names, nrow = nbNewConfigurations, parameters)
idx_elites <- sample.int(n = length(ids_elites), size = nbNewConfigurations,
prob = eliteConfigurations[[".WEIGHT."]], replace = TRUE)
Expand Down Expand Up @@ -286,11 +295,3 @@ sampleModel <- function(parameters, eliteConfigurations, model,
}
newConfigurations
}








19 changes: 7 additions & 12 deletions devel-examples/vignette-example/create-example-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ parameters <- readParameters(text = parameters_table)
## configuration on a single instance. For simplicity, we restrict to
## three-dimensional functions and we set the maximum number of
## iterations of SANN to 5000.

target_runner <- function(experiment, scenario)
{
instance <- experiment$instance
configuration <- experiment$configuration
D <- 3
D <- 3L
par <- runif(D, min=-1, max=1)
fn <- function(x) {
# Functions to be optimized:
Expand All @@ -39,7 +38,7 @@ target_runner <- function(experiment, scenario)
}
f_rastrigin <- function (x)
sum(x * x - 10 * cos(2 * pi * x) + 10)

(instance * f_rastrigin(x) + (1 - instance) * f_rosenbrock(x))
}
res <- stats::optim(par,fn, method="SANN",
Expand Down Expand Up @@ -79,10 +78,6 @@ save(iraceResults, file="sann.rda", version = 3L)

### ACOTSP example

iracebin <- system.file(package="irace", "bin/irace")
if (0 != file.access(iracebin, mode=1))
stop("Error: ", iracebin, " is not executable or not found!")

download_uncompress <- function(url, exdir, flat = FALSE) {
exts <- c(".tar.bz2", ".tar.gz", ".tgz", ".tar.xz", ".zip")
fileext <- exts[endsWith(url, exts)]
Expand Down Expand Up @@ -132,11 +127,14 @@ setup_acotsp <- function() {
setup_tsp_rue_2000()
setup_acotsp()

iracebin <- system.file(package="irace", "bin/irace")
if (0 != file.access(iracebin, mode=1))
stop("Error: ", iracebin, " is not executable or not found!")
system(paste0("nice -n 19 ", iracebin, " --parallel 2 | tee irace-acotsp-stdout.txt 2>&1"))

# Create log-ablation.Rdata
cat('**** Running ablation("irace-acotsp.Rdata")\n')
ablation("irace-acotsp.Rdata", parallel = 1)
ablation("irace-acotsp.Rdata", parallel = 2L)

iraceResults <- read_logfile("irace-acotsp.Rdata")

Expand Down Expand Up @@ -171,7 +169,7 @@ experiment <- list (
id_instance = res[["instanceID"]],
seed = res[["seed"]],
configuration = getConfigurationById(iraceResults, 1L, drop.metadata = TRUE),
instance = res[["instance"]],
instance = res[["instance"]],
switches = iraceResults$scenario$parameters$switches)

# Output
Expand All @@ -182,6 +180,3 @@ output <- list(

# save in the folder
save(experiment, output, file="examples.Rdata", version = 3L)



6 changes: 3 additions & 3 deletions man/ablation.Rd

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

6 changes: 3 additions & 3 deletions man/ablation_cmdline.Rd

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

4 changes: 2 additions & 2 deletions man/read_ablogfile.Rd

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

Loading

0 comments on commit 15c4c26

Please sign in to comment.