Skip to contents

This class is used to create visualizations and animations of optimization traces.

Super class

vistool::Visualizer2D -> Visualizer2DObjective

Public fields

objective

(`Objective`)
The objective which was optimized. This object is used to generate the surface/contour lines.

Methods

Inherited methods


Method new()

Creates a new instance of this [R6][R6::R6Class] class.

Usage

Visualizer2DObjective$new(
  objective,
  x1_limits = NULL,
  x2_limits = NULL,
  padding = 0,
  n_points = 100L
)

Arguments

objective

(`Objective`)
The objective which was optimized. This object is used to generate the surface/contour lines.

x1_limits

(`numeric(2)`)
The x1 limits.

x2_limits

(`numeric(2)`)
The x2 limits.

padding

(`numeric(1)`)
A margin that is added to x1limits and x2limits. The x1 margin is calculated by `max(x1lmits) - min(x1limits) * padding`.

n_points

(`integer(1)`)
The number of generated point per dimension. Note that a grid of `npoints^2` values is generated and evaluated by `objective$eval(x)` to plot the surface.


Method add_optimization_trace()

Add an optimization trace.

Usage

Visualizer2DObjective$add_optimization_trace(
  opt,
  line_color = colSampler(),
  mcolor_out = "black",
  npoints = NULL,
  npmax = NULL,
  name = NULL,
  offset = NULL,
  add_marker_at = 1,
  marker_shape = "circle",
  marker_color = NULL,
  ...
)

Arguments

opt

(`Optimizer`)
The optimizer from which the archive is extracted and used to plot the trace.

line_color

(`character(1)`)
The color of the trace.

mcolor_out

(`character(1)`)
The outer line color of the marker.

npoints

(`integer(1)`)
The number of used points from the archive. Default is `NULL` which means that all points are used. If set, a sequence from 1 to `nrow(opt$archive)` is created.

npmax

(`integer(1)`)
The number of points used from the sequence `seq_len(nrow(opt$archive))[seq_len(npmax)]`

name

(`character(1)`)
The name of the trace in the legend. Default is `NULL` which means that the name is pasted from `opt$id` and `objective$id`.

offset

(`numeric(3)`)
Trace shift in direction (x, y, z).

add_marker_at

(`integer()`)
Vector of iterations at which a marker is added.

marker_shape

(`character()`)
Vector indicating the shape of the markers. If `length(marker_shape) == 1`, all markers get the same shape. The other option is to specify all markers individually by passing a vector of `length(add_marker_at)`. For a list of all shapes see `schema(F)$traces$XXX$attributes$marker$symbol$values` with `XXX` one of `scatter` or `scatter3d`. If `marker_shape = NA`, no marker are added.

marker_color

(`character()`)
The colors for the markers.

...

Further arguments passed to `add_trace(...)`.


Method add_layer_taylor()

Add a Taylor approximation (for 1 and 2 degrees).

Usage

Visualizer2DObjective$add_layer_taylor(
  x0,
  degree = 2,
  x1margin = 0,
  x2margin = 0,
  npoints_per_dim = 20L,
  zlim = NULL,
  ...
)

Arguments

x0

(`numeric()) `
The point around which the approximation is done.

degree

(`integer(1)`)
The degree of the approximation (only 1 and 2 is implemented).

x1margin

(`numeric(1)`)
The "length" of the hyperplane in direction x1.

x2margin

(`numeric(1)`)
The "length" of the hyperplane in direction x2.

npoints_per_dim

(`integer(1)`)
Number of points per dimension for the plotting grid.

zlim

(`numeric(2)`)
The limits for z. Can be helpful if the hyperplane as a huge z range and therefore the plot looks ugly.

...

(`any`)
Additional parameter passed to `add_surface()`.


Method add_layer_hessian()

Add two "arrows" as eigenvectors of the Hessian.

Usage

Visualizer2DObjective$add_layer_hessian(
  x0,
  x1length = 0.1,
  x2length = 0.1,
  ...
)

Arguments

x0

(`numeric(2)`)
The point at which the Hessian is calculated.

x1length

(`numeric(1)`)
The length of the first eigenvector.

x2length

(`numeric(1)`)
The length of the second eigenvector.

...

(`any`)
Additional arguments passed to `add_trace`.


Method animate()

Create an animation of `$plot()`.

Usage

Visualizer2DObjective$animate(
  dir = "animation",
  nframes = 10L,
  view_start = list(x = 1, y = 1, z = 1),
  view_end = list(x = 1, y = 1, z = 1),
  fext = "png",
  stops = NULL,
  ...
)

Arguments

dir

(`character(1)`)
The directory in which all the images are saved.

nframes

(`integer(1)`)
The number of frames.

view_start

(`list()`)
The start view of the animation.

view_end

(`list()`)
The end view of the animation.

fext

(`character(1)`)
The file extension (default is `png`).

stops

(`integer()`)
The step / iteration in the archives of the optimizers added by `$addLayerOptimizationTrace()` at which a frame is taken. Must have exact the same length as defined in `nframes`. By default, a sequence with equidistant points is generated for `stops`.

...

(`any`)
Additional arguments passed to `$save(...)`.


Method clone()

The objects of this class are cloneable with this method.

Usage

Visualizer2DObjective$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.