{"id":19283021,"url":"https://github.com/david-cortes/approxcdf","last_synced_at":"2025-04-22T01:32:24.571Z","repository":{"id":99290001,"uuid":"505222015","full_name":"david-cortes/approxcdf","owner":"david-cortes","description":"(Python, R, C) Fast approximations for the CDF of multivariate normal distributions","archived":false,"fork":false,"pushed_at":"2024-06-18T16:54:31.000Z","size":101,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-18T21:23:19.503Z","etag":null,"topics":["cdf","multivariate-normal-distribution","statistics"],"latest_commit_sha":null,"homepage":"http://approxcdf.readthedocs.io","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/david-cortes.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-06-19T21:21:49.000Z","updated_at":"2024-06-18T16:54:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"d3b807b4-c0b5-4354-a0c4-d88685a34166","html_url":"https://github.com/david-cortes/approxcdf","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/david-cortes%2Fapproxcdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david-cortes%2Fapproxcdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david-cortes%2Fapproxcdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david-cortes%2Fapproxcdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/david-cortes","download_url":"https://codeload.github.com/david-cortes/approxcdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223887114,"owners_count":17219865,"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":["cdf","multivariate-normal-distribution","statistics"],"created_at":"2024-11-09T21:29:21.551Z","updated_at":"2024-11-09T21:29:22.107Z","avatar_url":"https://github.com/david-cortes.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ApproxCDF\n\nThis is a library for fast approximate calculations of the CDF (cumulative distribution function) of multivariate normal distributions, based on the TVBS (two-variate bivariate screening) method. Written in C++ with interfaces for R, Python, and C.\n\nCompared to the MVNDST library used by R's mvtnorm and Python's SciPy, calculations from this library are typically 2 to 3 orders of magnitue faster, while having results that typically match with MVNDST to around 3-5 decimal places.\n\nAlso implemented are Plackett's reduction for quadrivariate (4D) problems and Tsay's approximation for bivariate (2D) problems.\n\nCan alternatively output log-probabilities which can be more exact when dealing with probabilities too close to zero.\n\n# Installation\n\n* R:\n\n**Note:** This package benefits from extra optimizations that aren't enabled by default for R packages. See [this guide](https://github.com/david-cortes/installing-optimized-libraries) for instructions on how to enable them.\n\n```r\nremotes::install_github(\"david-cortes/approxcdf\")\n```\n\n* Python\n\n**Note:** requires C/C++ compilers configured for Python. See [this guide](https://github.com/david-cortes/installing-optimized-libraries) for instructions.\n\n```\npip install git+https://www.github.com/david-cortes/approxcdf.git\n```\n\n** *\n**IMPORTANT:** the setup script will try to add compilation flag `-march=native`. This instructs the compiler to tune the package for the CPU in which it is being installed (by e.g. using AVX instructions if available), but the result might not be usable in other computers. If building a binary wheel of this package or putting it into a docker image which will be used in different machines, this can be overriden either by (a) defining an environment variable `DONT_SET_MARCH=1`, or by (b) manually supplying compilation `CFLAGS` as an environment variable with something related to architecture. For maximum compatibility (but slowest speed), it's possible to do something like this:\n\n```\nexport DONT_SET_MARCH=1\npip install git+https://www.github.com/david-cortes/approxcdf.git\n```\n\nor, by specifying some compilation flag for architecture:\n```\nexport CFLAGS=\"-march=x86-64\"\nexport CXXFLAGS=\"-march=x86-64\"\npip install git+https://www.github.com/david-cortes/approxcdf.git\n```\n** *\n\n* C:\n\n(Requires BLAS and LAPACK)\n\n```\ngit clone https://www.github.com/david-cortes/approxcdf.git\ncd approxcdf\nmkdir build\ncd build\ncmake -DUSE_MARCH_NATIVE=1 ..\ncmake --build .\n\n### for a system-wide install in linux\nsudo make install\nsudo ldconfig\n```\n# Sample usage\n\n* R:\n```r\nlibrary(approxcdf)\n\n### Example from Plackett's paper\nb \u003c- c(0, 0, 0, 0)\nS \u003c- matrix(\nc( 1,  -0.60,  0.85,  0.75,\n-0.60,    1,  -0.70, -0.80,\n 0.85, -0.70,    1,   0.65,\n 0.75, -0.80,  0.65,    1),\nnrow=4, ncol=4, byrow=TRUE)\npmvn(b, S, is_standardized=TRUE)\n### (Plackett's estimate was 0.042323)\n```\n```\n[1] 0.04348699\n```\n\n* Python:\n```python\nimport numpy as np\nfrom approxcdf import mvn_cdf\n\n### Example from Plackett's paper\nb = np.array([0, 0, 0, 0], dtype=np.float64)\nS = np.array([\n    [   1,  -0.60,  0.85,  0.75,],\n    [-0.60,    1,  -0.70, -0.80,],\n    [ 0.85, -0.70,    1,   0.65,],\n    [ 0.75, -0.80,  0.65,    1],\n])\nmvn_cdf(b, S, is_standardized=True)\n```\n```\n0.043486989827893514\n```\n\n* C:\n```c\n#include \"approxcdf.h\"\n#include \u003cstdio.h\u003e\n#include \u003cstdbool.h\u003e\n\nint main()\n{\n    /* Example from Plackett's paper */\n    const int n = 4;\n    const double b[] = {0., 0., 0., 0.};\n    const double S[] = {\n        1,  -0.60,  0.85,  0.75,\n     -0.60,    1,  -0.70, -0.80,\n      0.85, -0.70,    1,   0.65,\n      0.75, -0.80,  0.65,    1\n    };\n    bool is_standardized = true;\n    bool logp = false; /* log-probability */\n    double prob = norm_cdf(\n        b,\n        S, n,\n        NULL,\n        n,\n        is_standardized,\n        logp,\n        NULL\n    );\n    printf(\"Obtained estimate for Plackett's example: %.6f\\n\", prob);\n    return 0;\n}\n```\n\n# Documentation\n\n* R: documentation is available internally (e.g. `help(pmvn)`).\n\n* Python: documentation is available at [ReadTheDocs](http://approxcdf.readthedocs.io/en/latest/).\n\n* C: documentation is available in the [public header](https://github.com/david-cortes/approxcdf/blob/master/include/approxcdf.h).\n\n# References\n\n* Bhat, Chandra R. \"New matrix-based methods for the analytic evaluation of the multivariate cumulative normal distribution function.\" Transportation Research Part B: Methodological 109 (2018): 238-256.\n* Plackett, Robin L. \"A reduction formula for normal multivariate integrals.\" Biometrika 41.3/4 (1954): 351-360.\n* Gassmann, H. I. \"Multivariate normal probabilities: implementing an old idea of Plackett's.\" Journal of Computational and Graphical Statistics 12.3 (2003): 731-752.\n* Drezner, Zvi, and George O. Wesolowsky. \"On the computation of the bivariate normal integral.\" Journal of Statistical Computation and Simulation 35.1-2 (1990): 101-107.\n* Drezner, Zvi. \"Computation of the trivariate normal integral.\" Mathematics of Computation 62.205 (1994): 289-294.\n* Genz, Alan. \"Numerical computation of rectangular bivariate and trivariate normal and t probabilities.\" Statistics and Computing 14.3 (2004): 251-260.\n* Gibson, Garvin Jarvis, C. A. Glasbey, and D. A. Elston. \"Monte Carlo evaluation of multivariate normal integrals and sensitivity to variate ordering.\" Advances in Numerical Methods and Applications (1994): 120-126.\n* Tsay, Wen-Jen, and Peng-Hsuan Ke. \"A simple approximation for the bivariate normal integral.\" Communications in Statistics-Simulation and Computation (2021): 1-14.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavid-cortes%2Fapproxcdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavid-cortes%2Fapproxcdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavid-cortes%2Fapproxcdf/lists"}