optimiseSD_genetic: Optimisation of sensor locations by a binary genetic...

Description Usage Arguments Details Value Author(s) Examples

View source: R/optimiseSD_genetic.R

Description

optimiseSD_genetic optimises sensors for a given Simulations object and costFunction. It starts from a population of sensor sets that can be provided and else are random. By testing them and recombining good locations, a new improved population is generated. This process continues until the aim or a stopping criterion is reached. It applies the binary genetic algorithm rbga.bin.
numberPenalty is the default evaluation function, it returns the penalty if aimNumber is exceeded, else the cost computed by costFun.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
optimiseSD_genetic(simulations, costFun,
  locationsAll = 1:nLocations(simulations), locationsFix = integer(0),
  locationsInitial = integer(0),
  aimCost = NA, aimNumber = NA,
  nameSave = NA, plot = FALSE, verbatim = FALSE,
  evalFunc = numberPenalty, 
  popSize = 200, iters = 100, 
  mutationChance = NA, elitism = NA)
numberPenalty(chromosome, simulations, costFun, 
  locationsAll, locationsFix, 
  aimNumberNF, penalty = 2)

Arguments

Some arguments are the same for all optimisation algorithms, they are marked by a *, for detail see optimiseSD. Others are directly forwarded to rbga.bin, they are marked by **

simulations

*

costFun

*

locationsAll

*

locationsFix

*

locationsInitial

*; here it may also be a matrix, each row indicates a set of sensors

aimCost

*

aimNumber

*; if locationsInitial given it must be NULL and is ignored, else it defines the number of sensors in the sets of the initial population

aimNumberNF

aimNumber minus length of locationsFix - to be used in evaluation

nameSave

*

plot

not yet implemented

verbatim

if more output is to be written to the console

evalFunc

**; this function has to take a chromosome and return its cost (including fix sensors); it can be modified by replaceDefault with type = "evalFunc.rbga.bin"

popSize

**

iters

**

mutationChance

**

elitism

**

chromosome

a vector of 0 and 1 of the same length as locationsAll indicating sensors at the positions of 1.

penalty

numeric to be returned if number of 1s in chromosome exceeds aimNumber.

Details

In general the function is used within the wrapper optimiseSD. The **-parameters 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 is given, the algorithm stops when the aim is reached by the best sampling design. In this case, nothing is returned, but the populations are saved (at nameSave and if nothing indicated at "opt_genetic.Rdata"), see examples how to extract the sampling designs in this case.

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

the generated "rbga" object as returned by rbga.bin

Author(s)

Kristina B. Helle, kristina.helle@uni-muenster.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# load data and compute required properties
demo(radioactivePlumes_addProperties)

# initial, fix, possible sensor locations
I = nLocations(radioactivePlumes)
set.seed(1000)
locInit_l = t(replicate(10, sample.int(I, 5))) 
locKeep_l = sample(setdiff(1:I, locInit_l), 2)
locAll_l = c(sample(setdiff(1:I, c(locInit_l, locKeep_l)),
                          round(I - (5 + 2)) * 0.5), locInit_l)

# the function is to be used inside of optimiseSD
# change algorithm specific parameters 'evalFunc', 'popSize', 'iters'
optimiseSD_genetic_1 = replaceDefault(
  optimiseSD_genetic, newDefaults = list(
    evalFunc = numberPenalty,
    popSize = 20,
    iters = 10
  ),
  type = "optimisationFun.optimiseSD")[[1]]

# run optimisation
## Not run: 
## takes some time
OptSD_gen1 = optimiseSD(
  simulations = radioactivePlumes,
  costFun = singleDetection,
  optimisationFun = optimiseSD_genetic_1,
  locationsAll = locAll_l,
  locationsFix = locKeep_l,
  locationsInitial = locInit_l[1,])

## End(Not run)
## this result is also in data(SDgenetic)

## Not run: 
# result is not returned but saved to file
## case with 'aimCost'
optimiseSD_genetic_2 = replaceDefault(
    optimiseSD_genetic, newDefaults = list(
      evalFunc = numberPenalty,
      popSize = 20,
      iters = 20
    ),
    type = "optimisationFun.optimiseSD")[[1]]

set.seed(07021916)
OptSD_gen2 = optimiseSD(
  simulations = radioactivePlumes,
  costFun = singleDetection,
  optimisationFun = optimiseSD_genetic_2,
  locationsAll = locAll_l,
  locationsFix = locKeep_l,
  locationsInitial = locInit_l[1,],
  aimCost = 0.05,
  nameSave = "optSD_genetic_2" # result is saved to file here
)
# OptSD_gen2 not found
## load generated populations and extract sampling designs and cost
load("optSD_genetic_2.Rdata")
finalIteration = sum(!is.na(populations[1,1,]))
costs = matrix(0, nrow = finalIteration, ncol = 20)
SDs = list()
for (j in 1:finalIteration){
  SDs[[j]] = list()
  for (i in 1:20){
    costs[j,i] = numberPenalty(populations[i,,j],
      simulations = radioactivePlumes,
      costFun = singleDetection,
      locationsAll = locAll_l,
      locationsFix = locKeep_l,
      aimNumber = length(locInit_l[1,]))
    SDs[[j]][[i]] = c(locAll_l[populations[i,,j] == 1], locKeep_l)
    if (sum(populations[i,,j]) > 5){
      costs[j,i] = 2
    }
    print(paste(j,i))
  }
}
apply(FUN = min, X = costs, MARGIN = 1) # best cost in each iteration
# best sampling design:
SDs[[finalIteration]][[which(costs[finalIteration,] == min(costs[finalIteration,]))]]

## End(Not run)

sensors4plumes documentation built on May 1, 2019, 10:27 p.m.