We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 67480b7 commit bce7f9fCopy full SHA for bce7f9f
2 files changed
src/Utilities/distance_to_set.jl
@@ -508,6 +508,20 @@ function _reshape(x::AbstractVector, set::MOI.PositiveSemidefiniteConeTriangle)
508
return LinearAlgebra.Symmetric(X)
509
end
510
511
+"""
512
+ distance_to_set(
513
+ ::ProjectionUpperBoundDistance,
514
+ x::AbstractVector,
515
+ set::Union{
516
+ MOI.PositiveSemidefiniteConeSquare,
517
+ MOI.PositiveSemidefiniteConeTriangle,
518
+ },
519
+ )
520
+
521
+Let ``X`` be `x` reshaped into the appropriate matrix. The returned distance is
522
+``||X - Y||_2^2`` where ``Y`` is the eigen decomposition of ``X`` with negative
523
+eigen values removed.
524
525
function distance_to_set(
526
::ProjectionUpperBoundDistance,
527
x::AbstractVector{T},
@@ -518,10 +532,11 @@ function distance_to_set(
532
) where {T<:Real}
533
_check_dimension(x, set)
534
λ, U = LinearAlgebra.eigen(_reshape(x, set))
- if minimum(λ) >= 0
535
+ if minimum(λ) >= zero(T)
536
return 0.0
537
538
λ_negative = LinearAlgebra.Diagonal(min.(zero(T), λ))
539
A = LinearAlgebra.Symmetric(U * λ_negative * U')
- return LinearAlgebra.norm(A, 2)
540
+ # Σ A^2 is needed to match the definition of Utilities.set_dot
541
+ return sum(Base.Fix2(^, 2), A)
542
test/Utilities/distance_to_set.jl
@@ -30,7 +30,7 @@ function _test_set(set, pairs...; mismatch = nothing)
30
)
31
32
for (x, d) in pairs
33
- @test MOI.Utilities.distance_to_set(x, set) ≈ d
+ @test ≈(MOI.Utilities.distance_to_set(x, set), d; atol = 1e-12)
34
35
return
36
@@ -313,7 +313,8 @@ function test_positivesemidefiniteconesquare()
313
MOI.PositiveSemidefiniteConeSquare(2),
314
[1.0, 0.0, 0.0, 1.0] => 0.0,
315
[1.0, -1.0, -1.0, 1.0] => 0.0,
316
- [1.0, -2.0, -2.0, 1.0] => 1.0;
+ [1.0, -2.0, -2.0, 1.0] => 1.0
317
+ [1.0 1.1; 1.1 -2.3] => 2.6330532015051946;
318
mismatch = [1.0],
319
320
@@ -324,7 +325,8 @@ function test_positivesemidefiniteconetriangle()
324
325
MOI.PositiveSemidefiniteConeTriangle(2),
326
[1.0, 0.0, 1.0] => 0.0,
327
[1.0, -1.0, 1.0] => 0.0,
- [1.0, -2.0, 1.0] => 1.0;
328
+ [1.0, -2.0, 1.0] => 1.0
329
+ [1.0, 1.1, -2.3] => 2.6330532015051946;
330
331
332
0 commit comments