Title: Feature-Based Landscape Analysis of Continuous and Constrained Optimization Problems
Description: Tools and features for "Exploratory Landscape Analysis (ELA)" of single-objective continuous optimization problems. Those features are able to quantify rather complex properties, such as the global structure, separability, etc., of the optimization problems.
URL: https://github.com/kerschke/flacco
BugReports: https://github.com/kerschke/flacco/issues
License: BSD_2_clause + file LICENSE
Encoding: UTF-8
Depends: R (≥ 3.0.0)
Imports: BBmisc, checkmate, mlr
Suggests: devtools, e1071, ggplot2, lhs, MASS, Matrix, mda, mlbench, numDeriv, parallel, parallelMap, ParamHelpers, plotly, plyr, RANN, R.rsp, rpart, shape, shiny, smoof, testthat
LazyData: yes
ByteCompile: yes
Version: 1.8
Date: 2020-03-31
RoxygenNote: 7.1.0
VignetteBuilder: R.rsp
NeedsCompilation: no
Packaged: 2020-03-31 18:16:56 UTC; kerschke
Author: Pascal Kerschke [aut, cre], Christian Hanster [ctb], Jan Dagefoerde [ctb]
Maintainer: Pascal Kerschke <kerschke@uni-muenster.de>
Repository: CRAN
Date/Publication: 2020-03-31 20:10:02 UTC

Shiny server function for BBOB import page module

Description

BBOBImport is a shiny server function which will control all aspects of the BBOBImportPage UI Module. It will be called with callModule.

Usage

BBOBImport(input, output, session, stringsAsFactors)

Arguments

input

[shiny-input]
shiny input variable for the specific UI module.

output

[shiny-output object]
shiny output variable for the specific UI module.

session

[shiny-session object]
shiny session variable for the specific UI module.

stringsAsFactors

[logical(1)]
How should strings be treated internally?


Shiny UI-Module for Batch Import of BBOB Functions

Description

BBOBImportPage is a shiny component which can be added to your shiny app so that you get a batch import for several BBOB functions.

Usage

BBOBImportPage(id)

Arguments

id

[character(1)]
Character representing the namespace of the shiny component.

Details

It will load a CSV-file with BBOB parameters (the function ID, instance ID and problem dimension) and then calculate the selected features for the specific function(s).


Create a Feature Object

Description

Create a FeatureObject, which will be used as input for all the feature computations.

Usage

createFeatureObject(
  init,
  X,
  y,
  fun,
  minimize,
  lower,
  upper,
  blocks,
  objective,
  force = FALSE
)

Arguments

init

[data.frame]
A data.frame, which can be used as initial design. If not provided, it will be created either based on the initial sample X and the objective values y or X and the function definition fun.

X

[data.frame or matrix]
A data.frame or matrix containing the initial sample. If not provided, it will be extracted from init.

y

[numeric or integer]
A vector containing the objective values of the initial design. If not provided, it will be extracted from init.

fun

[function]
A function, which allows the computation of the objective values. If it is not provided, features that require additional function evaluations, can't be computed.

minimize

[logical(1)]
Should the objective function be minimized? The default is TRUE.

lower

[numeric or integer]
The lower limits per dimension.

upper

[numeric or integer]
The upper limits per dimension.

blocks

[integer]
The number of blocks per dimension.

objective

[character(1)]
The name of the feature, which contains the objective values. The default is "y".

force

[logical(1)]
Only change this parameter IF YOU KNOW WHAT YOU ARE DOING! Per default (force = FALSE), the function checks whether the total number of cells that you are trying to generate, is below the (hard-coded) internal maximum of 25,000 cells. If you set this parameter to TRUE, you agree that you want to exceed that internal limit.
Note: *Exploratory Landscape Analysis (ELA)* is only useful when you are limited to a small budget (i.e., a small number of function evaluations) and in such scenarios, the number of cells should also be kept low!

Value

[FeatureObject].

Examples

# (1a) create a feature object using X and y:
X = createInitialSample(n.obs = 500, dim = 3,
  control = list(init_sample.lower = -10, init_sample.upper = 10))
y = apply(X, 1, function(x) sum(x^2))
feat.object1 = createFeatureObject(X = X, y = y, 
  lower = -10, upper = 10, blocks = c(5, 10, 4))

# (1b) create a feature object using X and fun:
feat.object2 = createFeatureObject(X = X, 
  fun = function(x) sum(sin(x) * x^2),
  lower = -10, upper = 10, blocks = c(5, 10, 4))

# (1c) create a feature object using a data.frame:
feat.object3 = createFeatureObject(iris[,-5], blocks = 5, 
  objective = "Petal.Length")

# (2) have a look at the feature objects:
feat.object1
feat.object2
feat.object3

# (3) now, one could calculate features
calculateFeatureSet(feat.object1, "ela_meta")
calculateFeatureSet(feat.object2, "cm_grad")
library(plyr)
calculateFeatureSet(feat.object3, "cm_angle", control = list(cm_angle.show_warnings = FALSE))


Shiny Server Function for Feature Set Component

Description

FeatureSetCalculation is a shiny server function which will control all aspects of the FeatureSetCalculationComponent UI Module. Will be called with callModule.

Usage

FeatureSetCalculation(input, output, session, stringsAsFactors, feat.object)

Arguments

input

[shiny-input]
shiny input variable for the specific UI module.

output

[shiny-output object]
shiny output variable for the specific UI module.

session

[shiny-session object]
shiny session variable for the specific UI module.

stringsAsFactors

[logical(1)]
How should strings be treated internally?

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

Details

It will take the user input and calculate the selected feature set. In order to calculate a feature set, the function needs a FeatureObject.


Shiny UI-Module for Calculating and Displaying Feature Sets

Description

FeatureSetCalculationComponent is a shiny UI-component which can be added to your shiny app so that you can calculate and display different feature sets.

Usage

FeatureSetCalculationComponent(id)

Arguments

id

[character(1)]
Character representing the namespace of the shiny component.

Details

The component integrates a select-Input for choosing the feature set, which should be calculated and displayed in a table. With the download button the calculated features can be exported as CSV-file.


Shiny Server Function for Feature Set Component

Description

FeatureSetVisualization is a shiny server function which will control all aspects of the FeatureSetVisualizationComponent UI-Module. It will be called with callModule.

Usage

FeatureSetVisualization(input, output, session, stringsAsFactors, feat.object)

Arguments

input

[shiny-input]
shiny input variable for the specific UI module.

output

[shiny-output object]
shiny output variable for the specific UI module.

session

[shiny-session object]
shiny session variable for the specific UI module.

stringsAsFactors

[logical(1)]
How should strings be treated internally?

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

Details

It will take the user input and plot the selected visualization. To create a flacco plot, the function needs a FeatureObject.


Shiny Component for Visualizing the Feature Sets

Description

FeatureSetVisualizationComponent is a shiny component which can be added to your shiny app so that you can display different feature set plots.

Usage

FeatureSetVisualizationComponent(id)

Arguments

id

[character(1)]
Character representing the namespace of the shiny component.

Details

It integrates a select input where the user can select the plot which should be created.


Shiny Server Function for BBOB Import Page Module

Description

SmoofImport is a shiny server function which will control all aspects of the SmoofImportPage-UI Module. It will be called with callModule.

Usage

SmoofImport(input, output, session, stringsAsFactors)

Arguments

input

[shiny-input]
shiny input variable for the specific UI module.

output

[shiny-output object]
shiny output variable for the specific UI module.

session

[shiny-session object]
shiny session variable for the specific UI module.

stringsAsFactors

[logical(1)]
How should strings be treated internally?


Shiny UI-Module for Batch Import of Smoof Functions

Description

SmoofImportPage is a shiny UI-component which can be added to your shiny app so that you get a batch import for a specific shiny function but different parameters.

Usage

SmoofImportPage(id)

Arguments

id

[character(1)]
Character representing the namespace of the shiny component.

Details

It will load a CSV-file with parameters for the smoof function and calculate the selected features for the specific function.


Calculate Landscape Features

Description

Performs an Exploratory Landscape Analysis of a continuous function and computes various features, which quantify the function's landscape. Currently, the following feature sets are provided:

Usage

calculateFeatureSet(feat.object, set, control, ...)

calculateFeatures(feat.object, control, ...)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

set

[character(1)]
Name of the feature set, which should be computed. All possible feature sets can be listed using listAvailableFeatureSets.

control

[list]
A list, which stores additional control arguments. For further information, see details.

...

[any]
Further arguments, e.g. handled by optim (within the computation of the ELA local search features) or density (within the computation of the ELA y-distribution features).

Details

Note that if you want to speed up the runtime of the features, you might consider running your feature computation parallelized. For more information, please refer to the parallelMap package or to https://mlr.mlr-org.com/articles/tutorial/parallelization.html.

Furthermore, please consider adapting the feature computation to your needs. Possible control arguments are:

Value

list of (numeric) features:

References

Examples

# (1) create a feature object:
X = t(replicate(n = 2000, expr = runif(n = 5, min = -10, max = 10)))
## Not run: feat.object = createFeatureObject(X = X, fun = function(x) sum(x^2))

# (2) compute all non-cellmapping features
ctrl = list(allow_cellmapping = FALSE)
## Not run: features = calculateFeatures(feat.object, control = ctrl)

# (3) in order to allow the computation of the cell mapping features, one
# has to provide a feature object that has knowledge about the number of
# cells per dimension:
f = function(x) sum(x^2)
feat.object = createFeatureObject(X = X, fun = f, blocks = 3)
## Not run: features = calculateFeatures(feat.object)

# (4) if you want to compute a specific feature set, you can use
# calculateFeatureSet:
features.angle = calculateFeatureSet(feat.object, "cm_angle")

# (5) as noted in the details, it might be useful to compute the levelset
# features parallelized:
## Not run: 
library(parallelMap)
library(parallel)
n.cores = detectCores()
parallelStart(mode = "socket", cpus = n.cores,
  logging = FALSE, show.info = FALSE)
system.time((levelset.par = calculateFeatureSet(feat.object, "ela_level")))
parallelStop()
system.time((levelset.seq = calculateFeatureSet(feat.object, "ela_level")))
## End(Not run)


Compute the Cell Centers of a Cell Mapping Grid

Description

Computes the cell centers and the corresponding cell IDs of a cell mapping grid.

Usage

computeGridCenters(lower, upper, blocks)

Arguments

lower

[numeric or integer]
The lower limits per dimension.

upper

[numeric or integer]
The upper limits per dimension.

blocks

[integer]
The number of blocks per dimension.

Value

[data.frame].
A data.frame, which includes the coordinates of the cell centers, as well as the corresponding cell ID (cell.ID).

Examples

computeGridCenters(lower = -10, upper = 10, blocks = c(10, 5, 8))


Converts an Initial Design into a Cell Mapping Grid

Description

This function takes an initial design – with rows being the observations and columns standing for the dimensions (plus the corresponding objective) – and adds an additional column to the data.frame. This additional column states the cell ID for each observation.

Usage

convertInitDesignToGrid(init, lower, upper, blocks)

Arguments

init

[data.frame]
The initial design, consisting of d + 1 columns (d dimensions and one column for the objective value) and one row per observation.

lower

[numeric or integer]
The lower limits per dimension.

upper

[numeric or integer]
The upper limits per dimension.

blocks

[integer]
The number of blocks per dimension.

Value

[data.frame].
A data.frame, which includes an additional column (cell.ID) compared to the initial design (init). The cell.ID will be a value between 1 and prod(blocks).

Examples

# (1) create an initial design:
X = t(replicate(n = 200, expr = runif(n = 5, min = -10, max = 10)))
f = function(x) sum(x^2)
y = apply(X = X, MARGIN = 1, FUN = f)
init = data.frame(X, y = y)

# (2) compute the cell mapping grid
convertInitDesignToGrid(init = init, lower = -10, upper = 10, blocks = 20)


Create Initial Sample

Description

Convenient helper function, which creates an initial sample - either based on random (uniform) sampling or using latin hypercube sampling.

Usage

createInitialSample(n.obs, dim, control)

Arguments

n.obs

[integer(1)]
Number of observations.

dim

[integer(1)]
Number of dimensions.

control

[list]
Control argument. For further information refer to the details.

Details

Per default, this function will produce n.obs observations of size dim in the range from 0 to 1. If you want to create a more specific initial sample, the following control arguments might be helpful:

Value

[matrix].
A matrix, consisting of n.obs rows of dim-dimensional observations.

Examples

# (1) create a simple initial sample:
X = createInitialSample(300, 5)
summary(X)

# (2) create a more specific initial sample:
ctrl = list(init_sample.type = "lhs",
  init_sample.lower = c(-5, 2, 0),
  init_sample.upper = 10)
X = createInitialSample(200, 3, control = ctrl)
summary(X)


Feature List

Description

Contains a list of features. This could be the result of a feature selection (based on a nested resampling strategy) executed on the Glass data.


Shiny UI-Module for Function Input

Description

featObject_sidebar is a shiny UI-component which can be added to your shiny app so that you can easily generate a feature object by providing all relevant information.

Usage

featureObject_sidebar(id)

Arguments

id

[character(1)]
Character representing the namespace of the shiny component.


Find Neighbouring Cells

Description

Given a vector of cell IDs (cell.ids) and a vector (blocks), which defines the number of blocks / cells per dimension, a list of all combinations of (linearly) neighbouring cells around each element of cell.ids is returned.

Usage

findLinearNeighbours(cell.ids, blocks, diag = FALSE)

Arguments

cell.ids

[integer]
Vector of cell IDs (one number per cell) for which the neighbouring cells should be computed.

blocks

[integer]
The number of blocks per dimension.

diag

[logical(1)]
logical, indicating whether only cells that are located parallel to the axes should be considered (diag = FALSE) as neighbours. Alternatively, one can also look for neighbours that are located diagonally to a cell. The default is diag = FALSE.

Value

[list of integer(3)].
List of neighbours. Each list element stands for a combination of predecessing, current and succeeding cell.

Examples

cell.ids = c(5, 84, 17, 23)
blocks = c(5, 4, 7)

# (1) Considering diagonal neighbours as well:
findLinearNeighbours(cell.ids = cell.ids, blocks = blocks, diag = TRUE)

# (2) Only consider neighbours which are parellel to the axes:
findLinearNeighbours(cell.ids = cell.ids, blocks = blocks)


Find Nearest Prototype

Description

For each cell of the initial design, select the closest observation to its center and use it as a representative for that cell.

Usage

findNearestPrototype(feat.object, dist_meth, mink_p, fast_k, ...)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

dist_meth

[character(1)]
Which distance method should be used for computing the distance between two observations? All methods of dist are possible options with "euclidean" being the default.

mink_p

[integer(1)]
Value of p in case dist_meth is "minkowski". The default is 2, i.e. the euclidean distance.

fast_k

[numeric(1)]
Percentage of elements that should be considered within the nearest neighbour computation. The default is 0.05.

...

[any]
Further arguments, which might be used within the distance computation (dist).

Value

[data.frame].
A data.frame containing one prototype (i.e. a representative observation) per cell. Each prototype consists of its values from the decision space, the corresponding objective value, its own cell ID and the cell ID of the cell, which it represents.

Examples

# (1) create the initial sample and feature object:
X = createInitialSample(n.obs = 1000, dim = 2,
  control = list(init_sample.lower = -10, init_sample.upper = 10))
feat.object = createFeatureObject(X = X, 
  fun = function(x) sum(x^2), blocks = 10)

# (2) find the nearest prototypes of all cells:
findNearestPrototype(feat.object)

Shiny Server Function for Feature Calculation of Function Input

Description

functionInput is a shiny server function which controls all aspects of the FlaccoFunctionInput UI Module. Will be called with callModule.

Usage

functionInput(input, output, session, stringsAsFactors)

Arguments

input

[shiny-input]
shiny input variable for the specific UI module.

output

[shiny-output object]
shiny output variable for the specific UI module.

session

[shiny-session object]
shiny session variable for the specific UI module.

stringsAsFactors

[logical(1)]
How should strings be treated internally?


Feature Importance Plot

Description

Creates a feature importance plot.

Usage

ggplotFeatureImportance(featureList, control = list(), ...)

plotFeatureImportance(featureList, control = list(), ...)

Arguments

featureList

[list]
List of vectors of features. One list element is expected to belong to one resampling iteration / fold.

control

[list]
A list, which stores additional configuration parameters:

  • featimp.col_{high/medium/low}: Color of the features, which are used often, sometimes or only a few times.

  • featimp.perc_{high/low}: Percentage of the total number of folds, defining when a features, is used often, sometimes or only a few times.

  • featimp.las: Alignment of axis labels.

  • featimp.lab_{feat/resample}: Axis labels (features and resample iterations).

  • featimp.string_angle: Angle for the features on the x-axis.

  • featimp.pch_{active/inactive}: Plot symbol of the active and inactive points.

  • featimp.col_inactive: Color of the inactive points.

  • featimp.col_vertical: Color of the vertical lines.

  • featimp.lab_{title/strip}: Label used for the title and/or strip label. These parameters are only relevant for ggplotFeatureImportance.

  • featimp.legend_position: Location of the legend. This parameter is only relevant for ggplotFeatureImportance.

  • featimp.flip_axes: Should the axes be flipped? This parameter is only relevant for ggplotFeatureImportance.

  • featimp.plot_tiles: Visualize (non-)selected features with tiles? This parameter is only relevant for ggplotFeatureImportance.

...

[any]
Further arguments, which can be passed to plot.

Value

[plot].
Feature Importance Plot, indicating which feature was used during which iteration.

Examples

## Not run: 
# At the beginning, one needs a list of features, e.g. derived during a
# nested feature selection within mlr (see the following 8 steps):
library(mlr)
library(mlbench)
data(Glass)

# (1) Create a classification task:
classifTask = makeClassifTask(data = Glass, target = "Type")

# (2) Define the model (here, a classification tree):
lrn = makeLearner(cl = "classif.rpart")

# (3) Define the resampling strategy, which is supposed to be used within 
# each inner loop of the nested feature selection:
innerResampling = makeResampleDesc("Holdout")

# (4) What kind of feature selection approach should be used? Here, we use a
# sequential backward strategy, i.e. starting from a model with all features,
# in each step the feature decreasing the performance measure the least is
# removed from the model:
ctrl = makeFeatSelControlSequential(method = "sbs")

# (5) Wrap the original model (see (2)) in order to allow feature selection:
wrappedLearner = makeFeatSelWrapper(learner = lrn,
  resampling = innerResampling, control = ctrl)

# (6) Define a resampling strategy for the outer loop. This is necessary in
# order to assess whether the selected features depend on the underlying
# fold:
outerResampling = makeResampleDesc(method = "CV", iters = 10L)

# (7) Perform the feature selection:
featselResult = resample(learner = wrappedLearner, task = classifTask,
  resampling = outerResampling, models = TRUE)

# (8) Extract the features, which were selected during each iteration of the
# outer loop (i.e. during each of the 10 folds of the cross-validation):
featureList = lapply(featselResult$models, 
  function(mod) getFeatSelResult(mod)$x)
## End(Not run)

########################################################################

# Now, one could inspect the features manually:
featureList

# Alternatively, one might use visual means such as the feature
# importance plot. There exist two versions for the feature importance
# plot. One based on the classical R figures
plotFeatureImportance(featureList)

# and one using ggplot
ggplotFeatureImportance(featureList)


List Available Feature Sets

Description

Lists all available feature sets w.r.t. certain restrictions.

Usage

listAvailableFeatureSets(
  subset,
  allow.cellmapping,
  allow.additional_costs,
  blacklist
)

Arguments

subset

[character]
Vector of feature sets, which should be considered. If not defined, all features will be considered.

allow.cellmapping

[logical(1)]
Should (general) cell mapping features be considered as well? The default is TRUE.

allow.additional_costs

[logical(1)]
Should feature sets be considered, which require additional function evaluations? The default is TRUE.

blacklist

[character]
Vector of feature sets, which should not be considered. The default is NULL.

Value

[character].
Feature sets, which could be computed - based on the provided input.

Examples

sets = listAvailableFeatureSets()

Measure Runtime of a Feature Computation

Description

Simple wrapper around proc.time.

Usage

measureTime(expr, prefix, envir = parent.frame())

Arguments

expr

[expression]
Expression of which the time should be measured.

prefix

[character(1)]
Name of the corresponding feature set. Used as a prefix for the runtime.

envir

[environment]
Environment in which expr should be evaluated.

Value

Returns the value(s) of the evaluated expr and adds two additional attributes: the number of function evaluations costs_fun_evals and the runtime costs_runtime, which was required for evaluating the expression.


Plot Barrier Tree in 2D

Description

Creates a 2D image containing the barrier tree of this cell mapping.

Usage

plotBarrierTree2D(feat.object, control)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

control

[list]
A list, which stores additional control arguments. For further information, see details.

Details

Possible control arguments are:

Value

[plot].
A 2D image, visualizing the barrier tree of this cell mapping.

Examples

# create a feature object
X = createInitialSample(n.obs = 900, dim = 2)
f = smoof::makeAckleyFunction(dimensions = 2)
y = apply(X, 1, f)
feat.object = createFeatureObject(X = X, y = y, fun = f, blocks = c(4, 6))

# plot the corresponing barrier tree
plotBarrierTree2D(feat.object)

Plot Barrier Tree in 3D

Description

Creates a 3D surface plot containing the barrier tree of this cell mapping.

Usage

plotBarrierTree3D(feat.object, control)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

control

[list]
A list, which stores additional control arguments. For further information, see details.

Details

Possible control arguments are:

Value

[plot].
A 3D-surface plot, visualizing the barrier tree of this cell mapping.

Examples

# create a feature object
X = createInitialSample(n.obs = 900, dim = 2)
f = smoof::makeAckleyFunction(dimensions = 2)
y = apply(X, 1, f)
feat.object = createFeatureObject(X = X, y = y, fun = f, blocks = c(4, 6))

# plot the corresponing barrier tree
plotBarrierTree3D(feat.object)

Plot Cell Mapping

Description

Visualizes the transitions among the cells in the General Cell Mapping approach.

Usage

plotCellMapping(feat.object, control)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

control

[list]
A list, which stores additional control arguments. For further information, see details.

Details

Possible control arguments are:

Value

[plot].

References

Examples

# (1) Define a function:
library(smoof)
f = makeHosakiFunction()

# (2) Create a feature object:
X = cbind(
  x1 = runif(n = 100, min = -32, max = 32),
  x2 = runif(n = 100, min = 0, max = 10)
)
y = apply(X, 1, f)
feat.object = createFeatureObject(X = X, y = y, blocks = c(4, 6))

# (3) Plot the cell mapping:
plotCellMapping(feat.object)

Plot Information Content

Description

Creates a plot of the Information Content Features.

Usage

plotInformationContent(feat.object, control)

Arguments

feat.object

[FeatureObject]
A feature object as created by createFeatureObject.

control

[list]
A list, which stores additional control arguments. For further information, see details.

Details

Possible control arguments are:

Value

[plot].
A plot visualizing the Information Content Features.

References

Examples

# (1) create a feature object:
X = t(replicate(n = 2000, expr = runif(n = 5, min = -10, max = 10)))
feat.object = createFeatureObject(X = X, fun = function(x) sum(x^2))

# (2) plot its information content features:
plotInformationContent(feat.object)

Run the flacco-GUI based on Shiny

Description

runFlaccoGUI starts a shiny application, which allows the user to compute the flacco features and also visualize the underlying functions.

Usage

runFlaccoGUI()

Details

A shiny application is a web-app which can be accessed through a browser.

References