@@ -175,6 +175,39 @@ function _check_dimension(v::AbstractVector, s)
175175 return
176176end
177177
178+ function _reshape (
179+ x:: AbstractVector ,
180+ set:: Union {
181+ MOI. PositiveSemidefiniteConeSquare,
182+ MOI. LogDetConeSquare,
183+ MOI. RootDetConeSquare,
184+ },
185+ )
186+ n = isqrt (length (x))
187+ return reshape (x, (n, n))
188+ end
189+
190+ function _reshape (
191+ x:: AbstractVector{T} ,
192+ set:: Union {
193+ MOI. PositiveSemidefiniteConeTriangle,
194+ MOI. LogDetConeTriangle,
195+ MOI. RootDetConeTriangle,
196+ },
197+ ) where {T}
198+ n = isqrt (2 * length (x))
199+ # The type annotation is needed for JET.
200+ X = zeros (T, n, n):: Matrix{T}
201+ k = 1
202+ for i in 1 : n
203+ for j in 1 : i
204+ X[j, i] = X[i, j] = x[k]
205+ k += 1
206+ end
207+ end
208+ return LinearAlgebra. Symmetric (X)
209+ end
210+
178211# This is the minimal L2-norm.
179212function distance_to_set (
180213 :: ProjectionUpperBoundDistance ,
@@ -499,28 +532,6 @@ function distance_to_set(
499532 return LinearAlgebra. norm (elements, 2 )
500533end
501534
502- function _reshape (x:: AbstractVector , set:: MOI.PositiveSemidefiniteConeSquare )
503- n = MOI. side_dimension (set)
504- return reshape (x, (n, n))
505- end
506-
507- function _reshape (
508- x:: AbstractVector{T} ,
509- set:: MOI.PositiveSemidefiniteConeTriangle ,
510- ) where {T}
511- n = MOI. side_dimension (set)
512- # The type annotation is needed for JET.
513- X = zeros (T, n, n):: Matrix{T}
514- k = 1
515- for i in 1 : n
516- for j in 1 : i
517- X[j, i] = X[i, j] = x[k]
518- k += 1
519- end
520- end
521- return LinearAlgebra. Symmetric (X)
522- end
523-
524535"""
525536 distance_to_set(
526537 ::ProjectionUpperBoundDistance,
@@ -608,3 +619,86 @@ function distance_to_set(
608619 sqrt (x[1 ]^ 2 + distance_to_set (distance, x[2 ], set. set)^ 2 ),
609620 )
610621end
622+
623+ """
624+ distance_to_set(::ProjectionUpperBoundDistance, x, set::MOI.NormNuclearCone)
625+
626+ Let `(t, y...) = x`. Return the epigraph distance `d` such that `(t + d, y...)`
627+ belongs to the set.
628+ """
629+ function distance_to_set (
630+ :: ProjectionUpperBoundDistance ,
631+ x:: AbstractVector{T} ,
632+ set:: MOI.NormNuclearCone ,
633+ ) where {T}
634+ _check_dimension (x, set)
635+ X = reshape (x[2 : end ], set. row_dim, set. column_dim)
636+ return max (sum (LinearAlgebra. svdvals (X)) - x[1 ], zero (T))
637+ end
638+
639+ """
640+ distance_to_set(::ProjectionUpperBoundDistance, x, set::MOI.NormSpectralCone)
641+
642+ Let `(t, y...) = x`. Return the epigraph distance `d` such that `(t + d, y...)`
643+ belongs to the set.
644+ """
645+ function distance_to_set (
646+ :: ProjectionUpperBoundDistance ,
647+ x:: AbstractVector{T} ,
648+ set:: MOI.NormSpectralCone ,
649+ ) where {T}
650+ _check_dimension (x, set)
651+ X = reshape (x[2 : end ], set. row_dim, set. column_dim)
652+ return max (maximum (LinearAlgebra. svdvals (X)) - x[1 ], zero (T))
653+ end
654+
655+ """
656+ distance_to_set(
657+ ::ProjectionUpperBoundDistance,
658+ x::AbstractVector,
659+ set::Union{MOI.RootDetConeSquare,MOI.RootDetConeTriangle},
660+ )
661+
662+ Let ``Y`` be `y` in `x = (t, y)`, reshaped into the appropriate matrix. The
663+ returned distance is ``||Y - Z||_2^2`` where ``Z`` is the eigen decomposition of
664+ ``Y`` with negative eigen values removed, plus the epigraph distance in `t`
665+ needed to satisfy the root-determinant constraint.
666+ """
667+ function distance_to_set (
668+ :: ProjectionUpperBoundDistance ,
669+ x:: AbstractVector{T} ,
670+ set:: Union{MOI.RootDetConeSquare,MOI.RootDetConeTriangle} ,
671+ ) where {T<: Real }
672+ _check_dimension (x, set)
673+ eigvals = LinearAlgebra. eigvals (_reshape (x[2 : end ], set))
674+ eigvals_neg = min .(zero (T), eigvals)
675+ eigvals_pos = max .(zero (T), eigvals)
676+ rootdet = prod (eigvals_pos)^ (1 / set. side_dimension)
677+ push! (eigvals_neg, max (x[1 ] - rootdet, zero (T)))
678+ return LinearAlgebra. norm (eigvals_neg, 2 )
679+ end
680+
681+ """
682+ distance_to_set(
683+ ::ProjectionUpperBoundDistance,
684+ x::AbstractVector,
685+ set::Union{MOI.LogDetConeSquare,MOI.LogDetConeTriangle},
686+ )
687+
688+ Let ``Y`` be `y` in `x = (t, y)`, reshaped into the appropriate matrix. The
689+ returned distance is ``||Y/u - Z||_2^2`` where ``Z`` is the eigen decomposition
690+ of ``Y`` with negative eigen values removed, plus the epigraph distance in `t`
691+ needed to satisfy the log-determinant constraint.
692+ """
693+ function distance_to_set (
694+ :: ProjectionUpperBoundDistance ,
695+ x:: AbstractVector{T} ,
696+ set:: Union{MOI.LogDetConeSquare,MOI.LogDetConeTriangle} ,
697+ ) where {T<: Real }
698+ _check_dimension (x, set)
699+ eigvals = LinearAlgebra. eigvals (_reshape (x[3 : end ] ./ x[2 ], set))
700+ eigvals_neg = min .(eps (T), eigvals)
701+ eigvals_pos = max .(eps (T), eigvals)
702+ push! (eigvals_neg, max (x[1 ] - x[2 ] * sum (log .(eigvals_pos)), zero (T)))
703+ return LinearAlgebra. norm (eigvals_neg, 2 )
704+ end
0 commit comments