@@ -4,7 +4,7 @@ import LinearAlgebra: norm
4
4
export norm
5
5
6
6
"""
7
- norm(x::AbstractExpression, p=2, [q,] [dim=1])
7
+ norm(x::AbstractExpression, p=2, [q,] [dim=1])
8
8
9
9
Returns the norm of `x`.
10
10
@@ -28,41 +28,41 @@ where ``\\mathbf{x}_i`` is the ``i``-th column if `dim == 1` (or row if `dim ==
28
28
29
29
"""
30
30
function norm (ex:: AbstractExpression , p:: Real = 2 )
31
- if p == 0
32
- f = NormL0 ()
33
- elseif p == 1
34
- f = NormL1 ()
35
- elseif p == 2
36
- f = NormL2 ()
37
- elseif p == Inf
38
- f = NormLinf ()
39
- else
40
- error (" function not implemented" )
41
- end
42
- return Term (f, ex)
31
+ if p == 0
32
+ f = NormL0 ()
33
+ elseif p == 1
34
+ f = NormL1 ()
35
+ elseif p == 2
36
+ f = NormL2 ()
37
+ elseif p == Inf
38
+ f = NormLinf ()
39
+ else
40
+ error (" function not implemented" )
41
+ end
42
+ return Term (f, ex)
43
43
end
44
44
45
45
# Nuclear norm
46
46
function norm (ex:: AbstractExpression , :: typeof (* ))
47
- return Term (NuclearNorm (), ex)
47
+ return Term (NuclearNorm (), ex)
48
48
end
49
49
50
50
# Mixed Norm
51
51
function norm (ex:: AbstractExpression , p1:: Int , p2:: Int , dim:: Int = 1 )
52
- if p1 == 2 && p2 == 1
53
- f = NormL21 (1.0 ,dim)
54
- else
55
- error (" function not implemented" )
56
- end
57
- return Term (f, ex)
52
+ if p1 == 2 && p2 == 1
53
+ f = NormL21 (1.0 ,dim)
54
+ else
55
+ error (" function not implemented" )
56
+ end
57
+ return Term (f, ex)
58
58
end
59
59
60
60
# Least square terms
61
61
62
62
export ls
63
63
64
64
"""
65
- ls(x::AbstractExpression)
65
+ ls(x::AbstractExpression)
66
66
67
67
Returns the squared norm (least squares) of `x`:
68
68
@@ -77,20 +77,20 @@ ls(ex) = Term(SqrNormL2(), ex)
77
77
import Base: ^
78
78
79
79
function (^ )(t:: Term{T1,T2,T3} , exp:: Integer ) where {T1, T2 <: NormL2 , T3}
80
- if exp == 2
81
- # The coefficient 2.0 is due to the fact that SqrNormL2 divides by 2.0
82
- return t. lambda^ 2 * Term (SqrNormL2 (2.0 ), t. A)
83
- else
84
- error (" function not implemented" )
85
- end
80
+ if exp == 2
81
+ # The coefficient 2.0 is due to the fact that SqrNormL2 divides by 2.0
82
+ return t. lambda^ 2 * Term (SqrNormL2 (2.0 ), t. A)
83
+ else
84
+ error (" function not implemented" )
85
+ end
86
86
end
87
87
88
88
# HingeLoss
89
89
90
90
export hingeloss
91
91
92
92
"""
93
- hingeloss(x::AbstractExpression, y::Array)
93
+ hingeloss(x::AbstractExpression, y::Array)
94
94
95
95
Applies the Hinge loss function
96
96
```math
@@ -106,7 +106,7 @@ Term(HingeLoss(b), ex)
106
106
export sqrhingeloss
107
107
108
108
"""
109
- sqrhingeloss(x::AbstractExpression, y::Array)
109
+ sqrhingeloss(x::AbstractExpression, y::Array)
110
110
111
111
Applies the squared Hinge loss function
112
112
```math
@@ -122,7 +122,7 @@ Term(SqrHingeLoss(b), ex)
122
122
export crossentropy
123
123
124
124
"""
125
- crossentropy(x::AbstractExpression, y::Array)
125
+ crossentropy(x::AbstractExpression, y::Array)
126
126
127
127
Applies the cross entropy loss function:
128
128
```math
@@ -138,7 +138,7 @@ Term(CrossEntropy(b), ex)
138
138
export logisticloss
139
139
140
140
"""
141
- logbarrier(x::AbstractExpression, y::AbstractArray)
141
+ logbarrier(x::AbstractExpression, y::AbstractArray)
142
142
143
143
Applies the logistic loss function:
144
144
```math
@@ -154,7 +154,7 @@ Term(LogisticLoss(y, 1.0), ex)
154
154
export logbarrier
155
155
156
156
"""
157
- logbarrier(x::AbstractExpression)
157
+ logbarrier(x::AbstractExpression)
158
158
159
159
Applies the log barrier function:
160
160
```math
@@ -169,7 +169,7 @@ Term(LogBarrier(1.0), ex)
169
169
export huberloss
170
170
171
171
"""
172
- huberloss(x::AbstractExpression, ρ=1.0)
172
+ huberloss(x::AbstractExpression, ρ=1.0)
173
173
174
174
Applies the Huber loss function:
175
175
```math
@@ -185,7 +185,7 @@ Term(HuberLoss(rho), ex)
185
185
import Base: maximum
186
186
187
187
"""
188
- maximum(x::AbstractExpression)
188
+ maximum(x::AbstractExpression)
189
189
190
190
Applies the function:
191
191
```math
@@ -198,7 +198,7 @@ Term(Maximum(), ex)
198
198
export sumpositive
199
199
200
200
"""
201
- sumpositive(x::AbstractExpression, ρ=1.0)
201
+ sumpositive(x::AbstractExpression, ρ=1.0)
202
202
203
203
Applies the function:
204
204
```math
@@ -212,7 +212,7 @@ import LinearAlgebra: dot
212
212
export dot
213
213
214
214
"""
215
- dot(c::AbstractVector, x::AbstractExpression)
215
+ dot(c::AbstractVector, x::AbstractExpression)
216
216
217
217
Applies the function:
218
218
```math
@@ -284,10 +284,10 @@ import Base: <=, >=, in
284
284
(>= )(ub, ex:: AbstractExpression ) = Term (IndBox (- Inf , ub), ex)
285
285
286
286
function in (ex:: AbstractExpression , bnds:: AbstractArray )
287
- if length (bnds) != 2
288
- error (" should provide 2 bounds!" )
289
- end
290
- return Term (IndBox (bnds[1 ], bnds[2 ]), ex)
287
+ if length (bnds) != 2
288
+ error (" should provide 2 bounds!" )
289
+ end
290
+ return Term (IndBox (bnds[1 ], bnds[2 ]), ex)
291
291
end
292
292
293
293
# Rank constraints
@@ -299,9 +299,9 @@ export rank
299
299
# rank(X) <= r,
300
300
# therefore here the parameter (1) doesn't really have a role.
301
301
# We should probably fix this: it allows weird things in expressing problems.
302
- # Maybe we should have Rank <: ProximableFunction (with no prox! nor gradient!
302
+ # Maybe we should have Rank (with no prox! nor gradient!
303
303
# defined), that gives IndBallRank when combined with <=.
304
- struct Rank <: ProximableFunction end
304
+ struct Rank end
305
305
rank (ex:: AbstractExpression ) = Term (Rank (), ex)
306
306
307
307
import Base: <=
368
368
import Base: conj
369
369
370
370
"""
371
- conj(t::Term)
371
+ conj(t::Term)
372
372
373
373
Returns the convex conjugate transform of `t`:
374
374
```math
@@ -388,19 +388,19 @@ julia> t = conj(norm(x,1))
388
388
389
389
"""
390
390
function conj (t:: Term )
391
- if typeof (operator (t)) <: Eye
392
- return Term (1.0 ,Conjugate (Postcompose (t. f,t. lambda)),t. A)
393
- else
394
- error (" cannot perform convex conjugation" )
395
- end
391
+ if typeof (operator (t)) <: Eye
392
+ return Term (1.0 ,Conjugate (Postcompose (t. f,t. lambda)),t. A)
393
+ else
394
+ error (" cannot perform convex conjugation" )
395
+ end
396
396
397
397
end
398
398
399
399
# Moreau Envelope
400
400
export smooth
401
401
402
402
"""
403
- smooth(t::Term, gamma = 1.0)
403
+ smooth(t::Term, gamma = 1.0)
404
404
405
405
Smooths the nonsmooth term `t` using Moreau envelope:
406
406
0 commit comments