{"id":16876960,"url":"https://github.com/jlmelville/funconstrain","last_synced_at":"2025-04-11T11:33:39.054Z","repository":{"id":20648543,"uuid":"90517223","full_name":"jlmelville/funconstrain","owner":"jlmelville","description":"R Package of Functions for Testing Unconstrained Numerical Optimization","archived":false,"fork":false,"pushed_at":"2024-04-13T23:02:00.000Z","size":1647,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T07:51:14.160Z","etag":null,"topics":["numerical-optimization","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlmelville.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-07T07:52:44.000Z","updated_at":"2023-02-17T04:23:11.000Z","dependencies_parsed_at":"2024-10-13T15:41:10.541Z","dependency_job_id":"dc3d33e5-f43a-47c8-984a-0da32ea2213f","html_url":"https://github.com/jlmelville/funconstrain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlmelville%2Ffunconstrain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlmelville%2Ffunconstrain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlmelville%2Ffunconstrain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlmelville%2Ffunconstrain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlmelville","download_url":"https://codeload.github.com/jlmelville/funconstrain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248384236,"owners_count":21094688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["numerical-optimization","r"],"created_at":"2024-10-13T15:41:05.535Z","updated_at":"2025-04-11T11:33:39.034Z","avatar_url":"https://github.com/jlmelville.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# funconstrain\n\nAn R Package of Functions for Testing Unconstrained Numerical Optimization.\n\n`funconstrain` is a pure R implementation of the 35 test functions in the paper\nby [Moré, Garbow, and Hillstrom](https://doi.org/10.1145/355934.355936) useful\n(to varying degrees) for testing unconstrained numerical optimization methods,\ne.g. those implementing the likes of steepest descent, Newton, BFGS, L-BFGS, \nconjugate gradient and so on.\n\n## Installing\n\n```R\n# if needed, install devtools:\n# install.packages(\"devtools\")\ndevtools::install_github(\"jlmelville/funconstrain\")\nlibrary(funconstrain)\n```\n\n## Documentation\n\n```R\npackage?funconstrain\n```\n\n## Examples\n\nIt's pretty simple. You call a function named after the test problem at hand,\nand get back a list. That list contains: a function that implements the \nobjective function; a function that implements the gradient; a function that\ncalculates the objective and the gradient in one go (if your fancy optimization\nroutine supports that); and a suggested starting point, which is also a function\nif the test problem supports different dimensionalities, and is a plain numeric\nvector otherwise.\n\n```R\n# The famous Rosenbrock function is a problem with two parameters\nrbrock \u003c- rosen()\n\n# rbrock is a list containing function (fn), gradient (gr) and starting point (x0, a 2D numeric vector)\n# Pass them to an optimization method:\nres \u003c- stats::optim(par = rbrock$x0, fn = rbrock$fn, gr = rbrock$gr, method = \"L-BFGS-B\")\n# Or feel free to ignore the suggested starting point and use your own:\nres \u003c- stats::optim(par = c(1.2, 1.2), fn = rbrock$fn, gr = rbrock$gr, method = \"L-BFGS-B\")\n\n# The Chebyquad function is defined for multiple parameters (any n \u003e 0)\ncheby \u003c- chebyquad()\n\n# To use different values of n, we provide it to the starting point x0, which is a function now that n can\n# take multiple values for this test set.\n# A five-parameter version:\nres_n5 \u003c- stats::optim(par = cheby$x0(n = 5), fn = cheby$fn, gr = cheby$gr, method = \"L-BFGS-B\")\n# And a 10-parameter version:\nres_n10 \u003c- stats::optim(par = cheby$x0(n = 10), fn = cheby$fn, gr = cheby$gr, method = \"L-BFGS-B\")\n```\nThe package and function documentation contain more examples.\n\n## Why do this?\n\nFor testing numerical optimization routines, the go-to set of test problems is\n[CUTEst](https://ccpforge.cse.rl.ac.uk/gf/project/cutest/wiki). However, if you\naren't compiling and linking to it directly, you'd have to write a parser for \nthe SIF file format it uses. Neither of those possibilities appealed.\n\nInstead, I re-implemented the functions as provided in the paper and also \ncalculated analytical gradients for them. I did look to see if all 35 problems\nwere implemented in one place in R, but failed to find such a package.\n\n## Are the functions correct?\n\nThere are unit tests for each test problem which ensure that:\n\n* The analytical gradients match finite difference estimates at the suggested\nstarting point.\n* If the location of a minima was given in the paper, that the analytical\ngradient is close to zero at that location.\n* If the location of a minima was given in the paper, that the objective\nfunction has the correct value at that location.\n* Running the L-BFGS or BFGS method as implemented in the `stats::optim`\nfunction gets to the specified minimum.\n\n## Is the implementation efficient?\n\nNot really. My goal was correctness, and to make the code clear. Also perhaps, \nto be useful if anyone ever wants to translate these into other languages \nwithout having to know a lot of idiomatic R.\n\nI have made use of vectorized arithmetic operation rather than explicit `for`\nloops where possible as well as using functions like `sum`. Also, I am pretty\nprofligate in storing pre-computed vectors, trading off memory consumption for\nclarity and potentially fast vectorized computations (I have not done any \nprofiling). But I consciously eschewed the use of  `apply` `sweep` or other \ncleverness. \n\nI think I have elided the most gratuitious inefficiencies, such as unnecessary\nrecomputation of values inside loops.\n\n## See also\n\n* The aforementioned \n[CUTEst](https://ccpforge.cse.rl.ac.uk/gf/project/cutest/wiki). I believe all\nor nearly all of the test problems in this package are implemented in CUTEst, \nbut I make no representation that you will get the same results (if there are\nany differences, assume it's a bug in `funconstrain`).\n* I made ample use of the excellent \n[Derivative Calculator](http://www.derivative-calculator.net) to calculate the\nanalytical gradients.\n* Shameless plug: I wrote this package to test \n[mize](https://github.com/jlmelville/mize), an R package for doing numerical\noptimization.\n\n## License\n\n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlmelville%2Ffunconstrain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlmelville%2Ffunconstrain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlmelville%2Ffunconstrain/lists"}