-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphaselift-method.py
More file actions
31 lines (24 loc) · 958 Bytes
/
Copy pathphaselift-method.py
File metadata and controls
31 lines (24 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
pip install cvxpy
import cvxpy as cp
#We'll first define the phase retrieval problem using the PhaseLift method.
def pr(b, a, W):
m = len(b)
n= len(a[0])
X = cp.Variable((n,n), symmetric=True)
constraints = [X >> 0]
constraints += [cp.trace(a[i]@(a[i].T) @ X) == b[i] for i in range(m)]
prob = cp.Problem(cp.Minimize(cp.trace(W @ X)), constraints)
prob.solve()
# print("The optimal value is", prob.value)
return X.value
W0 = pr(b,a,W) #this defined the solution to the problem when W is the identity matrix.
#Now, we'll define the PhaseLift method using a trace minimization problem with weighted matrices.
def itpr(b,a,eps,k):
W=np.eye(len(a[0]))
for i in range(k):
X=pr(b,a,W)
# print(X)
W=np.linalg.inv(X+eps*np.eye(len(a[0])))
return(X)
#This returns the optimal solution X, matrix, to the phase retrieval problem.