{"id":32203260,"url":"https://github.com/fifis/pnd","last_synced_at":"2025-10-22T04:36:22.593Z","repository":{"id":227865573,"uuid":"727950244","full_name":"Fifis/pnd","owner":"Fifis","description":"R package for accurate and quick numerical derivatives of arbitrary order","archived":false,"fork":false,"pushed_at":"2025-09-17T15:28:07.000Z","size":430,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-11T05:13:34.764Z","etag":null,"topics":["finite-differences","numerical-differentiation","parallel-algorithm","r-package","step-size"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fifis.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-05T23:00:09.000Z","updated_at":"2025-09-17T15:28:12.000Z","dependencies_parsed_at":"2025-02-11T23:25:46.868Z","dependency_job_id":"4a648026-8cd0-463b-a968-c65b4b7b8d1e","html_url":"https://github.com/Fifis/pnd","commit_stats":null,"previous_names":["fifis/pnd"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Fifis/pnd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fifis%2Fpnd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fifis%2Fpnd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fifis%2Fpnd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fifis%2Fpnd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fifis","download_url":"https://codeload.github.com/Fifis/pnd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fifis%2Fpnd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280382190,"owners_count":26321419,"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","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["finite-differences","numerical-differentiation","parallel-algorithm","r-package","step-size"],"created_at":"2025-10-22T04:36:19.496Z","updated_at":"2025-10-22T04:36:22.582Z","avatar_url":"https://github.com/Fifis.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- badges: start --\u003e\n[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n[![R-CMD-check](https://github.com/Fifis/pnd/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Fifis/pnd/actions/workflows/R-CMD-check.yaml)\n[![codecov](https://codecov.io/gh/Fifis/pnd/graph/badge.svg?token=2ZTHBCRLBR)](https://app.codecov.io/gh/Fifis/pnd)\n\u003c!-- badges: end --\u003e\n\n# pnd\n\nAn R package for computing fast and accurate numerical derivatives.\n\n\u003cimg src=\"https://kostyrka.lu/user/pages/50.programming/05.pnd.package/parallel-numerical-derivatives-R-package.png\" alt=\"Parallel numerical derivatives in R\" width=\"640\"/\u003e\n\nIn the past, I was using [numDeriv](https://CRAN.R-project.org/package=numDeriv) to compute numerical gradients.\nHowever, the results were not stable for some function, and I could not investigate the source of this instability.\nDifferent step sizes yielded different results. Small step sizes were sometimes better, sometimes worse.\n\nThe `pnd` package was designed to offer a comprehensive tool-kit containing popular algorithms for finite differences, numerical gradients, Jacobians, and Hessians.\n\nOptimal step sizes and parallel evaluation of numerical derivatives translate directly to faster numerical optimisation and statistical inference.\n\n\n## Features\n- **Robust numerical differentiation:** effortlessly compute derivatives while controlling the accuracy-speed trade-off.\n- **Gradient and Hessian calculations:** obtain the direction and curvature required by most quasi-Newton optimisation algorithms.\n- **Parallel capabilities:** evaluate multiple values under the best parallelisation scheme that reduces overhead. For example, on a 12-core machine, a 4th-order accurate Jacobian of a 3-dimensional function takes almost the same amount of time as one function evaluation.\n- **Optimal step size selection:** obtain adaptive step size to ensure the best trade-off between mathematical truncation error and computer floating-point rounding error for the best overall accuracy.\n- **Six optimal step selection algorithms:** choose between Curtis–Reid (1974) and its modern (2025) modification, Dumontet–Vignes (1977), Stepleman–Winarsky (1979), Mathur (2012), and Kostyrka (2025) algorithms. Future versions will feature parallelised algorithms.\n\n## Getting started\n\nThis package has `numDeriv`-compatible syntax.\nSimply replace the first letter of `numDeriv` commands with a capital one to get the improved commands: `Grad`, `Jacobian`, and `Hessian`.\n\nHere is how to compute the gradient of `f(x) = sum(sin(x))` at the point `x = (1, 2, 3, 4)`.\n\n```r\nf \u003c- function(x) sum(sin(x))\nx \u003c- 1:4\nnames(x) \u003c- c(\"Jan\", \"Feb\", \"Mar\", \"Apr\")\n\nnumDeriv::grad(f, x)\n#\u003e 0.5403023 -0.4161468 -0.9899925 -0.6536436\n\npnd::Grad(f, x)\n#\u003e Estimated gradient:\n#\u003e      Jan      Feb      Mar      Apr  \n#\u003e   0.5403  -0.4161  -0.9900  -0.6536  \n#\u003e (default step size: 6.1e-06, 1.2e-05, 1.8e-05, 2.4e-05).\n```\n\nThe output contains diagnostic information about the chosen step size.\nOur function preserved the names of the input argument, unlike `grad`.\n\nThe default step size in many implementations is proportional to the argument value, and this is reflected in the default output.\nShould the user desire a fixed step size, this can be easily achieved with an extra argument named `h`:\n\n```r\npnd::Grad(f, x, h = c(1e-5, 1e-5, 1e-5, 2e-5))\n#\u003e Estimated gradient:\n#\u003e      Jan      Feb      Mar      Apr  \n#\u003e   0.5403  -0.4161  -0.9900  -0.6536  \n#\u003e (user-supplied step size: 1.0e-05, 1.0e-05, 1.0e-05, 2.0e-05).\n```\n\nFinally, it is easy to request an algorithmically chosen optimal step size -- here is how to do it with the Stepleman--Winarsky (1979) rule, named `\"SW\"`, that works well in practice:\n\n```r\npnd::Grad(f, x, h = \"SW\")\n#\u003e Estimated gradient:\n#\u003e      Jan      Feb      Mar      Apr  \n#\u003e   0.5403  -0.4161  -0.9900  -0.6536  \n#\u003e (SW step size: 5.0e-06, 1.0e-05, 7.5e-06, 1.0e-05).\n```\n\nExtensive diagnostics requested at any time: the step-search tracing information is saved in the `attr(pnd::Grad(...), \"step.search\")` attribute that has an `$iterations` element.\nThe numerical gradients and Jacobian are simple numeric vectors and matrices with attributes that facilitate printing -- feel free to handle them as any other numeric object.\n\n## Learning resources\n\n- [PDF of a 2025 presentation at the University of Luxembourg.](https://kostyrka.lu/en/education/presentations/2025-dem-internal-seminar.pdf)\n- [PDF of an early 2024 presentation at the University of Luxembourg.](https://kostyrka.lu/en/education/presentations/2024-brown-bag-seminar.pdf) *(Obsolete – check the one above or the vignettes for up-to-date examples!)*\n\n## Literature\n\nThis package is supported by 3 vignettes:\n\n* Kostyrka, A. V. Fast and accurate parallel numerical derivatives in R. *In progress.*\n* Kostyrka, A. V. Compatilibility of pnd with the syntax of numDeriv. *In progress.*\n* Kostyrka, A. V. Step-size-selection algorithm benchmark. *In progress.*\n\nThe following articles provide the theory behind the methods implemented in this package:\n\n* [Kostyrka, A. V. (2025). Step size selection in numerical differences using a regression kink.](https://hdl.handle.net/10993/64958) *Department of Economics and Management discussion paper No. 2025-09, University of Luxembourg.*\n* Kostyrka, A. V. (2025). What are you doing, step size: a survey of step-size selection methods for numerical derivatives. *In progress.*\n* Kostyrka, A. V. (2025). In the steps of central differences: improved algorithms for numerical derivatives. *In progress.*\n\n## Installation\n\nThe stable version is on [CRAN](https://cran.r-project.org/package=pnd).\nTo install it, run the following line:\n```r\ninstall.packages(\"pnd\")\n```\n\nThe development version is available on GitHub. To install it, run the following two commands:\n```r\ninstall.packages(\"devtools\")\ndevtools::install_github(\"Fifis/pnd\")\n```\n\nTo load this package, include this line in the code:\n```r\nlibrary(pnd)\n```\n\nThis package is almost dependency-free; the `parallel` library belongs to the `base`\ngroup and is included in most R distributions.\n\n## Licence\n\nThis software is released under the free/open-source [EUPL 1.2 licence](https://interoperable-europe.ec.europa.eu/collection/eupl/eupl-text-eupl-12).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffifis%2Fpnd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffifis%2Fpnd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffifis%2Fpnd/lists"}