# Interpolations.jl Discrete CDF to PDF

**URL:** <https://discourse.julialang.org/t/interpolations-jl-discrete-cdf-to-pdf/60124>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package, diffeq\
**Created:** [April 27, 2021, 7:45pm UTC](https://discourse.julialang.org/t/interpolations-jl-discrete-cdf-to-pdf/60124 "2021-04-27T19:45:20Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![mateuszbaran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mateuszbaran/32/221842_2.png) [@mateuszbaran](https://discourse.julialang.org/u/mateuszbaran)\
**Post date:** [April 28, 2021, 9:27am UTC](https://discourse.julialang.org/t/interpolations-jl-discrete-cdf-to-pdf/60124/8 "2021-04-28T09:27:21Z")

</div>

Here, I’ve made an example for Interpolations.jl:

```julia
julia> using Interpolations, Plots, ImageFiltering

julia> percentile_values = [0.0, 0.01, 0.1, 
       1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 
       10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 
       90.0, 91.0, 92.0, 93.0, 94.0, 95.0, 96.0, 97.0, 98.0, 99.0, 
       99.9, 99.99, 100.0];

julia> y = sort(randn(length(percentile_values))); # just some random data

julia> smoothed_y = imfilter(y, ImageFiltering.Kernel.gaussian((3,))); # smoothing to get a more reasonable-looking PDF

julia> itp_cdf = extrapolate(interpolate(smoothed_y, percentile_values, SteffenMonotonicInterpolation()), Flat()); # you can change SteffenMonotonicInterpolation to some other monotonic algorithm from Interpolations.jl

julia> itp_pdf(t) = Interpolations.gradient1(itp_cdf, t); # this is the PDF generate

julia> t = -3.0:0.01:3.0 # just a range for plotting

julia> plot(t, itp_cdf.(t)) # plotting the CDF

julia> plot(t, itp_pdf.(t)) # plotting the PDF

```

I’ll try to improve docs for Interpolations.jl soon.

---

_[View the full topic](https://discourse.julialang.org/t/interpolations-jl-discrete-cdf-to-pdf/60124)._
