@@ -0,0 +1,65 | |||||
|
1 | ''' | |||
|
No newline at end of file | ||||
|
2 | Created on May 26, 2014 | |||
|
No newline at end of file | ||||
|
3 | ||||
|
No newline at end of file | ||||
|
4 | @author: Yolian Amaro | |||
|
No newline at end of file | ||||
|
5 | ''' | |||
|
No newline at end of file | ||||
|
6 | ||||
|
No newline at end of file | ||||
|
7 | import pywt | |||
|
No newline at end of file | ||||
|
8 | import numpy as np | |||
|
No newline at end of file | ||||
|
9 | ||||
|
No newline at end of file | ||||
|
10 | def FSfarras(): | |||
|
No newline at end of file | ||||
|
11 | #function [af, sf] = FSfarras | |||
|
No newline at end of file | ||||
|
12 | ||||
|
No newline at end of file | ||||
|
13 | # Farras filters organized for the dual-tree | |||
|
No newline at end of file | ||||
|
14 | # complex DWT. | |||
|
No newline at end of file | ||||
|
15 | # | |||
|
No newline at end of file | ||||
|
16 | # USAGE: | |||
|
No newline at end of file | ||||
|
17 | # [af, sf] = FSfarras | |||
|
No newline at end of file | ||||
|
18 | # OUTPUT: | |||
|
No newline at end of file | ||||
|
19 | # af{i}, i = 1,2 - analysis filters for tree i | |||
|
No newline at end of file | ||||
|
20 | # sf{i}, i = 1,2 - synthesis filters for tree i | |||
|
No newline at end of file | ||||
|
21 | # See farras, dualtree, dualfilt1. | |||
|
No newline at end of file | ||||
|
22 | # | |||
|
No newline at end of file | ||||
|
23 | # WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY | |||
|
No newline at end of file | ||||
|
24 | # http://taco.poly.edu/WaveletSoftware/ | |||
|
No newline at end of file | ||||
|
25 | # | |||
|
No newline at end of file | ||||
|
26 | # Translated to Python by Yolian Amaro | |||
|
No newline at end of file | ||||
|
27 | ||||
|
No newline at end of file | ||||
|
28 | ||||
|
No newline at end of file | ||||
|
29 | ||||
|
No newline at end of file | ||||
|
30 | a1 = np.array( [ | |||
|
No newline at end of file | ||||
|
31 | [ 0, 0], | |||
|
No newline at end of file | ||||
|
32 | [-0.08838834764832, -0.01122679215254], | |||
|
No newline at end of file | ||||
|
33 | [ 0.08838834764832, 0.01122679215254], | |||
|
No newline at end of file | ||||
|
34 | [ 0.69587998903400, 0.08838834764832], | |||
|
No newline at end of file | ||||
|
35 | [ 0.69587998903400, 0.08838834764832], | |||
|
No newline at end of file | ||||
|
36 | [ 0.08838834764832, -0.69587998903400], | |||
|
No newline at end of file | ||||
|
37 | [-0.08838834764832, 0.69587998903400], | |||
|
No newline at end of file | ||||
|
38 | [ 0.01122679215254, -0.08838834764832], | |||
|
No newline at end of file | ||||
|
39 | [ 0.01122679215254, -0.08838834764832], | |||
|
No newline at end of file | ||||
|
40 | [0, 0] | |||
|
No newline at end of file | ||||
|
41 | ] ); | |||
|
No newline at end of file | ||||
|
42 | ||||
|
No newline at end of file | ||||
|
43 | a2 = np.array([ | |||
|
No newline at end of file | ||||
|
44 | [ 0.01122679215254, 0], | |||
|
No newline at end of file | ||||
|
45 | [ 0.01122679215254, 0], | |||
|
No newline at end of file | ||||
|
46 | [-0.08838834764832, -0.08838834764832], | |||
|
No newline at end of file | ||||
|
47 | [ 0.08838834764832, -0.08838834764832], | |||
|
No newline at end of file | ||||
|
48 | [ 0.69587998903400, 0.69587998903400], | |||
|
No newline at end of file | ||||
|
49 | [ 0.69587998903400, -0.69587998903400], | |||
|
No newline at end of file | ||||
|
50 | [ 0.08838834764832, 0.08838834764832], | |||
|
No newline at end of file | ||||
|
51 | [-0.08838834764832, 0.08838834764832], | |||
|
No newline at end of file | ||||
|
52 | [ 0, 0.01122679215254], | |||
|
No newline at end of file | ||||
|
53 | [ 0, -0.01122679215254] | |||
|
No newline at end of file | ||||
|
54 | ]); | |||
|
No newline at end of file | ||||
|
55 | ||||
|
No newline at end of file | ||||
|
56 | #print a2.shape | |||
|
No newline at end of file | ||||
|
57 | ||||
|
No newline at end of file | ||||
|
58 | af = np.array([ [a1,a2] ], dtype=object) | |||
|
No newline at end of file | ||||
|
59 | ||||
|
No newline at end of file | ||||
|
60 | s1 = a1[::-1] | |||
|
No newline at end of file | ||||
|
61 | s2 = a2[::-1] | |||
|
No newline at end of file | ||||
|
62 | ||||
|
No newline at end of file | ||||
|
63 | sf = np.array([ [s1,s2] ], dtype=object) | |||
|
No newline at end of file | ||||
|
64 | ||||
|
No newline at end of file | ||||
|
65 | return af, sf No newline at end of file |
@@ -0,0 +1,38 | |||||
|
1 | ''' | |||
|
No newline at end of file | ||||
|
2 | Created on May 26, 2014 | |||
|
No newline at end of file | ||||
|
3 | ||||
|
No newline at end of file | ||||
|
4 | @author: Yolian Amaro | |||
|
No newline at end of file | ||||
|
5 | ''' | |||
|
No newline at end of file | ||||
|
6 | ||||
|
No newline at end of file | ||||
|
7 | import numpy as np | |||
|
No newline at end of file | ||||
|
8 | import FSfarras | |||
|
No newline at end of file | ||||
|
9 | import dualfilt1 | |||
|
No newline at end of file | ||||
|
10 | ||||
|
No newline at end of file | ||||
|
11 | def deb4_basis(N): | |||
|
No newline at end of file | ||||
|
12 | ||||
|
No newline at end of file | ||||
|
13 | Psi = np.zeros(shape=(N,2*N+1)); | |||
|
No newline at end of file | ||||
|
14 | idx = 1; | |||
|
No newline at end of file | ||||
|
15 | ||||
|
No newline at end of file | ||||
|
16 | J = 4; | |||
|
No newline at end of file | ||||
|
17 | [Faf, Fsf] = FSfarras; | |||
|
No newline at end of file | ||||
|
18 | [af, sf] = dualfilt1; | |||
|
No newline at end of file | ||||
|
19 | # # | |||
|
No newline at end of file | ||||
|
20 | # # # compute transform of zero vector | |||
|
No newline at end of file | ||||
|
21 | # # x = zeros(1,N); | |||
|
No newline at end of file | ||||
|
22 | # # w = dualtree(x, J, Faf, af); | |||
|
No newline at end of file | ||||
|
23 | # # | |||
|
No newline at end of file | ||||
|
24 | # # # Uses both real and imaginary wavelets | |||
|
No newline at end of file | ||||
|
25 | # # for i in range (1, J+1): | |||
|
No newline at end of file | ||||
|
26 | # # for j in range (1, 2): | |||
|
No newline at end of file | ||||
|
27 | # # for k in range (1, (w[i][j]).size): | |||
|
No newline at end of file | ||||
|
28 | # # w[i][j](k) = 1; | |||
|
No newline at end of file | ||||
|
29 | # # y = idualtree(w, J, Fsf, sf); | |||
|
No newline at end of file | ||||
|
30 | # # w[i][j](k) = 0; | |||
|
No newline at end of file | ||||
|
31 | # # # store it | |||
|
No newline at end of file | ||||
|
32 | # # Psi(:,idx) = y.T.conj(); | |||
|
No newline at end of file | ||||
|
33 | # # idx = idx + 1; | |||
|
No newline at end of file | ||||
|
34 | # # | |||
|
No newline at end of file | ||||
|
35 | # # # Add uniform vector (seems to be useful if there's a background | |||
|
No newline at end of file | ||||
|
36 | # # Psi(:,2*N+1) = 1/np.sqrt(N); | |||
|
No newline at end of file | ||||
|
37 | # | |||
|
No newline at end of file | ||||
|
38 | # return Psi No newline at end of file |
@@ -0,0 +1,65 | |||||
|
1 | ''' | |||
|
No newline at end of file | ||||
|
2 | Created on May 29, 2014 | |||
|
No newline at end of file | ||||
|
3 | ||||
|
No newline at end of file | ||||
|
4 | @author: Yolian Amaro | |||
|
No newline at end of file | ||||
|
5 | ''' | |||
|
No newline at end of file | ||||
|
6 | ||||
|
No newline at end of file | ||||
|
7 | import numpy as np | |||
|
No newline at end of file | ||||
|
8 | ||||
|
No newline at end of file | ||||
|
9 | def dualfilt1(): | |||
|
No newline at end of file | ||||
|
10 | ||||
|
No newline at end of file | ||||
|
11 | # Kingsbury Q-filters for the dual-tree complex DWT | |||
|
No newline at end of file | ||||
|
12 | # | |||
|
No newline at end of file | ||||
|
13 | # USAGE: | |||
|
No newline at end of file | ||||
|
14 | # [af, sf] = dualfilt1 | |||
|
No newline at end of file | ||||
|
15 | # OUTPUT: | |||
|
No newline at end of file | ||||
|
16 | # af{i}, i = 1,2 - analysis filters for tree i | |||
|
No newline at end of file | ||||
|
17 | # sf{i}, i = 1,2 - synthesis filters for tree i | |||
|
No newline at end of file | ||||
|
18 | # note: af{2} is the reverse of af{1} | |||
|
No newline at end of file | ||||
|
19 | # REFERENCE: | |||
|
No newline at end of file | ||||
|
20 | # N. G. Kingsbury, "A dual-tree complex wavelet | |||
|
No newline at end of file | ||||
|
21 | # transform with improved orthogonality and symmetry | |||
|
No newline at end of file | ||||
|
22 | # properties", Proceedings of the IEEE Int. Conf. on | |||
|
No newline at end of file | ||||
|
23 | # Image Proc. (ICIP), 2000 | |||
|
No newline at end of file | ||||
|
24 | # See dualtree | |||
|
No newline at end of file | ||||
|
25 | # | |||
|
No newline at end of file | ||||
|
26 | # WAVELET SOFTWARE AT POLYTECHNIC UNIVERSITY, BROOKLYN, NY | |||
|
No newline at end of file | ||||
|
27 | # http://taco.poly.edu/WaveletSoftware/ | |||
|
No newline at end of file | ||||
|
28 | ||||
|
No newline at end of file | ||||
|
29 | # These cofficients are rounded to 8 decimal places. | |||
|
No newline at end of file | ||||
|
30 | ||||
|
No newline at end of file | ||||
|
31 | a1 = np.array([ | |||
|
No newline at end of file | ||||
|
32 | [ 0.03516384000000, 0], | |||
|
No newline at end of file | ||||
|
33 | [ 0, 0], | |||
|
No newline at end of file | ||||
|
34 | [-0.08832942000000, -0.11430184000000], | |||
|
No newline at end of file | ||||
|
35 | [ 0.23389032000000, 0], | |||
|
No newline at end of file | ||||
|
36 | [ 0.76027237000000, 0.58751830000000], | |||
|
No newline at end of file | ||||
|
37 | [ 0.58751830000000, -0.76027237000000], | |||
|
No newline at end of file | ||||
|
38 | [ 0, 0.23389032000000], | |||
|
No newline at end of file | ||||
|
39 | [-0.11430184000000, 0.08832942000000], | |||
|
No newline at end of file | ||||
|
40 | [ 0, 0], | |||
|
No newline at end of file | ||||
|
41 | [ 0, -0.03516384000000] | |||
|
No newline at end of file | ||||
|
42 | ]); | |||
|
No newline at end of file | ||||
|
43 | ||||
|
No newline at end of file | ||||
|
44 | a2 = np.array([ | |||
|
No newline at end of file | ||||
|
45 | [ 0, -0.03516384000000], | |||
|
No newline at end of file | ||||
|
46 | [ 0, 0], | |||
|
No newline at end of file | ||||
|
47 | [-0.11430184000000, 0.08832942000000], | |||
|
No newline at end of file | ||||
|
48 | [ 0, 0.23389032000000], | |||
|
No newline at end of file | ||||
|
49 | [ 0.58751830000000, -0.76027237000000], | |||
|
No newline at end of file | ||||
|
50 | [ 0.76027237000000, 0.58751830000000], | |||
|
No newline at end of file | ||||
|
51 | [ 0.23389032000000, 0], | |||
|
No newline at end of file | ||||
|
52 | [ -0.08832942000000, -0.11430184000000], | |||
|
No newline at end of file | ||||
|
53 | [ 0, 0], | |||
|
No newline at end of file | ||||
|
54 | [ 0.03516384000000, 0] | |||
|
No newline at end of file | ||||
|
55 | ]); | |||
|
No newline at end of file | ||||
|
56 | ||||
|
No newline at end of file | ||||
|
57 | af = np.array([ [a1,a2] ], dtype=object) | |||
|
No newline at end of file | ||||
|
58 | ||||
|
No newline at end of file | ||||
|
59 | s1 = a1[::-1] | |||
|
No newline at end of file | ||||
|
60 | s2 = a2[::-1] | |||
|
No newline at end of file | ||||
|
61 | ||||
|
No newline at end of file | ||||
|
62 | sf = np.array([ [s1,s2] ], dtype=object) | |||
|
No newline at end of file | ||||
|
63 | ||||
|
No newline at end of file | ||||
|
64 | ||||
|
No newline at end of file | ||||
|
65 | return af, sf No newline at end of file |
@@ -0,0 +1,80 | |||||
|
1 | ''' | |||
|
No newline at end of file | ||||
|
2 | Created on May 27, 2014 | |||
|
No newline at end of file | ||||
|
3 | ||||
|
No newline at end of file | ||||
|
4 | @author: Yolian Amaro | |||
|
No newline at end of file | ||||
|
5 | ''' | |||
|
No newline at end of file | ||||
|
6 | ||||
|
No newline at end of file | ||||
|
7 | #from scipy.sparse import eye | |||
|
No newline at end of file | ||||
|
8 | from scipy import linalg | |||
|
No newline at end of file | ||||
|
9 | import scipy.sparse as sps | |||
|
No newline at end of file | ||||
|
10 | import numpy as np | |||
|
No newline at end of file | ||||
|
11 | ||||
|
No newline at end of file | ||||
|
12 | def irls_dn(A,b,p,lambda1): | |||
|
No newline at end of file | ||||
|
13 | ||||
|
No newline at end of file | ||||
|
14 | ||||
|
No newline at end of file | ||||
|
15 | # Minimize lambda*||u||_p + ||A*u-b||_2, 0 < p <= 1 | |||
|
No newline at end of file | ||||
|
16 | # using Iterative Reweighted Least Squares | |||
|
No newline at end of file | ||||
|
17 | # (see http://math.lanl.gov/Research/Publications/Docs/chartrand-2008-iteratively.pdf | |||
|
No newline at end of file | ||||
|
18 | # and http://web.eecs.umich.edu/~aey/sparse/sparse11.pdf) | |||
|
No newline at end of file | ||||
|
19 | ||||
|
No newline at end of file | ||||
|
20 | # Note to self: I found that "warm-starting" didn't really help too much. | |||
|
No newline at end of file | ||||
|
21 | ||||
|
No newline at end of file | ||||
|
22 | [M,N] = A.shape; | |||
|
No newline at end of file | ||||
|
23 | # Initialize and precompute: | |||
|
No newline at end of file | ||||
|
24 | eps = 1e-2; # damping parameter | |||
|
No newline at end of file | ||||
|
25 | [Q,R] = linalg.qr(A.T.conj(),0); | |||
|
No newline at end of file | ||||
|
26 | print A.shape | |||
|
No newline at end of file | ||||
|
27 | print R.shape | |||
|
No newline at end of file | ||||
|
28 | print b.shape | |||
|
No newline at end of file | ||||
|
29 | c = linalg.solve(R.T.conj(),b); # will be used later also | |||
|
No newline at end of file | ||||
|
30 | u = Q*c; # minimum 2-norm solution | |||
|
No newline at end of file | ||||
|
31 | I = sps.eye(M); | |||
|
No newline at end of file | ||||
|
32 | ||||
|
No newline at end of file | ||||
|
33 | # Spacing of floating point numbers | |||
|
No newline at end of file | ||||
|
34 | eps = np.spacing(1) | |||
|
No newline at end of file | ||||
|
35 | ||||
|
No newline at end of file | ||||
|
36 | # Loop until damping parameter is small enough | |||
|
No newline at end of file | ||||
|
37 | while (eps > 1e-7): | |||
|
No newline at end of file | ||||
|
38 | epschange = 0; | |||
|
No newline at end of file | ||||
|
39 | # Loop until it's time to change eps | |||
|
No newline at end of file | ||||
|
40 | while (~epschange): | |||
|
No newline at end of file | ||||
|
41 | # main loop | |||
|
No newline at end of file | ||||
|
42 | # u_n = W*A'*(A*W*A'+ lambda*I)^-1 * b | |||
|
No newline at end of file | ||||
|
43 | # where W = diag(1/w) | |||
|
No newline at end of file | ||||
|
44 | # where w = (u.^2 + eps).^(p/2-1) | |||
|
No newline at end of file | ||||
|
45 | ||||
|
No newline at end of file | ||||
|
46 | # Update | |||
|
No newline at end of file | ||||
|
47 | w = (u**2 + eps)**(1-p/2); | |||
|
No newline at end of file | ||||
|
48 | ||||
|
No newline at end of file | ||||
|
49 | # Empty temporary N x N matrix | |||
|
No newline at end of file | ||||
|
50 | temp = np.zeros(shape=(N,N)) | |||
|
No newline at end of file | ||||
|
51 | ||||
|
No newline at end of file | ||||
|
52 | # Sparse matrix | |||
|
No newline at end of file | ||||
|
53 | for i in range (1, N): | |||
|
No newline at end of file | ||||
|
54 | for j in range (1,N): | |||
|
No newline at end of file | ||||
|
55 | if(i==j): | |||
|
No newline at end of file | ||||
|
56 | temp[i,j] = w | |||
|
No newline at end of file | ||||
|
57 | ||||
|
No newline at end of file | ||||
|
58 | # Compressed Sparse Matrix | |||
|
No newline at end of file | ||||
|
59 | W = sps.csr_matrix(temp); #Compressed Sparse Row matrix | |||
|
No newline at end of file | ||||
|
60 | ||||
|
No newline at end of file | ||||
|
61 | ||||
|
No newline at end of file | ||||
|
62 | WAT = W*A.T.conj(); | |||
|
No newline at end of file | ||||
|
63 | u_new = WAT * ( linalg.solve (A*WAT + lambda1*I), b); | |||
|
No newline at end of file | ||||
|
64 | ||||
|
No newline at end of file | ||||
|
65 | # See if this subproblem is converging | |||
|
No newline at end of file | ||||
|
66 | delu = np.linalg.norm(u_new-u)/np.linalg.norm(u); | |||
|
No newline at end of file | ||||
|
67 | epschange = delu < (np.sqrt(eps)/100); | |||
|
No newline at end of file | ||||
|
68 | ||||
|
No newline at end of file | ||||
|
69 | # Make update | |||
|
No newline at end of file | ||||
|
70 | u = u_new; | |||
|
No newline at end of file | ||||
|
71 | ||||
|
No newline at end of file | ||||
|
72 | ||||
|
No newline at end of file | ||||
|
73 | eps = eps/10; # decrease eps | |||
|
No newline at end of file | ||||
|
74 | # Print info | |||
|
No newline at end of file | ||||
|
75 | print 'eps =',eps; | |||
|
No newline at end of file | ||||
|
76 | ||||
|
No newline at end of file | ||||
|
77 | return u | |||
|
No newline at end of file | ||||
|
78 | ||||
|
No newline at end of file | ||||
|
79 | ||||
|
No newline at end of file | ||||
|
80 | No newline at end of file |
@@ -0,0 +1,50 | |||||
|
1 | ''' | |||
|
No newline at end of file | ||||
|
2 | Created on May 27, 2014 | |||
|
No newline at end of file | ||||
|
3 | ||||
|
No newline at end of file | ||||
|
4 | @author: Yolian Amaro | |||
|
No newline at end of file | ||||
|
5 | ''' | |||
|
No newline at end of file | ||||
|
6 | ||||
|
No newline at end of file | ||||
|
7 | from irls_dn import * | |||
|
No newline at end of file | ||||
|
8 | ||||
|
No newline at end of file | ||||
|
9 | def irls_dn2(A,b,p,G): | |||
|
No newline at end of file | ||||
|
10 | ||||
|
No newline at end of file | ||||
|
11 | # Minimize ||u||_p subject to ||A*u-b||_2^2 <= G (0 < p <= 1) | |||
|
No newline at end of file | ||||
|
12 | ||||
|
No newline at end of file | ||||
|
13 | # What this function actually does is finds the lambda1 so that the solution | |||
|
No newline at end of file | ||||
|
14 | # to the following problem satisfies ||A*u-b||_2^2 <= G: | |||
|
No newline at end of file | ||||
|
15 | # Minimize lambda1*||u||_p + ||A*u-b||_2 | |||
|
No newline at end of file | ||||
|
16 | ||||
|
No newline at end of file | ||||
|
17 | # Start with a large lambda1, and do a line search until fidelity <= G. | |||
|
No newline at end of file | ||||
|
18 | # (Inversions with large lambda1 are really fast anyway). | |||
|
No newline at end of file | ||||
|
19 | ||||
|
No newline at end of file | ||||
|
20 | # Then spin up fzero to localize the root even better | |||
|
No newline at end of file | ||||
|
21 | ||||
|
No newline at end of file | ||||
|
22 | # Line Search | |||
|
No newline at end of file | ||||
|
23 | ||||
|
No newline at end of file | ||||
|
24 | alpha = 2; # Line search parameter | |||
|
No newline at end of file | ||||
|
25 | lambda1 = 1e5; # What's a reasonable but safe initial guess? | |||
|
No newline at end of file | ||||
|
26 | u = irls_dn(A,b,p,lambda1); | |||
|
No newline at end of file | ||||
|
27 | # fid = np.norm(A*u-b)^2; | |||
|
No newline at end of file | ||||
|
28 | # | |||
|
No newline at end of file | ||||
|
29 | # print '----------------------------------\n'; | |||
|
No newline at end of file | ||||
|
30 | # | |||
|
No newline at end of file | ||||
|
31 | # while (fid >= G) | |||
|
No newline at end of file | ||||
|
32 | # lambda1 = lambda1 / alpha; # Balance between speed and accuracy | |||
|
No newline at end of file | ||||
|
33 | # u = irls_dn(A,b,p,lambda1); | |||
|
No newline at end of file | ||||
|
34 | # fid = np.norm(A*u-b)^2; | |||
|
No newline at end of file | ||||
|
35 | # print 'lambda1 = #2e \t ||A*u-b||^2 = #.1f\n',lambda1,fid); | |||
|
No newline at end of file | ||||
|
36 | # | |||
|
No newline at end of file | ||||
|
37 | # # Refinement using fzero | |||
|
No newline at end of file | ||||
|
38 | # lambda10 = [lambda1 lambda1*alpha]; # interval with zero-crossing | |||
|
No newline at end of file | ||||
|
39 | # f = @(lambda1) np.norm(A*irls_dn(A,b,p,lambda1) - b)^2 - G; | |||
|
No newline at end of file | ||||
|
40 | # opts = optimset('fzero'); | |||
|
No newline at end of file | ||||
|
41 | # # opts.Display = 'iter'; | |||
|
No newline at end of file | ||||
|
42 | # opts.Display = 'none'; | |||
|
No newline at end of file | ||||
|
43 | # opts.TolX = 0.01*lambda1; | |||
|
No newline at end of file | ||||
|
44 | # lambda1 = fzero(f,lambda10,opts); | |||
|
No newline at end of file | ||||
|
45 | # | |||
|
No newline at end of file | ||||
|
46 | # u = irls_dn(A,b,p,lambda1); | |||
|
No newline at end of file | ||||
|
47 | # | |||
|
No newline at end of file | ||||
|
48 | # | |||
|
No newline at end of file | ||||
|
49 | # return u; | |||
|
No newline at end of file | ||||
|
50 | No newline at end of file |
@@ -1,430 +1,468 | |||||
1 | #!/usr/bin/env python No newline at end of file |
|
1 | #!/usr/bin/env python | |
2 | No newline at end of file |
|
2 | ||
3 | #---------------------------------------------------------- No newline at end of file |
|
3 | #---------------------------------------------------------- | |
4 | # Original MATLAB code developed by Brian Harding No newline at end of file |
|
4 | # Original MATLAB code developed by Brian Harding | |
5 | # Rewritten in python by Yolian Amaro No newline at end of file |
|
5 | # Rewritten in python by Yolian Amaro | |
6 | # Python version 2.7 No newline at end of file |
|
6 | # Python version 2.7 | |
7 | # May 15, 2014 No newline at end of file |
|
7 | # May 15, 2014 | |
8 | # Jicamarca Radio Observatory No newline at end of file |
|
8 | # Jicamarca Radio Observatory | |
9 | #---------------------------------------------------------- No newline at end of file |
|
9 | #---------------------------------------------------------- | |
10 | No newline at end of file |
|
10 | ||
11 | import math |
|
11 | import math | |
No newline at end of file |
|
||||
12 | #import cmath |
|
|||
No newline at end of file |
|
||||
13 | #import scipy |
|
|||
No newline at end of file |
|
||||
14 | #import matplotlib No newline at end of file |
|
|||
15 | import numpy as np |
|
12 | import numpy as np | |
No newline at end of file |
|
||||
16 | #from numpy import linalg No newline at end of file |
|
|||
17 | import matplotlib.pyplot as plt No newline at end of file |
|
13 | import matplotlib.pyplot as plt | |
18 | from scipy import linalg No newline at end of file |
|
14 | from scipy import linalg | |
19 | import time No newline at end of file |
|
15 | import time | |
20 | from y_hysell96 import* No newline at end of file |
|
16 | from y_hysell96 import* | |
21 | from deb4_basis import * No newline at end of file |
|
17 | from deb4_basis import * | |
22 | from modelf import * |
|
18 | from modelf import * | |
No newline at end of file |
|
19 | #from scipy.optimize import fsolve No newline at end of file | ||
23 | from scipy.optimize import fsolve No newline at end of file |
|
|||
24 | from scipy.optimize import root No newline at end of file |
|
20 | from scipy.optimize import root | |
25 | import pywt No newline at end of file |
|
21 | import pywt | |
|
22 | from irls_dn2 import * No newline at end of file | |||
26 | No newline at end of file |
|
23 | ||
27 | No newline at end of file |
|
24 | ||
28 | ## Calculate Forward Model No newline at end of file |
|
25 | ## Calculate Forward Model | |
29 | lambda1 = 6.0 No newline at end of file |
|
26 | lambda1 = 6.0 | |
30 | k = 2*math.pi/lambda1 No newline at end of file |
|
27 | k = 2*math.pi/lambda1 | |
31 | No newline at end of file |
|
28 | ||
32 | ## Calculate Magnetic Declination No newline at end of file |
|
29 | ## Calculate Magnetic Declination | |
33 | No newline at end of file |
|
30 | ||
34 | # [~,~,dec] = igrf11magm(350e3, -11-56/60, -76-52/60, 2012); check this No newline at end of file |
|
31 | # [~,~,dec] = igrf11magm(350e3, -11-56/60, -76-52/60, 2012); check this | |
35 | No newline at end of file |
|
32 | ||
36 | # or calculate it with the above function No newline at end of file |
|
33 | # or calculate it with the above function | |
37 | dec = -1.24 No newline at end of file |
|
34 | dec = -1.24 | |
38 | No newline at end of file |
|
35 | ||
39 | # loads rx, ry (Jicamarca antenna positions) #this can be done with numpy.loadtxt() No newline at end of file |
|
36 | # loads rx, ry (Jicamarca antenna positions) #this can be done with numpy.loadtxt() | |
40 | rx = np.array( [[127.5000], [91.5000], [127.5000], [19.5000], [91.5000], [-127.5000], [-55.5000], [-220.8240]] ) No newline at end of file |
|
37 | rx = np.array( [[127.5000], [91.5000], [127.5000], [19.5000], [91.5000], [-127.5000], [-55.5000], [-220.8240]] ) | |
41 | ry = np.array( [[127.5000], [91.5000], [91.5000], [55.5000], [-19.5000], [-127.5000], [-127.5000], [-322.2940]] ) No newline at end of file |
|
38 | ry = np.array( [[127.5000], [91.5000], [91.5000], [55.5000], [-19.5000], [-127.5000], [-127.5000], [-322.2940]] ) | |
42 | No newline at end of file |
|
39 | ||
43 | antpos = np.array( [[127.5000, 91.5000, 127.5000, 19.5000, 91.5000, -127.5000, -55.5000, -220.8240], No newline at end of file |
|
40 | antpos = np.array( [[127.5000, 91.5000, 127.5000, 19.5000, 91.5000, -127.5000, -55.5000, -220.8240], | |
44 | [127.5000, 91.5000, 91.5000, 55.5000, -19.5000, -127.5000, -127.5000, -322.2940]] ) No newline at end of file |
|
41 | [127.5000, 91.5000, 91.5000, 55.5000, -19.5000, -127.5000, -127.5000, -322.2940]] ) | |
45 | No newline at end of file |
|
42 | ||
46 | plt.figure(1) No newline at end of file |
|
43 | plt.figure(1) | |
47 | plt.plot(rx, ry, 'ro') No newline at end of file |
|
44 | plt.plot(rx, ry, 'ro') | |
48 | plt.draw() No newline at end of file |
|
45 | plt.draw() | |
49 | No newline at end of file |
|
46 | ||
50 | # Jicamarca is nominally at a 45 degree angle No newline at end of file |
|
47 | # Jicamarca is nominally at a 45 degree angle | |
51 | theta = 45 - dec; No newline at end of file |
|
48 | theta = 45 - dec; | |
52 | No newline at end of file |
|
49 | ||
53 | # Rotation matrix from antenna coord to magnetic coord (East North) No newline at end of file |
|
50 | # Rotation matrix from antenna coord to magnetic coord (East North) | |
54 | theta_rad = math.radians(theta) # trig functions take radians as argument No newline at end of file |
|
51 | theta_rad = math.radians(theta) # trig functions take radians as argument | |
55 | val1 = float( math.cos(theta_rad) ) No newline at end of file |
|
52 | val1 = float( math.cos(theta_rad) ) | |
56 | val2 = float( math.sin(theta_rad) ) No newline at end of file |
|
53 | val2 = float( math.sin(theta_rad) ) | |
57 | val3 = float( -1*math.sin(theta_rad)) No newline at end of file |
|
54 | val3 = float( -1*math.sin(theta_rad)) | |
58 | val4 = float( math.cos(theta_rad) ) No newline at end of file |
|
55 | val4 = float( math.cos(theta_rad) ) | |
59 | No newline at end of file |
|
56 | ||
60 | # Rotation matrix from antenna coord to magnetic coord (East North) No newline at end of file |
|
57 | # Rotation matrix from antenna coord to magnetic coord (East North) | |
61 | R = np.array( [[val1, val3], [val2, val4]] ); No newline at end of file |
|
58 | R = np.array( [[val1, val3], [val2, val4]] ); | |
62 | No newline at end of file |
|
59 | ||
63 | # Rotate antenna positions to magnetic coord. No newline at end of file |
|
60 | # Rotate antenna positions to magnetic coord. | |
64 | AR = np.dot(R.T, antpos); No newline at end of file |
|
61 | AR = np.dot(R.T, antpos); | |
65 | No newline at end of file |
|
62 | ||
66 | # Only take the East component No newline at end of file |
|
63 | # Only take the East component | |
67 | r = AR[0,:] No newline at end of file |
|
64 | r = AR[0,:] | |
68 | r.sort() # ROW VECTOR? No newline at end of file |
|
65 | r.sort() # ROW VECTOR? | |
69 | No newline at end of file |
|
66 | ||
70 | # Truth model (high and low resolution) No newline at end of file |
|
67 | # Truth model (high and low resolution) | |
71 | Nt = (1024.0)*(16.0); # number of pixels in truth image: high resolution No newline at end of file |
|
68 | Nt = (1024.0)*(16.0); # number of pixels in truth image: high resolution | |
72 | thbound = 9.0/180*math.pi; # the width of the domain in angle space No newline at end of file |
|
69 | thbound = 9.0/180*math.pi; # the width of the domain in angle space | |
73 | thetat = np.linspace(-thbound, thbound,Nt) # image domain No newline at end of file |
|
70 | thetat = np.linspace(-thbound, thbound,Nt) # image domain | |
74 | thetat = np.transpose(thetat) # transpose # FUNCIONA?????????????????????????????? No newline at end of file |
|
71 | thetat = np.transpose(thetat) # transpose # FUNCIONA?????????????????????????????? | |
75 | Nr = (256.0); # number of pixels in reconstructed image: low res No newline at end of file |
|
72 | Nr = (256.0); # number of pixels in reconstructed image: low res | |
76 | thetar = np.linspace(-thbound, thbound,Nr) # reconstruction domain No newline at end of file |
|
73 | thetar = np.linspace(-thbound, thbound,Nr) # reconstruction domain | |
77 | thetar = np.transpose(thetar) #transpose # FUNCIONA????????????????????????????? No newline at end of file |
|
74 | thetar = np.transpose(thetar) #transpose # FUNCIONA????????????????????????????? | |
78 | No newline at end of file |
|
75 | ||
79 | # Model for f: Gaussian(s) with amplitudes a, centers mu, widths sig, and No newline at end of file |
|
76 | # Model for f: Gaussian(s) with amplitudes a, centers mu, widths sig, and | |
80 | # background constant b. No newline at end of file |
|
77 | # background constant b. | |
81 | No newline at end of file |
|
78 | ||
82 | # Triple Gaussian No newline at end of file |
|
79 | # Triple Gaussian | |
83 | # a = np.array([3, 5, 2]); No newline at end of file |
|
80 | # a = np.array([3, 5, 2]); | |
84 | # mu = np.array([-5.0/180*math.pi, 2.0/180*math.pi, 7.0/180*math.pi]); No newline at end of file |
|
81 | # mu = np.array([-5.0/180*math.pi, 2.0/180*math.pi, 7.0/180*math.pi]); | |
85 | # sig = np.array([2.0/180*math.pi, 1.5/180*math.pi, 0.3/180*math.pi]); No newline at end of file |
|
82 | # sig = np.array([2.0/180*math.pi, 1.5/180*math.pi, 0.3/180*math.pi]); | |
86 | # b = 0; # background No newline at end of file |
|
83 | # b = 0; # background | |
87 | No newline at end of file |
|
84 | ||
88 | # Double Gaussian No newline at end of file |
|
85 | # Double Gaussian | |
89 | # a = np.array([3, 5]); No newline at end of file |
|
86 | # a = np.array([3, 5]); | |
90 | # mu = np.array([-5.0/180*math.pi, 2.0/180*math.pi]); No newline at end of file |
|
87 | # mu = np.array([-5.0/180*math.pi, 2.0/180*math.pi]); | |
91 | # sig = np.array([2.0/180*math.pi, 1.5/180*math.pi]); No newline at end of file |
|
88 | # sig = np.array([2.0/180*math.pi, 1.5/180*math.pi]); | |
92 | # b = 0; # background No newline at end of file |
|
89 | # b = 0; # background | |
93 | No newline at end of file |
|
90 | ||
94 | # Single Gaussian No newline at end of file |
|
91 | # Single Gaussian | |
95 | a = np.array( [3] ); No newline at end of file |
|
92 | a = np.array( [3] ); | |
96 | mu = np.array( [-3.0/180*math.pi] ) No newline at end of file |
|
93 | mu = np.array( [-3.0/180*math.pi] ) | |
97 | sig = np.array( [2.0/180*math.pi] ) No newline at end of file |
|
94 | sig = np.array( [2.0/180*math.pi] ) | |
98 | b = 0; No newline at end of file |
|
95 | b = 0; | |
99 | No newline at end of file |
|
96 | ||
100 | fact = np.zeros(shape=(Nt,1)); No newline at end of file |
|
97 | fact = np.zeros(shape=(Nt,1)); | |
101 | factr = np.zeros(shape=(Nr,1)); No newline at end of file |
|
98 | factr = np.zeros(shape=(Nr,1)); | |
102 | No newline at end of file |
|
99 | ||
103 | for i in range(0, a.size): No newline at end of file |
|
100 | for i in range(0, a.size): | |
104 | temp = (-(thetat-mu[i])**2/(sig[i]**2)) No newline at end of file |
|
101 | temp = (-(thetat-mu[i])**2/(sig[i]**2)) | |
105 | tempr = (-(thetar-mu[i])**2/(sig[i]**2)) No newline at end of file |
|
102 | tempr = (-(thetar-mu[i])**2/(sig[i]**2)) | |
106 | for j in range(0, temp.size): No newline at end of file |
|
103 | for j in range(0, temp.size): | |
107 | fact[j] = fact[j] + a[i]*math.exp(temp[j]); No newline at end of file |
|
104 | fact[j] = fact[j] + a[i]*math.exp(temp[j]); | |
108 | for m in range(0, tempr.size): No newline at end of file |
|
105 | for m in range(0, tempr.size): | |
109 | factr[m] = factr[m] + a[i]*math.exp(tempr[m]); No newline at end of file |
|
106 | factr[m] = factr[m] + a[i]*math.exp(tempr[m]); | |
110 | fact = fact + b; No newline at end of file |
|
107 | fact = fact + b; | |
111 | factr = factr + b; No newline at end of file |
|
108 | factr = factr + b; | |
112 | No newline at end of file |
|
109 | ||
113 | # # model for f: Square pulse No newline at end of file |
|
110 | # # model for f: Square pulse | |
114 | # for j in range(0, fact.size): No newline at end of file |
|
111 | # for j in range(0, fact.size): | |
115 | # if (theta > -5.0/180*math.pi and theta < 2.0/180*math.pi): No newline at end of file |
|
112 | # if (theta > -5.0/180*math.pi and theta < 2.0/180*math.pi): | |
116 | # fact[j] = 0 No newline at end of file |
|
113 | # fact[j] = 0 | |
117 | # else: No newline at end of file |
|
114 | # else: | |
118 | # fact[j] = 1 No newline at end of file |
|
115 | # fact[j] = 1 | |
119 | # for k in range(0, factr.size): No newline at end of file |
|
116 | # for k in range(0, factr.size): | |
120 | # if (thetar[k] > -5.0/180*math.pi and thetar[k] < 2/180*math.pi): No newline at end of file |
|
117 | # if (thetar[k] > -5.0/180*math.pi and thetar[k] < 2/180*math.pi): | |
121 | # fact[k] = 0 No newline at end of file |
|
118 | # fact[k] = 0 | |
122 | # else: No newline at end of file |
|
119 | # else: | |
123 | # fact[k] = 1 No newline at end of file |
|
120 | # fact[k] = 1 | |
124 | # No newline at end of file |
|
121 | # | |
125 | # No newline at end of file |
|
122 | # | |
126 | # # model for f: triangle pulse No newline at end of file |
|
123 | # # model for f: triangle pulse | |
127 | # mu = -1.0/180*math.pi; No newline at end of file |
|
124 | # mu = -1.0/180*math.pi; | |
128 | # sig = 5.0/180*math.pi; No newline at end of file |
|
125 | # sig = 5.0/180*math.pi; | |
129 | # wind1 = theta > mu-sig and theta < mu; No newline at end of file |
|
126 | # wind1 = theta > mu-sig and theta < mu; | |
130 | # wind2 = theta < mu+sig and theta > mu; No newline at end of file |
|
127 | # wind2 = theta < mu+sig and theta > mu; | |
131 | # fact = wind1 * (theta - (mu - sig)); No newline at end of file |
|
128 | # fact = wind1 * (theta - (mu - sig)); | |
132 | # factr = wind1 * (thetar - (mu - sig)); No newline at end of file |
|
129 | # factr = wind1 * (thetar - (mu - sig)); | |
133 | # fact = fact + wind2 * (-(theta-(mu+sig))); No newline at end of file |
|
130 | # fact = fact + wind2 * (-(theta-(mu+sig))); | |
134 | # factr = factr + wind2 * (-(thetar-(mu+sig))); No newline at end of file |
|
131 | # factr = factr + wind2 * (-(thetar-(mu+sig))); | |
135 | No newline at end of file |
|
132 | ||
136 | No newline at end of file |
|
133 | ||
137 | # fact = fact/(sum(fact)[0]*2*thbound/Nt); # normalize to integral(f)==1 No newline at end of file |
|
134 | # fact = fact/(sum(fact)[0]*2*thbound/Nt); # normalize to integral(f)==1 | |
138 | I = sum(fact)[0]; No newline at end of file |
|
135 | I = sum(fact)[0]; | |
139 | fact = fact/I; # normalize to sum(f)==1 No newline at end of file |
|
136 | fact = fact/I; # normalize to sum(f)==1 | |
140 | factr = factr/I; # normalize to sum(f)==1 |
|
137 | factr = factr/I; # normalize to sum(f)==1 | |
No newline at end of file |
|
138 | #plt.figure() | ||
141 | #plot(thetat,fact,'r'); hold on; |
|
No newline at end of file | ||
No newline at end of file |
|
139 | #plt.plot(thetat,fact,'r'); | ||
142 | #plot(thetar,factr,'k.'); hold off; No newline at end of file |
|
No newline at end of file | ||
|
140 | #plt.plot(thetar,factr,'k.'); No newline at end of file | |||
143 | #xlim([min(thetat) max(thetat)]); No newline at end of file |
|
141 | #xlim([min(thetat) max(thetat)]); | |
144 | No newline at end of file |
|
142 | ||
145 | #x = np.linspace(thetat.min(), thetat.max) ???? No newline at end of file |
|
143 | #x = np.linspace(thetat.min(), thetat.max) ???? | |
146 | #for i in range(0, thetat.size): No newline at end of file |
|
144 | #for i in range(0, thetat.size): | |
147 | plt.figure(2) No newline at end of file |
|
145 | plt.figure(2) | |
148 | plt.plot(thetat, fact, 'r--') No newline at end of file |
|
146 | plt.plot(thetat, fact, 'r--') | |
149 | plt.plot(thetar, factr, 'ro') No newline at end of file |
|
147 | plt.plot(thetar, factr, 'ro') | |
150 | plt.draw() No newline at end of file |
|
148 | plt.draw() | |
151 | # xlim([min(thetat) max(thetat)]); FALTA ARREGLAR ESTO No newline at end of file |
|
149 | # xlim([min(thetat) max(thetat)]); FALTA ARREGLAR ESTO | |
152 | No newline at end of file |
|
150 | ||
153 | No newline at end of file |
|
151 | ||
154 | ## No newline at end of file |
|
152 | ## | |
155 | # Control the type and number of inversions with: No newline at end of file |
|
153 | # Control the type and number of inversions with: | |
156 | # SNRdBvec: the SNRs that will be used. No newline at end of file |
|
154 | # SNRdBvec: the SNRs that will be used. | |
157 | # NN: the number of trials for each SNR No newline at end of file |
|
155 | # NN: the number of trials for each SNR | |
158 | No newline at end of file |
|
156 | ||
159 | #SNRdBvec = np.linspace(5,20,10); No newline at end of file |
|
157 | #SNRdBvec = np.linspace(5,20,10); | |
160 | SNRdBvec = np.array([15]); No newline at end of file |
|
158 | SNRdBvec = np.array([15]); | |
161 | NN = 1; # number of trial at each SNR No newline at end of file |
|
159 | NN = 1; # number of trial at each SNR | |
162 | No newline at end of file |
|
160 | ||
163 | # if using vector arguments should be: (4,SNRdBvec.size,NN) No newline at end of file |
|
161 | # if using vector arguments should be: (4,SNRdBvec.size,NN) | |
164 | corr = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) No newline at end of file |
|
162 | corr = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) | |
165 | corrc = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) No newline at end of file |
|
163 | corrc = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) | |
166 | rmse = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) No newline at end of file |
|
164 | rmse = np.zeros(shape=(4,SNRdBvec.size,NN)); # (method, SNR, trial) | |
167 | No newline at end of file |
|
165 | ||
168 | for snri in range(0, SNRdBvec.size): # change 1 for SNRdBvec.size when using SNRdBvec as vector No newline at end of file |
|
166 | for snri in range(0, SNRdBvec.size): # change 1 for SNRdBvec.size when using SNRdBvec as vector | |
169 | for Ni in range(0, NN): No newline at end of file |
|
167 | for Ni in range(0, NN): | |
170 | SNRdB = SNRdBvec[snri]; No newline at end of file |
|
168 | SNRdB = SNRdBvec[snri]; | |
171 | SNR = 10**(SNRdB/10.0); No newline at end of file |
|
169 | SNR = 10**(SNRdB/10.0); | |
172 | No newline at end of file |
|
170 | ||
173 | # Calculate cross-correlation matrix (Fourier components of image) No newline at end of file |
|
171 | # Calculate cross-correlation matrix (Fourier components of image) | |
174 | # This is an inefficient way to do this. No newline at end of file |
|
172 | # This is an inefficient way to do this. | |
175 | R = np.zeros(shape=(r.size, r.size), dtype=object); No newline at end of file |
|
173 | R = np.zeros(shape=(r.size, r.size), dtype=object); | |
176 | No newline at end of file |
|
174 | ||
177 | for i1 in range(0, r.size): No newline at end of file |
|
175 | for i1 in range(0, r.size): | |
178 | for i2 in range(0,r.size): No newline at end of file |
|
176 | for i2 in range(0,r.size): | |
179 | R[i1,i2] = np.dot(fact.T, np.exp(1j*k*np.dot((r[i1]-r[i2]),np.sin(thetat)))) No newline at end of file |
|
177 | R[i1,i2] = np.dot(fact.T, np.exp(1j*k*np.dot((r[i1]-r[i2]),np.sin(thetat)))) | |
180 | R[i1,i2] = sum(R[i1,i2]) No newline at end of file |
|
178 | R[i1,i2] = sum(R[i1,i2]) | |
181 | No newline at end of file |
|
179 | ||
182 | # Add uncertainty No newline at end of file |
|
180 | # Add uncertainty | |
183 | # This is an ad-hoc way of adding "noise". It models some combination of No newline at end of file |
|
181 | # This is an ad-hoc way of adding "noise". It models some combination of | |
184 | # receiver noise and finite integration times. We could use a more No newline at end of file |
|
182 | # receiver noise and finite integration times. We could use a more | |
185 | # advanced model (like in Yu et al 2000) in the future. No newline at end of file |
|
183 | # advanced model (like in Yu et al 2000) in the future. | |
186 | No newline at end of file |
|
184 | ||
187 | # This is a way of adding noise while maintaining the No newline at end of file |
|
185 | # This is a way of adding noise while maintaining the | |
188 | # positive-semi-definiteness of the matrix. No newline at end of file |
|
186 | # positive-semi-definiteness of the matrix. | |
189 | No newline at end of file |
|
187 | ||
190 | U = linalg.cholesky(R.astype(complex), lower=False); # U'*U = R No newline at end of file |
|
188 | U = linalg.cholesky(R.astype(complex), lower=False); # U'*U = R | |
191 | No newline at end of file |
|
189 | ||
192 | sigma_noise = (np.linalg.norm(U,'fro')/SNR); No newline at end of file |
|
190 | sigma_noise = (np.linalg.norm(U,'fro')/SNR); | |
193 | No newline at end of file |
|
191 | ||
194 | temp1 = (-1*np.random.rand(U.shape[0], U.shape[1]) + 0.5) No newline at end of file |
|
192 | temp1 = (-1*np.random.rand(U.shape[0], U.shape[1]) + 0.5) | |
195 | temp2 = 1j*(-1*np.random.rand(U.shape[0], U.shape[1]) + 0.5) No newline at end of file |
|
193 | temp2 = 1j*(-1*np.random.rand(U.shape[0], U.shape[1]) + 0.5) | |
196 | temp3 = ((abs(U) > 0).astype(float)) # upper triangle of 1's No newline at end of file |
|
194 | temp3 = ((abs(U) > 0).astype(float)) # upper triangle of 1's | |
197 | temp4 = (sigma_noise * (temp1 + temp2))/np.sqrt(2.0) No newline at end of file |
|
195 | temp4 = (sigma_noise * (temp1 + temp2))/np.sqrt(2.0) | |
198 | No newline at end of file |
|
196 | ||
199 | nz = np.multiply(temp4, temp3) No newline at end of file |
|
197 | nz = np.multiply(temp4, temp3) | |
200 |
|
|
198 | ||
|
199 | #---------------------- Eliminar esto:------------------------------------------ | |||
|
No newline at end of file | ||||
|
200 | #nz = ((abs(np.multiply(temp4, temp3)) > 0).astype(int)) No newline at end of file | |||
201 | #nz = ((abs(np.dot(temp4, temp3)) > 0).astype(int)) No newline at end of file |
|
201 | #nz = ((abs(np.dot(temp4, temp3)) > 0).astype(int)) | |
202 | No newline at end of file |
|
202 | #nz = np.dot(np.dot(sigma_noise, (temp1 + temp2)/math.sqrt(2), temp3 )); | |
203 | No newline at end of file |
|
203 | #nz = np.dot(sigma_noise, (np.dot((np.random.rand(8,8) + j*np.random.rand(8,8))/math.sqrt(2.0) , (abs(U) > 0).astype(int)))); | |
204 | #nz = np.dot(np.dot(sigma_noise, (temp1 + temp2)/math.sqrt(2), temp3 )); No newline at end of file |
|
204 | #-------------------------------------------------------------------------------- | |
205 | #nz = np.dot(sigma_noise, (np.dot((np.random.rand(8,8) + j*np.random.rand(8,8))/math.sqrt(2.0) , (abs(U) > 0).astype(int)))); No newline at end of file |
|
205 | ||
|
206 | Unz = U + nz; No newline at end of file | |||
206 | No newline at end of file |
|
207 | Rnz = np.dot(Unz.T.conj(),Unz); # the noisy version of R | |
207 | Unz = U + nz; No newline at end of file |
|
208 | plt.figure(3); | |
208 | Rnz = np.dot(Unz.T.conj(),Unz); # the noisy version of R No newline at end of file |
|
209 | plt.pcolor(abs(Rnz)); | |
209 |
plt. |
|
210 | plt.colorbar(); | |
210 | plt.pcolor(abs(Rnz)); No newline at end of file |
|
211 | ||
211 | plt.colorbar(); No newline at end of file |
|
212 | # Fourier Inversion ################### | |
212 | No newline at end of file |
|
213 | f_fourier = np.zeros(shape=(Nr,1), dtype=complex); | |
213 | # Fourier Inversion ################### No newline at end of file |
|
214 | ||
214 | f_fourier = np.zeros(shape=(Nr,1), dtype=complex); No newline at end of file |
|
215 | for i in range(0, thetar.size): | |
215 | No newline at end of file |
|
216 | th = thetar[i]; | |
216 | for i in range(0, thetar.size): No newline at end of file |
|
217 | w = np.exp(1j*k*np.dot(r,np.sin(th))); | |
217 | th = thetar[i]; No newline at end of file |
|
218 | ||
218 | w = np.exp(1j*k*np.dot(r,np.sin(th))); No newline at end of file |
|
219 | temp = np.dot(w.T.conj(),U) | |
219 |
|
|
220 | ||
220 |
|
|
221 | f_fourier[i] = np.dot(temp, w); | |
221 |
|
|
222 | ||
222 | f_fourier[i] = np.dot(temp, w); No newline at end of file |
|
223 | f_fourier = f_fourier.real; # get rid of numerical imaginary noise | |
223 | No newline at end of file |
|
224 | ||
224 | f_fourier = f_fourier.real; # get rid of numerical imaginary noise No newline at end of file |
|
225 | #print f_fourier | |
225 | No newline at end of file |
|
226 | ||
226 | #print f_fourier No newline at end of file |
|
227 | ||
227 | No newline at end of file |
|
228 | # Capon Inversion ###################### | |
228 | No newline at end of file |
|
229 | ||
229 | # Capon Inversion ###################### No newline at end of file |
|
230 | f_capon = np.zeros(shape=(Nr,1)); | |
230 | No newline at end of file |
|
231 | ||
231 |
|
|
232 | tic_capon = time.time(); | |
232 |
|
233 | |||
No newline at end of file |
|
234 | for i in range(0, thetar.size): No newline at end of file | ||
233 | #tic_capon = time.time(); No newline at end of file |
|
|||
234 | No newline at end of file |
|
235 | th = thetar[i]; | |
235 | for i in range(0, thetar.size): No newline at end of file |
|
236 | w = np.exp(1j*k*np.dot(r,np.sin(th))); | |
236 | th = thetar[i]; No newline at end of file |
|
237 | f_capon[i] = np.divide(1, ( np.dot( w.T.conj(), (linalg.solve(Rnz,w)) ) ).real) | |
237 | w = np.exp(1j*k*np.dot(r,np.sin(th))); No newline at end of file |
|
238 | ||
238 | f_capon[i] = np.divide(1, ( np.dot( w.T.conj(), (linalg.solve(Rnz,w)) ) ).real) No newline at end of file |
|
239 | ||
239 |
|
240 | toc_capon = time.time() | ||
No newline at end of file |
|
241 | |||
240 | #toc_capon = time.time() |
|
No newline at end of file | ||
No newline at end of file |
|
242 | elapsed_time_capon = toc_capon - tic_capon; | ||
241 |
|
No newline at end of file | |||
No newline at end of file |
|
243 | |||
242 | # elapsed_time_capon = toc_capon - tic_capon; No newline at end of file |
|
No newline at end of file | ||
|
244 | f_capon = f_capon.real; # get rid of numerical imaginary noise No newline at end of file | |||
243 | No newline at end of file |
|
245 | ||
244 | f_capon = f_capon.real; # get rid of numerical imaginary noise No newline at end of file |
|
246 | # MaxEnt Inversion ##################### | |
245 |
|
|
247 | ||
246 | # MaxEnt Inversion ##################### No newline at end of file |
|
248 | # create the appropriate sensing matrix (split into real and imaginary # parts) | |
247 | No newline at end of file |
|
249 | M = (r.size-1)*(r.size); | |
248 | # create the appropriate sensing matrix (split into real and imaginary # parts) No newline at end of file |
|
250 | Ht = np.zeros(shape=(M,Nt)); # "true" sensing matrix | |
249 | M = (r.size-1)*(r.size); No newline at end of file |
|
251 | Hr = np.zeros(shape=(M,Nr)); # approximate sensing matrix for reconstruction | |
250 | Ht = np.zeros(shape=(M,Nt)); # "true" sensing matrix No newline at end of file |
|
252 | ||
251 | Hr = np.zeros(shape=(M,Nr)); # approximate sensing matrix for reconstruction No newline at end of file |
|
253 | # need to re-index our measurements from matrix R into vector g | |
252 | No newline at end of file |
|
254 | g = np.zeros(shape=(M,1)); | |
253 | # need to re-index our measurements from matrix R into vector g No newline at end of file |
|
255 | gnz = np.zeros(shape=(M,1)); # noisy version of g | |
254 | g = np.zeros(shape=(M,1)); No newline at end of file |
|
256 | ||
255 | gnz = np.zeros(shape=(M,1)); # noisy version of g No newline at end of file |
|
257 | # triangular indexing to perform this re-indexing | |
256 | No newline at end of file |
|
258 | T = np.ones(shape=(r.size,r.size)); | |
257 | # triangular indexing to perform this re-indexing No newline at end of file |
|
259 | [i1v,i2v] = np.where(np.triu(T,1) > 0); # converts linear to triangular indexing | |
258 | T = np.ones(shape=(r.size,r.size)); No newline at end of file |
|
260 | ||
259 | [i1v,i2v] = np.where(np.triu(T,1) > 0); # converts linear to triangular indexing No newline at end of file |
|
261 | # build H | |
260 | No newline at end of file |
|
262 | for i1 in range(0, r.size): | |
261 | # build H No newline at end of file |
|
263 | for i2 in range(i1+1, r.size): | |
262 | for i1 in range(0, r.size): No newline at end of file |
|
264 | idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward | |
263 | for i2 in range(i1+1, r.size): No newline at end of file |
|
265 | idx1 = 2*idx; # because index starts at 0 | |
264 | idx = np.where(np.logical_and((i1==i1v), (i2==i2v)))[0]; # kind of awkward No newline at end of file |
|
266 | idx2 = 2*idx+1; | |
265 | idx1 = 2*idx; # because index starts at 0 No newline at end of file |
|
267 | Hr[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetar)).T; | |
266 | idx2 = 2*idx+1; No newline at end of file |
|
268 | Hr[idx2,:] = np.sin(k*(r[i1]-r[i2])*np.sin(thetar)).T; | |
267 |
H |
|
269 | Ht[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetat)).T*Nr/Nt; | |
268 |
H |
|
270 | Ht[idx2,:] = np.sin(k*(r[i1]-r[i2])*np.sin(thetat)).T*Nr/Nt; | |
269 | Ht[idx1,:] = np.cos(k*(r[i1]-r[i2])*np.sin(thetat)).T*Nr/Nt; No newline at end of file |
|
271 | g[idx1] = (R[i1,i2]).real*Nr/Nt; # check this again later | |
270 |
|
|
272 | g[idx2] = (R[i1,i2]).imag*Nr/Nt; # check again | |
271 |
g[idx1] = (R[i1,i2]).real*Nr/Nt; |
|
273 | gnz[idx1] = (Rnz[i1,i2]).real*Nr/Nt; | |
272 |
g[idx2] = (R[i1,i2]).imag*Nr/Nt; |
|
274 | gnz[idx2] = (Rnz[i1,i2]).imag*Nr/Nt; | |
273 | gnz[idx1] = (Rnz[i1,i2]).real*Nr/Nt; No newline at end of file |
|
275 | ||
274 | gnz[idx2] = (Rnz[i1,i2]).imag*Nr/Nt; No newline at end of file |
|
276 | # inversion | |
275 | No newline at end of file |
|
277 | F = Nr/Nt; # normalization | |
276 | # inversion No newline at end of file |
|
278 | sigma = 1; # set to 1 because the difference is accounted for in G | |
277 | F = Nr/Nt; # normalization No newline at end of file |
|
279 | ||
278 | sigma = 1; # set to 1 because the difference is accounted for in G No newline at end of file |
|
280 | ##### ADD *10 for consistency with old model, NEED TO VERIFY THIS!!!!? line below | |
279 | No newline at end of file |
|
281 | G = np.linalg.norm(g-gnz)**2 ; # pretend we know in advance the actual value of chi^2 | |
280 | ##### ADD *10 for consistency with old model, NEED TO VERIFY THIS!!!!? line below |
|
282 | ||
No newline at end of file |
|
283 | tic_maxent = time.time(); | ||
281 | G = np.linalg.norm(g-gnz)**2; # pretend we know in advance the actual value of chi^2 No newline at end of file |
|
No newline at end of file | ||
|
284 | ||||
|
No newline at end of file | ||||
|
285 | lambda0 = 1e-5*np.ones(shape=(M,1)); # initial condition (can be set to anything) No newline at end of file | |||
282 |
|
|
286 | ||
283 | lambda0 = 1e-5*np.ones(shape=(M,1)); # initial condition (can be set to anything) No newline at end of file |
|
287 | toc_maxent = time.time() | |
|
288 | elapsed_time_maxent = toc_maxent - tic_maxent; | |||
|
No newline at end of file | ||||
|
289 | ||||
|
No newline at end of file | ||||
|
290 | # Whitened solution No newline at end of file | |||
284 | No newline at end of file |
|
291 | def myfun(lambda1): | |
285 | # Whitened solution No newline at end of file |
|
292 | return y_hysell96(lambda1,gnz,sigma,F,G,Hr); | |
286 | def myfun(lambda1): No newline at end of file |
|
293 | ||
287 | return y_hysell96(lambda1,gnz,sigma,F,G,Hr); No newline at end of file |
|
294 | tic_maxEnt = time.time(); | |
288 | No newline at end of file |
|
295 | ||
289 | tic_maxEnt = time.time(); No newline at end of file |
|
296 | #sol1 = fsolve(myfun,lambda0.ravel(), args=(), xtol=1e-14, maxfev=100000); | |
290 | No newline at end of file |
|
297 | lambda1 = root(myfun,lambda0, method='krylov', tol=1e-14); | |
291 | #sol1 = fsolve(myfun,lambda0.ravel(), args=(), xtol=1e-14, maxfev=100000); No newline at end of file |
|
298 | ||
292 | lambda1 = root(myfun,lambda0, method='krylov', tol=1e-14); No newline at end of file |
|
299 | #print lambda1 | |
293 | No newline at end of file |
|
300 | #print lambda1.x | |
294 | #print lambda1 No newline at end of file |
|
301 | ||
295 |
|
|
302 | lambda1 = lambda1.x; | |
296 | No newline at end of file |
|
303 | ||
297 | lambda1 = lambda1.x; No newline at end of file |
|
304 | toc_maxEnt = time.time(); | |
298 | No newline at end of file |
|
305 | f_maxent = modelf(lambda1, Hr, F); | |
299 | toc_maxEnt = time.time(); No newline at end of file |
|
306 | ystar = myfun(lambda1); | |
300 | f_maxent = modelf(lambda1, Hr, F); No newline at end of file |
|
307 | Lambda = np.sqrt(sum(lambda1**2.*sigma**2)/(4*G)); | |
301 | ystar = myfun(lambda1); No newline at end of file |
|
308 | ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda); | |
302 | Lambda = np.sqrt(sum(lambda1**2.*sigma**2)/(4*G)); No newline at end of file |
|
309 | es = np.dot(Hr, f_maxent) - gnz; # should be same as ep | |
303 | ep = np.multiply(-lambda1,sigma**2)/ (2*Lambda); No newline at end of file |
|
310 | chi2 = np.sum((es/sigma)**2); | |
304 | es = np.dot(Hr, f_maxent) - gnz; # should be same as ep No newline at end of file |
|
311 | ||
305 | chi2 = np.sum((es/sigma)**2); No newline at end of file |
|
312 | ||
306 | No newline at end of file |
|
313 | # CS inversion using irls ######################## | |
307 | No newline at end of file |
|
314 | ||
308 | No newline at end of file |
|
315 | # (Use Nr, thetar, gnz, and Hr from MaxEnt above) | |
309 | # CS inversion using irls ######################## No newline at end of file |
|
316 | ||
310 | No newline at end of file |
|
317 | Psi = deb4_basis(Nr); ###### REPLACED BY LINE BELOW (?) | |
311 | # (Use Nr, thetar, gnz, and Hr from MaxEnt above) No newline at end of file |
|
318 | ||
312 |
|
319 | # REMOVE THIS?-------------------------------- | ||
No newline at end of file |
|
320 | #wavelet1 = pywt.Wavelet('db4') | ||
313 | #Psi = deb4_basis(Nr); ###### REPLACED BY LINE BELOW (?) |
|
No newline at end of file | ||
No newline at end of file |
|
321 | #Phi, Psi, x = wavelet1.wavefun(level=3) | ||
314 |
|
No newline at end of file | |||
No newline at end of file |
|
322 | # -------------------------------------------- | ||
315 | wavelet1 = pywt.Wavelet('db4') |
|
No newline at end of file | ||
No newline at end of file |
|
323 | |||
316 | Phi, Psi, x = wavelet1.wavefun(level=3) No newline at end of file |
|
No newline at end of file | ||
|
324 | # add "sum to 1" constraint | |||
|
No newline at end of file | ||||
|
325 | H2 = np.concatenate( (Hr, np.ones(shape=(1,Nr))), axis=0 ); No newline at end of file | |||
317 | No newline at end of file |
|
326 | N_temp = np.array([[Nr/Nt]]); | |
318 | # add "sum to 1" constraint No newline at end of file |
|
327 | g2 = np.concatenate( (gnz, N_temp), axis=0 ); | |
319 | H2 = np.concatenate( (Hr, np.ones(shape=(1,Nr))), axis=0 ); No newline at end of file |
|
328 | H2 = H2.T.conj(); | |
320 | N_temp = np.array([[Nr/Nt]]); No newline at end of file |
|
329 | ||
321 | g2 = np.concatenate( (gnz, N_temp), axis=0 ); |
|
330 | print 'H2 shape', H2.shape | |
No newline at end of file |
|
331 | print 'Psi shape', Psi.shape | ||
322 |
|
No newline at end of file | |||
No newline at end of file |
|
332 | |||
323 |
|
No newline at end of file | |||
No newline at end of file |
|
333 | s = irls_dn2(H2*Psi,g2,0.5,G); | ||
324 | #s = irls_dn2(H2*Psi,g2,0.5,G); No newline at end of file |
|
No newline at end of file | ||
|
334 | # f_cs = Psi*s; | |||
|
No newline at end of file | ||||
|
335 | # | |||
|
No newline at end of file | ||||
|
336 | # # plot No newline at end of file | |||
325 |
# |
|
337 | # plot(thetar,f_cs,'r.-'); | |
326 | # No newline at end of file |
|
338 | # hold on; | |
327 |
# |
|
339 | # plot(thetat,fact,'k-'); | |
328 | # plot(thetar,f_cs,'r.-'); No newline at end of file |
|
340 | # hold off; | |
329 | # hold on; No newline at end of file |
|
341 | ||
330 | # plot(thetat,fact,'k-'); No newline at end of file |
|
342 | ||
331 | # hold off; No newline at end of file |
|
343 | # # # Scaling and shifting | |
332 | No newline at end of file |
|
344 | # # # Only necessary for capon solution | |
333 | No newline at end of file |
|
345 | ||
334 | # # # Scaling and shifting No newline at end of file |
|
346 | ||
335 | # # # Only necessary for capon solution No newline at end of file |
|
347 | f_capon = f_capon/np.max(f_capon)*np.max(fact); | |
336 | No newline at end of file |
|
348 | ||
337 | No newline at end of file |
|
349 | ||
338 | f_capon = f_capon/np.max(f_capon)*np.max(fact); No newline at end of file |
|
350 | ### analyze stuff ###################### | |
339 | No newline at end of file |
|
351 | # calculate MSE | |
340 | No newline at end of file |
|
352 | rmse_fourier = np.sqrt(np.mean((f_fourier - factr)**2)); | |
341 | ### analyze stuff ###################### No newline at end of file |
|
353 | rmse_capon = np.sqrt(np.mean((f_capon - factr)**2)); | |
342 | # calculate MSE No newline at end of file |
|
354 | rmse_maxent = np.sqrt(np.mean((f_maxent - factr)**2)); | |
343 |
|
|
355 | #rmse_cs = np.sqrt(np.mean((f_cs - factr).^2)); | |
344 | rmse_capon = np.sqrt(np.mean((f_capon - factr)**2)); No newline at end of file |
|
356 | ||
345 | rmse_maxent = np.sqrt(np.mean((f_maxent - factr)**2)); No newline at end of file |
|
357 | ||
346 | #rmse_cs = np.sqrt(np.mean((f_cs - factr).^2)); No newline at end of file |
|
358 | relrmse_fourier = rmse_fourier / np.linalg.norm(fact); | |
347 | No newline at end of file |
|
359 | relrmse_capon = rmse_capon / np.linalg.norm(fact); | |
348 |
relrmse_ |
|
360 | relrmse_maxent = rmse_maxent / np.linalg.norm(fact); | |
349 |
relrmse_c |
|
361 | #relrmse_cs = rmse_cs / np.norm(fact); | |
350 | relrmse_maxent = rmse_maxent / np.linalg.norm(fact); No newline at end of file |
|
362 | ||
351 | #relrmse_cs = rmse_cs / np.norm(fact); No newline at end of file |
|
363 | # To be able to perform dot product (align matrices) done below within the dot calculations | |
352 |
|
364 | |||
No newline at end of file |
|
365 | |||
353 | factr = factr.T.conj() No newline at end of file |
|
No newline at end of file | ||
|
366 | #f_fourier = f_fourier.T.conj() | |||
|
No newline at end of file | ||||
|
367 | #f_capon = f_capon.T.conj() | |||
|
No newline at end of file | ||||
|
368 | #f_maxent = f_maxent.T.conj() | |||
|
No newline at end of file | ||||
|
369 | ||||
|
No newline at end of file | ||||
|
370 | #factr = factr.T.conj() | |||
|
No newline at end of file | ||||
|
371 | ||||
|
No newline at end of file | ||||
|
372 | # calculate correlation No newline at end of file | |||
354 | No newline at end of file |
|
373 | ||
355 | # calculate correlation |
|
374 | corr_fourier = np.dot(f_fourier.T.conj(),factr) / (np.linalg.norm(f_fourier)*np.linalg.norm(factr)); | |
No newline at end of file |
|
375 | corr_capon = np.dot(f_capon.T.conj(),factr) / (np.linalg.norm(f_capon)*np.linalg.norm(factr)); | ||
356 | corr_fourier = np.dot(f_fourier,factr) / (np.linalg.norm(f_fourier)*np.linalg.norm(factr)); |
|
No newline at end of file | ||
No newline at end of file |
|
376 | corr_maxent = np.dot(f_maxent.T.conj(),factr) / (np.linalg.norm(f_maxent)*np.linalg.norm(factr)); | ||
357 | corr_capon = np.dot(f_capon,factr) / (np.linalg.norm(f_capon)*np.linalg.norm(factr)); |
|
No newline at end of file | ||
No newline at end of file |
|
377 | #corr_cs = np.dot(f_cs,factr) / (norm(f_cs)*norm(factr)); | ||
358 | corr_maxent = np.dot(f_maxent,factr) / (np.linalg.norm(f_maxent)*np.linalg.norm(factr)); No newline at end of file |
|
No newline at end of file | ||
|
378 | No newline at end of file | |||
359 | #corr_cs = np.dot(f_cs,factr) / (norm(f_cs)*norm(factr)); No newline at end of file |
|
379 | ||
360 | No newline at end of file |
|
380 | # calculate centered correlation | |
361 | # calculate centered correlation No newline at end of file |
|
381 | f0 = factr - np.mean(factr); | |
362 |
|
|
382 | f1 = f_fourier - np.mean(f_fourier); | |
363 | f1 = f_fourier - np.mean(f_fourier); |
|
383 | ||
No newline at end of file |
|
384 | corrc_fourier = np.dot(f0.T.conj(),f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); | ||
364 | corrc_fourier = np.dot(f0,f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); No newline at end of file |
|
No newline at end of file | ||
|
385 | f1 = f_capon - np.mean(f_capon); No newline at end of file | |||
365 | f1 = f_capon - np.mean(f_capon); |
|
386 | corrc_capon = np.dot(f0.T.conj(),f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); | |
No newline at end of file |
|
387 | f1 = f_maxent - np.mean(f_maxent); No newline at end of file | ||
366 | corrc_capon = np.dot(f0,f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); No newline at end of file |
|
|||
367 | f1 = f_maxent - np.mean(f_maxent); |
|
388 | corrc_maxent = np.dot(f0.T.conj(),f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); | |
No newline at end of file |
|
389 | #f1 = f_cs - mean(f_cs); No newline at end of file | ||
368 | corrc_maxent = np.dot(f0,f1) / (np.linalg.norm(f0)*np.linalg.norm(f1)); No newline at end of file |
|
|||
369 | #f1 = f_cs - mean(f_cs); No newline at end of file |
|
390 | #corrc_cs = dot(f0,f1) / (norm(f0)*norm(f1)); | |
370 | #corrc_cs = dot(f0,f1) / (norm(f0)*norm(f1)); No newline at end of file |
|
391 | ||
371 | No newline at end of file |
|
392 | ||
372 | No newline at end of file |
|
393 | ||
373 | No newline at end of file |
|
394 | # # # plot stuff ######################### | |
374 | # # # plot stuff ######################### No newline at end of file |
|
395 | ||
375 | No newline at end of file |
|
396 | #---- Capon---- | |
376 | #---- Capon---- No newline at end of file |
|
397 | plt.figure(4) | |
377 | plt.figure(4) No newline at end of file |
|
398 | plt.subplot(2, 1, 1) | |
378 | plt.subplot(2, 1, 1) No newline at end of file |
|
399 | plt.plot(180/math.pi*thetar, f_capon, 'r', label='Capon') | |
379 |
plt.plot(180/math.pi*theta |
|
400 | plt.plot(180/math.pi*thetat,fact, 'k--', label='Truth') | |
380 | plt.plot(180/math.pi*thetat,fact, 'k--', label='Truth') No newline at end of file |
|
401 | plt.ylabel('Power (arbitrary units)') | |
381 | plt.ylabel('Power (arbitrary units)') No newline at end of file |
|
402 | plt.legend(loc='upper right') | |
382 | plt.legend(loc='upper right') No newline at end of file |
|
403 | ||
383 | No newline at end of file |
|
404 | # formatting y-axis | |
384 | # formatting y-axis No newline at end of file |
|
405 | locs,labels = plt.yticks() | |
385 | locs,labels = plt.yticks() No newline at end of file |
|
406 | plt.yticks(locs, map(lambda x: "%.1f" % x, locs*1e4)) | |
386 | plt.yticks(locs, map(lambda x: "%.1f" % x, locs*1e4)) No newline at end of file |
|
407 | plt.text(0.0, 1.01, '1e-4', fontsize=10, transform = plt.gca().transAxes) | |
387 | plt.text(0.0, 1.01, '1e-4', fontsize=10, transform = plt.gca().transAxes) No newline at end of file |
|
408 | ||
388 | No newline at end of file |
|
409 | ||
389 | No newline at end of file |
|
410 | #---- MaxEnt---- | |
390 | #---- MaxEnt---- No newline at end of file |
|
411 | plt.subplot(2, 1, 2) | |
391 | plt.subplot(2, 1, 2) No newline at end of file |
|
412 | plt.plot(180/math.pi*thetar, f_maxent, 'r', label='MaxEnt') | |
392 |
plt.plot(180/math.pi*theta |
|
413 | plt.plot(180/math.pi*thetat,fact, 'k--', label='Truth') | |
393 | plt.plot(180/math.pi*thetat,fact, 'k--', label='Truth') No newline at end of file |
|
414 | plt.ylabel('Power (arbitrary units)') | |
394 | plt.ylabel('Power (arbitrary units)') No newline at end of file |
|
415 | plt.legend(loc='upper right') | |
395 | plt.legend(loc='upper right') No newline at end of file |
|
416 | ||
396 | No newline at end of file |
|
417 | # formatting y-axis | |
397 | # formatting y-axis No newline at end of file |
|
418 | locs,labels = plt.yticks() | |
398 | locs,labels = plt.yticks() No newline at end of file |
|
419 | plt.yticks(locs, map(lambda x: "%.1f" % x, locs*1e4)) | |
399 | plt.yticks(locs, map(lambda x: "%.1f" % x, locs*1e4)) No newline at end of file |
|
420 | plt.text(0.0, 1.01, '1e-4', fontsize=10, transform = plt.gca().transAxes) | |
400 | plt.text(0.0, 1.01, '1e-4', fontsize=10, transform = plt.gca().transAxes) No newline at end of file |
|
421 | ||
401 | No newline at end of file |
|
422 | plt.show() | |
402 | plt.show() No newline at end of file |
|
423 | ||
403 | No newline at end of file |
|
424 | ||
404 |
|
425 | # # PLOT PARA COMPRESSED SENSING | ||
No newline at end of file |
|
426 | # # No newline at end of file | ||
405 | # # subplot(3,1,2); |
|
|||
No newline at end of file |
|
||||
406 | # # plot(180/pi*thetar,f_maxent,'r-'); |
|
|||
No newline at end of file |
|
||||
407 | # # hold on; |
|
|||
No newline at end of file |
|
||||
408 | # # plot(180/pi*thetat,fact,'k--'); |
|
|||
No newline at end of file |
|
||||
409 | # # hold off; |
|
|||
No newline at end of file |
|
||||
410 | # # ylim([min(f_cs) 1.1*max(fact)]); |
|
|||
No newline at end of file |
|
||||
411 | # # # title(sprintf('rel. RMSE: #.2e\tCorr: #.3f Corrc: #.3f', relrmse_maxent, corr_maxent, corrc_maxent)); |
|
|||
No newline at end of file |
|
||||
412 | # # ylabel({'Power';'(arbitrary units)'}) |
|
|||
No newline at end of file |
|
||||
413 | # # # title 'Maximum Entropy Method' |
|
|||
No newline at end of file |
|
||||
414 | # # legend('MaxEnt','Truth'); No newline at end of file |
|
|||
415 | # # No newline at end of file |
|
427 | # # subplot(3,1,3); | |
416 | # # subplot(3,1,3); No newline at end of file |
|
428 | # # plot(180/pi*thetar,f_cs,'r-'); | |
417 | # # plot(180/pi*thetar,f_cs,'r-'); No newline at end of file |
|
429 | # # hold on; | |
418 | # # hold on; No newline at end of file |
|
430 | # # plot(180/pi*thetat,fact,'k--'); | |
419 | # # plot(180/pi*thetat,fact,'k--'); No newline at end of file |
|
431 | # # hold off; | |
420 | # # hold off; No newline at end of file |
|
432 | # # ylim([min(f_cs) 1.1*max(fact)]); | |
421 | # # ylim([min(f_cs) 1.1*max(fact)]); No newline at end of file |
|
433 | # # # title(sprintf('rel. RMSE: #.2e\tCorr: #.3f Corrc: #.3f', relrmse_cs, corr_cs, corrc_cs)); | |
422 | # # # title(sprintf('rel. RMSE: #.2e\tCorr: #.3f Corrc: #.3f', relrmse_cs, corr_cs, corrc_cs)); No newline at end of file |
|
434 | # # # title 'Compressed Sensing - Debauchies Wavelets' | |
423 | # # # title 'Compressed Sensing - Debauchies Wavelets' No newline at end of file |
|
435 | # # xlabel 'Degrees' | |
424 | # # xlabel 'Degrees' No newline at end of file |
|
436 | # # ylabel({'Power';'(arbitrary units)'}) | |
425 | # # ylabel({'Power';'(arbitrary units)'}) No newline at end of file |
|
437 | # # legend('Comp. Sens.','Truth'); | |
426 | # # legend('Comp. Sens.','Truth'); No newline at end of file |
|
438 | # # | |
427 | # # No newline at end of file |
|
439 | # # # set(gcf,'Position',[749 143 528 881]); # CSL | |
428 |
# # # set(gcf,'Position',[ |
|
440 | # # # set(gcf,'Position',[885 -21 528 673]); # macbook | |
429 | # # # set(gcf,'Position',[885 -21 528 673]); # macbook No newline at end of file |
|
441 | # # pause(0.01); | |
430 | # # pause(0.01); No newline at end of file |
|
442 | ||
|
443 | ||||
|
No newline at end of file | ||||
|
444 | # # Store Results | |||
|
No newline at end of file | ||||
|
445 | corr[0, snri, Ni] = corr_fourier; | |||
|
No newline at end of file | ||||
|
446 | corr[1, snri, Ni] = corr_capon; | |||
|
No newline at end of file | ||||
|
447 | corr[2, snri, Ni] = corr_maxent; | |||
|
No newline at end of file | ||||
|
448 | #corr[3, snri, Ni] = corr_cs; | |||
|
No newline at end of file | ||||
|
449 | ||||
|
No newline at end of file | ||||
|
450 | rmse[0,snri,Ni] = relrmse_fourier; | |||
|
No newline at end of file | ||||
|
451 | rmse[1,snri,Ni] = relrmse_capon; | |||
|
No newline at end of file | ||||
|
452 | rmse[2,snri,Ni] = relrmse_maxent; | |||
|
No newline at end of file | ||||
|
453 | #rmse[3,snri,Ni] = relrmse_cs; | |||
|
No newline at end of file | ||||
|
454 | ||||
|
No newline at end of file | ||||
|
455 | corrc[0,snri,Ni] = corrc_fourier; | |||
|
No newline at end of file | ||||
|
456 | corrc[1,snri,Ni] = corrc_capon; | |||
|
No newline at end of file | ||||
|
457 | corrc[2,snri,Ni] = corrc_maxent; | |||
|
No newline at end of file | ||||
|
458 | #corrc[3,snri,Ni] = corrc_cs; | |||
|
No newline at end of file | ||||
|
459 | ||||
|
No newline at end of file | ||||
|
460 | ||||
|
No newline at end of file | ||||
|
461 | print 'Capon:\t', elapsed_time_capon, 'sec'; | |||
|
No newline at end of file | ||||
|
462 | print 'Maxent:\t',elapsed_time_maxent, 'sec'; | |||
|
No newline at end of file | ||||
|
463 | #print 'CS:\t%3.3f sec\n',elapsed_time_cs; | |||
|
No newline at end of file | ||||
|
464 | ||||
|
No newline at end of file | ||||
|
465 | print (NN*(snri+1) + Ni), '/', (SNRdBvec.size*NN); | |||
|
No newline at end of file | ||||
|
466 | ||||
|
No newline at end of file | ||||
|
467 | print corr | |||
|
No newline at end of file | ||||
|
468 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now