{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "A uniform distribution with exponential tails is useful for some applications where a particular range is of equal weight but the limits are soft. I was using it for the example of searching for a property within a particular price range. I might have a particular price range in mind but I don't want a step cutoff at a particular value. It is defined as:\n", "$$\n", "pdf(x) = \\frac{1}{2(\\mu+\\sigma)} \\left\\{\n", " \\begin{array}\n", " 11 & |x| \\leq \\mu \\\\\n", " e^{-(x-\\mu)/\\sigma} & |x| > \\mu\n", " \\end{array}\n", "\\right.\n", "$$\n", "Where $\\mu$ is the half width of the uniform section and $\\sigma$ is the half width of the exponential tail. The factor of " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "1\n", "\n", "\n", "2\n", "\n", "\n", "3\n", "\n", "\n", "0.0\n", "\n", "\n", "0.1\n", "\n", "\n", "0.2\n", "\n", "\n", "0.3\n", "\n", "\n", "0.4\n", "\n", "\n", "\n", "\n", "\n", "\n", "y1\n", "\n", "\n" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Plots\n", "μ=1\n", "σ=0.2\n", "z=1/(2(μ+σ))\n", "UniformExp(x) = abs(x) > μ ? z*exp(-(x-μ)/σ) : z\n", "plot(0:0.001:3, UniformExp)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\u001b[1mTest Passed\u001b[22m\u001b[39m" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using QuadGK, Test\n", "@test quadgk(UniformExp, 0, Inf, rtol=1e-10)[1] ≈ 0.5" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.2.0", "language": "julia", "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 2 }