Title: | Multipopulation Evolutionary Strategy HMS |
---|---|
Description: | The HMS (Hierarchic Memetic Strategy) is a composite global optimization strategy consisting of a multi-population evolutionary strategy and some auxiliary methods. The HMS makes use of a dynamically-evolving data structure that provides an organization among the component populations. It is a tree with a fixed maximal height and variable internal node degree. Each component population is governed by a particular evolutionary engine. This package provides a simple R implementation with examples of using different genetic algorithms as the population engines. References: J. Sawicki, M. Łoś, M. Smołka, J. Alvarez-Aramberri (2022) <doi:10.1007/s11047-020-09836-w>. |
Authors: | Wojciech Achtelik [aut, cre], Marcin Kozubek [aut], Maciej Smołka [ths, aut] (<https://orcid.org/0000-0002-3386-0555>, Java original), AGH University of Kraków [cph] |
Maintainer: | Wojciech Achtelik <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1 |
Built: | 2025-02-06 04:42:46 UTC |
Source: | https://github.com/wojtacht/hms |
Calculate selected ELA features for given fitness.
calculate_ela_features(fitness, lower, upper)
calculate_ela_features(fitness, lower, upper)
fitness |
fitness function, that returns a numerical value. |
lower |
numeric - lower bound of the domain, a vector of length equal to the decision variables. |
upper |
numeric - upper bound of the domain, a vector of length equal to the decision variables. |
Returns a named list with values of selected ELA features.
Classify optimization problem using selected ELA features and Random Forest model trained on BBOB dataset.
classify_optimization_problem(fitness, lower, upper)
classify_optimization_problem(fitness, lower, upper)
fitness |
fitness function, that returns a numerical value, to be classified. The domain should be at least two dimensional. |
lower |
numeric - lower bound of the domain, a vector of length equal to the decision variables. |
upper |
numeric - upper bound of the domain, a vector of length equal to the decision variables. |
Returns one of c("low-conditioning", "multimodal-adequate", "multimodal-weak", "separable", "unimodal").
f <- function(x) x[[1]] + x[[2]] result <- classify_optimization_problem(fitness = f, lower = c(-5, -5), upper = c(5, 5))
f <- function(x) x[[1]] + x[[2]] result <- classify_optimization_problem(fitness = f, lower = c(-5, -5), upper = c(5, 5))
Function that runs one cmaes metaepoch. Wrapper function for cmaes::cma_es.
cma_es_metaepoch(config_cmaes)
cma_es_metaepoch(config_cmaes)
config_cmaes |
|
list with named fields: solution, population, value. See
ga_metaepoch
for more details.
tree_height <- 3 empty_config_cma_es <- lapply(1:tree_height, function(x) { list() }) cma_es_metaepoch(empty_config_cma_es)
tree_height <- 3 empty_config_cma_es <- lapply(1:tree_height, function(x) { list() }) cma_es_metaepoch(empty_config_cma_es)
Function that runs gradient method for one deme. Wrapper function for stats::optim.
default_run_gradient_method(deme, fitness, optim_args)
default_run_gradient_method(deme, fitness, optim_args)
deme |
|
fitness |
|
optim_args |
|
list with named fields: solution, population, value. See
ga_metaepoch
for more details.
Function that generates run_metaepoch function for two level HMS. First level: DE, second level: CMA-ES.
deoptim_cma_es_metaepoch(deoptim_cma_es_config)
deoptim_cma_es_metaepoch(deoptim_cma_es_config)
deoptim_cma_es_config |
|
list with named fields: solution, population, value. See
ga_metaepoch
for more details.
tree_height <- 2 de_config <- list() cma_es_config <- list() config <- list(de_config, cma_es_config) deoptim_cma_es_metaepoch(config)
tree_height <- 2 de_config <- list() cma_es_config <- list() config <- list(de_config, cma_es_config) deoptim_cma_es_metaepoch(config)
Function that runs one differential evolution metaepoch. Wrapper function for DEoptim::DEoptim.
deoptim_metaepoch(config_deoptim)
deoptim_metaepoch(config_deoptim)
config_deoptim |
|
list with named fields: solution, population, value. See
ga_metaepoch
for more details.
tree_height <- 3 empty_config_deoptim <- lapply(1:tree_height, function(x) { list() }) deoptim_metaepoch(empty_config_deoptim)
tree_height <- 3 empty_config_deoptim <- lapply(1:tree_height, function(x) { list() }) deoptim_metaepoch(empty_config_deoptim)
Function that runs one ecr metaepoch. Wrapper function for ecr::ecr.
ecr_metaepoch(config_ecr)
ecr_metaepoch(config_ecr)
config_ecr |
|
list with named fields: solution, population, value, fitness_values.
See ga_metaepoch
for more details.
tree_height <- 3 empty_config_ecr <- lapply(1:tree_height, function(x) { list() }) ecr_metaepoch(empty_config_ecr)
tree_height <- 3 empty_config_ecr <- lapply(1:tree_height, function(x) { list() }) ecr_metaepoch(empty_config_ecr)
Euclidean distance
euclidean_distance(x, y)
euclidean_distance(x, y)
x |
|
y |
|
numeric - euclidean distance between x and y
euclidean_distance(c(1, 1), c(1, 2))
euclidean_distance(c(1, 1), c(1, 2))
Function that generates run_metaepoch function for two level HMS. First level: GA, second level: CMA-ES.
ga_cma_es_metaepoch(ga_cma_es_config)
ga_cma_es_metaepoch(ga_cma_es_config)
ga_cma_es_config |
|
list with named fields: solution, population, value. See
ga_metaepoch
for more details.
tree_height <- 2 ga_config <- list() cma_es_config <- list() config <- list(ga_config, cma_es_config) ga_cma_es_metaepoch(config)
tree_height <- 2 ga_config <- list() cma_es_config <- list() config <- list(ga_config, cma_es_config) ga_cma_es_metaepoch(config)
Function that runs one GA metaepoch. Wrapper function for GA::ga.
ga_metaepoch(config_ga)
ga_metaepoch(config_ga)
config_ga |
|
list with named fields: solution, population, value, fitness_values, context or NULL. A solution is a value of the decision variable giving the best fitness. A population is a matrix representing final population. A value is the value of a fitness function for the solution. A fitness_values is a vector of fitness values for the final population. A context is a list with internal state of the metaepoch (or NULL if it's not necessary). NULL can be returned if GA::ga fails and "ignore_errors" is TRUE in the config.
tree_height <- 3 empty_config_ga <- lapply(1:tree_height, function(x) { list("ignore_errors" = TRUE) }) ga_metaepoch(empty_config_ga)
tree_height <- 3 empty_config_ga <- lapply(1:tree_height, function(x) { list("ignore_errors" = TRUE) }) ga_metaepoch(empty_config_ga)
Factory function for a global stopping condition that stops the computation after fitness function has been evaluated given number of times.
gsc_max_fitness_evaluations(max_evaluations)
gsc_max_fitness_evaluations(max_evaluations)
max_evaluations |
|
Function that receives a list of metaepoch snapshots and returns a Boolean value determining whether the computation should be stopped based on how many fitness function evaluations have been made, which can be used as a global stopping condition for the hms function.
global_stopping_condition <- gsc_max_fitness_evaluations(10000)
global_stopping_condition <- gsc_max_fitness_evaluations(10000)
Factory function for a global stopping condition that stops the computation after given number of metaepochs.
gsc_metaepochs_count(metaepochs_count)
gsc_metaepochs_count(metaepochs_count)
metaepochs_count |
|
Function that receives a list of metaepoch snapshots and returns a Boolean value determining whether the computation should be stopped based on how many metaepochs have passed, which can be used as a global stopping condition for the hms function.
global_stopping_condition <- gsc_metaepochs_count(10)
global_stopping_condition <- gsc_metaepochs_count(10)
Factory function for a global stopping condition that never stops the computation. It results in hms running until there are no more active demes.
gsc_trivial()
gsc_trivial()
function that always returns FALSE
, which can be used
as a global stopping condition for the hms function.
global_stopping_condition <- gsc_trivial()
global_stopping_condition <- gsc_trivial()
Maximization (or minimization) of a fitness function using Hierarchic Memetic Strategy.
hms( tree_height = 3, minimize = FALSE, fitness, lower, upper, sigma = default_sigma(lower, upper, tree_height), population_sizes = default_population_sizes(tree_height), run_metaepoch = default_ga_metaepoch(tree_height), gsc = gsc_default, lsc = lsc_default, sc = sc_max_metric(euclidean_distance, sprouting_default_euclidean_distances(sigma)), create_population = default_create_population(sigma), suggestions = NULL, with_gradient_method = FALSE, gradient_method_args = default_gradient_method_args, run_gradient_method, monitor_level = "basic", parallel = FALSE, use_memoise = FALSE )
hms( tree_height = 3, minimize = FALSE, fitness, lower, upper, sigma = default_sigma(lower, upper, tree_height), population_sizes = default_population_sizes(tree_height), run_metaepoch = default_ga_metaepoch(tree_height), gsc = gsc_default, lsc = lsc_default, sc = sc_max_metric(euclidean_distance, sprouting_default_euclidean_distances(sigma)), create_population = default_create_population(sigma), suggestions = NULL, with_gradient_method = FALSE, gradient_method_args = default_gradient_method_args, run_gradient_method, monitor_level = "basic", parallel = FALSE, use_memoise = FALSE )
tree_height |
numeric - default value: 5. It determines the maximum tree height which will usually be reached unless a very strict local stopping condition, global stopping condition or sprouting condition is used. |
minimize |
logical - |
fitness |
fitness function, that returns a numerical value, to be optimized by the strategy. |
lower |
numeric - lower bound of the domain, a vector of length equal to the decision variables. |
upper |
numeric - upper bound of the domain, a vector of length equal to the decision variables. |
sigma |
numeric - Vector of standard deviations for each tree level used to create a population of a sprouted deme. |
population_sizes |
numeric - Sizes of deme populations on each tree level. |
run_metaepoch |
A function that takes 5 parameters: fitness, suggestions, lower, upper, tree_level, runs a metaepoch on the given deme population and returns list with 3 named fields: solution, population, value. |
gsc |
global stopping condition function taking a list of MetaepochSnapshot
objects and returning a logical value; it is evaluated after every metaepoch and
determines whether whole computation should be stopped. See |
lsc |
local stopping condition - function taking a deme and a list of MetaepochSmapshot
objects representing previous metaepochs; it is run on every deme after it has run a metaepoch
and determines whether that deme will remain active. See |
sc |
sprouting condition - function taking 3 arguments: an individual, a tree level
and a list of Deme objects; it determines whether the given individual can sprout a new deme
on the given level. See |
create_population |
function taking 6 parameters: mean, lower, upper, population_size, tree_level, sigma that returns a population for a Deme object to be created on the given tree level. |
suggestions |
matrix of individuals for the initial population of the root |
with_gradient_method |
logical determining whether a gradient method should be run for all leaves at the end of the computation to refine their best solutions. |
gradient_method_args |
list of parameters that are passed to the gradient method |
run_gradient_method |
function - returns list with named fields: solution, population, value |
monitor_level |
string - one of: 'none', 'basic', 'basic_tree', 'verbose_tree'. |
parallel |
logical - |
use_memoise |
logical - |
Returns an object of class hms.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5)
A S4 class representing a result of hms.
root_id
character - UUID of a root Deme.
metaepoch_snapshots
list of objects of class MetaepochSnapshot.
best_fitness
numeric - best fitness value of all metaepochs.
best_solution
numeric - best solution of all metaepochs.
total_time_in_seconds
numeric - time of a hms execution in seconds.
total_metaepoch_time_in_seconds
numeric - time of all metaepochs in seconds.
metaepochs_count
numeric - total number of all metaepochs.
deme_population_sizes
numeric - sizes of deme populations on each tree level.
Same as population_sizes
parameter of hms function.
lower
numeric - lower bound of the domain, a vector of length equal to the decision variables.
upper
numeric - upper bound of the domain, a vector of length equal to the decision variables.
call
language - an object of class "call" representing the matched call.
Factory function for a local stopping condition that stops a deme after given number of fitness function evaluations has been made in that deme.
lsc_max_fitness_evaluations(max_evaluations)
lsc_max_fitness_evaluations(max_evaluations)
max_evaluations |
|
Function that can be used as a local stopping condition for hms.
local_stopping_condition <- lsc_max_fitness_evaluations(500)
local_stopping_condition <- lsc_max_fitness_evaluations(500)
Factory function for a local stopping condition that stops a deme after given number of metaepochs have past since last metaepoch during which this deme had an active child.
lsc_metaepochs_without_active_child(metaepochs_limit)
lsc_metaepochs_without_active_child(metaepochs_limit)
metaepochs_limit |
|
Function that can be used as a local stopping condition for hms.
local_stopping_condition <- lsc_metaepochs_without_active_child(3)
local_stopping_condition <- lsc_metaepochs_without_active_child(3)
Factory function for a local stopping condition that stops a deme after given number of consecutive metaeopochs without an improvement of the best solution found in that deme.
lsc_metaepochs_without_improvement(max_metaepochs_without_improvement)
lsc_metaepochs_without_improvement(max_metaepochs_without_improvement)
max_metaepochs_without_improvement |
|
Function that can be used as a local stopping condition for hms.
local_stopping_condition <- lsc_metaepochs_without_improvement(5)
local_stopping_condition <- lsc_metaepochs_without_improvement(5)
Factory function for a trivial local stopping condition that lets a deme be active forever. It is usually used in the root of a hms tree.
lsc_trivial()
lsc_trivial()
Function that always returns FALSE
, which can be
used as a local stopping condition for hms.
local_stopping_condition <- lsc_trivial()
local_stopping_condition <- lsc_trivial()
Manhattan distance
manhattan_distance(x, y)
manhattan_distance(x, y)
x |
|
y |
|
numeric - manhattan distance between x and y
manhattan_distance(c(1, 1), c(1, 2))
manhattan_distance(c(1, 1), c(1, 2))
A S4 class representing a snapshot of one metaepoch.
demes
list of objects of class Deme.
best_fitness
numeric - best fitness value of a metaepoch.
best_solution
numeric - best solution of a metaepoch.
time_in_seconds
numeric - time of metaepoch in seconds.
fitness_evaluations
numeric - number of fitness evaluations.
blocked_sprouts
list - list of sprouts that were blocked by sprouting
condition. A sprout is a potential origin of a new Deme, it can be blocked
by sc – sprouting condition. See sc_max_metric
for more details.
is_evolutionary
logical - TRUE
for all metaepochs except the
gradient one.
Plot method for "hms" class.
## S4 method for signature 'hms' plot(x)
## S4 method for signature 'hms' plot(x)
x |
|
It doesn't return anything meaningful. It plots the fitness by metaepoch count.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plot(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plot(result)
plotActiveDemes method for "hms" class.
plotActiveDemes(object)
plotActiveDemes(object)
object |
|
It doesn't return anything meaningful. It plots the number of active demes per metaepoch.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotActiveDemes(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotActiveDemes(result)
plotActiveDemes method for "hms" class.
## S4 method for signature 'hms' plotActiveDemes(object)
## S4 method for signature 'hms' plotActiveDemes(object)
object |
|
It doesn't return anything meaningful. It plots the number of active demes per metaepoch.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotActiveDemes(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotActiveDemes(result)
plotPopulation method for "hms" class.
plotPopulation(object, dimensions)
plotPopulation(object, dimensions)
object |
|
dimensions |
|
It doesn't return anything meaningful. It plots the selected two dimensions of a population.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotPopulation(result, c(1, 1))
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotPopulation(result, c(1, 1))
plotPopulation method for "hms" class.
## S4 method for signature 'hms' plotPopulation(object, dimensions)
## S4 method for signature 'hms' plotPopulation(object, dimensions)
object |
|
dimensions |
|
It doesn't return anything meaningful. It plots the selected two dimensions of a population.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotPopulation(result, c(1, 1))
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) plotPopulation(result, c(1, 1))
Print method for class "hms".
## S4 method for signature 'hms' print(x, ...)
## S4 method for signature 'hms' print(x, ...)
x |
|
... |
|
It does not return anything. The obvious side effect is output to the terminal.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) print(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) print(result)
printBlockedSprouts method for "hms" class.
printBlockedSprouts(object)
printBlockedSprouts(object)
object |
|
It doesn't return anything. It prints blocked sprouts per metaepoch.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printBlockedSprouts(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printBlockedSprouts(result)
printBlockedSprouts method for "hms" class.
## S4 method for signature 'hms' printBlockedSprouts(object)
## S4 method for signature 'hms' printBlockedSprouts(object)
object |
|
It doesn't return anything. It prints blocked sprouts per metaepoch.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printBlockedSprouts(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printBlockedSprouts(result)
printTree method for class "hms".
printTree(object)
printTree(object)
object |
|
It does not return anything. It prints the hms tree.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printTree(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printTree(result)
printTree method for class "hms".
## S4 method for signature 'hms' printTree(object)
## S4 method for signature 'hms' printTree(object)
object |
|
It does not return anything. It prints the hms tree.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printTree(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) printTree(result)
Given the domain bounds and standard deviation returns a function compatible with GA interface that performs a mutation on the given individual using truncated normal distribution.
rtnorm_mutation(lower, upper, sd)
rtnorm_mutation(lower, upper, sd)
lower |
|
upper |
|
sd |
|
Function that takes two parameters (the GA object object
and an individual to perform the mutation on parent
) and returns
a new individual that is the result of normal mutation applied to the parent.
mutation <- rtnorm_mutation( lower = rep(-500, 5), upper = rep(500, 5), sd = rep(50, 5) )
mutation <- rtnorm_mutation( lower = rep(-500, 5), upper = rep(500, 5), sd = rep(50, 5) )
saveMetaepochsPopulations method for "hms" class.
saveMetaepochsPopulations(object, path, dimensions)
saveMetaepochsPopulations(object, path, dimensions)
object |
hms s4 object |
path |
path |
dimensions |
vector of two selected dimensions e.g. c(1,2) |
It doesn't return anything. It creates plots and saves them to a specified directory.
fitness <- function(x) x[1] + x[2] lower <- c(-5, -5) upper <- c(5, 5) result <- hms(fitness = fitness, lower = lower, upper = upper) selected_dimensions <- c(1, 2) saveMetaepochsPopulations(result, tempdir(), selected_dimensions)
fitness <- function(x) x[1] + x[2] lower <- c(-5, -5) upper <- c(5, 5) result <- hms(fitness = fitness, lower = lower, upper = upper) selected_dimensions <- c(1, 2) saveMetaepochsPopulations(result, tempdir(), selected_dimensions)
saveMetaepochsPopulations
## S4 method for signature 'hms' saveMetaepochsPopulations(object, path, dimensions)
## S4 method for signature 'hms' saveMetaepochsPopulations(object, path, dimensions)
object |
hms s4 object |
path |
path |
dimensions |
vector of two selected dimensions e.g. c(1,2) |
It doesn't return anything. It creates plots and saves them to a specified directory.
fitness <- function(x) x[1] + x[2] lower <- c(-5, -5) upper <- c(5, 5) result <- hms(fitness = fitness, lower = lower, upper = upper) selected_dimensions <- c(1, 2) saveMetaepochsPopulations(result, tempdir(), selected_dimensions)
fitness <- function(x) x[1] + x[2] lower <- c(-5, -5) upper <- c(5, 5) result <- hms(fitness = fitness, lower = lower, upper = upper) selected_dimensions <- c(1, 2) saveMetaepochsPopulations(result, tempdir(), selected_dimensions)
It allows an individual to sprout only if there are no other demes on the target level that have centroid within the given distance.
sc_max_metric(metric, max_distances)
sc_max_metric(metric, max_distances)
metric |
|
max_distances |
|
Function that can be used as a sprouting condition of hms.
sprouting_condition <- sc_max_metric(euclidean_distance, c(20, 10))
sprouting_condition <- sc_max_metric(euclidean_distance, c(20, 10))
Show method for class "hms".
## S4 method for signature 'hms' show(object)
## S4 method for signature 'hms' show(object)
object |
|
It returns the names of the slots and the classes associated with the slots in the "hms" class. It prints call details.
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) show(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) show(result)
Summary method for class "hms".
## S4 method for signature 'hms' summary(object, ...)
## S4 method for signature 'hms' summary(object, ...)
object |
|
... |
|
Returns a list with fields: fitness, solution, metaepochs, deme_population_sizes, lower_bound, upper_bound, computation_time. These fields should match fields of class "hms".
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) summary(result)
f <- function(x) x result <- hms(fitness = f, lower = -5, upper = 5) summary(result)
Train Random Forest model on BBOB dataset (data/ela_features.rda).
train_random_forest_model()
train_random_forest_model()
Returns a Random Forest model trained on ela_features dataset which is stored internally in sysdata.rda. The ela_features dataset, created using the flacco package, includes ELA features for all BBOB functions (all available fids) across different dimensions (2, 5, 10, 20) and instances (1:20). Key features captured are ic.eps.ratio, nbc.nb_fitness.cor, ela_meta.quad_simple.adj_r2, and ela_meta.lin_simple.adj_r2, along with function type.