It is represented typically by either `\mathcal{D}^{n}` or
`\mathcal{DNN}`.
-
"""
-from sage.all import *
-
-from mjo.cone.symmetric_psd import (factor_psd,
- random_symmetric_psd)
-from mjo.basis_repr import basis_repr
-
-
def is_doubly_nonnegative(A):
"""
Determine whether or not the matrix ``A`` is doubly-nonnegative.
False
"""
+ from sage.symbolic.ring import SR
if A.base_ring() == SR:
msg = 'The matrix ``A`` cannot be the symbolic.'
# something unexpected.
raise ValueError('The matrix ``A`` must be symmetric.')
- r = rank(A)
+ from sage.rings.all import ZZ
+ r = A.rank()
n = ZZ(A.nrows()) # Columns would work, too, since ``A`` is symmetric.
return is_admissible_extreme_rank(r,n)
sage: A = A.change_ring(QQ)
sage: is_extreme_doubly_nonnegative(A)
True
- sage: v = vector(map(abs, random_vector(ZZ, 10)))
+ sage: v = vector(map(abs, random_vector(ZZ, 8)))
sage: A = v.column() * v.row()
sage: A = A.change_ring(QQ)
- sage: is_extreme_doubly_nonnegative(A)
+ sage: is_extreme_doubly_nonnegative(A) # long time
True
The following matrix is completely positive but has rank 3, so by a
False
"""
+ from sage.modules.free_module import VectorSpace
+ from sage.symbolic.ring import SR
if not A.base_ring().is_exact() and not A.base_ring() is SR:
msg = 'The base ring of ``A`` must be either exact or symbolic.'
return False
# Step 2
+ from mjo.cone.symmetric_psd import factor_psd
X = factor_psd(A)
# Step 3
# can't compute the dimension of a set of matrices anyway, so we
# convert them all to vectors and just ask for the dimension of the
# resulting vector space.
+ from mjo.basis_repr import basis_repr
(phi, phi_inverse) = basis_repr(A.matrix_space())
vectors = map(phi,spanning_set)
- V = span(vectors, A.base_ring())
- d = V.dimension()
+ V = VectorSpace(A.base_ring(), A.nrows()*A.ncols())
+ d = V.span(vectors).dimension()
# Needed to safely divide by two here (we don't want integer
# division). We ensured that the base ring of ``A`` is a field
# Generate random symmetric positive-semidefinite matrices until
# one of them is nonnegative, then return that.
+ from mjo.cone.symmetric_psd import random_symmetric_psd
A = random_symmetric_psd(V, accept_zero, rank)
while not all( x >= 0 for x in A.list() ):