## a LOGICAL neighbourhood
x <- logical(8)
x[1:3] <- TRUE
N <- neighbourfun(type = "logical", kmin = 3, kmax = 3)
cat(ifelse(x, "o", "."), " | initial solution ",
sep = "", fill = TRUE)
for (i in 1:5) {
x <- N(x)
cat(ifelse(x, "o", "."), sep = "", fill = TRUE)
}
## ooo..... | initial solution
## oo....o.
## o...o.o.
## o.o.o...
## oo..o...
## oo....o.
## UPDATING a numeric neighbourhood
## the vector is 'x' is used in the product 'Ax'
A <- array(rnorm(100*25), dim = c(100, 25))
N <- neighbourfun(type = "numeric",
stepsize = 0.05,
update = "Ax",
A = A)
x <- rep(1/25, 25)
attr(x, "Ax") <- A %*% x
for (i in 1:10)
x <- N(x, A)
all.equal(A %*% x, attr(x, "Ax"))
## a PERMUTATION neighbourhood
x <- 1:5
N <- neighbourfun(type = "permute")
N(x)
## [1] 1 2 5 4 3
## ^ ^
N <- neighbourfun(type = "permute", stepsize = 5)
N(x)
## 'x' is not restricted to integers
x <- letters[1:5]
N(x)
## a useful way to STORE/SPECIFY PARAMETERS, e.g. in config files
settings <- list(type = "numeric",
min = 0.0,
max = 0.2)
do.call(neighbourfun, settings)
Run the code above in your browser using DataLab