]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/completely_positive.py
2 The completely positive cone `$\mathcal{K}$` over `\mathbb{R}^{n}$` is
3 the set of all matrices `$A$`of the form `$\sum uu^{T}$` for `$u \in
4 \mathbb{R}^{n}_{+}$`. Equivalently, `$A = XX{T}$` where all entries of
8 # Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
9 # have to explicitly mangle our sitedir here so that "mjo.cone"
11 from os
.path
import abspath
12 from site
import addsitedir
13 addsitedir(abspath('../../'))
14 from mjo
.cone
.symmetric_psd
import factor_psd
, is_symmetric_psd
17 def is_completely_positive(A
):
19 Determine whether or not the matrix ``A`` is completely positive.
23 - ``A`` - The matrix in question
27 Either ``True`` if ``A`` is completely positive, or ``False``
32 Generate an extreme completely positive matrix and check that we
33 identify it correctly::
35 sage: v = vector(map(abs, random_vector(ZZ, 10)))
36 sage: A = v.column() * v.row()
37 sage: A = A.change_ring(QQ)
38 sage: is_completely_positive(A)
41 The following matrix isn't positive semidefinite, so it can't be
44 sage: A = matrix(QQ, [[1, 2], [2, 1]])
45 sage: is_completely_positive(A)
48 This matrix isn't even symmetric, so it can't be completely
51 sage: A = matrix(QQ, [[1, 2], [3, 4]])
52 sage: is_completely_positive(A)
57 if A
.base_ring() == SR
:
58 msg
= 'The matrix ``A`` cannot be the symbolic.'
59 raise ValueError.new(msg
)
61 if not is_symmetric_psd(A
):
64 # Would crash if we hadn't ensured that ``A`` was symmetric
65 # positive-semidefinite.