equal
deleted
inserted
replaced
|
1 #!/usr/bin/python |
|
2 # Determines the first row that is dependent on the previous rows of S. |
|
3 # Returns the coefficients of dependence |
|
4 |
|
5 import pylab as pl |
|
6 from makezero import makezero |
|
7 |
|
8 def indep(S, gap=1e8): |
|
9 S = pl.atleast_2d(S) |
|
10 E = pl.finfo(float).eps |
|
11 r, c = S.shape |
|
12 ind = 1 |
|
13 i = 2 |
|
14 while ind and i<=r: |
|
15 shortS = S[:i,:] |
|
16 sigma = pl.svd(pl.dot(shortS,shortS.T))[1] |
|
17 if(sigma[-1]/sigma[0] < (E*max(i, c))): |
|
18 ind = 0 |
|
19 else: |
|
20 shsig = sigma.copy() |
|
21 shsig[:-1] = sigma[1:] |
|
22 if pl.any(sigma/shsig > gap): |
|
23 ind = 0 |
|
24 else: |
|
25 ind = 1 |
|
26 i += 1 |
|
27 if ind: |
|
28 b = pl.atleast_2d([]) |
|
29 |
|
30 else: |
|
31 A, B = S[i-1,:], S[:i-1,:] |
|
32 # c = A/B, |
|
33 # c = (B.T\A.T).T |
|
34 c = pl.lstsq(B.T, A.T)[0].T |
|
35 # c = pl.solve(B.T, A.T).T |
|
36 c = makezero(c, gap) |
|
37 c = c.squeeze() |
|
38 b = pl.hstack((-c, 1)) |
|
39 b = pl.atleast_2d(b) |
|
40 return b |
|
41 |
|
42 if __name__== "__main__": |
|
43 pass |