Skip to content

Commit

Permalink
decrease memory overhead in model construction for expdesign (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscoey authored Oct 21, 2021
1 parent e74eef2 commit d422820
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/experimentdesign/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ function build(inst::ExperimentDesignJuMP{T}) where {T <: Float64}
JuMP.@variable(model, x[1:k] >= 0)
JuMP.@constraint(model, sum(x) == k)

vec_dim = Cones.svec_length(d)
Q = V * diagm(x) * V' # information matrix
Q_vec = zeros(JuMP.AffExpr, vec_dim)
Cones.smat_to_svec!(Q_vec, Q, sqrt(T(2)))
# vectorized information matrix
rt2 = sqrt(T(2))
Q_vec = [JuMP.@expression(model, (i == j ? one(T) : rt2) *
sum(V[i, k] * x[k] * V[j, k] for k in 1:k)) for i in 1:d for j in 1:i]

# convex objective
JuMP.@variable(model, epi)
JuMP.@objective(model, Min, epi)
add_homog_spectral(inst.ext, d, vcat(1.0 * epi, Q_vec), model)

# save for use in tests
model.ext[:Q_var] = Q
model.ext[:V] = V
model.ext[:x] = x

return model
end
Expand All @@ -53,8 +54,9 @@ function test_extra(inst::ExperimentDesignJuMP{T}, model::JuMP.Model) where T

# check objective
tol = eps(T)^0.2
Q_opt = JuMP.value.(model.ext[:Q_var])
λ = eigvals(Symmetric(Q_opt, :U))
V = model.ext[:V]
x_opt = JuMP.value.(model.ext[:x])
λ = eigvals(Symmetric(V * Diagonal(x_opt) * V', :U))
@test minimum(λ) >= -tol
obj_result = get_val(pos_only(λ), inst.ext)
@test JuMP.objective_value(model) obj_result atol=tol rtol=tol
Expand Down

0 comments on commit d422820

Please sign in to comment.