Skip to content

Commit

Permalink
moved stuff around, excluded symmetricpacked from 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lostella committed Oct 17, 2016
1 parent 68d9cf8 commit 1a81fdc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 42 deletions.
8 changes: 7 additions & 1 deletion src/Prox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ abstract NormFunction <: ProximableFunction
abstract IndicatorFunction <: ProximableFunction
abstract IndicatorConvex <: IndicatorFunction

################################################################################
# looks like there are some issues in 0.4
if VERSION >= v"0.5-"
include("utilities/symmetricpacked.jl")
end
################################################################################

################################################################################
# experimental stuff
abstract SeparableFunction <: ProximableFunction
Expand All @@ -49,7 +56,6 @@ include("functions/absoluteValue.jl")
include("calculus/conjugate.jl")
include("calculus/postcomposition.jl")
include("calculus/precomposition.jl")
include("calculus/symmetricpacked.jl")

include("functions/distL2.jl")
include("functions/elasticNet.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/functions/indExp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

IndExpDual() = IndExpDual(IndExpPrimal())

EXP_CONE_CALL_TOL = 1e-8
EXP_CONE_CALL_TOL = 1e-6

@compat function (f::IndExpPrimal){R <: Real}(x::AbstractArray{R})
if (x[2] > 0.0 && x[2]*exp(x[1]/x[2]) <= x[3]+EXP_CONE_CALL_TOL) ||
Expand Down
58 changes: 31 additions & 27 deletions src/functions/indPSD.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# indicator of a PSD

"""
IndPDS(a::HermOrSym{T})
IndPSD(a::HermOrSym{T})
Returns the function `g = ind{A : A ⪰ 0}`, i.e. an indicator of
positive semidefinite cone
Expand Down Expand Up @@ -29,32 +29,6 @@ function prox!{T <: RealOrComplex}(f::IndPSD, X::HermOrSym{T}, Y::HermOrSym{T},
return 0.0
end

@compat function (f::IndPSD){T <: Float64}(x::AbstractVector{T})
Z = dspev!('N', 'L', copy(x))
for i in 1:length(Z)
#Do we allow for some tolerance here?
if Z[i] <= -1e-14
return +Inf
end
end
return 0.0
end

function prox!(f::IndPSD, x::AbstractVector{Float64}, y::AbstractVector{Float64}, gamma::Real=1.0)
y[:] = x # Copy x since dspev! corrupts input
(W, Z) = dspev!('V', 'L', y)
W = max(W, 0) # NonNeg eigenvalues
M = Z.*W' # Equivalent to Z*diagm(W) without constructing W matrix
M = M*Z' # Now let M = Z*diagm(W)*Z'
n = length(W)
k = 1
for j in 1:n, i in j:n # Store lower diagonal of M in y
y[k] = M[i,j]
k = k+1
end
return 0.0
end

################################################################################
# temporary: 'similar' doesn't yield a Symmetric or Hermitian object in 0.4
################################################################################
Expand Down Expand Up @@ -89,6 +63,34 @@ function prox_naive{T <: RealOrComplex}(f::IndPSD, X::HermOrSym{T}, gamma::Real=
return F.vectors * diagm(max(0.0, F.values)) * F.vectors', 0.0;
end

if isdefined(:dspev!)

@compat function (f::IndPSD){T <: Float64}(x::AbstractVector{T})
Z = dspev!('N', 'L', copy(x))
for i in 1:length(Z)
#Do we allow for some tolerance here?
if Z[i] <= -1e-14
return +Inf
end
end
return 0.0
end

function prox!(f::IndPSD, x::AbstractVector{Float64}, y::AbstractVector{Float64}, gamma::Real=1.0)
y[:] = x # Copy x since dspev! corrupts input
(W, Z) = dspev!('V', 'L', y)
W = max(W, 0) # NonNeg eigenvalues
M = Z.*W' # Equivalent to Z*diagm(W) without constructing W matrix
M = M*Z' # Now let M = Z*diagm(W)*Z'
n = length(W)
k = 1
for j in 1:n, i in j:n # Store lower diagonal of M in y
y[k] = M[i,j]
k = k+1
end
return 0.0
end

function prox_naive{T<:Float64}(f::IndPSD, x::AbstractVector{T}, gamma::Real=1.0)
n = Int(sqrt(1/4+2*length(x))-1/2) # Formula for size of matrix
X = Array{T,2}(n,n)
Expand All @@ -109,3 +111,5 @@ function prox_naive{T<:Float64}(f::IndPSD, x::AbstractVector{T}, gamma::Real=1.0
end
return y
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Base.LinAlg.BLAS.@blasfunc
Computes all the eigenvalues and optionally the eigenvectors of a real
symmetric `n×n` matrix `A` in packed storage. Will corrupt `x`.
Arguments:
`jobz`: `'N'` if only eigenvalues, `'V'` if eigenvalues and eigenvectors
Expand All @@ -17,11 +16,11 @@ Arguments:
`x`: `A` represented as vector of the lower (upper) n*(n+1)/2 elements, packed columnwise.
Returns:
`W,Z` if `jobz == 'V'` or: `W` if `jobz == 'N'` such that `A=Z*diagm(W)*Z'`
"""

function dspev!(jobz::Char, uplo::Char, A::StridedVector{Float64})
chkstride1(A)
vecN = length(A)
Expand Down
28 changes: 17 additions & 11 deletions test/test_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ stuff = [
"f(y)" => 0.0,
),

Dict( "f" => IndPSD(),
"x" => Float64[1.0, 2.0, 3.0, 2.0, 2.0, 6.0, 2.5, 3.0, 1.5, 1.0],
"f(x)" => +Inf,
"gamma" => 1.0,
"y" => Float64[1.6410947195520720, 2.3777145021117252, 2.5281090002887159, 1.4927448378285653,
3.9278061374789126, 4.2522683130214816, 1.9740014117486600,
4.6140313368981438, 2.0691378959547362,
1.4316113417275229],
"f(y)" => 0.0,
),

Dict( "f" => IndBallL1(3.5),
"x" => [0.183227263001437, -1.029767543566621, 0.949221831131023, 0.307061919146703,
0.135174942099456, 0.515246335524849, 0.261406324055383, -0.941485770955434,
Expand Down Expand Up @@ -219,6 +208,23 @@ stuff = [
)
]

if isdefined(:dspev!)

stuff = [stuff;
Dict( "f" => IndPSD(),
"x" => Float64[1.0, 2.0, 3.0, 2.0, 2.0, 6.0, 2.5, 3.0, 1.5, 1.0],
"f(x)" => +Inf,
"gamma" => 1.0,
"y" => Float64[1.6410947195520720, 2.3777145021117252, 2.5281090002887159, 1.4927448378285653,
3.9278061374789126, 4.2522683130214816, 1.9740014117486600,
4.6140313368981438, 2.0691378959547362,
1.4316113417275229],
"f(y)" => 0.0,
)
]

end

for i = 1:length(stuff)

println("----------------------------------------------------------")
Expand Down

0 comments on commit 1a81fdc

Please sign in to comment.