kern-smooth


Namekern-smooth JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/AlexanderButyaev/kern_smooth
SummaryA python implementation of KernSmooth package (https://cran.r-project.org/web/packages/KernSmooth):kernel smoothing and density estimation functions based on the book: Wand, M.P. and Jones, M.C. (1995) "Kernel Smoothing".
upload_time2023-12-06 04:55:23
maintainer
docs_urlNone
authorAlexander Butyaev
requires_python
licenseMIT
keywords statistics probability kde pdf kernel density estimation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            KernSmooth for Python
=====================
Porting popular R library KernSmooth to python.

Functions for Kernel Smoothing and Density Estimation.

Transformed R and Fortran functions into Python(2,3) code.

Attention:
----------

Please use kern-smooth 1.1.0 or newer.
Reason: found not needed log10 density transformation.


Installation:
-------------

.. code:: shell

		pip install kern-smooth


Main function of the module:
----------------------------

.. code:: python
        
        def densCols(x, y=None, nbin=128, bandwidth=None)


Produces a vector of numbers which encode the local densities at each point in dataset.

x, y : 1D numpy array with coordinates of the points density will be estimated on

nbin : [optional] int or [int, int] - number of bins along each axis
    (in case of single value - [nbin, nbin] will be used). Default value 128.

bandwidth : [optional] numeric vector (len of 1 or 2) of smoothing bandwidth.

Returns: numpy array with numerical representation (in range [0,1]) of point densities.

Attention: For return value numpy.nan values are allowed in case of nan / infinite values in original dataset 

Source: R::grDevices::densCols


Usage
-----

Generate data for plotting (make sure Matplotlib is installed)

.. code:: python

    from matplotlib import pyplot as plt
    from matplotlib import cm
    import numpy as np
    np.random.seed(0)
    # create two 'bulbs' with normal distributions
    mean1 = [0, 0]
    cov1 = [[5, 0], [0, 30]]  # diagonal covariance
    x1, y1 = np.random.multivariate_normal(mean1, cov1, 50000).T
    mean2 = [5, 17]
    cov2 = [[30, 0], [0, 5]]  # diagonal covariance
    x2, y2 = np.random.multivariate_normal(mean2, cov2, 50000).T
    x = np.hstack([x1,x2])
    y = np.hstack([y1,y2])


Generate point densities:

.. code:: python

    from kern_smooth import densCols
    densities = densCols(x, y, nbin = 128)


Plot the result

.. code:: python

    sc = plt.scatter(x, y, c=densities, s=15, edgecolors='none', alpha=0.75, cmap=cm.jet)
    plt.colorbar(sc)
    plt.show()


Result
------
![Result](https://github.com/AlexanderButyaev/kern_smooth/blob/master/example_density.png) 

Author
------
Alexander Butyaev

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AlexanderButyaev/kern_smooth",
    "name": "kern-smooth",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "statistics,probability,KDE,PDF,kernel density estimation",
    "author": "Alexander Butyaev",
    "author_email": "alexander.butyaev@mail.mcgill.ca",
    "download_url": "https://files.pythonhosted.org/packages/bc/d0/d61b3eae81a033a4c1a37537fcac2419afd59549ee7deabc147cf5351a31/kern-smooth-1.2.3.tar.gz",
    "platform": null,
    "description": "KernSmooth for Python\n=====================\nPorting popular R library KernSmooth to python.\n\nFunctions for Kernel Smoothing and Density Estimation.\n\nTransformed R and Fortran functions into Python(2,3) code.\n\nAttention:\n----------\n\nPlease use kern-smooth 1.1.0 or newer.\nReason: found not needed log10 density transformation.\n\n\nInstallation:\n-------------\n\n.. code:: shell\n\n\t\tpip install kern-smooth\n\n\nMain function of the module:\n----------------------------\n\n.. code:: python\n        \n        def densCols(x, y=None, nbin=128, bandwidth=None)\n\n\nProduces a vector of numbers which encode the local densities at each point in dataset.\n\nx, y : 1D numpy array with coordinates of the points density will be estimated on\n\nnbin : [optional] int or [int, int] - number of bins along each axis\n    (in case of single value - [nbin, nbin] will be used). Default value 128.\n\nbandwidth : [optional] numeric vector (len of 1 or 2) of smoothing bandwidth.\n\nReturns: numpy array with numerical representation (in range [0,1]) of point densities.\n\nAttention: For return value numpy.nan values are allowed in case of nan / infinite values in original dataset \n\nSource: R::grDevices::densCols\n\n\nUsage\n-----\n\nGenerate data for plotting (make sure Matplotlib is installed)\n\n.. code:: python\n\n    from matplotlib import pyplot as plt\n    from matplotlib import cm\n    import numpy as np\n    np.random.seed(0)\n    # create two 'bulbs' with normal distributions\n    mean1 = [0, 0]\n    cov1 = [[5, 0], [0, 30]]  # diagonal covariance\n    x1, y1 = np.random.multivariate_normal(mean1, cov1, 50000).T\n    mean2 = [5, 17]\n    cov2 = [[30, 0], [0, 5]]  # diagonal covariance\n    x2, y2 = np.random.multivariate_normal(mean2, cov2, 50000).T\n    x = np.hstack([x1,x2])\n    y = np.hstack([y1,y2])\n\n\nGenerate point densities:\n\n.. code:: python\n\n    from kern_smooth import densCols\n    densities = densCols(x, y, nbin = 128)\n\n\nPlot the result\n\n.. code:: python\n\n    sc = plt.scatter(x, y, c=densities, s=15, edgecolors='none', alpha=0.75, cmap=cm.jet)\n    plt.colorbar(sc)\n    plt.show()\n\n\nResult\n------\n![Result](https://github.com/AlexanderButyaev/kern_smooth/blob/master/example_density.png) \n\nAuthor\n------\nAlexander Butyaev\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python implementation of KernSmooth package (https://cran.r-project.org/web/packages/KernSmooth):kernel smoothing and density estimation functions based on the book: Wand, M.P. and Jones, M.C. (1995) \"Kernel Smoothing\".",
    "version": "1.2.3",
    "project_urls": {
        "Homepage": "https://github.com/AlexanderButyaev/kern_smooth"
    },
    "split_keywords": [
        "statistics",
        "probability",
        "kde",
        "pdf",
        "kernel density estimation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcd0d61b3eae81a033a4c1a37537fcac2419afd59549ee7deabc147cf5351a31",
                "md5": "d0b4de17c293957291e20093eca8d909",
                "sha256": "f8eed9ee2a26352593fea4814bc9509dced9e9c26c049cfce190d5c1a0a16c2c"
            },
            "downloads": -1,
            "filename": "kern-smooth-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d0b4de17c293957291e20093eca8d909",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 295593,
            "upload_time": "2023-12-06T04:55:23",
            "upload_time_iso_8601": "2023-12-06T04:55:23.332214Z",
            "url": "https://files.pythonhosted.org/packages/bc/d0/d61b3eae81a033a4c1a37537fcac2419afd59549ee7deabc147cf5351a31/kern-smooth-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-06 04:55:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlexanderButyaev",
    "github_project": "kern_smooth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "kern-smooth"
}
        
Elapsed time: 0.17154s