roptim
General Purpose Optimization in R using C++: provides a unified C++ wrapper to call functions of the algorithms underlying the optim() solver
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
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
- Host: GitHub
- Owner: ypan1988
- Language: C++
- Default Branch: master
- Homepage: https://cran.r-project.org/web/packages/roptim/index.html
- Size: 356 KB
Statistics
- Stars: 20
- Watchers: 1
- Forks: 4
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
roptim: General Purpose Optimization in R using C++.
Features
- Perform general purpose optimization in
Rusing theArmadilloC++library for numerical linear algebra. - A unified wrapper interface is used to call
Ccode of the five optimization algorithms (namelyNelder-Mead,BFGS,CG,L-BFGS-BandSANN) underlying functionoptim()(packagestats) provided by defaultRinstallation.
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
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
- Repositories: 38
- Profile: https://github.com/ypan1988
GitHub Events
Total
Last Year
Committers
Last synced: almost 3 years ago
Top Committers
| Name | 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++
- Homepage: https://github.com/ypan1988/roptim/
- Documentation: http://cran.r-project.org/web/packages/roptim/roptim.pdf
- License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
-
Latest release: 0.1.6
published over 3 years ago
Rankings
Maintainers (1)
conda-forge.org: r-roptim
- Homepage: https://github.com/ypan1988/roptim/
- License: GPL-2.0-or-later
-
Latest release: 0.1.6
published over 3 years ago
Rankings
Dependencies
- Rcpp >= 0.12.14 imports
- R.rsp * suggests
- testthat >= 3.0.0 suggests