Commit 6a5994f9 authored by davidkep's avatar davidkep

Merge branch 'master' into develop

* master:
  fix README
  fix README
  update readme
  Update README with example
  update version nr
  Add LICENSE
parents b4eab35c c583828a
......@@ -2,25 +2,23 @@ Package: nsoptim
Type: Package
Title: Utility Library to Implement Non-Smooth Optimization in C++
Version: 0.1.0
Date: 2019-01-30
Date: 2019-10-24
Authors@R: person("David", "Kepplinger", , "david.kepplinger@gmail.com",
role = c("aut", "cre"))
Copyright: See the file COPYRIGHTS for copyright details on some of the
functions and algorithms used.
Encoding: UTF-8
SystemRequirements: C++11
URL: https://github.com/dakep/nsoptim-rpkg
BugReports: https://github.com/dakep/nsoptim-rpkg/issues
Description: A C++ library to help solve non-smooth optimziation problems
in R packages.
URL: https://gitlab.math.ubc.ca/dakep/nsoptim
BugReports: https://gitlab.math.ubc.ca/dakep/nsoptim/issues
Description: A C++ template library for non-smooth optimziation.
Depends:
R (>= 3.4.0)
Imports:
Rcpp
LinkingTo:
Rcpp,
RcppArmadillo (>= 0.9.100),
testthat
RcppArmadillo (>= 0.9.100)
Suggests:
testthat (>= 2.1.0)
License: MIT + file LICENSE
......
......@@ -11,5 +11,39 @@ Due to the early stage of the library, the interface might change considerably i
The C++ header files are in [inst/include](inst/include) and can be used from within other R packages by adding `nsoptim`
to the `LinkingTo` field in the package's DESCRIPTION file.
## Example Usage
```cpp
#include <memory>
#include <nsoptim.hpp> // This also includes the armadillo library
// Alias for a linearized ADMM optimizer operating on the standard LS regression loss and an EN penalty using a dense coefficient vector.
using LinearizedAdmmOptimizer = nsoptim::LinearizedAdmmOptimizer<nsoptim::LsLoss, nsoptim::EnPenalty, nsoptim::RegressionCoefficients<arma::vec>>;
typename LinearizedAdmmOptimizer::Coefficients Foo() {
// Generate dummy data with 100 observations and 10 predictors.
auto data = std::make_shared<nsoptim::PredictorResponseData>(arma::randn(100, 10), arma::randn(10));
nsoptim::LsLoss loss(data); // Create a LS loss function object with the generated data
nsoptim::EnPenalty penalty1(0.5, 2.4) // Create an EN penalty function object with alpha=0.5 and lambda=2.4
nsoptim::EnPenalty penalty2(0.5, 1.5) // Create an EN penalty function object with alpha=0.5 and lambda=1.5
// Create an optimizer for the given loss and penalty function, using default parameters for the ADMM algorithm.
LinearizedAdmmOptimizer optim(loss, penalty1);
// Compute the optimum for `penalty1`, starting at the 0-vector.
typename LinearizedAdmmOptimizer::Optimum optimum = optim.Optimize();
// Change the penalty to `penalty2`.
optim.penalty(penalty2);
// Compute the optimum for `penalty2`, starting at the optimum for `penalty1`.
typename LinearizedAdmmOptimizer::Optimum optimum = optim.Optimize();
// Only return the coefficients.
return optimum.coefs;
}
```
## Documentation
The documentation for the library is a work in progress. Currently, source code files include doxygen-style comments.
The documentation for the library is available at https://nsoptim.readthedocs.org.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment