The way I did this was to represent the pdf as
\exp\left(\sum_{i=1}^N a_i \sqrt{1 + ((x - c_i)/s)^2}\right)/Z
With fixed centers c_i and unknown basis expansion coefficients a_i. I then wrote functions which normalized this, calculated the entropy, and calculated the gini… and used NLopt as follows:
for g in collect(0.25:0.05:0.45)
opt = Opt(:LN_COBYLA,13)
opt.max_objective = (x,g) -> ent(x)
equality_constraint!(opt, (x,gg) -> gin(x) - g,0.005)
equality_constraint!(opt, (x,g) -> muval(x) - 1.0,0.005)
opt.maxtime=120
opt.ftol_rel = 3e-3
opt.xtol_rel = 1e-2
opt.xtol_abs = 1e-3
(optf,optx,ret) = optimize(opt,startx)
startx = optx ./ 2.0
@show(ret)
pp = PdfRbf(centers,optx,3.0,1.0)
normalize!(pp)
push!(pps,pp)
end
It takes tens of seconds to do the calculation, but it’s no big deal, it’s just a one-time calc and then I do my other calculations on the curves.
