Minimising an expectation #368
Replies: 1 comment
-
Hi @abojchevski, Sorry for the late reply, I missed your message. Optimizing functions over multiple distributions is a challenging optimization problem and not exactly what InfiniteOpt was intended for this is primarily relies on discretization techniques (e.g., sample average approximation to solve them). A natural way to solve your example would be with Gauss-Hermite quadrature (which is perfect for computing expectations over Normal variables) which will convert this into a finite optimization problem. In InfiniteOpt, this becomes: using InfiniteOpt, HiGHS
# Data (TODO replace with actual values)
p1 = 1
p2 = 2
c = 1
# Initialize the model and add f(t)
model = InfiniteModel(HiGHS.Optimizer)
@infinite_parameter(model, x in [-Inf, Inf])
@variable(model, 0 <= f <= 1, Infinite(x))
# Set up the integral settings necessary to use Gauss-Hermite quadrature for the integrals
# Also create weighting functions that can be used to use the proper PDF in each case.
set_uni_integral_defaults(eval_method = GaussHermite(), num_nodes = 100)
undo_weight(x) = exp(x^2)
pdf(x, u, s) = exp(-(x-u)^2 / (2s^2)) / sqrt(2pi * s^2)
weighting(x, u, s) = undo_weight(x) * pdf(x, u, s)
@objective(model, Min, ∫(f, x, weight_func = x -> weighting(x, c, 1)))
@constraint(model, ∫(f, x, weight_func = x -> weighting(x, 0, 1)) == p1)
@constraint(model, ∫(f, x, weight_func = x -> weighting(x, 0, 2)) == p2)
optimize!(model)
if has_values(model)
println("x = ", value(x))
println("f = ", value(f))
end However, this becomes infeasible since there is no f(x) that satisfies both constraints simultaneously. Do solution do you expect? |
Beta Was this translation helpful? Give feedback.
-
I'm new to Julia and I'm having a bit of trouble understanding how to use this package.
How can I solve$\min_{0 \leq f(x) \leq 1} E_{x \sim N(c, 1)}[f(x)]$ subject to $E_{x \sim N(0, 1)}[f(x)] == p_1$ and $E_{x \sim N(0, 2)}[f(x)] == p_2$ where $c, p_1, p_2$ are some constants.
Beta Was this translation helpful? Give feedback.
All reactions