# splitfngr v0.1.2

Monthly downloads

## Combined Evaluation and Split Access of Functions

Some R functions, such as optim(), require a function
its gradient passed as separate arguments. When these are
expensive to calculate it may be much faster to calculate
the function (fn) and gradient (gr) together since they often share
many calculations (chain rule). This package allows the user
to pass in a single function that returns both the function
and gradient, then splits (hence 'splitfngr') them
so the results can be accessed
separately. The functions provided allow this to be done with
any number of functions/values, not just for functions and gradients.

## Readme

# splitfngr

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.

## Functions in splitfngr

Name | Description | |

lbfgs_share | Use splitfngr with lbfgs | |

make_share | Convert a function from multiple function arguments to a single function | |

fngr | Access a list of values separately but calculate them together. This function generalizes grad_share for any number of functions. | |

nlminb_share | Use splitfngr with nlminb | |

optim_share | Use splitfngr with optim | |

grad_share | Split function and gradient calculation | |

No Results! |

## Last month downloads

## Details

Type | Package |

License | GPL-3 |

LazyData | TRUE |

Encoding | UTF-8 |

RoxygenNote | 6.1.1 |

NeedsCompilation | no |

Packaged | 2019-01-30 14:12:15 UTC; cbe117 |

Repository | CRAN |

Date/Publication | 2019-01-30 15:20:03 UTC |

imports | lbfgs |

Contributors | Collin Erickson |

#### Include our badge in your README

```
[![Rdoc](http://www.rdocumentation.org/badges/version/splitfngr)](http://www.rdocumentation.org/packages/splitfngr)
```