Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rcpp Implementation #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .Rproj.user/864BD013/cpp-compilation-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"args": [
"-std=gnu++11",
"-IC:/PROGRA~1/R/R-41~1.2/include",
"-DNDEBUG",
"-IC:/Users/vrfra/Documents/GitHub/optimg/inst/include",
"-DBOOST_NO_LONG_LONG",
"-DBOOST_NO_AUTO_PTR",
"-DBOOST_BIND_GLOBAL_PLACEHOLDERS",
"-DRCPP_NO_RTTI",
"-DRCPP_USE_UNWIND_PROTECT",
"-IC:/Users/vrfra/Documents/R/win-library/4.1/Rcpp/include",
"-IC:/Users/vrfra/Documents/R/win-library/4.1/RcppArmadillo/include",
"-nostdinc",
"-IC:/rtools40/mingw64/include/c++/8.3.0",
"-IC:/rtools40/mingw64/include/c++/8.3.0/x86_64-w64-mingw32",
"-IC:/rtools40/mingw64/include/c++/8.3.0/backward",
"-IC:/rtools40/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/include",
"-IC:/rtools40/mingw64/include",
"-IC:/rtools40/mingw64/lib/gcc/x86_64-w64-mingw32/8.3.0/include-fixed",
"-IC:/rtools40/mingw64/x86_64-w64-mingw32/include"
],
"pch": "RcppArmadillo",
"is_cpp": true,
"hash": "165330913916533285431653328560",
"compiler": "2977220399556355138",
"rversion": "4.1.2"
}
161 changes: 161 additions & 0 deletions .Rproj.user/864BD013/cpp-definition-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
[
{
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"file_last_write": 1653248994.0,
"definitions": [
{
"usr": "c:@F@grad#$@N@Rcpp@S@Function_Impl>#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#d#",
"kind": 6,
"parent_name": "",
"name": "grad(Rcpp::Function, Rcpp::NumericVector, double)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 11,
"column": 21
},
{
"usr": "c:@F@binCoef#I#I#",
"kind": 6,
"parent_name": "",
"name": "binCoef(int, int)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 25,
"column": 5
},
{
"usr": "c:@F@gradN#$@N@Rcpp@S@Function_Impl>#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#d#I#",
"kind": 6,
"parent_name": "",
"name": "gradN(Rcpp::Function, Rcpp::NumericVector, double, int)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 32,
"column": 21
},
{
"usr": "c:@F@reltol#d#d#",
"kind": 6,
"parent_name": "",
"name": "reltol(double, double)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 74,
"column": 8
},
{
"usr": "c:@F@order_#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "order_(Rcpp::NumericVector)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 78,
"column": 15
},
{
"usr": "c:@F@mean_v#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#I#",
"kind": 6,
"parent_name": "",
"name": "mean_v(Rcpp::NumericVector, int)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 84,
"column": 8
},
{
"usr": "c:@F@crit_v#$@N@Rcpp@S@Matrix>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "crit_v(Rcpp::NumericMatrix)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 96,
"column": 8
},
{
"usr": "c:@F@steepSGD#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI19#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "steepSGD(Rcpp::NumericVector, Rcpp::List)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 109,
"column": 8
},
{
"usr": "c:@F@steepSTGD#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI19#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "steepSTGD(Rcpp::NumericVector, Rcpp::List)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 117,
"column": 8
},
{
"usr": "c:@F@steepLMM#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI19#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "steepLMM(Rcpp::NumericVector, Rcpp::List)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 130,
"column": 8
},
{
"usr": "c:@F@fibonacci#d#d#$@N@Rcpp@S@Vector>#VI19#@N@Rcpp@ST>1#T@PreserveStorage#I#",
"kind": 6,
"parent_name": "",
"name": "fibonacci(double, double, Rcpp::List, int)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 141,
"column": 8
},
{
"usr": "c:Algorithms.cpp@T@funcPtr",
"kind": 8,
"parent_name": "",
"name": "funcPtr",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 173,
"column": 18
},
{
"usr": "c:@F@putFunPtrInXPtr#$@N@std@N@__cxx11@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C#",
"kind": 6,
"parent_name": "",
"name": "putFunPtrInXPtr(std::string)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 175,
"column": 15
},
{
"usr": "c:@F@nelder_mead#$@N@std@N@__cxx11@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI19#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "nelder_mead(std::string, Rcpp::NumericVector, Rcpp::List)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 186,
"column": 12
},
{
"usr": "c:@F@SGD#$@N@Rcpp@S@Function_Impl>#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#S0_#d#I#d#b#",
"kind": 6,
"parent_name": "",
"name": "SGD(Rcpp::Function, Rcpp::NumericVector, Rcpp::Function, double, int, double, bool)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 305,
"column": 6
},
{
"usr": "c:@F@STGD#$@N@Rcpp@S@Function_Impl>#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#S0_#d#I#d#b#",
"kind": 6,
"parent_name": "",
"name": "STGD(Rcpp::Function, Rcpp::NumericVector, Rcpp::Function, double, int, double, bool)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 382,
"column": 6
},
{
"usr": "c:@F@LMM#$@N@Rcpp@S@Function_Impl>#@N@Rcpp@ST>1#T@PreserveStorage#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#S0_#d#I#d#b#",
"kind": 6,
"parent_name": "",
"name": "LMM(Rcpp::Function, Rcpp::NumericVector, Rcpp::Function, double, int, double, bool)",
"file": "C:/Users/vrfra/Documents/GitHub/optimg/src/Algorithms.cpp",
"line": 463,
"column": 6
}
]
}
]
5 changes: 5 additions & 0 deletions .Rproj.user/864BD013/pcs/debug-breakpoints.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"debugBreakpointsState": {
"breakpoints": []
}
}
9 changes: 9 additions & 0 deletions .Rproj.user/864BD013/pcs/files-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sortOrder": [
{
"columnIndex": 2,
"ascending": true
}
],
"path": "~/GitHub/optimg"
}
3 changes: 3 additions & 0 deletions .Rproj.user/864BD013/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"activeTab": -1
}
14 changes: 14 additions & 0 deletions .Rproj.user/864BD013/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"left": {
"splitterpos": 376,
"topwindowstate": "HIDE",
"panelheight": 904,
"windowheight": 942
},
"right": {
"splitterpos": 565,
"topwindowstate": "NORMAL",
"panelheight": 904,
"windowheight": 942
}
}
5 changes: 5 additions & 0 deletions .Rproj.user/864BD013/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"TabSet1": 3,
"TabSet2": 3,
"TabZoom": {}
}
8 changes: 8 additions & 0 deletions .Rproj.user/864BD013/persistent-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build-last-errors="[]"
build-last-errors-base-dir="~/GitHub/optimg/"
build-last-outputs="[{\"type\":0,\"output\":\"==> Rcpp::compileAttributes()\\n\\n\"},{\"type\":1,\"output\":\"* Updated R/RcppExports.R\\r\\n\"},{\"type\":1,\"output\":\"\\n\"},{\"type\":0,\"output\":\"==> Rcmd.exe INSTALL --no-multiarch --with-keep.source optimg\\n\\n\"},{\"type\":1,\"output\":\"* installing to library 'C:/Users/vrfra/AppData/Local/R/win-library/4.2'\\r\\n\"},{\"type\":1,\"output\":\"* installing *source* package 'optimg' ...\\r\\n\"},{\"type\":1,\"output\":\"** using staged installation\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"make: Nothing to be done for 'all'.\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** libs\\r\\n\"},{\"type\":1,\"output\":\"installing to C:/Users/vrfra/AppData/Local/R/win-library/4.2/00LOCK-optimg/00new/optimg/libs/x64\\r\\n\"},{\"type\":1,\"output\":\"** R\\r\\n\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\r\\n\"},{\"type\":1,\"output\":\"*** installing help indices\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** building package indices\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\r\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\r\\n\"},{\"type\":1,\"output\":\"* DONE (optimg)\\r\\n\"},{\"type\":1,\"output\":\"\"}]"
compile_pdf_state="{\"tab_visible\":false,\"running\":false,\"target_file\":\"\",\"output\":\"\",\"errors\":[]}"
files.monitored-path=""
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"ignoreCase\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOn\":[],\"matchOff\":[],\"replaceMatchOn\":[],\"replaceMatchOff\":[]},\"running\":false,\"replace\":false,\"preview\":false,\"gitFlag\":false,\"replacePattern\":\"\"}"
imageDirtyState="0"
saveActionState="0"
5 changes: 5 additions & 0 deletions .Rproj.user/864BD013/rmd-outputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@





1 change: 1 addition & 0 deletions .Rproj.user/864BD013/saved_source_markers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"active_set":"","sets":[]}
34 changes: 22 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
Package: optimg
Type: Package
Title: General-purpose Gradient-based Optimization
Version: 0.1.0
Year: 2021, October
Author: Vithor Rosa Franco <[email protected]>
Package: optimg
Title: General-Purpose Gradient-Based Optimization
Version: 0.2.0
Date: 2022-05-19
Authors@R: c(person(given = "Vithor Rosa", family = "Franco", role = c("aut", "cre", "cph"), email = "[email protected]"), person(given="Alexandre Augusto de Sá", family = "dos Santos", role = c("aut", "cph")), person(given = "Felipe Ofugi", family = "Hara", role = c("aut", "cph")))
Author: Vithor Rosa Franco [aut, cre, cph],
Alexandre Augusto de Sá dos Santos [aut, cph],
Felipe Ofugi Hara [aut, cph]
Maintainer: Vithor Rosa Franco <[email protected]>
Description: This package is a general purpose tool for helping users to implement
gradient descent methods for function optimization. Currently, the
Steepest 2-Groups Gradient Descent and the Adaptive Moment Estimation
(Adam) are the methods implemented. Other methods will be implemented
in the future.
Imports: ucminf (>= 1.1-4)
Description: Provides general purpose tools for helping users to implement steepest
gradient descent methods for function optimization; for details see
Ruder (2016) <arXiv:1609.04747v2>. Currently, the Stepeest Gradient
Descent, the Steepest 2-Groups Gradient Descent and the Adaptive Moment
Estimation (Adam) are the methods implemented. Other methods will be
implemented in the future.
License: GPL-3
Encoding: UTF-8
Depends: R(>= 4.0)
Imports: Rcpp (>= 1.0.8)
LinkingTo: Rcpp,
RcppArmadillo
SystemRequirements: C++11
LazyData: true
URL: https://github.com/vthorrf/optimg
BugReports: https://github.com/vthorrf/optimg/issues
Encoding: UTF-8
NeedsCompilation: yes
7 changes: 3 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
useDynLib(optimg, .registration=TRUE)
importFrom(Rcpp, evalCpp)
#exportPattern("^[[:alpha:]]+")
export(optimg)
importFrom("ucminf", "ucminf")
importFrom("stats", "optim", "rnorm", "sd")
importFrom("utils", "setTxtProgressBar", "txtProgressBar")
export(optimg, gradient)
23 changes: 23 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

grad <- function(Model, par, h = 1e-6) {
.Call(`_optimg_grad`, Model, par, h)
}

gradN <- function(f, par, h = 1e-6, order = 1L) {
.Call(`_optimg_gradN`, f, par, h, order)
}

SGD <- function(fn, startvalue, gr, h = 1e-6, maxit = 10L, tol = 1e-8, verbose = FALSE) {
.Call(`_optimg_SGD`, fn, startvalue, gr, h, maxit, tol, verbose)
}

STGD <- function(fn, startvalue, gr, h = 1e-6, maxit = 10L, tol = 1e-8, verbose = FALSE) {
.Call(`_optimg_STGD`, fn, startvalue, gr, h, maxit, tol, verbose)
}

LMM <- function(fn, startvalue, gr, h = 1e-6, maxit = 10L, tol = 1e-8, verbose = FALSE) {
.Call(`_optimg_LMM`, fn, startvalue, gr, h, maxit, tol, verbose)
}

Loading