Skip to content

Commit

Permalink
BUG: Fixed some complex number handling in objective functions
Browse files Browse the repository at this point in the history
The squared two-norm could not handle complex vectors correctly
(absolute value was omitted).
  • Loading branch information
Thomas Arildsen committed Jul 5, 2018
1 parent ded1832 commit c934ab1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pyunlocbox/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init__(self, y=0, A=None, At=None, tight=True, nu=1, tol=1e-3,
elif callable(A):
self.At = A
else:
self.At = lambda x: A.T.dot(x)
self.At = lambda x: A.T.conj().dot(x)
else:
if callable(At):
self.At = At
Expand Down Expand Up @@ -493,7 +493,7 @@ def __init__(self, **kwargs):

def _eval(self, x):
sol = self.A(x) - self.y()
return self.lambda_ * np.sum((self.w * sol)**2)
return self.lambda_ * x.conj().dot(x).real

def _prox(self, x, T):
# Gamma is T in the matlab UNLocBox implementation.
Expand All @@ -502,8 +502,9 @@ def _prox(self, x, T):
sol = x + 2. * gamma * self.At(self.y() * self.w**2)
sol /= 1. + 2. * gamma * self.nu * self.w**2
else:
res = minimize(fun=lambda z: 0.5 * np.sum((z - x)**2) + gamma *
np.sum((self.w * (self.A(z) - self.y()))**2),
res = minimize(fun=lambda z: 0.5 * np.sum(np.abs(z - x)**2)
+ gamma * np.sum((self.w * np.abs(self.A(z)
- self.y()))**2),
x0=x,
method='BFGS',
jac=lambda z: z - x + 2. * gamma *
Expand Down

0 comments on commit c934ab1

Please sign in to comment.