File: grfwd.Rd

package info (click to toggle)
r-cran-optimx 2020-4.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,492 kB
  • sloc: sh: 21; makefile: 5
file content (71 lines) | stat: -rwxr-xr-x 1,546 bytes parent folder | download | duplicates (3)
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
\name{grfwd}
\alias{grfwd}
\alias{optsp}

\title{Forward difference numerical gradient approximation.}

\description{
   \code{grfwd} computes the forward difference approximation to the gradient of 
          user function \code{userfn}. 
}
\usage{
   grfwd(par, userfn, fbase=NULL, env=optsp, ...)
}
\arguments{
     
    \item{par}{
        parameters to the user objective function userfn
        }
    \item{userfn}{
        User-supplied objective function
        }
    \item{fbase}{
        The value of the function at the parameters, else NULL. This is to save
        recomputing the function at this point.
        }
    \item{env}{
        Environment for scratchpad items (like \code{deps} for approximation 
        control in this routine). Default \code{optsp}.
        }
    \item{\dots}{
        optional arguments passed to the objective function.
        }
}


\details{
\tabular{ll}{
Package: \tab grfwd\cr
Depends: \tab R (>= 2.6.1)\cr
License: \tab GPL Version 2.\cr
}  
}

\value{
\code{grfwd} returns a single vector object \code{df} which approximates the 
gradient of userfn at the parameters par. The approximation is controlled by a
global value \code{optderiveps} that is set when the package is attached.
}
\author{
    John C. Nash
}

\examples{
cat("Example of use of grfwd\n")

myfn<-function(xx, shift=100){
    ii<-1:length(xx)
    result<-shift+sum(xx^ii)
}
xx<-c(1,2,3,4)
ii<-1:length(xx)
print(xx)
gn<-grfwd(xx,myfn, shift=0)
print(gn)
ga<-ii*xx^(ii-1)
cat("compare to\n")
print(ga)
}

\keyword{optimize}