RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
StartExample()
## Here some alternative optimisers to 'optim' are considered.
## All but the \pkg{nloptr} algorithms are largely slower than 'optim'.
## Only a few of them return results as good as 'optim'.
data(soil)
str(soil)
soil <- RFspatialPointsDataFrame(
coords = soil[ , c("x.coord", "y.coord")],
data = soil[ , c("moisture", "NO3.N", "Total.N", "NH4.N", "DOC", "N20N")],
RFparams=list(vdim=6, n=1)
)
data <- soil["moisture"]
if (RFoptions()$internal$examples_red) {
warning("data have been reduced !")
All <- 1:7
data(soil)
soil <- RFspatialPointsDataFrame(
coords = soil[All, c("x.coord", "y.coord")],
data = soil[All, c("moisture", "NO3.N", "Total.N",
"NH4.N", "DOC", "N20N")],
RFparams=list(vdim=6, n=1)
)
data <- soil["moisture"]
}
model <- ~1 + RMwhittle(scale=NA, var=NA, nu=NA) + RMnugget(var=NA)
if (RFoptions()$internal$examples_red){model<-~1+RMwhittle(scale=NA,var=NA,nu=1/2)}
## standard optimiser 'optim'
print(unix.time(fit <- RFfit(model, data=data)))
print(fit)
opt <- "minqa" # 330 sec %ok
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt))))
print(fit2)
opt <- "soma" # 450 sec % sehr schlecht
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt))))
print(fit2)
opt <- "optimx" # 30 sec; better result
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt))))
print(fit2)
opt <- "nloptr"
algorithm <- RC_NLOPTR_NAMES
if(!interactive()) algorithm <- RC_NLOPTR_NAMES[1]
for (i in 1:length(algorithm)) { print(algorithm[i])
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt,
algorithm=algorithm[i]))))
print(fit2)
}
if (interactive()) {
## the following two optimisers are too slow to be run on CRAN.
opt <- "pso" # 600 sec
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt))))
print(fit2)
opt <- "GenSA" # 10^4 sec
print(unix.time(fit2 <- try(RFfit(model, data=data, optimiser=opt))))
print(fit2)
}
RFoptions(modus_operandi="normal")
FinalizeExample()
Run the code above in your browser using DataLab