Title: | Translate R Linear Algebra Code to Armadillo C++ |
---|---|
Description: | Compile linear algebra R code to C++ using the Armadillo Template Library. The package further supports mathematical optimization purely in C++. |
Authors: | Dirk Schumacher [aut, cre] |
Maintainer: | Dirk Schumacher <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-09-05 03:22:51 UTC |
Source: | https://github.com/dirkschumacher/armacmp |
Compile Linear Algebra Code to C++
compile(fun, verbose = FALSE)
compile(fun, verbose = FALSE)
fun |
a function |
verbose |
optional logical, print out compiler information This function always compiles functions.
Every function needs to have a Take a look at function reference vignette for more information. |
## Not run: trans <- compile(function(X) { return(t(X)) }) trans(matrix(1:10)) ## End(Not run)
## Not run: trans <- compile(function(X) { return(t(X)) }) trans(matrix(1:10)) ## End(Not run)
The function compiles the code to C++ and uses Armadillo and ensmallen to optimize it.
compile_optimization_problem( data = list(), evaluate, gradient, optimizer = optimizer_SA() )
compile_optimization_problem( data = list(), evaluate, gradient, optimizer = optimizer_SA() )
data |
a named list of prior data you would like to supply to the evaluate function. |
evaluate |
a function that is to be minimized. It should return a single numeric. |
gradient |
optional, a function computing the gradient of |
optimizer |
one of the many optimizers |
## Not run: optimize <- compile_optimization_problem( data = list(), evaluate = function(x) { return(2 * norm(x)^2) }, optimizer = optimizer_SA() ) # should be roughly c(0, 0, 0) result <- optimize(matrix(c(1, -1, 1), ncol = 1)) ## End(Not run)
## Not run: optimize <- compile_optimization_problem( data = list(), evaluate = function(x) { return(2 * norm(x)^2) }, optimizer = optimizer_SA() ) # should be roughly c(0, 0, 0) result <- optimize(matrix(c(1, -1, 1), ncol = 1)) ## End(Not run)
Conventional Neural Evolution Optimizer
optimizer_CNE( populationSize = 500, maxGenerations = 5000, mutationProb = 0.1, mutationSize = 0.02, selectPercent = 0.2, tolerance = 1e-05 )
optimizer_CNE( populationSize = 500, maxGenerations = 5000, mutationProb = 0.1, mutationSize = 0.02, selectPercent = 0.2, tolerance = 1e-05 )
populationSize |
The number of candidates in the population. This should be at least 4 in size 500 |
maxGenerations |
The maximum number of generations allowed for CNE 5000 |
mutationProb |
Probability that a weight will get mutated 0.1 |
mutationSize |
The range of mutation noise to be added. This range is between 0 and mutationSize 0.02 |
selectPercent |
The percentage of candidates to select to become the the next generation 0.2 |
tolerance |
The final value of the objective function for termination. If set to negative value, tolerance is not considered 1e-5 |
Gradient Descent Optimizer
optimizer_GradientDescent( stepSize = 0.01, maxIterations = 1e+05, tolerance = 1e-05 )
optimizer_GradientDescent( stepSize = 0.01, maxIterations = 1e+05, tolerance = 1e-05 )
stepSize |
Step size for each iteration |
maxIterations |
Maximum number of iterations allowed (0 means no limit). |
tolerance |
Maximum absolute tolerance to terminate algorithm. |
L-BFGS Optimizer
optimizer_L_BFGS( numBasis = 10, maxIterations = 10000, armijoConstant = 1e-04, wolfe = 0.9, minGradientNorm = 1e-06, factr = 1e-15, maxLineSearchTrials = 50, minStep = 1e-20, maxStep = 1e+20 )
optimizer_L_BFGS( numBasis = 10, maxIterations = 10000, armijoConstant = 1e-04, wolfe = 0.9, minGradientNorm = 1e-06, factr = 1e-15, maxLineSearchTrials = 50, minStep = 1e-20, maxStep = 1e+20 )
numBasis |
Number of memory points to be stored (default 10) |
maxIterations |
Maximum number of iterations for the optimization (0 means no limit and may run indefinitely) |
armijoConstant |
Controls the accuracy of the line search routine for determining the Armijo condition |
wolfe |
Parameter for detecting the Wolfe condition |
minGradientNorm |
Minimum gradient norm required to continue the optimization |
factr |
Minimum relative function value decrease to continue the optimization |
maxLineSearchTrials |
The maximum number of trials for the line search (before giving up) |
minStep |
The minimum step of the line search |
maxStep |
The maximum step of the line search |
Simulated-Annealing with exponential schedule
optimizer_SA()
optimizer_SA()
Simultaneous Perturbation Stochastic Approximation (SPSA)
optimizer_SPSA( alpha = 0.602, gamma = 0.101, stepSize = 0.16, evaluationStepSize = 0.3, maxIterations = 1e+05, tolerance = 1e-05 )
optimizer_SPSA( alpha = 0.602, gamma = 0.101, stepSize = 0.16, evaluationStepSize = 0.3, maxIterations = 1e+05, tolerance = 1e-05 )
alpha |
Scaling exponent for the step size. |
gamma |
Scaling exponent for evaluation step size. |
stepSize |
Scaling parameter for step size. |
evaluationStepSize |
Scaling parameter for evaluation step size. |
maxIterations |
Maximum number of iterations allowed (0 means no limit). |
tolerance |
Maximum absolute tolerance to terminate algorithm. |
Compile a function to C++
translate(fun, function_name)
translate(fun, function_name)
fun |
a function |
function_name |
the function name |
a list of type "armacmp_cpp_fun"