{ "info": { "author": "Adam Ginsburg", "author_email": "adam.g.ginsburg@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Power-law Distribution Fitting\n==============================\nThis is a python implementation of a power-law distribution fitter. The code\nhere was originally hosted on `agpy\n`_ but was\nmoved and re-packaged to make setup.py cleaner. \n\n`API Documentation `_\n\nSee also http://code.google.com/p/powerlaw, an alternate implementation of the same algorithm with additional bells & whistles.\n\nInstallation\n------------\n\nI've attempted to make the setup.py file work nicely, but it includes some hacks, so if you run into trouble,\nplease report it on `github `_::\n\n git clone git@github.com:keflavich/plfit.git\n cd plfit\n python setup.py install\n\n*If* ``python setup.py install`` doesn't work, you can try the following:\n\nTo install the cython function, run:\n``python setup.py build_ext --inplace``\n\nTo install the fortran function::\n\n cd plfit/plfit/ \n f2py -c fplfit.f -m fplfit --fcompiler=gfortran\n\nDescription\n-----------\n\nAaron Clauset et al. address the issue of fitting power-laws to distributions\non `this website `_ and in their paper\n`Power-law distributions in empirical\ndata `_. I have\ncreated a python implementation of their code because I didn't have matlab or R\nand wanted to do some power-law fitting. \n\nPower-laws are very commonly used in astronomy and are typically used to\ndescribe the initial mass function (IMF), the core mass function (CMF), and\noften luminosity distributions. Most distributions in astronomy tend to be\napparent power-laws because the source counts are too few or too narrow to\ndistinguish powerlaws from log-normal and other distributions. But, to this\nend, I've included the testing mechanism to test for consistency with a power\nlaw as described in the above paper.\n\nThe python internal documentation is complete. A brief description of relevant functions is included here for convenience:\n\nplfit is implemented as a class. This means that you import plfit, and declare an instance of the plfit class::\n\n import plfit\n X = rand(1000)\n myplfit = plfit.plfit(X)\n\nThe results of the fit are printed to the screen (if desired) and are stored as part of the object.\n\n``alpha_`` and ``kstest_`` are functions used internally to determine the ks-statistic and alpha values as a function of xmin.\n\nThere are 3 predefined plotting functions:\n * ``alphavsks`` plots alpha on the y-axis vs. the ks statistic value on the\n x-axis with the 'best-fit' alpha value plotted with error bars. These\n plots are a useful way to determine if other values of xmin are similarly\n good fits.\n * ``plotcdf`` plots the cumulative distribution function along with the\n best-fit power law\n * ``plotpdf`` plots a histogram of the PDF with the best fit power law. It\n defaults to log binning (i.e. a linear power-law fit) but can do dN/dS and\n linear binning as well.\n\nOther useful functions:\n * ``test_pl`` uses the fitted power-law as the starting point for a monte-carlo\n test of whether the powerlaw is an acceptable fit. It returns a \"p-value\" that\n should be >0.1 if a power-law fit is to be considered (though a high p-value\n does not ensure that the distribution function is a power law!).\n\n * ``plexp_inv`` creates a cutoff power-law distribution with an exponential\n tail-off. It is useful for tests.\n * ``pl_inv`` creates a pure cutoff power-law distribution\n * ``test_fitter`` uses the previous two functions to test the fitter's ability\n to return the correct xmin and alpha values for large numbers of iterations\n\n\nThe powerlaw fitter is very effective at returning the correct value of alpha\nbut not as good at returning the correct value of xmin.\n\nThere are 3 implementations of the code internals. fplfit.f is a fortran\nfunction, cplfit.pyx is a cython function, and plfit.py is the wrapper and\nincludes a python-only implementation that requires numpy. FORTRAN is fastest,\nfollow closely by cython. Python is ~3x slower. \n\nAs of November 21, 2011, there is a pure python (i.e., no numpy) implementation\nat - you can just\nput this file in your local working directory and import it, since it contains\nno requirements beyond pure python. It's slower and hobbled, but it works, and perhaps\nwill run fast with `pypy `_.\n\n\nFor usage *examples*, see\n * ``_\n * ``_\n * ``_\n\nA very simple example::\n\n import plfit\n from numpy.random import rand,seed\n\n # generate a power law using the \"inverse\" power-law generator code\n X=plfit.plexp_inv(rand(1000),1,2.5)\n\n # use the numpy version to fit (usefortran=False is only needed if you installed the fortran version)\n myplfit=plfit.plfit(X,usefortran=False)\n # output should look something like this:\n # PYTHON plfit executed in 0.201362 seconds\n # xmin: 0.621393 n(>xmin): 263 alpha: 2.39465 +/- 0.0859979 Log-Likelihood: -238.959 ks: 0.0278864 p(ks): 0.986695\n\n # generate some plots\n from pylab import *\n figure(1)\n myplfit.plotpdf()\n\n figure(2)\n myplfit.plotcdf()\n\n\n*If you use this code, please cite Clauset et al 2009 and consider posting a comment below.* \n\nDirection citations to the source are welcome! The python translation has been cited in the following works (and perhaps others?):\n\n * http://adsabs.harvard.edu/abs/2011ApJ...735...51M\n * http://adsabs.harvard.edu/abs/2011ApJ...736..149G\n * http://www.rsc.org/suppdata/CC/c0/c0cc00366b/c0cc00366b.pdf\n * http://adsabs.harvard.edu/cgi-bin/bib_query (http://code.google.com/p/powerlaw)\n\n\n.. image:: https://d2weczhvl823v0.cloudfront.net/keflavich/plfit/trend.png\n :alt: Bitdeli badge\n :target: https://bitdeli.com/free\n\nv1.0.1 - bugfix to pypi only; just adds things to MANIFEST.in\nv1.0 - first release", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/keflavich/plfit/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/keflavich/plfit", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "plfit", "package_url": "https://pypi.org/project/plfit/", "platform": "Linux,MacOS X", "project_url": "https://pypi.org/project/plfit/", "project_urls": { "Download": "https://github.com/keflavich/plfit/archive/master.zip", "Homepage": "https://github.com/keflavich/plfit" }, "release_url": "https://pypi.org/project/plfit/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "Python implementation of Aaron Clauset's power-law distribution fitter", "version": "1.0.2" }, "last_serial": 967532, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "f89861673fd86bd0fe740037d97dafe0", "sha256": "71db7ad405e4216fae1a47943e345f0a5c5c9508a96842f1ad1fab0b290560ef" }, "downloads": -1, "filename": "plfit-1.0.1.tar.gz", "has_sig": false, "md5_digest": "f89861673fd86bd0fe740037d97dafe0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 170899, "upload_time": "2013-06-05T15:42:05", "url": "https://files.pythonhosted.org/packages/95/7e/77db449bd9f89f6a9a9b47ac01b1edabf9006360aac0d12e2068d9354992/plfit-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "17c3d1afebdc052914f2d236fe5157ec", "sha256": "11bd5d24706ff55d16e4c70902d0ff005f6b0cc80c709889f7abc18220d53d82" }, "downloads": -1, "filename": "plfit-1.0.2.tar.gz", "has_sig": false, "md5_digest": "17c3d1afebdc052914f2d236fe5157ec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 172084, "upload_time": "2014-01-13T14:01:52", "url": "https://files.pythonhosted.org/packages/56/f3/5c9d5e07f7279e35957bc0a6115062ef82995fafd15497db1e8372a8f834/plfit-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "17c3d1afebdc052914f2d236fe5157ec", "sha256": "11bd5d24706ff55d16e4c70902d0ff005f6b0cc80c709889f7abc18220d53d82" }, "downloads": -1, "filename": "plfit-1.0.2.tar.gz", "has_sig": false, "md5_digest": "17c3d1afebdc052914f2d236fe5157ec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 172084, "upload_time": "2014-01-13T14:01:52", "url": "https://files.pythonhosted.org/packages/56/f3/5c9d5e07f7279e35957bc0a6115062ef82995fafd15497db1e8372a8f834/plfit-1.0.2.tar.gz" } ] }