{ "info": { "author": "Matthew Pitkin", "author_email": "m.pitkin@lancaster.ac.uk", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU General Public License (GPL)", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: C", "Programming Language :: Python" ], "description": "# lintegrate\n\nA numerical integration library for when you want/need to work with the natural logarithm of the function requiring integration.\n\nThis library provides three numerical integration functions, heavily based on [GSL](https://www.gnu.org/software/gsl/) functions, to integrate a function when only its natural logarithm is given, and return the natural logarithm of that integral. The three functions:\n\n * `lintegrate_qag`\n * `lintegrate_qng`\n * `lintegrate_cquad`\n\n are equivalents of the GSL functions:\n\n * [`gsl_integration_qag`](https://www.gnu.org/software/gsl/doc/html/integration.html#qag-adaptive-integration)\n * [`gsl_integration_qng`](https://www.gnu.org/software/gsl/doc/html/integration.html#qng-non-adaptive-gauss-kronrod-integration)\n * [`gsl_integration_cquad`](https://www.gnu.org/software/gsl/doc/html/integration.html#cquad-doubly-adaptive-integration)\n\nrespectively. These can be useful when, e.g., you can calculate the natural logarithm of a Gaussian likelihood function (in cases where the exponentiation of the Gaussian function would lead to zeros or infinities) and you want to numerically find the integral of the Gaussian function itself.\n\nThe functions `lintegrate_qag`, `lintegrate_qng`, and `lintegrate_cquad`, all have wrappers functions (with `_split` appended to their names) that allow the user to specify a set of intervals that the integrals will be split into when performing the calculation. The intervals could, for example, be spaced evenly in log-space, for cases where the integral function has a very pronounced peak as it approaches zero.\n\n## Example\n\nAn [example](example/example.c) of the use the functions is:\n\n```C\n/* example using lintegrate functionality */\n\n#include \n#include \n#include \n#include \n#include \n\n#include \n\n/* create function for integration */\ndouble lintegrand(double x, void *params);\n\nstruct intparams {\n double mu;\n double sig;\n};\n\ndouble lintegrand(double x, void *params){\n struct intparams * p = (struct intparams *)params;\n double mu = p->mu;\n double sig = p->sig;\n\n return -0.5*(mu-x)*(mu-x)/(sig*sig);\n}\n\ndouble integrand(double x, void *params){\n struct intparams * p = (struct intparams *)params;\n double mu = p->mu;\n double sig = p->sig;\n\n return exp(-0.5*(mu-x)*(mu-x)/(sig*sig));\n}\n\nint main( int argv, char **argc ){\n gsl_function F;\n struct intparams params;\n gsl_integration_workspace *w = gsl_integration_workspace_alloc (100);\n gsl_integration_cquad_workspace *cw = gsl_integration_cquad_workspace_alloc(50);\n double qaganswer = 0., qnganswer = 0., cquadanswer = 0., answer = 0.;\n double abserr = 0.;\n size_t neval = 0;\n\n double minlim = -6.; /* minimum for integration range */\n double maxlim = 6.; /* maximum for integration range */\n\n double abstol = 1e-10; /* absolute tolerance */\n double reltol = 1e-10; /* relative tolerance */\n\n params.mu = 0.;\n params.sig = 1.;\n\n F.function = &lintegrand;\n F.params = ¶ms;\n\n /* integrate log of function using QAG */\n lintegration_qag(&F, minlim, maxlim, abstol, reltol, 100, GSL_INTEG_GAUSS31, w, &qaganswer, &abserr);\n\n /* integrate log of function using QNG */\n lintegration_qng(&F, minlim, maxlim, abstol, reltol, &qnganswer, &abserr, &neval);\n\n /* integrate log of function using CQUAD */\n lintegration_cquad(&F, minlim, maxlim, abstol, reltol, cw, &cquadanswer, &abserr, &neval);\n\n /* integrate function using GSL QAG */\n F.function = &integrand;\n gsl_integration_qag(&F, minlim, maxlim, abstol, reltol, 100, GSL_INTEG_GAUSS31, w, &answer, &abserr);\n\n gsl_integration_workspace_free(w);\n gsl_integration_cquad_workspace_free(cw);\n\n fprintf(stdout, \"Answer \\\"lintegrate QAG\\\" = %.8lf\\n\", qaganswer);\n fprintf(stdout, \"Answer \\\"lintegrate QNG\\\" = %.8lf\\n\", qnganswer);\n fprintf(stdout, \"Answer \\\"lintegrate CQUAD\\\" = %.8lf\\n\", cquadanswer);\n fprintf(stdout, \"Answer \\\"gsl_integrate_qag\\\" = %.8lf\\n\", log(answer));\n fprintf(stdout, \"Analytical answer = %.8lf\\n\", log(sqrt(2.*M_PI)));\n\n return 0;\n}\n```\n\n## Requirements\n\n* [GSL](https://www.gnu.org/software/gsl/) - on Debian/Ubuntu (16.04) install with e.g. `sudo apt-get install libgsl-dev`\n\n## Installation\n\nThe library can be built using [scons](http://scons.org) by just typing `sudo scons` in the base directory. To install\nthe library system-wide (in `/usr/local/lib` by default) run:\n```\nsudo scons\nsudo scons install\n```\n\nA Python module containing wrappers to the functions can be built by running, e.g.:\n```\nsudo python setup.py install\n```\nfor a system-wide install (add `--user` and remove `sudo` if just wanting to install for a single user, and using `--prefix=INSTALLPATH` if wanting to specify this install location).\n\nThe Python module can also be installed from [PyPI](https://pypi.org/project/lintegrate/) using pip with:\n```bash\npip install lintegrate\n```\n\nor in a Conda environment with:\n```bash\nconda install -c conda-forge lintegrate\n```\n\n## Python\n\nIf the Python module has been installed it has the following functions:\n * `lqng` - a wrapper to `lintegration_qng`\n * `lqag` - a wrapper to `lintegration_qag`\n * `lcquad` - a wrapper to `lintegration_cquad`\n * `logtrapz` - using the trapezium rule for integration on a grid of values\n\nThe `lqng`, `lqag`, and `lcquad` functions are used in a similar way to the scipy [`quad`](https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.integrate.quad.html) function.\n\nAn example of their use would be:\n\n```python\nfrom lintegrate import lqag, lqng, lcquad, logtrapz\nimport numpy as np\n\n# define the log of the function to be integrated\ndef integrand(x, args):\n mu, sig = args # unpack extra arguments\n return -0.5*((x-mu)/sig)**2\n\n# set integration limits\nxmin = -6.\nxmax = 6.\n\n# set additional arguments\nmu = 0.\nsig = 1.\n\nresqag = lqag(integrand, xmin, xmax, args=(mu, sig))\nresqng = lqng(integrand, xmin, xmax, args=(mu, sig))\nrescquad = lcquad(integrand, xmin, xmax, args=(mu, sig))\nrestrapz = logtrapz(integrand, np.linspace(xmin, xmax, 100), args=(mu, sig))\n```\n\n## R\n\nIn [R](https://www.r-project.org/) one can use the [**reticulate**](https://github.com/rstudio/reticulate) package to call the functions in `lintegrate`.\nThe above example would be:\n```R\nlibrary(reticulate)\nlint <- import(\"lintegrate\", convert = FALSE)\nintegrand <- function(x, args){\n mu = args[1]\n sig = args[2]\n return(-.5 * ((x-mu)/sig)^2 )\n} \nintegrand <- Vectorize(integrand)\nmu <- 0\nsig <- 1\nmmin <- -10\nmmax <- 10\nlint$lqag(py_func(integrand), r_to_py(mmin), r_to_py(mmax), c(mu, sig))\n```\n\n[![DOI](https://zenodo.org/badge/93165960.svg)](https://zenodo.org/badge/latestdoi/93165960)\n[![Build Status](https://travis-ci.org/mattpitkin/lintegrate.svg?branch=master)](https://travis-ci.org/mattpitkin/lintegrate)\n[![PyPI version](https://badge.fury.io/py/lintegrate.svg)](https://badge.fury.io/py/lintegrate)\n[![Anaconda-Server Badge](https://anaconda.org/conda-forge/lintegrate/badges/version.svg)](https://anaconda.org/conda-forge/lintegrate)\n\n© 2017 Matthew Pitkin", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mattpitkin/lintegrate", "keywords": "", "license": "GPL", "maintainer": "", "maintainer_email": "", "name": "lintegrate", "package_url": "https://pypi.org/project/lintegrate/", "platform": "", "project_url": "https://pypi.org/project/lintegrate/", "project_urls": { "Homepage": "https://github.com/mattpitkin/lintegrate" }, "release_url": "https://pypi.org/project/lintegrate/0.1.3/", "requires_dist": null, "requires_python": "", "summary": "Python functions implementing numerical integration of functions in log-space.", "version": "0.1.3" }, "last_serial": 5909207, "releases": { "0.0.10": [ { "comment_text": "", "digests": { "md5": "3fb94dbb183b7c3c4285b43f1167b4c7", "sha256": "5774f98a18f9d461fa19c009f00aecdb650783592323d1f1c1a8af0208b9fd9b" }, "downloads": -1, "filename": "lintegrate-0.0.10.tar.gz", "has_sig": false, "md5_digest": "3fb94dbb183b7c3c4285b43f1167b4c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 116132, "upload_time": "2017-07-06T16:10:15", "url": "https://files.pythonhosted.org/packages/66/26/dc1947c5f7063997a568e30fa645a314226fc83164f102bfb9b14b1c0873/lintegrate-0.0.10.tar.gz" } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "786065cc814854a9ad4beff0d255f2e3", "sha256": "9b81f57a20245fd0871e0f054686830dd7edf5880869e0088cc517cbbb3cb91b" }, "downloads": -1, "filename": "lintegrate-0.0.11-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "786065cc814854a9ad4beff0d255f2e3", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 269208, "upload_time": "2019-05-31T13:28:08", "url": "https://files.pythonhosted.org/packages/61/a5/221e21ce78adb6efce4786fac565934de7615856ed585f3415bbecc31a62/lintegrate-0.0.11-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "8ef22e9a71335a99131a9dc7b851c740", "sha256": "1a06dc44855c40b4c8443482bd06e5776902d36028ad94596cd8ebb963c89f70" }, "downloads": -1, "filename": "lintegrate-0.0.11.tar.gz", "has_sig": false, "md5_digest": "8ef22e9a71335a99131a9dc7b851c740", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14029, "upload_time": "2019-05-31T13:28:10", "url": "https://files.pythonhosted.org/packages/a5/88/23dbef4341d80a1f249237fd2f48755d501151263a26ee14ef44b7f6de57/lintegrate-0.0.11.tar.gz" } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "77d8a6dc26b542ee2654f40662b825f5", "sha256": "246c9a1c8effa7f30f7915ee63314062960740f9317a5a37d4940d68ae442f14" }, "downloads": -1, "filename": "lintegrate-0.0.12.tar.gz", "has_sig": false, "md5_digest": "77d8a6dc26b542ee2654f40662b825f5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 95040, "upload_time": "2019-05-31T13:45:43", "url": "https://files.pythonhosted.org/packages/8c/38/8d354612846d24f6658b2b39e24d2e476a17c99feebd50e1c3cc808f65e8/lintegrate-0.0.12.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "f7f8f5f90e319b4886c2c6d83de738aa", "sha256": "d5a09898529c6199545c2142fb08888e5425f8823704067f9703d5c7f85ae19f" }, "downloads": -1, "filename": "lintegrate-0.0.4.tar.gz", "has_sig": false, "md5_digest": "f7f8f5f90e319b4886c2c6d83de738aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5467, "upload_time": "2017-07-06T14:28:12", "url": "https://files.pythonhosted.org/packages/fa/00/a742354ef86edda0dc17b93e0fd1bb28caf7b6fd3bc55c5e7e7e6232064d/lintegrate-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "22ba105a2c173295f6f956829718c6fd", "sha256": "abd2ec496e708dadd9a3cf0a5ae07c0a9aadf7f9c4a7d80ed74e140fefac686f" }, "downloads": -1, "filename": "lintegrate-0.0.5.tar.gz", "has_sig": false, "md5_digest": "22ba105a2c173295f6f956829718c6fd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5641, "upload_time": "2017-07-06T14:39:06", "url": "https://files.pythonhosted.org/packages/db/9b/4f38e53fc29cfd353ea9f2ba51e57c113343231b3d95346bd5491d6296a2/lintegrate-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "1a4b16442b57ffb3471481bb5973ad3f", "sha256": "85f927badb80b6ce5cdbf5bae90c4ba1e52f93e7c096883cee3ffdf907c94d24" }, "downloads": -1, "filename": "lintegrate-0.0.6.tar.gz", "has_sig": false, "md5_digest": "1a4b16442b57ffb3471481bb5973ad3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5603, "upload_time": "2017-07-06T14:43:17", "url": "https://files.pythonhosted.org/packages/72/31/ba0a979e2d8eb5136dee7ab8d5d42239106eb70102d959070026560358e4/lintegrate-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "7627ec22812bfe71feed20d90c7c7ed9", "sha256": "6195e81547f42e1176a4adbeb22ece726521f49f337c10473af3a57f8e326a68" }, "downloads": -1, "filename": "lintegrate-0.0.7.tar.gz", "has_sig": false, "md5_digest": "7627ec22812bfe71feed20d90c7c7ed9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5633, "upload_time": "2017-07-06T14:50:18", "url": "https://files.pythonhosted.org/packages/15/52/dd5c39c2d09cdb381565cd562bc26281975b585eafe02756c76a2d38db03/lintegrate-0.0.7.tar.gz" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "f226373c7bee63978687f8a5058091d1", "sha256": "e82902454838d02a4118fe39723e3a14ad10a795142b44c2a1b5a5e32a05014f" }, "downloads": -1, "filename": "lintegrate-0.0.8.tar.gz", "has_sig": false, "md5_digest": "f226373c7bee63978687f8a5058091d1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 116138, "upload_time": "2017-07-06T16:02:52", "url": "https://files.pythonhosted.org/packages/31/79/c3a340c9c4f780b69204fa0843ef581c9217a996bfae0be8d6655902fdc5/lintegrate-0.0.8.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "7ab2e9c705c485de0c3d8cbaec130ce2", "sha256": "72ac4676593616aa284e1d211183a213ffd1faca83c76ce8a0d52e83842646bf" }, "downloads": -1, "filename": "lintegrate-0.0.9.tar.gz", "has_sig": false, "md5_digest": "7ab2e9c705c485de0c3d8cbaec130ce2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 116144, "upload_time": "2017-07-06T16:04:41", "url": "https://files.pythonhosted.org/packages/ea/c0/39b00d8e38353cbe53565c9039aca1c59f2c412bf3ffd011bd26c71f5d29/lintegrate-0.0.9.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "cac2f99037edf6b8ea8247a61fc424c1", "sha256": "b6abae4eb08eabc6d6a62cbc74ed1d664cd4e15b1d8d49145daff7a431164abd" }, "downloads": -1, "filename": "lintegrate-0.1.0-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "cac2f99037edf6b8ea8247a61fc424c1", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 271333, "upload_time": "2019-06-04T10:15:42", "url": "https://files.pythonhosted.org/packages/a5/d4/bd08501eb33ba20948aa2c0e09bb3bf4402236946da8b6b2cba3e9afdb80/lintegrate-0.1.0-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "3303fd62c45e059a1664995d53ea2b37", "sha256": "4b5d58f60317baf543e76f3bd26e4f603f23ec40ffe95001d7f2c631041b89cc" }, "downloads": -1, "filename": "lintegrate-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3303fd62c45e059a1664995d53ea2b37", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 140249, "upload_time": "2019-06-04T10:15:44", "url": "https://files.pythonhosted.org/packages/db/7b/9962acb1ea7f858ff7d27ba3c28e2a20d11ea635e11d0f33e56ddaa5c5b2/lintegrate-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "93c0980aa4695255f987ec37686f58d7", "sha256": "b2b5dd9bafcc202a06c35f1b03607b8de27592dda34b8f32d01e64ff47a123ff" }, "downloads": -1, "filename": "lintegrate-0.1.1-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "93c0980aa4695255f987ec37686f58d7", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 310409, "upload_time": "2019-06-04T13:58:17", "url": "https://files.pythonhosted.org/packages/af/68/81c82f660ce512f63e437afa7bdf0fc6ad7a9e67e2f5fd158460f12b8fd3/lintegrate-0.1.1-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "7ca4e065626037d2596f286425cddb85", "sha256": "57b7caad93c87cac87b77af983a0167fddfd3011819537c1148c0ea35ec02c01" }, "downloads": -1, "filename": "lintegrate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "7ca4e065626037d2596f286425cddb85", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 144278, "upload_time": "2019-06-04T13:58:19", "url": "https://files.pythonhosted.org/packages/cd/42/e35f61e75fd547cbf552a6e50ff2bb6d515b33874ba0c534abb22d355140/lintegrate-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "9114ea257b6e056f0417c13ce8dd7481", "sha256": "b3e5c3372d582c79ef81f64c30e87bb79bdcb8dfbb68a3f4b0496a5956ea8c0e" }, "downloads": -1, "filename": "lintegrate-0.1.2-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "9114ea257b6e056f0417c13ce8dd7481", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 303004, "upload_time": "2019-09-30T10:45:55", "url": "https://files.pythonhosted.org/packages/cf/ee/4d2a0be5cb015412465ea345fdb1b6ca0a836a3d05864f81708412f8e67e/lintegrate-0.1.2-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "6abd336d92dbc6b75a3d38f9e3eab2f0", "sha256": "ef8aa9da61947c616a4ac2726011ae2a3c04e6db9623d8e71fb3d686c88c76a0" }, "downloads": -1, "filename": "lintegrate-0.1.2.tar.gz", "has_sig": false, "md5_digest": "6abd336d92dbc6b75a3d38f9e3eab2f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 144756, "upload_time": "2019-09-30T10:45:57", "url": "https://files.pythonhosted.org/packages/7f/1e/7e923a05f33ac902d7abe55d4e4d38dbbcf9eebd633ea0ee6511d05a2355/lintegrate-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "5a397aae6164848025ce8b2c095baa59", "sha256": "ad6e19eb56584a75191660c847896849b05273765bd6ebf58f3a9c2d0a03edb4" }, "downloads": -1, "filename": "lintegrate-0.1.3-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "5a397aae6164848025ce8b2c095baa59", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 306084, "upload_time": "2019-09-30T21:46:28", "url": "https://files.pythonhosted.org/packages/67/23/a331eef2128cba0a34f6fd2784f521ac781d46883615855d11159c35b338/lintegrate-0.1.3-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "96c2cdcdf82d901688d9c074c9b6464c", "sha256": "c8e65589cf0f98c0a9cc28e5222026c5cfc11cb24d3867342c0fb9d1ac0a9a1a" }, "downloads": -1, "filename": "lintegrate-0.1.3.tar.gz", "has_sig": false, "md5_digest": "96c2cdcdf82d901688d9c074c9b6464c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 148047, "upload_time": "2019-09-30T21:46:31", "url": "https://files.pythonhosted.org/packages/34/1b/95186e87334060eb472b42667cad2f5cc9faf535e8492aefee4f56f505b9/lintegrate-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5a397aae6164848025ce8b2c095baa59", "sha256": "ad6e19eb56584a75191660c847896849b05273765bd6ebf58f3a9c2d0a03edb4" }, "downloads": -1, "filename": "lintegrate-0.1.3-py3.7-linux-x86_64.egg", "has_sig": false, "md5_digest": "5a397aae6164848025ce8b2c095baa59", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 306084, "upload_time": "2019-09-30T21:46:28", "url": "https://files.pythonhosted.org/packages/67/23/a331eef2128cba0a34f6fd2784f521ac781d46883615855d11159c35b338/lintegrate-0.1.3-py3.7-linux-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "96c2cdcdf82d901688d9c074c9b6464c", "sha256": "c8e65589cf0f98c0a9cc28e5222026c5cfc11cb24d3867342c0fb9d1ac0a9a1a" }, "downloads": -1, "filename": "lintegrate-0.1.3.tar.gz", "has_sig": false, "md5_digest": "96c2cdcdf82d901688d9c074c9b6464c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 148047, "upload_time": "2019-09-30T21:46:31", "url": "https://files.pythonhosted.org/packages/34/1b/95186e87334060eb472b42667cad2f5cc9faf535e8492aefee4f56f505b9/lintegrate-0.1.3.tar.gz" } ] }