Skip to content

Commit

Permalink
fix analyze formulation aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscoey committed Jul 23, 2021
1 parent 23b227e commit d371020
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
10 changes: 4 additions & 6 deletions benchmarks/natvsext/analyze.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using CSV
using DataFrames

include(joinpath(@__DIR__, "../../examples/Examples.jl"))
using Main.Examples
import Main.Examples

bench_file = joinpath(@__DIR__, "raw", "bench.csv")
output_dir = mkpath(joinpath(@__DIR__, "analysis"))
Expand Down Expand Up @@ -137,10 +137,8 @@ residual_tol_satisfied(a, tol = 1e-5) =
relative_tol_satisfied(a::T, b::T, tol::T = 1e-4) where {T <: Real} =
(abs(a - b) / (1 + max(abs(a), abs(b))) < tol)

ex_wide_file(ex_name::String) = joinpath(stats_dir, ex_name * "_wide.csv")

get_name(x::Any) = x
get_name(x::Main.Examples.SpectralExtender) = nameof(typeof(x))
get_name(x::Any) = string(x)
get_name(x::Main.Examples.SpectralExtender) = Main.Examples.nat_name(x)

function make_wide_csv(ex_df, ex_name, ex_params)
@info("making wide csv for $ex_name")
Expand Down Expand Up @@ -208,7 +206,7 @@ function make_wide_csv(ex_df, ex_name, ex_params)
]
ex_df_wide = outerjoin(unstacked_dims..., unstacked_res..., on = inst_keys)

CSV.write(ex_wide_file(ex_name), ex_df_wide)
CSV.write(joinpath(stats_dir, ex_name * "_wide.csv"), ex_df_wide)

return (ex_df_wide, inst_solvers)
end
Expand Down
25 changes: 14 additions & 11 deletions examples/spectral_functions_JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ const MatSepSpecEigOrd = Union{MatNegLogEigOrd, MatNegEntropyEigOrd,
MatNegEntropyConjEigOrd, MatNegSqrtConjEigOrd, MatNegPower01ConjEigOrd,
MatPower12ConjEigOrd}

const SepSpecAll = Union{VecSepSpecPrimAll, VecSepSpecDualAll,
MatSepSpecPrimAll, MatSepSpecDualAll}
const NegGeomAll = Union{VecNegGeomAll, MatNegGeomAll}
const SepSpecPrimAll = Union{VecSepSpecPrimAll, MatSepSpecPrimAll}
const SepSpecDualAll = Union{VecSepSpecDualAll, MatSepSpecDualAll}
const SepSpecAll = Union{SepSpecPrimAll, SepSpecDualAll}

# helpers
get_vec_ef(::MatNegGeomEFExp) = VecNegGeomEFExp()
Expand Down Expand Up @@ -142,16 +144,17 @@ get_ssf(ext::Union{VecPower12, VecPower12EF, VecPower12Conj, VecPower12ConjEF,
MatPower12, MatPower12EigOrd, MatPower12Conj, MatPower12ConjEigOrd}) =
Cones.Power12SSF(ext.p)

nat_name(::VecNegGeomAll) = "NegGeom"
get_name_ssf(ext::SepSpecAll) = string(nameof(typeof(get_ssf(ext))))
nat_name(ext::SepSpecPrimAll) = get_name_ssf(ext)
nat_name(ext::SepSpecDualAll) = get_name_ssf(ext) * "Conj"

is_domain_pos(::SpectralExtender) = true
is_domain_pos(ext::Union{VecSepSpecDualAll, MatSepSpecDualAll}) =
Cones.h_conj_dom_pos(get_ssf(ext))
is_domain_pos(ext::SepSpecDualAll) = Cones.h_conj_dom_pos(get_ssf(ext))

get_val(x::Vector, ::Union{VecNegGeomAll, MatNegGeomAll}) =
-exp(sum(log, x) / length(x))
get_val(x::Vector, ext::Union{VecSepSpecPrimAll, MatSepSpecPrimAll}) =
Cones.h_val(x, get_ssf(ext))
get_val(x::Vector, ext::Union{VecSepSpecDualAll, MatSepSpecDualAll}) =
Cones.h_conj(x, get_ssf(ext))
get_val(x::Vector, ::NegGeomAll) = -exp(sum(log, x) / length(x))
get_val(x::Vector, ext::SepSpecPrimAll) = Cones.h_val(x, get_ssf(ext))
get_val(x::Vector, ext::SepSpecDualAll) = Cones.h_conj(x, get_ssf(ext))

pos_only(x::Vector{T}, minval::T = eps(T)) where {T <: Real} =
[(x_i < minval ? minval : x_i) for x_i in x]
Expand Down Expand Up @@ -454,7 +457,7 @@ helpers
=#

# get epigraph and perspective variables, swapping if using dual cone
swap_if_dual(x, y, ext::Union{VecSepSpecDualAll, MatSepSpecDualAll}) = (y, x)
swap_if_dual(x, y, ext::SepSpecDualAll) = (y, x)
swap_if_dual(x, y, ext::SepSpecAll) = (x, y)

# check dimension and get symmetric matrix W (upper triangle) of vectorized w
Expand Down

0 comments on commit d371020

Please sign in to comment.