def L1_min(Phi, y, K): # inequalities matrix with M, Nf = Phi.shape G = matrx( rearrange_G( scipy.linalg.block_diag(*[ matrix([[-1, -1], [1, -1.0]]), ] * Nf))) # objective function row-matrix c = matrx(hstack([ones(Nf), zeros(Nf)])) # RHS for inequalities h = matrx([ 0.0, ] * (Nf * 2), (Nf * 2, 1), 'd') # equality constraint matrix A = matrx(hstack([Phi * 0, Phi])) # RHS for equality constraints b = matrx(y) # suppress standard output #old_stdout = sys.stdout #sys.stdout = mystdout = StringIO() print hstack([Phi * 0, Phi]).shape sol = solvers.lp(c, G, h, A, b) # restore standard output #sys.stdout = old_stdout sln = array(sol['x']).flatten()[:Nf].round(4) return sln
def L1_min(Phi,y,K): # inequalities matrix with M,Nf = Phi.shape G=matrx(rearrange_G(scipy.linalg.block_diag(*[matrix([[-1,-1],[1,-1.0]]),]*Nf) )) # objective function row-matrix c=matrx(np.hstack([ones(Nf),zeros(Nf)])) # RHS for inequalities h = matrx([0.0,]*(Nf*2),(Nf*2,1),'d') # equality constraint matrix A = matrix(hstack([Phi*0,Phi])) # RHS for equality constraints b=matrix(y) # suppress standard output old_stdout = sys.stdout sys.stdout = mystdout = StringIO() sol = solvers.lp(c, G, h,A,b) # restore standard output sys.stdout = old_stdout sln = array(sol['x']).flatten()[:Nf].round(4) return sln
Nf = len(ftime) N = 2 * Nf time_samples = np.array(range(0, N / 2, 2)) #print time_samples.shape,ftime.shape,N,Nf half_indexed_time_samples = (array(time_samples) / 2).astype(int) Phi = dftmatrix(N / 2).real * Q_rmatrix(N) Phi_i = Phi[half_indexed_time_samples, :] # inequalities matrix with G = matrx( rearrange_G( scipy.linalg.block_diag(*[ matrix([[-1, -1], [1, -1.0]]), ] * N))) # objective function row-matrix #c=matrx(hstack([100*ones(N),zeros(N)])) #if i==0: c = matrx(hstack([ones(N), zeros(N)])) #else: #c=matrix(hstack(ff,zeros(N))) # RHS for inequalities h = matrx([ 0.0, ] * (N * 2), (N * 2, 1), 'd') # equality constraint matrix A = matrx(hstack([Phi_i, Phi_i * 0])) # RHS for equality constraints
Nf=len(ftime) N=2*Nf time_samples=np.array(range(0,N/2,2)) #print time_samples.shape,ftime.shape,N,Nf half_indexed_time_samples = (array(time_samples)/2).astype(int) Phi = dftmatrix(N/2).real*Q_rmatrix(N) Phi_i = Phi[half_indexed_time_samples,:] # inequalities matrix with G=matrx(rearrange_G(scipy.linalg.block_diag(*[matrix([[-1,-1],[1,-1.0]]),]*N) )) # objective function row-matrix #c=matrx(hstack([100*ones(N),zeros(N)])) #if i==0: c=matrx(hstack([ones(N),zeros(N)])) #else: #c=matrix(hstack(ff,zeros(N))) # RHS for inequalities h = matrx([0.0,]*(N*2),(N*2,1),'d') # equality constraint matrix A = matrx(hstack([Phi_i,Phi_i*0])) # RHS for equality constraints b=matrx(ftime[half_indexed_time_samples]) sol = solvers.lp(c, G, h,A,b)