Cannot evaluate a vector for some ProductDistribution

So, I implemented the following workaround:

# So first we draw from the product distribution 
function LogNormal_SqrtScaledInverseChiSquared(ν, tau²)
    dgf(n)   = (n + 1) / 2
    pd       = ProductDistribution(LogNormal(0, 1), InverseGamma(dgf(ν), dgf(ν) * tau²))
    rv       = Random.rand!(pd, zeros(2, 1000000))
    rv[2, :] = sqrt.(rv[2, :]) 
    rv       = vec(prod(rv, dims=1))

    rv_cdf = ecdf(rv)
    obs    = unique(rv)
    # Percentiles 
    cdf_obs = map(x -> rv_cdf(x), sort(obs))  

    # Generate probability mass function for next part 
    pmf = Float64[]
    for i in 1:length(obs)
        if i == 1 
            append!(pmf,cdf_obs[1])
        else
            append!(pmf, cdf_obs[i]-cdf_obs[i-1])
        end
    end
    # Generate, using MLE, the distribution object 
    d      = DiscreteNonParametric(sort(obs), pmf)
    sample = rand(d, 1000000)

    # Make continuous 
    U = kde(sample)
    return U
end
1 Like