def __format(self): """Internal version of format with cached results. Returns ------- tuple (equality constraints, inequality constraints) """ upper_tri = lu.upper_tri(self.A) lower_tri = lu.upper_tri(lu.transpose(self.A)) eq_constr = lu.create_eq(upper_tri, lower_tri) leq_constr = lu.create_geq(self.A) return ([eq_constr], [leq_constr])
def graph_implementation(arg_objs, size, data=None): """Vectorized strictly upper triagonal entries. Parameters ---------- arg_objs : list LinExpr for each argument. size : tuple The size of the resulting expression. data : Additional data required by the atom. Returns ------- tuple (LinOp for objective, list of constraints) """ return (lu.upper_tri(arg_objs[0]), [])
def graph_implementation(arg_objs, size, data=None): """Reduces the atom to an affine expression and list of constraints. Creates the equivalent problem:: maximize sum(log(D[i, i])) subject to: D diagonal diag(D) = diag(Z) Z is upper triangular. [D Z; Z.T A] is positive semidefinite The problem computes the LDL factorization: .. math:: A = (Z^TD^{-1})D(D^{-1}Z) This follows from the inequality: .. math:: \det(A) >= \det(D) + \det([D, Z; Z^T, A])/\det(D) >= \det(D) because (Z^TD^{-1})D(D^{-1}Z) is a feasible D, Z that achieves det(A) = det(D) and the objective maximizes det(D). Parameters ---------- arg_objs : list LinExpr for each argument. size : tuple The size of the resulting expression. data : Additional data required by the atom. Returns ------- tuple (LinOp for objective, list of constraints) """ A = arg_objs[0] # n by n matrix. n, _ = A.size X = lu.create_var((2 * n, 2 * n)) X, constraints = Semidef(2 * n).canonical_form Z = lu.create_var((n, n)) D = lu.create_var((n, 1)) # Require that X and A are PSD. constraints += [SDP(A)] # Fix Z as upper triangular, D as diagonal, # and diag(D) as diag(Z). Z_lower_tri = lu.upper_tri(lu.transpose(Z)) constraints.append(lu.create_eq(Z_lower_tri)) # D[i, i] = Z[i, i] constraints.append(lu.create_eq(D, lu.diag_mat(Z))) # Fix X using the fact that A must be affine by the DCP rules. # X[0:n, 0:n] == D index.block_eq(X, lu.diag_vec(D), constraints, 0, n, 0, n) # X[0:n, n:2*n] == Z, index.block_eq(X, Z, constraints, 0, n, n, 2 * n) # X[n:2*n, n:2*n] == A index.block_eq(X, A, constraints, n, 2 * n, n, 2 * n) # Add the objective sum(log(D[i, i]) obj, constr = log.graph_implementation([D], (n, 1)) return (lu.sum_entries(obj), constraints + constr)
def _get_eq_constr(self): """Returns the equality constraints for the SDP constraint. """ upper_tri = lu.upper_tri(self.A) lower_tri = lu.upper_tri(lu.transpose(self.A)) return lu.create_eq(upper_tri, lower_tri)
def graph_implementation(arg_objs, size, data=None): """Reduces the atom to an affine expression and list of constraints. Creates the equivalent problem:: maximize sum(log(D[i, i])) subject to: D diagonal diag(D) = diag(Z) Z is upper triangular. [D Z; Z.T A] is positive semidefinite The problem computes the LDL factorization: .. math:: A = (Z^TD^{-1})D(D^{-1}Z) This follows from the inequality: .. math:: \det(A) >= \det(D) + \det([D, Z; Z^T, A])/\det(D) >= \det(D) because (Z^TD^{-1})D(D^{-1}Z) is a feasible D, Z that achieves det(A) = det(D) and the objective maximizes det(D). Parameters ---------- arg_objs : list LinExpr for each argument. size : tuple The size of the resulting expression. data : Additional data required by the atom. Returns ------- tuple (LinOp for objective, list of constraints) """ A = arg_objs[0] # n by n matrix. n, _ = A.size X = lu.create_var((2*n, 2*n)) Z = lu.create_var((n, n)) D = lu.create_var((n, 1)) # Require that X and A are PSD. constraints = [SDP(X), SDP(A)] # Fix Z as upper triangular, D as diagonal, # and diag(D) as diag(Z). Z_lower_tri = lu.upper_tri(lu.transpose(Z)) constraints.append(lu.create_eq(Z_lower_tri)) # D[i, i] = Z[i, i] constraints.append(lu.create_eq(D, lu.diag_mat(Z))) # Fix X using the fact that A must be affine by the DCP rules. # X[0:n, 0:n] == D index.block_eq(X, lu.diag_vec(D), constraints, 0, n, 0, n) # X[0:n, n:2*n] == Z, index.block_eq(X, Z, constraints, 0, n, n, 2*n) # X[n:2*n, n:2*n] == A index.block_eq(X, A, constraints, n, 2*n, n, 2*n) # Add the objective sum(log(D[i, i]) obj, constr = log.graph_implementation([D], (n, 1)) return (lu.sum_entries(obj), constraints + constr)