]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/cone.py
3 def is_lyapunov_like(L
,K
):
5 Determine whether or not ``L`` is Lyapunov-like on ``K``.
7 We say that ``L`` is Lyapunov-like on ``K`` if `\left\langle
8 L\left\lparenx\right\rparen,s\right\rangle = 0` for all pairs
9 `\left\langle x,s \right\rangle` in the complementarity set of
10 ``K``. It is known [Orlitzky]_ that this property need only be
11 checked for generators of ``K`` and its dual.
15 - ``L`` -- A linear transformation or matrix.
17 - ``K`` -- A polyhedral closed convex cone.
21 ``True`` if it can be proven that ``L`` is Lyapunov-like on ``K``,
22 and ``False`` otherwise.
26 If this function returns ``True``, then ``L`` is Lyapunov-like
27 on ``K``. However, if ``False`` is returned, that could mean one
28 of two things. The first is that ``L`` is definitely not
29 Lyapunov-like on ``K``. The second is more of an "I don't know"
30 answer, returned (for example) if we cannot prove that an inner
35 M. Orlitzky. The Lyapunov rank of an improper cone.
36 http://www.optimization-online.org/DB_HTML/2015/10/5135.html
40 The identity is always Lyapunov-like in a nontrivial space::
42 sage: set_random_seed()
43 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
44 sage: L = identity_matrix(K.lattice_dim())
45 sage: is_lyapunov_like(L,K)
48 As is the "zero" transformation::
50 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
51 sage: R = K.lattice().vector_space().base_ring()
52 sage: L = zero_matrix(R, K.lattice_dim())
53 sage: is_lyapunov_like(L,K)
56 Everything in ``K.lyapunov_like_basis()`` should be Lyapunov-like
59 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
60 sage: all([ is_lyapunov_like(L,K) for L in K.lyapunov_like_basis() ])
64 return all([(L
*x
).inner_product(s
) == 0
65 for (x
,s
) in K
.discrete_complementarity_set()])
68 def motzkin_decomposition(K
):
70 Return the pair of components in the motzkin decomposition of this cone.
72 Every convex cone is the direct sum of a strictly convex cone and a
73 linear subspace. Return a pair ``(P,S)`` of cones such that ``P`` is
74 strictly convex, ``S`` is a subspace, and ``K`` is the direct sum of
79 An ordered pair ``(P,S)`` of closed convex polyhedral cones where
80 ``P`` is strictly convex, ``S`` is a subspace, and ``K`` is the
81 direct sum of ``P`` and ``S``.
85 The nonnegative orthant is strictly convex, so it is its own
86 strictly convex component and its subspace component is trivial::
88 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
89 sage: (P,S) = motzkin_decomposition(K)
90 sage: K.is_equivalent(P)
95 Likewise, full spaces are their own subspace components::
97 sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)])
98 sage: K.is_full_space()
100 sage: (P,S) = motzkin_decomposition(K)
101 sage: K.is_equivalent(S)
108 A random point in the cone should belong to either the strictly
109 convex component or the subspace component. If the point is nonzero,
110 it cannot be in both::
112 sage: set_random_seed()
113 sage: K = random_cone(max_ambient_dim=8)
114 sage: (P,S) = motzkin_decomposition(K)
115 sage: x = K.random_element()
116 sage: P.contains(x) or S.contains(x)
118 sage: x.is_zero() or (P.contains(x) != S.contains(x))
121 The strictly convex component should always be strictly convex, and
122 the subspace component should always be a subspace::
124 sage: set_random_seed()
125 sage: K = random_cone(max_ambient_dim=8)
126 sage: (P,S) = motzkin_decomposition(K)
127 sage: P.is_strictly_convex()
129 sage: S.lineality() == S.dim()
132 The generators of the strictly convex component are obtained from
133 the orthogonal projections of the original generators onto the
134 orthogonal complement of the subspace component::
136 sage: set_random_seed()
137 sage: K = random_cone(max_ambient_dim=8)
138 sage: (P,S) = motzkin_decomposition(K)
139 sage: S_perp = S.linear_subspace().complement()
140 sage: A = S_perp.matrix().transpose()
141 sage: proj = A * (A.transpose()*A).inverse() * A.transpose()
142 sage: expected = Cone([ proj*g for g in K ], K.lattice())
143 sage: P.is_equivalent(expected)
146 linspace_gens
= [ copy(b
) for b
in K
.linear_subspace().basis() ]
147 linspace_gens
+= [ -b
for b
in linspace_gens
]
149 S
= Cone(linspace_gens
, K
.lattice())
151 # Since ``S`` is a subspace, its dual is its orthogonal complement
152 # (albeit in the wrong lattice).
153 S_perp
= Cone(S
.dual(), K
.lattice())
154 P
= K
.intersection(S_perp
)
158 def positive_operator_gens(K
):
160 Compute generators of the cone of positive operators on this cone.
164 A list of `n`-by-``n`` matrices where ``n == K.lattice_dim()``.
165 Each matrix ``P`` in the list should have the property that ``P*x``
166 is an element of ``K`` whenever ``x`` is an element of
167 ``K``. Moreover, any nonnegative linear combination of these
168 matrices shares the same property.
172 The trivial cone in a trivial space has no positive operators::
174 sage: K = Cone([], ToricLattice(0))
175 sage: positive_operator_gens(K)
178 Positive operators on the nonnegative orthant are nonnegative matrices::
180 sage: K = Cone([(1,)])
181 sage: positive_operator_gens(K)
184 sage: K = Cone([(1,0),(0,1)])
185 sage: positive_operator_gens(K)
187 [1 0] [0 1] [0 0] [0 0]
188 [0 0], [0 0], [1 0], [0 1]
191 Every operator is positive on the ambient vector space::
193 sage: K = Cone([(1,),(-1,)])
194 sage: K.is_full_space()
196 sage: positive_operator_gens(K)
199 sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)])
200 sage: K.is_full_space()
202 sage: positive_operator_gens(K)
204 [1 0] [-1 0] [0 1] [ 0 -1] [0 0] [ 0 0] [0 0] [ 0 0]
205 [0 0], [ 0 0], [0 0], [ 0 0], [1 0], [-1 0], [0 1], [ 0 -1]
210 A positive operator on a cone should send its generators into the cone::
212 sage: set_random_seed()
213 sage: K = random_cone(max_ambient_dim=5)
214 sage: pi_of_K = positive_operator_gens(K)
215 sage: all([K.contains(p*x) for p in pi_of_K for x in K.rays()])
218 The dimension of the cone of positive operators is given by the
219 corollary in my paper::
221 sage: set_random_seed()
222 sage: K = random_cone(max_ambient_dim=5)
223 sage: n = K.lattice_dim()
225 sage: l = K.lineality()
226 sage: pi_of_K = positive_operator_gens(K)
227 sage: L = ToricLattice(n**2)
228 sage: actual = Cone([p.list() for p in pi_of_K], lattice=L).dim()
229 sage: expected = n**2 - l*(m - l) - (n - m)*m
230 sage: actual == expected
233 The lineality of the cone of positive operators is given by the
234 corollary in my paper::
236 sage: set_random_seed()
237 sage: K = random_cone(max_ambient_dim=5)
238 sage: n = K.lattice_dim()
239 sage: pi_of_K = positive_operator_gens(K)
240 sage: L = ToricLattice(n**2)
241 sage: actual = Cone([p.list() for p in pi_of_K], lattice=L).lineality()
242 sage: expected = n**2 - K.dim()*K.dual().dim()
243 sage: actual == expected
246 The cone ``K`` is proper if and only if the cone of positive
247 operators on ``K`` is proper::
249 sage: set_random_seed()
250 sage: K = random_cone(max_ambient_dim=5)
251 sage: pi_of_K = positive_operator_gens(K)
252 sage: L = ToricLattice(K.lattice_dim()**2)
253 sage: pi_cone = Cone([p.list() for p in pi_of_K], lattice=L)
254 sage: K.is_proper() == pi_cone.is_proper()
257 # Matrices are not vectors in Sage, so we have to convert them
258 # to vectors explicitly before we can find a basis. We need these
259 # two values to construct the appropriate "long vector" space.
260 F
= K
.lattice().base_field()
263 tensor_products
= [ s
.tensor_product(x
) for x
in K
for s
in K
.dual() ]
265 # Convert those tensor products to long vectors.
266 W
= VectorSpace(F
, n
**2)
267 vectors
= [ W(tp
.list()) for tp
in tensor_products
]
269 # Create the *dual* cone of the positive operators, expressed as
271 pi_dual
= Cone(vectors
, ToricLattice(W
.dimension()))
273 # Now compute the desired cone from its dual...
274 pi_cone
= pi_dual
.dual()
276 # And finally convert its rays back to matrix representations.
277 M
= MatrixSpace(F
, n
)
278 return [ M(v
.list()) for v
in pi_cone
.rays() ]
281 def Z_transformation_gens(K
):
283 Compute generators of the cone of Z-transformations on this cone.
287 A list of `n`-by-``n`` matrices where ``n == K.lattice_dim()``.
288 Each matrix ``L`` in the list should have the property that
289 ``(L*x).inner_product(s) <= 0`` whenever ``(x,s)`` is an element the
290 discrete complementarity set of ``K``. Moreover, any nonnegative
291 linear combination of these matrices shares the same property.
295 Z-transformations on the nonnegative orthant are just Z-matrices.
296 That is, matrices whose off-diagonal elements are nonnegative::
298 sage: K = Cone([(1,0),(0,1)])
299 sage: Z_transformation_gens(K)
301 [ 0 -1] [ 0 0] [-1 0] [1 0] [ 0 0] [0 0]
302 [ 0 0], [-1 0], [ 0 0], [0 0], [ 0 -1], [0 1]
304 sage: K = Cone([(1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)])
305 sage: all([ z[i][j] <= 0 for z in Z_transformation_gens(K)
306 ....: for i in range(z.nrows())
307 ....: for j in range(z.ncols())
311 The trivial cone in a trivial space has no Z-transformations::
313 sage: K = Cone([], ToricLattice(0))
314 sage: Z_transformation_gens(K)
317 Z-transformations on a subspace are Lyapunov-like and vice-versa::
319 sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)])
320 sage: K.is_full_space()
322 sage: lls = span([ vector(l.list()) for l in K.lyapunov_like_basis() ])
323 sage: zs = span([ vector(z.list()) for z in Z_transformation_gens(K) ])
329 The Z-property is possessed by every Z-transformation::
331 sage: set_random_seed()
332 sage: K = random_cone(max_ambient_dim=6)
333 sage: Z_of_K = Z_transformation_gens(K)
334 sage: dcs = K.discrete_complementarity_set()
335 sage: all([(z*x).inner_product(s) <= 0 for z in Z_of_K
336 ....: for (x,s) in dcs])
339 The lineality space of Z is LL::
341 sage: set_random_seed()
342 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
343 sage: lls = span([ vector(l.list()) for l in K.lyapunov_like_basis() ])
344 sage: z_cone = Cone([ z.list() for z in Z_transformation_gens(K) ])
345 sage: z_cone.linear_subspace() == lls
348 And thus, the lineality of Z is the Lyapunov rank::
350 sage: set_random_seed()
351 sage: K = random_cone(max_ambient_dim=6)
352 sage: Z_of_K = Z_transformation_gens(K)
353 sage: L = ToricLattice(K.lattice_dim()**2)
354 sage: z_cone = Cone([ z.list() for z in Z_of_K ], lattice=L)
355 sage: z_cone.lineality() == K.lyapunov_rank()
358 The lineality spaces of pi-star and Z-star are equal:
360 sage: set_random_seed()
361 sage: K = random_cone(max_ambient_dim=5)
362 sage: pi_of_K = positive_operator_gens(K)
363 sage: Z_of_K = Z_transformation_gens(K)
364 sage: L = ToricLattice(K.lattice_dim()**2)
365 sage: pi_star = Cone([p.list() for p in pi_of_K], lattice=L).dual()
366 sage: z_star = Cone([ z.list() for z in Z_of_K], lattice=L).dual()
367 sage: pi_star.linear_subspace() == z_star.linear_subspace()
370 # Matrices are not vectors in Sage, so we have to convert them
371 # to vectors explicitly before we can find a basis. We need these
372 # two values to construct the appropriate "long vector" space.
373 F
= K
.lattice().base_field()
376 # These tensor products contain generators for the dual cone of
377 # the cross-positive transformations.
378 tensor_products
= [ s
.tensor_product(x
)
379 for (x
,s
) in K
.discrete_complementarity_set() ]
381 # Turn our matrices into long vectors...
382 W
= VectorSpace(F
, n
**2)
383 vectors
= [ W(m
.list()) for m
in tensor_products
]
385 # Create the *dual* cone of the cross-positive operators,
386 # expressed as long vectors..
387 Sigma_dual
= Cone(vectors
, lattice
=ToricLattice(W
.dimension()))
389 # Now compute the desired cone from its dual...
390 Sigma_cone
= Sigma_dual
.dual()
392 # And finally convert its rays back to matrix representations.
393 # But first, make them negative, so we get Z-transformations and
394 # not cross-positive ones.
395 M
= MatrixSpace(F
, n
)
396 return [ -M(v
.list()) for v
in Sigma_cone
.rays() ]
400 gens
= Z_transformation_gens(K
)
404 return Cone([ g
.list() for g
in gens
], lattice
=L
)
407 gens
= positive_operator_gens(K
)
411 return Cone([ g
.list() for g
in gens
], lattice
=L
)