File: RFfitOptimiser.Rd

package info (click to toggle)
r-cran-randomfields 3.3.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,916 kB
  • sloc: cpp: 52,159; ansic: 3,015; makefile: 2; sh: 1
file content (130 lines) | stat: -rw-r--r-- 3,927 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
\name{RFfitoptimiser}
\alias{RFfitoptimiser}
\alias{RFfitOptimiser}
\title{Optimisers for
  fitting model parameters to spatial data
}
\description{
  See \command{\link{RFfit}} for a detailed description of
  the fitting procedure.
}

\details{
  Two parameters, see also \command{\link{RFoptions}}
  can be passed to \command{\link{RFfit}} that allow
  for choosing an optimiser different from \command{\link[stats]{optim}}:

  \code{optimiser} takes one of the values
  \code{"optim"}, \code{"optimx"}, \code{"soma"}, \code{"nloptr"},
  \code{"GenSA"}, \code{"minqa"}, \code{"pso"} or \code{"DEoptim"},
  see the corresponding packages for a description.

  If \code{optimiser="nloptr"}, then the additional parameter
  \code{algorithm} must be given which takes the values
  \code{"NLOPT_GN_DIRECT"},  
  \code{"NLOPT_GN_DIRECT_L"},
  \code{"NLOPT_GN_DIRECT_L_RAND"}, 
  \code{"NLOPT_GN_DIRECT_NOSCAL"},
  \code{"NLOPT_GN_DIRECT_L_NOSCAL"}, 
  \code{"NLOPT_GN_DIRECT_L_RAND_NOSCAL"},
  \code{"NLOPT_GN_ORIG_DIRECT"}, 
  \code{"NLOPT_GN_ORIG_DIRECT_L"},
  \code{"NLOPT_LN_PRAXIS"}, 
  \code{"NLOPT_GN_CRS2_LM"}, 
  \code{"NLOPT_LN_COBYLA"},
  \code{"NLOPT_LN_NELDERMEAD"}, 
  \code{"NLOPT_LN_SBPLX"},
  \code{"NLOPT_LN_BOBYQA"},
  \code{"NLOPT_GN_ISRES"},
  see \pkg{nloptr} for a description.
    
}

\me

\seealso{
  \command{\link{RFfit}}, \command{\link{RFoptions}}
}
\examples{\dontshow{StartExample()}
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
##                   RFoptions(seed=NA) to make them all random again

\dontrun{
## 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)
)
dta <- soil["moisture"]
\dontshow{if (RFoptions()$internal$examples_red) {
  warning("data have been reduced !")
  All <- 1:7 
  rm(soil)
  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)
  )
  dta <- soil["moisture"]
}}

model <- ~1 + RMwhittle(scale=NA, var=NA, nu=NA) + RMnugget(var=NA)
\dontshow{if (RFoptions()$internal$examples_red){model<-~1+RMwhittle(scale=NA,var=NA,nu=1/2)}}
## standard optimiser 'optim'
print(system.time(fit <- RFfit(model, data=dta)))
print(fit)

opt <- "optimx" #  30 sec; better result
print(system.time(fit2 <- try(RFfit(model, data=dta, optimiser=opt))))
print(fit2)

\dontshow{\dontrun{ %in 6 sep 2017, soma has leak problems
opt <- "soma" #  450 sec % sehr schlecht
print(system.time(fit2 <- try(RFfit(model, data=dta, optimiser=opt))))
print(fit2)
}}

opt <- "minqa" # 330 sec %ok
print(system.time(fit2 <- try(RFfit(model, data=dta, optimiser=opt))))
print(fit2)


opt <- "nloptr"
algorithm <- RC_NLOPTR_NAMES
\dontshow{if(!interactive()) algorithm <- RC_NLOPTR_NAMES[1]}
for (i in 1:length(algorithm)) { % all algorithms are fast
  print(algorithm[i])
  print(system.time(fit2 <- try(RFfit(model, data=dta, 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(system.time(fit2 <- try(RFfit(model, data=dta, optimiser=opt))))
print(fit2)

opt <- "GenSA" #  10^4 sec
print(system.time(fit2 <- try(RFfit(model, data=dta, optimiser=opt))))
print(fit2)
}
}

\dontshow{RFoptions(modus_operandi="normal")}
\dontshow{FinalizeExample()}}

\keyword{spatial}
\keyword{optimize}