How to write a custom distribution using pdf from a Kernel Density Estimator?

Something like this

using Distributions, KernelDensity

struct KDEDist{D, K} <: ContinuousUnivariateDistribution
    data::D
    kde::K
end
function KDEDist(data)
    KDE_fit = kde(d.data)
    ik = InterpKDE(KDE_fit)
    return KDEDist(data, ik)
end

function Distributions.pdf(d::KDEDist, x::Real)
    return pdf(d.kde, x)
end
1 Like