Description Details References Examples

Define a problem for ManifoldOptim to solve.

A problem definition contains an objective function *f* and a gradient
function *g*. The gradient *g* is computed as if *f* is defined
on a Euclidean space. If *g* is not specified it will be computed
numerically, which is potentially much slower.

The easiest way to define a problem is completely in R. Example 1
below illustrates how to construct a problem using a given *f* and
*g*. Example 2 constructs the same problem without providing *g*.
The `Rcpp Module`

framework (Eddelbuettel, 2013) creates underlying
C++ objects necessary to invoke the `ROPTLIB`

library.

The performance of solving an `RProblem`

may be too slow for some
applications; here, the C++ optimizer calls R functions,
which requires some overhead. A faster alternative is to code your problem
in C++ directly, and allow it to be manipulated in R. An
example is provided in this package, under
`tests/brockett/cpp_standalone/`

. Example 3 below shows how to
instantiate this problem.

Package authors may want to use `ManifoldOptim`

within a package to solve
a problem written in C++. In this case, the author would probably
not want to use `sourceCpp`

, but instead have the problem compiled
when the package was installed. An example is provided within this package;
`tests/brockett/cpp_pkg/driver.R`

instantiates the problem defined in:

`src/ManifoldOptim/BrockettProblem.cpp`

.

Dirk Eddelbuettel. Seamless R and C++ Integration with Rcpp, Chapter 7: Modules, pages 83-102. Springer New York, New York, NY, 2013.

Wen Huang, P.A. Absil, K.A. Gallivan, Paul Hand (2016a). "ROPTLIB: an object-oriented C++ library for optimization on Riemannian manifolds." Technical Report FSU16-14, Florida State University.

S. Martin, A. Raim, W. Huang, and K. Adragni (2020). "ManifoldOptim: An R Interface to the ROPTLIB Library for Riemannian Manifold Optimization." Journal of Statistical Software, 93(1):1-32.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```
## Not run:
# --- Example 1: Define a problem in R ---
f <- function(x) { ... }
g <- function(x) { ... }
mod <- Module("ManifoldOptim_module", PACKAGE = "ManifoldOptim")
prob <- new(mod$RProblem, f, g)
# --- Example 2: Define a problem in R without specifying gradient ---
f <- function(x) { ... }
mod <- Module("ManifoldOptim_module", PACKAGE = "ManifoldOptim")
prob <- new(mod$RProblem, f)
# --- Example 3: Instantiate a problem written in C++ ---
p <- 5; n <- 150
B <- matrix(rnorm(n*n), nrow=n)
B <- B + t(B) # force symmetric
D <- diag(p:1, p)
Rcpp::sourceCpp("brockett_problem.cpp")
prob <- new(BrockettProblem, B, D)
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.