0
|
1 |
#!/usr/bin/python
|
|
2 |
|
|
3 |
import pylab as pl
|
|
4 |
from makezero import makezero
|
|
5 |
|
|
6 |
def cindep(S, gap=None):
|
|
7 |
E = pl.finfo(float).eps
|
|
8 |
|
|
9 |
if gap == None:
|
|
10 |
gap = 1e8
|
|
11 |
|
|
12 |
r, c = pl.atleast_2d(S).shape
|
|
13 |
|
|
14 |
if r>c:
|
|
15 |
ind = 0
|
|
16 |
else:
|
|
17 |
sigma = pl.svd(S)[1]
|
|
18 |
l = len(sigma)
|
|
19 |
if(sigma[-1]/sigma[0] < (E*max(1, c))):
|
|
20 |
ind = 0
|
|
21 |
else:
|
|
22 |
if pl.any(sigma[:-1]/sigma[1:] >= gap):
|
|
23 |
ind = 0
|
|
24 |
else:
|
|
25 |
ind = 1
|
|
26 |
if ind:
|
|
27 |
b = pl.array([])
|
|
28 |
|
|
29 |
else:
|
|
30 |
A, B = S[r-1,:], S[:r-1,:]
|
|
31 |
b = pl.lstsq(B.T, A.T)[0].T
|
|
32 |
b = makezero(b, gap)
|
|
33 |
b = b.squeeze()
|
|
34 |
return pl.atleast_2d(b)
|
|
35 |
|
|
36 |
if __name__== "__main__":
|
|
37 |
pass
|