{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "ae7e631a",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "4f0525e7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.stats import levy_stable\nimport matplotlib.pyplot as plt\nfig, ax = plt.subplots(1, 1)",
            "outputs": []
        },
        {
            "id": "91712e86",
            "cell_type": "markdown",
            "source": "Get the support:\n",
            "metadata": {}
        },
        {
            "id": "7a15ccbb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "alpha, beta = 1.8, -0.5\nlb, ub = levy_stable.support(alpha, beta)",
            "outputs": []
        },
        {
            "id": "b3597b17",
            "cell_type": "markdown",
            "source": "Calculate the first four moments:\n",
            "metadata": {}
        },
        {
            "id": "d220333a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "mean, var, skew, kurt = levy_stable.stats(alpha, beta, moments='mvsk')",
            "outputs": []
        },
        {
            "id": "c528fe13",
            "cell_type": "markdown",
            "source": "Display the probability density function (``pdf``):\n",
            "metadata": {}
        },
        {
            "id": "e68b4bfc",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.linspace(levy_stable.ppf(0.01, alpha, beta),\n                levy_stable.ppf(0.99, alpha, beta), 100)\nax.plot(x, levy_stable.pdf(x, alpha, beta),\n       'r-', lw=5, alpha=0.6, label='levy_stable pdf')",
            "outputs": []
        },
        {
            "id": "df1c2cb9",
            "cell_type": "markdown",
            "source": "Alternatively, the distribution object can be called (as a function)\nto fix the shape, location and scale parameters. This returns a \"frozen\"\nRV object holding the given parameters fixed.\n\nFreeze the distribution and display the frozen ``pdf``:\n",
            "metadata": {}
        },
        {
            "id": "5a07c4d6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "rv = levy_stable(alpha, beta)\nax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')",
            "outputs": []
        },
        {
            "id": "e4e40c11",
            "cell_type": "markdown",
            "source": "Check accuracy of ``cdf`` and ``ppf``:\n",
            "metadata": {}
        },
        {
            "id": "5aeb5bc6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "vals = levy_stable.ppf([0.001, 0.5, 0.999], alpha, beta)\nnp.allclose([0.001, 0.5, 0.999], levy_stable.cdf(vals, alpha, beta))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "369613b8",
            "cell_type": "markdown",
            "source": "Generate random numbers:\n",
            "metadata": {}
        },
        {
            "id": "f269d79e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "r = levy_stable.rvs(alpha, beta, size=1000)",
            "outputs": []
        },
        {
            "id": "780d416a",
            "cell_type": "markdown",
            "source": "And compare the histogram:\n",
            "metadata": {}
        },
        {
            "id": "bbe59834",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)\nax.set_xlim([x[0], x[-1]])\nax.legend(loc='best', frameon=False)\nplt.show()",
            "outputs": []
        }
    ]
}