Skip to content

Commit

Permalink
Programmatically create parameter spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
MLopez-Ibanez committed Mar 7, 2024
1 parent 101043a commit c158eb1
Show file tree
Hide file tree
Showing 18 changed files with 1,247 additions and 972 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(print,ParameterSpace)
export(CommandArgsParser)
export(ablation)
export(ablation_cmdline)
Expand All @@ -25,6 +26,11 @@ export(irace.main)
export(irace.version)
export(irace_summarise)
export(multi_irace)
export(param_cat)
export(param_int)
export(param_ord)
export(param_real)
export(parametersNew)
export(path_rel2abs)
export(plotAblation)
export(printParameters)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

* Initial configurations are sampled using Sobol low-discrepancy sequences using `spacefillr::generate_sobol_set()`. This should provide a better initial distribution of parameter values.

* Parameter spaces can be constructed programmatically using `parametersNew()`.

* Ablation will report configurations that produced the same results, which
indicates parameter values that have the same effect on the target algorithm,
possibly indicating a bug in the target algorithm.
Expand Down Expand Up @@ -130,7 +132,6 @@
same or different scenarios and parameters, possibly in parallel.
(Contributed by @Saethox)


## Fixes

* Fix #66: when using `maxTime > 0`, irace estimates the time per run by
Expand Down
22 changes: 11 additions & 11 deletions R/ablation.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ fixDependenciesWithReference <- function(configuration, ref_configuration, param
{
# Search parameters that need a value
changed <- c()
for (pname in names(which(!parameters[["isFixed"]]))) {
for (pname in parameters$names_variable) {
# If dependent parameter has been activated, set the value of the reference.
if (is.na(configuration[,pname]) && conditionsSatisfied(parameters, configuration, pname)) {
if (is.na(configuration[[pname]]) && conditionsSatisfied(parameters$conditions[[pname]], configuration)) {
if (!is.null(ref_configuration)) {
configuration[,pname] <- ref_configuration[pname]
configuration[[pname]] <- ref_configuration[pname]
}
changed <- c(changed, pname)
# MANUEL: Why do we need to recurse here?
Expand All @@ -158,28 +158,28 @@ fixDependenciesWithReference <- function(configuration, ref_configuration, param
generateAblation <- function(initial_configuration, final_configuration,
parameters, param_names = NULL)
{
# Only change variable parameters
if (is.null(param_names))
param_names <- parameters[["names"]]

# Only change non-fixed
param_names <- param_names[!parameters[["isFixed"]][param_names]]
param_names <- parameters$names_variable
else
param_names <- setdiff(param_names, parameters$names_fixed)

configurations <- NULL
changed_params <- list()
for (pname in param_names) {
# Check if parameter is active.
if (!conditionsSatisfied(parameters, initial_configuration, pname)) next
if (!conditionsSatisfied(parameters$conditions[[pname]], initial_configuration)) next
# Check value is different in the initial and final configuration and if
# so, change the value.
if (initial_configuration[, pname] == final_configuration[, pname]) next
if (initial_configuration[[pname]] == final_configuration[[pname]]) next
new_configuration <- initial_configuration
new_configuration[, pname]<- final_configuration[,pname]
new_configuration[[pname]] <- final_configuration[[pname]]
# Set newly activated parameters if needed.
aux <- fixDependenciesWithReference(new_configuration, final_configuration, parameters)
new_configuration <- aux[["configuration"]]
changed_params[[length(changed_params) + 1L]] <- c(pname, aux[["changed"]])
new_configuration[[".PARENT."]] <- initial_configuration[[".ID."]]
configurations <- rbind.data.frame(configurations, new_configuration)
configurations <- rbind.data.frame(configurations, new_configuration)
}
rownames(configurations) <- NULL
list(configurations=configurations, changed_params=changed_params)
Expand Down
4 changes: 2 additions & 2 deletions R/configurations.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configurations_alloc <- function(colnames, nrow, parameters)
.WEIGHT. = NA_real_,
parameter_type(types[x])), n)

x <- sapply(colnames, column_type, n=nrow, types = parameters$types,
x <- sapply(colnames, column_type, n=nrow, types = parameters[["types"]],
simplify=FALSE, USE.NAMES=TRUE)
setDT(x)
x
Expand All @@ -43,7 +43,7 @@ which_satisfied <- function(configurations, condition)
{
# If there is no condition, do not waste time evaluating it.
if (isTRUE(condition))
return(seq_len(nrow(configurations)))
return(seq_nrow(configurations))
r <- eval(condition, configurations)
# Return TRUE if TRUE, FALSE if FALSE or NA
## FIXME: If we byte-compile the condition, then we should incorporate the
Expand Down
Loading

0 comments on commit c158eb1

Please sign in to comment.