Skip to content

A wrapper around R's optimisation routines where function gradients are computed with auto-diff

Notifications You must be signed in to change notification settings

mkomod/ad-optim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ad-optim

Optimisation routines in R rely on functions to compute gradients. ad-optim is a wrapper around R's optimisations routines where function gradients are computed automatically via algorithmic differentiation (through CppAD).

Installation

R> devtools::install_github("mkomod/ad-optim")

Usage

adoptim is used via Rcpp by the inclusion of the "adoptim.hpp" header

#include "adoptim.hpp"

using namespace adoptim;

// define a function
class Func : public AD_func {
    // define the fn method
    ad_double fn(const ad_vec_double &x) {
	return 100 * pow(x[1] - x[0]*x[0], 2) + pow(1-x[0], 2);
    }
}


void some_other_function() {
    // ...
    Func func;
    std::vector<double> par = { ... }; // parmeter values
    func.set_grad(par); // initialise the gradient function

    optim(func, par); // optimise
}

About

A wrapper around R's optimisation routines where function gradients are computed with auto-diff

Topics

Resources

Stars

Watchers

Forks