Description Usage Arguments Details Value Author(s) Examples
fnchk
checks a user-provided R function, ffn
.
1 |
xpar |
the (double) vector of parameters to the objective funcion |
ffn |
a user-provided function to compute the objective function |
trace |
set >0 to provide output from fnchk to the console, 0 otherwise |
... |
optional arguments passed to the objective function. |
fnchk
attempts to discover various errors in function setup in user-supplied
functions primarily intended for use in optimization calculations. There are always
more conditions that could be tested!
The output is a list consisting of list(fval=fval, infeasible=infeasible, excode=excode, msg=msg)
fval |
The calculated value of the function at parameters |
infeasible |
FALSE if the function can be evaluated, TRUE if not. |
excode |
An exit code, which has a relationship to |
msg |
A text string giving information about the result of the function check: Messages and
the corresponding values of
|
John C. Nash <nashjc@uottawa.ca>
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 | # Want to illustrate each case.
# Ben Bolker idea for a function that is NOT scalar
benbad<-function(x, y){
# y may be provided with different structures
f<-(x-y)^2
} # very simple, but ...
y<-1:10
x<-c(1)
cat("test benbad() with y=1:10, x=c(1)\n")
tryfc01 <- try(fc01<-fnchk(x, benbad, trace=3, y))
print(tryfc01)
print(fc01)
y<-as.vector(y)
cat("test benbad() with y=as.vector(1:10), x=c(1)\n")
tryfc02 <- try(fc02<-fnchk(x, benbad, trace=1, y))
print(tryfc02)
print(fc02)
y<-as.matrix(y)
cat("test benbad() with y=as.matrix(1:10), x=c(1)\n")
tryfc03 <- try(fc03<-fnchk(x, benbad, trace=1, y))
print(tryfc03)
print(fc03)
y<-as.array(y)
cat("test benbad() with y=as.array(1:10), x=c(1)\n")
tryfc04 <- try(fc04<-fnchk(x, benbad, trace=1, y))
print(tryfc04)
print(fc04)
y<-"This is a string"
cat("test benbad() with y a string, x=c(1)\n")
tryfc05 <- try(fc05<-fnchk(x, benbad, trace=1, y))
print(tryfc05)
print(fc05)
fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
xtrad<-c(-1.2,1)
ros1<-fnchk(xtrad, fr, trace=1)
print(ros1)
## Too complicated
## npar<-2
## opros<-list2env(list(fn=fr, gr=NULL, hess=NULL, MAXIMIZE=FALSE,
## PARSCALE=rep(1,npar), FNSCALE=1,
#3 KFN=0, KGR=0, KHESS=0, dots=NULL))
## uros1<-fnchk(xtrad, ufn, trace=1, fnuser=opros)
## print(uros1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.