optimUSER | R Documentation |
Optimize a sample configuration using a user-defined objective function.
optimUSER(
points,
candi,
fun,
...,
schedule,
plotit = FALSE,
track = FALSE,
boundary,
progress = "txt",
verbose = FALSE
)
points |
Integer value, integer vector, data frame (or matrix), or list. The number of sampling points (sample size) or the starting sample configuration. Four options are available:
Most users will want to set an integer value simply specifying the required sample size. Using an integer vector or data frame (or matrix) will generally be helpful to users willing to evaluate starting sample configurations, test strategies to speed up the optimization, and fine-tune or thin an existing sample configuration. Users interested in augmenting a possibly existing real-world sample configuration or fine-tuning only a subset of the existing sampling points will want to use a list. |
candi |
Data frame (or matrix). The Cartesian x- and y-coordinates (in this order) of the
cell centres of a spatially exhaustive, rectangular grid covering the entire spatial sampling
domain. The spatial sampling domain can be contiguous or composed of disjoint areas and contain
holes and islands. |
fun |
A function defining the objective function that should be used to evaluate the energy state of the system configuration at each random perturbation of a candidate sample point. See ‘Details’ for more information. |
... |
Other arguments passed to the objective function. See ‘Details’ for more information. |
schedule |
List with named sub-arguments setting the control parameters of the annealing
schedule. See |
plotit |
(Optional) Logical for plotting the evolution of the optimization. Plot updates
occur at each ten (10) spatial jitters. Defaults to
|
track |
(Optional) Logical value. Should the evolution of the energy state be recorded and
returned along with the result? If |
boundary |
(Optional) An object of class SpatialPolygons (see sp::SpatialPolygons()) with
the outer and inner limits of the spatial sampling domain (see |
progress |
(Optional) Type of progress bar that should be used, with options |
verbose |
(Optional) Logical for printing messages about the progress of the optimization.
Defaults to |
The user-defined objective function fun
must be an object of class function
and
include the argument points
. The argument points
is defined in optimUSER
as a matrix
with three columns: [, 1]
the identification of each sample point given by the respective row
indexes of candi
, [, 2]
the x-coordinates, and [, 3]
the y-coordinates. The
identification is useful to retrieve information from any data matrix used by the objective function
defined by the user.
optimUSER
returns an object of class OptimizedSampleConfiguration
: the optimized sample
configuration with details about the optimization.
Alessandro Samuel-Rosa alessandrosamuelrosa@gmail.com
#####################################################################
# NOTE: The settings below are unlikely to meet your needs. #
#####################################################################
## Not run:
# This example takes more than 5 seconds
require(sp)
require(SpatialTools)
data(meuse.grid)
candi <- meuse.grid[, 1:2]
schedule <- scheduleSPSANN(chains = 1, initial.temperature = 30,
x.max = 1540, y.max = 2060, x.min = 0,
y.min = 0, cellsize = 40)
# Define the objective function - number of points per lag distance class
objUSER <-
function (points, lags, n_lags, n_pts) {
dm <- SpatialTools::dist1(points[, 2:3])
ppl <- vector()
for (i in 1:n_lags) {
n <- which(dm > lags[i] & dm <= lags[i + 1], arr.ind = TRUE)
ppl[i] <- length(unique(c(n)))
}
distri <- rep(n_pts, n_lags)
res <- sum(distri - ppl)
}
lags <- seq(1, 1000, length.out = 10)
# Run the optimization using the user-defined objective function
set.seed(2001)
timeUSER <- Sys.time()
resUSER <- optimUSER(points = 10, fun = objUSER, lags = lags, n_lags = 9,
n_pts = 10, candi = candi, schedule = schedule)
timeUSER <- Sys.time() - timeUSER
# Run the optimization using the respective function implemented in spsann
set.seed(2001)
timePPL <- Sys.time()
resPPL <- optimPPL(points = 10, candi = candi, lags = lags,
schedule = schedule)
timePPL <- Sys.time() - timePPL
# Compare results
timeUSER
timePPL
lapply(list(resUSER, resPPL), countPPL, candi = candi, lags = lags)
objSPSANN(resUSER) - objSPSANN(resPPL)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.