Learn R Programming

sensors4plumes (version 0.9.3)

optimiseSD_greedy: Greedy optimisation algorithm

Description

Runs greedy optimisation for a given Simulations object and cost function. The aim may be given as a number of sensors or as cost value, then the algorithm determines if sensors need to be added or deleted. Greedy optimisation adds (or respectively deletes) sensors one by one, always checking all possibilities and adding/deleting the sensor that yields minimal cost, given the already defined sensors; it stops when the aim is reached. In addition this algorithm can continue search when the greedy optimum is found by adding and deleting sensors in turns, this can help to get rid of redundant sensors and thus may improve the result. The algorithm may take into account fix sensors and start from a given initial sensor set.

Usage

optimiseSD_greedy(simulations, costFun,
  locationsAll = 1:nLocations(simulations), locationsFix = integer(0),
  locationsInitial = integer(0),
  aimCost = NA, aimNumber = NA,
  nameSave = NA, plot = FALSE, verbatim = FALSE,
  maxIterations = 100, swap = FALSE)

Arguments

simulations

*

costFun

*

locationsAll

*

locationsFix

*

locationsInitial

*

aimCost

*, ignored

aimNumber

*

nameSave

*

plot

not implemented yet

verbatim

logical, not implemented yet

maxIterations

maximal number of iterations, then it stops

swap

logical if algorithm continues, when greedy optimum is found, by adding and deleting sensors in turns

Value

A list, the first two entries are common to all optimisation algorithms, they are marked with *, see optimiseSD for details.

SD

* best sampling designs

evaluation

* cost and size of SD

report

a list of SDsa list of the sampling designs of all iterations evalSDs a data.frame: cost and number of sensors for the sampling designs SDs.

Details

In general the function is used within the wrapper optimiseSD. The parameters maxIterations and swap are specific to optimiseSD_greedy, they may be changed beforehand via replaceDefault with type = "optimisationFun.optimiseSD"; all other parameters are forwarded from optimiseSD.

If aimCost and aimNumber are given, aimNumber is ignored with a warning.

Examples

Run this code
# NOT RUN {
# optimisation function: is to be used inside of optimiseSD
# change parameters 'swap' and 'maxIterations'
optGr_20_true = replaceDefault(
  optimiseSD_greedy,
  newDefaults = list(
    maxIterations = 20,
    swap = TRUE)
)
# cost function
meanFun = function(x){mean(x, na.rm = TRUE)}
minDist = replaceDefault(
  spatialSpread, newDefaults = list(
    fun = minimalDistance,
    fun_R = meanFun
  ), type = "costFun.optimiseSD"
)[["fun"]]

# define possible, fix, and initial sensors
data(SimulationsSmall)
I = nLocations(SimulationsSmall)
set.seed(9345872)
locInit1 = sample.int(I, 2)
locKeep1 = sample(setdiff(1:I, locInit1), 2)
locAll1 = c(sample(setdiff(1:I, c(locInit1, locKeep1)), 4), locInit1)

# run optimisation
# }
# NOT RUN {
## takes some time
optSD_greedy = optimiseSD(
  simulations = SimulationsSmall,
  costFun = minDist,
  optimisationFun = optGr_20_true[[1]],
  locationsAll = locAll1,
  locationsFix = locKeep1,
  locationsInitial = locInit1,
  aimNumber = 7
)

# }
# NOT RUN {
## this result is also in data(SDgreedy)
# }

Run the code above in your browser using DataLab