Skip to content

Commit

Permalink
Almost all gradients (Issue #43) implemented, test still missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mfalt committed Oct 23, 2017
1 parent 14a3764 commit fa29a3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/functions/elasticNet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function prox!{R <: Real}(y::AbstractArray{Complex{R}}, f::ElasticNet{R}, x::Abs
return f.mu*norm1x + (f.lambda/2)*sqnorm2x
end

function gradient!{T <: RealOrComplex, R <: Real}(y::AbstractArray{T}, f::Conjugate{IndBallL1{R}}, x::AbstractArray{T})
function gradient!{T <: RealOrComplex, R <: Real}(y::AbstractArray{T}, f::ElasticNet{R}, x::AbstractArray{T})
# Gradient of 1 norm
y .= f.mu.*sign.(x)
# Gradient of 2 norm
Expand Down
7 changes: 6 additions & 1 deletion src/functions/sumPositive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ is_separable(f::SumPositive) = true
is_convex(f::SumPositive) = true

function (f::SumPositive){T <: Real}(x::AbstractArray{T})
return sum(max.(0.0, x))
return sum(xi -> max(xi,0), x)
end

function prox!{T <: Real}(y::AbstractArray{T}, f::SumPositive, x::AbstractArray{T}, gamma::Real=1.0)
Expand All @@ -31,6 +31,11 @@ function prox!{T <: Real}(y::AbstractArray{T}, f::SumPositive, x::AbstractArray{
return fsum
end

function gradient!{T <: Real}(y::AbstractArray{T}, f::SumPositive, x::AbstractArray{T})
y .= max.(0, sign.(x))
return sum(xi -> max(xi,0), x)
end

fun_name(f::SumPositive) = "Sum of the positive coefficients"
fun_dom(f::SumPositive) = "AbstractArray{Real}"
fun_expr(f::SumPositive) = "x ↦ sum(max(0, x))"
Expand Down

0 comments on commit fa29a3f

Please sign in to comment.