Skip to content
/ splitfngr Public

❗ This is a read-only mirror of the CRAN R package repository. splitfngr — Combined Evaluation and Split Access of Functions

Notifications You must be signed in to change notification settings

cran/splitfngr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

splitfngr

Travis-CI Build Status

Sometimes multiple values are returned by a single function. This makes sense when their combined evaluation is faster than separate evaluations, such as function and corresponding gradient values which require solving the same matrix system. If the user wants to have separate functions for the function and gradient, such as when passing to an optimization routine.

Functions provided in this package allow this to be done in a general situation.

Below is an example. The R function optim with method BFGS requires a function for the function value and gradient value separately. In this trivial example the gradient value is not recalculated when it is called.

# A function that returns
quad_share <- function(x){list(sum(x^4), 4*x^3)}
# Run BFGS using function with gradient
splitfngr::optim_share(par=c(3, -5), quad_share, method="BFGS")
#> $par
#> [1] -0.0003599207  0.0006973696
#> 
#> $value
#> [1] 2.532927e-13
#> 
#> $counts
#> function gradient 
#>       42       36 
#> 
#> $convergence
#> [1] 0
#> 
#> $message
#> NULL

See the documentation for more examples and details on usage.

About

❗ This is a read-only mirror of the CRAN R package repository. splitfngr — Combined Evaluation and Split Access of Functions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages