Skip to contents

Maximization (or minimization) of a fitness function using Hierarchic Memetic Strategy.

Usage

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
)

Arguments

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 - TRUE when fitness shall be minimized.

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 gsc_metaepochs_count for more details.

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 lsc_max_fitness_evaluations for more details.

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 sc_max_metric for more details.

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 - TRUE when run_metaepoch runs in parallel.

use_memoise

logical - FALSE when memoise package shall be used to cache fitness function values.

Value

Returns an object of class hms.

Examples

f <- function(x) x
result <- hms(fitness = f, lower = -5, upper = 5)
#> A list of standard deviations (sigma) or a function to create population should be provided.
#> Metaepoch: 0 Best fitness: 4.724964 
#> Metaepoch: 1 Best fitness: 4.96739 
#> Metaepoch: 2 Best fitness: 4.996584 
#> Metaepoch: 3 Best fitness: 4.996584 
#> Metaepoch: 4 Best fitness: 4.997446 
#> Metaepoch: 5 Best fitness: 4.997446 
#> Metaepoch: 6 Best fitness: 4.999751 
#> Metaepoch: 7 Best fitness: 4.999751 
#> Metaepoch: 8 Best fitness: 4.999751 
#> Metaepoch: 9 Best fitness: 4.999751