Learn R Programming

sensors4plumes (version 0.9.3)

optimiseSD_manual: Plot cost map for interactive adding and deleting of sensors

Description

Given a costMap function and a set of sensors it computes the cost map and plots it. Then the user can interactively add or delete sensors and plot the resulting cost and cost map..

Usage

optimiseSD_manual(simulations, costFun,
  locationsAll = 1:nLocations(simulations), locationsFix = integer(0),
  locationsInitial = integer(0),
  aimCost = NA, aimNumber = NA,
  nameSave = NA, plot = TRUE, verbatim = FALSE,
  costMap = NA, maxIterations = 10, 
  valuesPlot = integer(0), colors = grey.colors)

Arguments

simulations

*

costFun

* ignored - cost is derived from costMap

locationsAll

*

locationsFix

*

locationsInitial

*

aimCost

* ignored

aimNumber

* ignored

nameSave

* ignored

plot

* ignored

verbatim

ignored

costMap

A function to return a list of "cost": cost in general, a single value, "costLocations": a cost value for each location(vector of length equal to nLocations(simulations)). Needs to have the same parameters (simulations, locations) as costFun and may also be prepared by replaceDefault with type = "costFun.optimiseSD".

maxIterations

maximal number of iterations to add or delete sensors

valuesPlot

names of values in the data associated with the locations of simulations to be plotted in addition to the cost map

colors

color ramp for plotting - a function like grey.colors)

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 cost: cost in each iteration, based on fix and current sensors identify: identity of points chosen in each iteration; these identities are 'raw' -for "SpatialIndexDataFrame" and "SpatialPolygridDataFrame" they may differ from the indices of the actual locations as data is transformed into SpatialPixels before plotting, they may also include invalid and multiple choices. locationsCurrent: indices of sampling design in each iteration; locationsFix are not included

Examples

Run this code
# NOT RUN {
# prepare data and functions
data(radioactivePlumes)

meanFun = function(x){mean(x, na.rm = TRUE)}
spatialSpreadMinDist = replaceDefault(
  spatialSpread,
  newDefaults = list(
    weightByArea = TRUE,
    fun = minimalDistance,
    fun_R = meanFun),
  type = "costFun.optimiseSD"
  )[[1]]

radioactivePlumes@locations@data$p1 = getValues(
  subset(radioactivePlumes, plumes = 1, kinds = 1)@values)

optimSD_man_minDist = replaceDefault(
  optimiseSD_manual,
  newDefaults = list(
    costMap = spatialSpreadMinDist
    )
)[["fun"]]

# }
# NOT RUN {
## interactive optimisation
# inside optimiseSD
optSD_manual1 = optimiseSD(simulations = radioactivePlumes,
                          costFun = spatialSpreadMinDist,
                          optimisationFun = optimSD_man_minDist,
                          locationsFix = seq(1, 2001, 300),
                          locationsInitial = seq(1, 2001, 70),
                          locationsAll = setdiff(1:2001, seq(1,2001, 30)))

# directly using optimiseSD_manual
optSD_manual2 = optimiseSD_manual(simulations = radioactivePlumes,
                                  costFun = spatialSpreadMinDist,
                                  costMap = spatialSpreadMinDist,
                                  locationsFix = seq(1, 2001, 300),
                                  locationsInitial = seq(1, 2001, 70),
                                  locationsAll = setdiff(1:2001, seq(1,2001, 30)))
# }
# NOT RUN {
## the result of such a manual optimisation is in data(SDmanual)
# }

Run the code above in your browser using DataLab