def __init__(self,x,y,λ=0.1,W=None): # W = list of matricies n = x.shape[0] m = y.shape[0] q = x.shape[1] assert y.shape[1] == q Q = zeros(m*n,m*n) c = zeros(m*n) for i in range(q): if W is None: Q += np.kron(eye(m), x[:,i] * x[:,i].T) c += np.kron(eye(m), x[:,i]) *y[:,i] else: Q += np.kron(eye(m), x[:,i] * W[i].T * W[i]* x[:,i].T) c += np.kron(eye(m), x[:,i]) * W[i].T * W[i] * y[:,i] Q *= 2 c *= -2 vec_A = norm.linear_QP_reg_l_1( Q, c ).solve() A = mat( vec_A, m, n ) t = np.mean(np.abs(vec_A)) for i in range(m): for j in range(n): if abs(A[i,j]) < t: A[i,j] = 0 self.A = sparse(A)
def __init__(self,A, λ = 0.1): m = A.shape[0] n = A.shape[1] x = norm.linear_l_p_reg_q( np.kron(eye(n),A.T), vec(eye(n)), λ, 2, 1).solve() mu = np.mean(x) for i in range(len(x)): if abs(x[i]) < mu: x[i]=0 self.pinv_A = mat(x,n,m) self.spinv_A = sparse(self.pinv_A)
def __init__(self,s): """ x ∈ R^n """ s = sampled_convex_set.remove_interior_points(s) n = s.shape[0] m = s.shape[1] A_ub = np.bmat([[zeros(m,n),-eye(m)],[zeros(m,n),eye(m)]]) b_ub = np.bmat([[zeros(m)],[ones(m)]]) A_eq = np.bmat([[-eye(n),s],[zeros(1,n),ones(1,m)]]) b_eq = np.bmat([[zeros(n)],[ones(1)]]) self.P = poly(A_ub,b_ub,A_eq,b_eq)
def __init__(self, P1, P2, q): n = P1.n assert P2.n is n A = np.bmat([[eye(n),-eye(n)]]) b = zeros(n,1) P = poly.diag(P1,P2) if q is 1: self.problem = norm.linear_l_1(A,b,P) elif q is 2: self.problem = norm.linear_l_2(A,b,P) elif q is 'inf': self.problem = norm.linear_l_inf(A,b,P) else: assert False, "q must be 1, 2, or \'inf\'" self.P1 = P1 self.P2 = P2 self.P = P self.n = n self.q = q self.sol = None
def full_rank_right_pseudo_inverse(self, A, b): """ min J = f( A x - b ) 🠊 min J = f( A y ) x ∈ R^n y ∈ R^n s.t. x ∈ POLYHEDRON_self s.t. y ∈ POLYHEDRON_out y + A^+ b ∈ POLYHEDRON_self 🠊 y ∈ POLYHEDRON_out """ m = A.shape[0] n = A.shape[1] if is_full_rank(A) and min(m, n) is m: return self.affine_transform(eye(n), pinv(A) * b) else: print("warning: full_rank_right_pseudo_inverse") return None
def init_E(EA, Ex, Eb, EAx, EAoA, EAox, EAoAx, EAob, W, m ,n): if W is None: M = eye(m) else: M = W.T * W if EA is None: EA = zeros(m,n) if Ex is None: Ex = zeros(n,1) if Eb is None: Eb = zeros(m,1) if EAx is None: EAx = zeros(m,1) if EAoA is None: EAoA = zeros(m*m,n*n) if EAox is None: EAox = zeros(m*n,n*1) if EAoAx is None: EAoAx = zeros(m*m,n*1) if EAob is None: EAob = zeros(m*m,n*1) return (EA, Ex, Eb, EAx, EAoA, EAox, EAoAx, EAob, M)
def dz_j_dvec_A_j(self, j): return self.Ds(self.A[j]*self.z[j-1]-self.b[j])\ * np.kron( eye(self.m[j]), self.z[j-1].T )
def test(): P1 = poly.rand(2,4,0,1).affine_transform(eye(2),2*ones(2,1)) P2 = poly.rand(2,4,0,1).affine_transform(eye(2),-2*ones(2,1)) problem = interset(P1,P2,2) problem.solve() print(problem)