roptim

General Purpose Optimization in R using C++: provides a unified C++ wrapper to call functions of the algorithms underlying the optim() solver

https://github.com/ypan1988/roptim

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary

Keywords

armadillo bfgs conjugate-gradient cran l-bfgs-b nelder-mead optim rcpp simulated-annealing
Last synced: 6 months ago · JSON representation

Repository

General Purpose Optimization in R using C++: provides a unified C++ wrapper to call functions of the algorithms underlying the optim() solver

Basic Info
Statistics
  • Stars: 20
  • Watchers: 1
  • Forks: 4
  • Open Issues: 0
  • Releases: 0
Topics
armadillo bfgs conjugate-gradient cran l-bfgs-b nelder-mead optim rcpp simulated-annealing
Created over 7 years ago · Last pushed over 3 years ago
Metadata Files
Readme

README.md

roptim: General Purpose Optimization in R using C++.

Build Status cran version downloads total downloads

Features

  • Perform general purpose optimization in R using the Armadillo C++ library for numerical linear algebra.
  • A unified wrapper interface is used to call C code of the five optimization algorithms (namely Nelder-Mead, BFGS, CG, L-BFGS-B and SANN) underlying function optim() (package stats) provided by default R installation.

Installation

Get the development version from github: R install.packages("devtools") library(devtools) devtools::install_github("ypan1988/roptim", dependencies=TRUE)

Or the released version from CRAN: R install.packages("roptim")

A Quick Example

An example of using stats::optim() in R environment: R fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 } grr <- function(x) { ## Gradient of 'fr' x1 <- x[1] x2 <- x[2] c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1), 200 * (x2 - x1 * x1)) } res <- optim(c(-1.2,1), fr, grr, method = "BFGS", control = list(trace=T), hessian = TRUE) res

Corresponding code written in C++ using package roptim (file demo.cpp): ```cpp

include // std::pow

include

// [[Rcpp::depends(RcppArmadillo)]]

include

// [[Rcpp::depends(roptim)]]

using namespace roptim;

class Rosen : public Functor { public: double operator()(const arma::vec &x) override { double x1 = x(0); double x2 = x(1); return 100 * std::pow((x2 - x1 * x1), 2) + std::pow(1 - x1, 2); }

void Gradient(const arma::vec &x, arma::vec &gr) override { gr = arma::zerosarma::vec(2);

double x1 = x(0);
double x2 = x(1);
gr(0) = -400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1);
gr(1) = 200 * (x2 - x1 * x1);

} };

// [[Rcpp::export]] void rosenbfgs() { Rosen rb; Roptim opt("BFGS"); opt.control.trace = 1; opt.sethessian(true);

arma::vec x = {-1.2, 1}; opt.minimize(rb, x);

Rcpp::Rcout << "-------------------------" << std::endl; opt.print(); } ```

Compile and run the function in R: R library(Rcpp) sourceCpp("~/demo.cpp") # you may need to change the directory rosen_bfgs()

Then you will get expected output as follows: ``` initial value 24.200000 iter 10 value 1.367383 iter 20 value 0.134560 iter 30 value 0.001978 iter 40 value 0.000000 final value 0.000000

converged

.par() 1.0000 1.0000

.value() 9.59496e-018

.fncount() 110

.grcount() 43

.convergence() 0

.message() NULL

.hessian() 8.0200e+002 -4.0000e+002 -4.0000e+002 2.0000e+002 ```

Note: more examples are provided in src/roptim_examples.cpp.

Owner

  • Name: Yi Pan
  • Login: ypan1988
  • Kind: user
  • Location: Birmingham
  • Company: University of Birmingham

GitHub Events

Total
Last Year

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 42
  • Total Committers: 5
  • Avg Commits per committer: 8.4
  • Development Distribution Score (DDS): 0.452
Past Year
  • Commits: 5
  • Committers: 2
  • Avg Commits per committer: 2.5
  • Development Distribution Score (DDS): 0.2
Top Committers
Name Email Commits
Yi Pan Y****n@b****k 23
Yi Pan y****8@g****m 16
Yi Pan y****8@u****m 1
Florian Privé f****1@g****m 1
Yi Pan y****n@y****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 8
  • Total pull requests: 1
  • Average time to close issues: 11 days
  • Average time to close pull requests: 2 days
  • Total issue authors: 5
  • Total pull request authors: 1
  • Average comments per issue: 4.38
  • Average comments per pull request: 2.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • SachaEpskamp (3)
  • privefl (2)
  • teng-gao (1)
  • zhiiiyang (1)
  • mengqi00 (1)
Pull Request Authors
  • privefl (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 1,259 last-month
  • Total docker downloads: 20,482
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 2
    (may contain duplicates)
  • Total versions: 9
  • Total maintainers: 1
cran.r-project.org: roptim

General Purpose Optimization in R using C++

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 1,259 Last month
  • Docker Downloads: 20,482
Rankings
Downloads: 11.5%
Forks count: 12.2%
Stargazers count: 12.6%
Docker downloads count: 12.6%
Average: 16.2%
Dependent repos count: 19.3%
Dependent packages count: 28.8%
Maintainers (1)
Last synced: 7 months ago
conda-forge.org: r-roptim
  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Average: 45.5%
Stargazers count: 47.3%
Forks count: 49.6%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • Rcpp >= 0.12.14 imports
  • R.rsp * suggests
  • testthat >= 3.0.0 suggests