Skip to content

Commit

Permalink
Merge pull request #664 from chriscoey/barriertestupdates
Browse files Browse the repository at this point in the history
cleanup cone oracle tests, check oracle allocations
  • Loading branch information
chriscoey authored Mar 31, 2021
2 parents ea5ca1d + 6dc6f67 commit 49e0cdb
Show file tree
Hide file tree
Showing 16 changed files with 2,676 additions and 2,503 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GSL = "92c85e6c-cbff-5e0c-80f7-495c94daaecd"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
PolyJuMP = "ddf597a6-d67e-5340-b84c-e37d84115374"
Expand All @@ -42,4 +43,4 @@ SemialgebraicSets = "8e049039-38e8-557d-ae3a-bc521ccf6204"
SumOfSquares = "4b9e565b-77fc-50a5-a571-1244f986bda1"

[targets]
test = ["CSV", "DataFrames", "DataStructures", "DelimitedFiles", "Distributions", "DynamicPolynomials", "GSL", "JuMP", "PolyJuMP", "Random", "SemialgebraicSets", "SumOfSquares"]
test = ["CSV", "DataFrames", "DataStructures", "DelimitedFiles", "Distributions", "DynamicPolynomials", "ForwardDiff", "GSL", "JuMP", "PolyJuMP", "Random", "SemialgebraicSets", "SumOfSquares"]
2 changes: 1 addition & 1 deletion examples/common_JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ cone_from_hyp(cone::Cones.EpiPerSquare) = MOI.RotatedSecondOrderCone(Cones.dimen
cone_from_hyp(cone::Cones.HypoPerLog) = (@assert Cones.dimension(cone) == 3; MOI.ExponentialCone())
cone_from_hyp(cone::Cones.EpiRelEntropy) = MOI.RelativeEntropyCone(Cones.dimension(cone))
cone_from_hyp(cone::Cones.HypoGeoMean) = MOI.GeometricMeanCone(Cones.dimension(cone))
cone_from_hyp(cone::Cones.Power) = (@assert Cones.dimension(cone) == 3; MOI.PowerCone{Float64}(cone.alpha[1]))
cone_from_hyp(cone::Cones.GeneralizedPower) = (@assert Cones.dimension(cone) == 3; MOI.PowerCone{Float64}(cone.alpha[1]))
cone_from_hyp(cone::Cones.EpiNormSpectral) = (Cones.use_dual_barrier(cone) ? MOI.NormNuclearCone : MOI.NormSpectralCone)(cone.n, cone.m)
cone_from_hyp(cone::Cones.PosSemidefTri{T, R}) where {R <: Hypatia.RealOrComplex{T}} where {T <: Real} = MOI.PositiveSemidefiniteConeTriangle(cone.side)
cone_from_hyp(cone::Cones.LinMatrixIneq{T}) where {T <: Real} = Hypatia.LinMatrixIneqCone{T}(cone.As)
Expand Down
6 changes: 3 additions & 3 deletions examples/matrixcompletion/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,21 @@ function build(inst::MatrixCompletionNative{T}) where {T <: Real}
G_geo_unknown[1, 1] = -1
G_geo_unknown[2, 2] = -1
G_geo_newvars[3, 1] = -1
push!(cones, Cones.Power{T}(fill(inv(T(2)), 2), 1))
push!(cones, Cones.GeneralizedPower{T}(fill(inv(T(2)), 2), 1))
offset = 4
# loop over new vars
for i in 1:(num_unknown - 3)
G_geo_newvars[offset + 2, i + 1] = -1
G_geo_newvars[offset + 1, i] = -1
G_geo_unknown[offset, i + 2] = -1
push!(cones, Cones.Power{T}([inv(T(i + 2)), T(i + 1) / T(i + 2)], 1))
push!(cones, Cones.GeneralizedPower{T}([inv(T(i + 2)), T(i + 1) / T(i + 2)], 1))
offset += 3
end

# last row also special because hypograph variable is fixed
G_geo_unknown[offset, num_unknown] = -1
G_geo_newvars[offset + 1, num_unknown - 2] = -1
push!(cones, Cones.Power{T}([inv(T(num_unknown)), T(num_unknown - 1) / T(num_unknown)], 1))
push!(cones, Cones.GeneralizedPower{T}([inv(T(num_unknown)), T(num_unknown - 1) / T(num_unknown)], 1))
h = vcat(h_norm, zeros(T, 3 * (num_unknown - 2)), T[0, 0, 1])

# if using extended with spectral objective G_geo needs to be prepadded with an epigraph variable
Expand Down
6 changes: 3 additions & 3 deletions examples/maxvolume/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function build(inst::MaxVolumeNative{T}) where {T <: Real}
G_geo_orig[1, 1] = -1
G_geo_orig[2, 2] = -1
G_geo_newvars[3, 1] = -1
push!(cones, Cones.Power{T}(fill(inv(T(2)), 2), 1))
push!(cones, Cones.GeneralizedPower{T}(fill(inv(T(2)), 2), 1))
offset = 4
# loop over new vars
for i in 1:(n - 3)
G_geo_newvars[offset + 2, i + 1] = -1
G_geo_newvars[offset + 1, i] = -1
G_geo_orig[offset, i + 2] = -1
push!(cones, Cones.Power{T}([inv(T(i + 2)), T(i + 1) / T(i + 2)], 1))
push!(cones, Cones.GeneralizedPower{T}([inv(T(i + 2)), T(i + 1) / T(i + 2)], 1))
offset += 3
end
# last row also special becuase hypograph variable is involved
Expand All @@ -65,7 +65,7 @@ function build(inst::MaxVolumeNative{T}) where {T <: Real}
G = [
vcat(zeros(T, len_power - 1), -one(T)) G_geo_orig G_geo_newvars
]
push!(cones, Cones.Power{T}([inv(T(n)), T(n - 1) / T(n)], 1))
push!(cones, Cones.GeneralizedPower{T}([inv(T(n)), T(n - 1) / T(n)], 1))
h = zeros(T, 3 * (n - 1))
else
@assert inst.use_epipersquare == true
Expand Down
28 changes: 13 additions & 15 deletions src/Cones/Cones.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#=
functions and caches for cones
TODO maybe write a fallback dual feas check that checks if ray of dual point intersects dikin ellipsoid at primal point
=#

module Cones
Expand Down Expand Up @@ -33,29 +31,29 @@ hessian_cache(T::Type{<:Real}) = DensePosDefCache{T}()
abstract type Cone{T <: Real} end

include("nonnegative.jl")
include("possemideftri.jl")
include("doublynonnegativetri.jl")
include("possemideftrisparse.jl")
include("linmatrixineq.jl")
include("epinorminf.jl")
include("epinormeucl.jl")
include("epiperentropy.jl")
include("epipertraceentropytri.jl")
include("epipersquare.jl")
include("epirelentropy.jl")
include("hypoperlog.jl")
include("power.jl")
include("hypopowermean.jl")
include("hypogeomean.jl")
include("epinormspectral.jl")
include("linmatrixineq.jl")
include("possemideftri.jl")
include("possemideftrisparse.jl")
include("doublynonnegativetri.jl")
include("matrixepipersquare.jl")
include("hypoperlogdettri.jl")
include("generalizedpower.jl")
include("hypopowermean.jl")
include("hypogeomean.jl")
include("hyporootdettri.jl")
include("hypoperlog.jl")
include("hypoperlogdettri.jl")
include("epiperentropy.jl")
include("epipertraceentropytri.jl")
include("epirelentropy.jl")
include("epitracerelentropytri.jl")
include("wsosinterpnonnegative.jl")
include("wsosinterppossemideftri.jl")
include("wsosinterpepinormone.jl")
include("wsosinterpepinormeucl.jl")
include("wsosinterppossemideftri.jl")

use_dual_barrier(cone::Cone) = cone.use_dual_barrier
dimension(cone::Cone) = cone.dim
Expand Down
24 changes: 12 additions & 12 deletions src/Cones/power.jl → src/Cones/generalizedpower.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ barrier from "On self-concordant barriers for generalized power cones" by Roy &
-log(prod_i((u_i)^(2 * alpha_i)) - norm_2(w)^2) - sum_i((1 - alpha_i)*log(u_i))
=#

mutable struct Power{T <: Real} <: Cone{T}
mutable struct GeneralizedPower{T <: Real} <: Cone{T}
use_dual_barrier::Bool
use_heuristic_neighborhood::Bool
dim::Int
Expand Down Expand Up @@ -37,7 +37,7 @@ mutable struct Power{T <: Real} <: Cone{T}
auiproduuw::Vector{T}
tempm::Vector{T}

function Power{T}(
function GeneralizedPower{T}(
alpha::Vector{T},
n::Int;
use_dual::Bool = false,
Expand All @@ -60,10 +60,10 @@ mutable struct Power{T <: Real} <: Cone{T}
end
end

dimension(cone::Power) = length(cone.alpha) + cone.n
dimension(cone::GeneralizedPower) = length(cone.alpha) + cone.n

# TODO only allocate the fields we use
function setup_extra_data(cone::Power{T}) where {T <: Real}
function setup_extra_data(cone::GeneralizedPower{T}) where {T <: Real}
dim = cone.dim
cone.hess = Symmetric(zeros(T, dim, dim), :U)
cone.inv_hess = Symmetric(zeros(T, dim, dim), :U)
Expand All @@ -75,16 +75,16 @@ function setup_extra_data(cone::Power{T}) where {T <: Real}
return cone
end

get_nu(cone::Power) = length(cone.alpha) + 1
get_nu(cone::GeneralizedPower) = length(cone.alpha) + 1

function set_initial_point(arr::AbstractVector, cone::Power)
function set_initial_point(arr::AbstractVector, cone::GeneralizedPower)
m = length(cone.alpha)
@. @views arr[1:m] = sqrt(1 + cone.alpha)
@views arr[(m + 1):cone.dim] .= 0
return arr
end

function update_feas(cone::Power{T}) where {T <: Real}
function update_feas(cone::GeneralizedPower{T}) where {T <: Real}
@assert !cone.feas_updated
m = length(cone.alpha)
@views u = cone.point[1:m]
Expand All @@ -101,7 +101,7 @@ function update_feas(cone::Power{T}) where {T <: Real}
return cone.is_feas
end

function is_dual_feas(cone::Power{T}) where {T <: Real}
function is_dual_feas(cone::GeneralizedPower{T}) where {T <: Real}
alpha = cone.alpha
m = length(cone.alpha)
@views u = cone.dual_point[1:m]
Expand All @@ -115,7 +115,7 @@ function is_dual_feas(cone::Power{T}) where {T <: Real}
return false
end

function update_grad(cone::Power)
function update_grad(cone::GeneralizedPower)
@assert cone.is_feas
m = length(cone.alpha)
@views u = cone.point[1:m]
Expand All @@ -132,7 +132,7 @@ function update_grad(cone::Power)
return cone.grad
end

function update_hess(cone::Power)
function update_hess(cone::GeneralizedPower)
@assert cone.grad_updated
m = length(cone.alpha)
@views u = cone.point[1:m]
Expand Down Expand Up @@ -167,7 +167,7 @@ function update_hess(cone::Power)
return cone.hess
end

function hess_prod!(prod::AbstractVecOrMat, arr::AbstractVecOrMat, cone::Power)
function hess_prod!(prod::AbstractVecOrMat, arr::AbstractVecOrMat, cone::GeneralizedPower)
@assert cone.grad_updated
m = length(cone.alpha)
@views u = cone.point[1:m]
Expand All @@ -194,7 +194,7 @@ function hess_prod!(prod::AbstractVecOrMat, arr::AbstractVecOrMat, cone::Power)
return prod
end

function correction(cone::Power, primal_dir::AbstractVector)
function correction(cone::GeneralizedPower, primal_dir::AbstractVector)
m = length(cone.alpha)
@views u = cone.point[1:m]
@views w = cone.point[(m + 1):end]
Expand Down
Loading

0 comments on commit 49e0cdb

Please sign in to comment.