forked from pog2/python_estimation_PolInSAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
2212 lines (1883 loc) · 79.8 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 4 11:46:59 2015
@author: capdessus
"""
from __future__ import division
from copy import copy
import tomosar_synth as tom
import plot_tomo as pt
import RVoG_MB as mb
import basic_lib as bl
import estimation as e
import load_param as lp
import numpy as np
import numpy.linalg as npl
import matplotlib
import matplotlib.pyplot as plt
import scipy.optimize as opti
import pdb
plt.ion()
def test_equivalence_normalisation():
#Verifie que faire normlexico+Ti=T+Tebaldini pareil que
#Ti=T+Tebaldini
A = 0.95
E = 71
Na = 2
Np =3
k_z = [0.1,0.2]
param_SB = mb.param_rvog(Na)
param_SB.N = 10000
param_SB = mb.rvog_reduction(param_SB,A,E)
param_SB.k_z = [k_z[0]]
param_SB.z_g = 0
W_k_vrai_SB = tom.UPS_to_MPMB(param_SB.get_upsilon(),2)
data_synth = tom.TomoSARDataSet_synth(Na,param_SB)
taille_test = param_SB.N
W_k1= data_synth.get_W_k_norm_rect(taille_test,Na,'mat+ps+tebald')
W_k2= data_synth.get_W_k_norm_rect(taille_test,Na,'ps+tebald')
np.set_printoptions(linewidth=150,precision=2)
R_t1,C_t1 = tom.sm_separation(W_k1,Np,Na)
interv_a1,interv_b1,Cond1,alpha1 = tom.search_space_definition(R_t1,C_t1,Na)
R_t2,C_t2 = tom.sm_separation(W_k2,Np,Na)
interv_a2,interv_b2,Cond2,alpha2 = tom.search_space_definition(R_t2,C_t2,Na)
print '1'
print 'a',interv_a1
print 'b',interv_b1
print 'gamma_1_1',R_t1[0][0,1]
print 'gamma_2_1',R_t1[1][0,1]
print '\n\n2'
print 'a',interv_a2
print 'b',interv_b2
print 'gamma_1_2',R_t2[0][0,1]
print 'gamma_2_2',R_t2[1][0,1]
def test_plot_cu_plus_tebaldini_plus_legend():
Na = 3
Np = 3
A = 0.75
E = 71
k_z = [0.1,0.2]
ant1=0
ant2=1
#MB
param_MB = mb.param_rvog()
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z = k_z
param_MB.z_g = 0
param_MB.theta=np.pi/4
param_MB.Na=len(param_MB.k_z)+1
param_MB.h_v=30
param_MB.sigma_v=0.0345
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon(),Na)
data_tomo=tom.TomoSARDataSet_synth(param_MB)
W_k_noise=data_tomo.get_W_k_rect(param_MB,nb_echant=1000)
W_k_MB = W_k_noise
R_t_MB,C_t_MB,G_MB = tom.sm_separation(W_k_MB,Np,Na)
interv_a_MB,interv_b_MB,Cond,alpha = tom.search_space_definition(R_t_MB,C_t_MB,Na)
vec_a_MB = interv_a_MB[0][1]
vec_b_MB = np.linspace(interv_b_MB[0][0],interv_b_MB[0][1],50)
dist_g_MB,dist_v_MB = tom.proximity_C_T(W_k_MB,Na,R_t_MB,C_t_MB,\
vec_a_MB,vec_b_MB,param_MB)
_,R_g_min_MB,R_v_min_MB,_,_ = tom.value_R_C(R_t_MB,C_t_MB,interv_a_MB[0][0],\
vec_b_MB[np.argmin(dist_g_MB)])
Ups = tom.UPS_to_MPMB(W_k_MB,Na)
pt.plot_cu_plus_tebaldini_plus_legend(Ups,R_t_MB,R_g_min_MB,\
R_v_min_MB,\
interv_a_MB,interv_b_MB,\
ant1,ant2)
def test_evol_domaine_possib_SB_vs_MB(data_type='pure'):
print 'test_evol_domaine_possib_SB_vs_MB'
Na = 3
Np = 3
A = 0.95
E = 200
k_z = [0.1,0.2]
#SB
param_SB = mb.param_rvog(2)
param_SB = mb.rvog_reduction(param_SB,A,E)
param_SB.k_z = [k_z[0]]
W_k_vrai_SB = tom.UPS_to_MPMB(param_SB.get_upsilon(),2)
#MB
param_MB = mb.param_rvog(Na)
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z = k_z
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon(),Na)
if data_type=='pure':
W_k_SB = tom.UPS_to_MPMB(param_SB.get_upsilon(),2)
W_k_MB = tom.UPS_to_MPMB(param_MB.get_upsilon(),Na)
elif data_type =='noisy':
data_MB = tom.TomoSARDataSet_synth(Na,param_MB)
data_SB = tom.TomoSARDataSet_synth(2,param_SB)
taille_test = 100
W_k_MB = data_MB.get_W_k_norm_rect(taille_test,Na)
W_k_SB = data_SB .get_W_k_norm_rect(taille_test,2)
#sm_separation SB
W_k_SB_norm = tom.normalize_MPMB_PS_Tebald(W_k_SB,2)
R_t_SB,C_t_SB,G_SB = tom.sm_separation(W_k_SB_norm,Np,2)
interv_a_SB,interv_b_SB,Cond_SB,alpha_SB =\
tom.search_space_definition(R_t_SB,C_t_SB,2)
SKP_1 = np.kron(C_t_SB[0],R_t_SB[0])+np.kron(C_t_SB[1],R_t_SB[1])
diff_1 = G_SB - SKP_1
norm_SB = np.trace(diff_1.dot(diff_1.T.conj()))
print '||G_SB-SKP_1||',norm_SB
#print param_MB.k_z
#print param_MB.get_k_z(0,1,Na)
#sm_separation MB
W_k_MB_norm = tom.normalize_MPMB_PS_Tebald(W_k_MB,Na)
R_t_MB,C_t_MB,G_MB = tom.sm_separation(W_k_MB_norm,Np,Na)
interv_a_MB,interv_b_MB,Cond,alpha = tom.search_space_definition(R_t_MB,C_t_MB,Na)
SKP_2 = np.kron(C_t_MB[0],R_t_MB[0])+np.kron(C_t_MB[1],R_t_MB[1])
diff_2 = G_MB - SKP_2
norm_MB = np.trace(diff_2.dot(diff_2.T.conj()))
print '||G_MB-SKP_2||',norm_MB
vec_a_SB = interv_a_SB[0][0]
vec_b_SB = np.linspace(interv_b_SB[0][0],interv_b_SB[0][1],50)
vec_a_MB = interv_a_MB[0][0]
vec_b_MB = np.linspace(interv_b_MB[0][0],interv_b_MB[0][1],50)
#SB
dist_g_SB,dist_v_SB = tom.proximity_C_T(W_k_SB,2,R_t_SB,C_t_SB,\
vec_a_SB,vec_b_SB,param_SB)
_,R_g_min_SB,R_v_min_SB,C_g_min_SB,C_v_min_SB =\
tom.value_R_C(R_t_SB,C_t_SB,interv_a_SB[0][0],\
vec_b_SB[np.argmin(dist_g_SB)])
T_g,T_v = tom.denormalisation_teb(W_k_SB,2,C_g_min_SB,C_v_min_SB)
SKP_1min = np.kron(C_v_min_SB,R_v_min_SB)+\
np.kron(C_g_min_SB,R_g_min_SB)
diff_min1 = G_SB - SKP_1min
norm_SB_min = np.trace(diff_min1.dot(diff_min1.T.conj()))
np.set_printoptions(precision=5)
print '/////////////// TEST MB vs SV /////////////////////'
print '======================= SB ==================='
print '-- Polar --'
print '||G_SB-SKP_min1||',norm_SB_min
print 'ground'
print T_g
print param_SB.T_ground*param_SB.get_a()
print '\nvol'
print T_v
print param_SB.T_vol*param_SB.get_I1()
print '-- Structure --'
print 'R_g_min_SB'
print R_g_min_SB
print 'R_v_min_SB'
print R_v_min_SB
print 'R_v_vrai'
print param_SB.get_R_v()
#MB
dist_g_MB,dist_v_MB = tom.proximity_C_T(W_k_MB,Na,R_t_MB,C_t_MB,\
vec_a_MB,vec_b_MB,param_MB)
_,R_g_min_MB,R_v_min_MB,C_g_min_MB,C_v_min_MB =\
tom.value_R_C(R_t_MB,C_t_MB,interv_a_MB[0][0],\
vec_b_MB[np.argmin(dist_g_MB)])
T_g,T_v = tom.denormalisation_teb(W_k_MB,Na,C_g_min_MB,C_v_min_MB)
SKP_2min = np.kron(C_v_min_MB,R_v_min_MB)+\
np.kron(C_g_min_MB,R_g_min_MB)
diff_min2 = G_MB- SKP_2min
norm_MB_min = np.trace(diff_min2.dot(diff_min2.T.conj()))
plt.figure()
plt.plot(vec_b_MB,dist_g_MB[0,:],'-*')
print '===================== MB ===================='
print '||G_MB_MB-SKP_min2||',norm_MB_min
print 'ground'
print T_g
print param_MB.T_ground*param_MB.get_a()
print '\nvol'
print T_v
print param_MB.T_vol*param_MB.get_I1()
print '-- Structure --'
print 'R_g_min_MB'
print R_g_min_MB
print 'R_v_min_MB'
print R_v_min_MB
print 'R_v_vrai'
print param_MB.get_R_v()
def test_denormalisation_tebaldini():
"""
A=np.array([[1,2],[3,4]])
#B=np.array([[5,6,7],[8,9,10],[11,12,13]])
B=np.array([[5,6],[8,9]])
A_kro_B=np.kron(A,B)
P_t=np.transpose(tom4.p_rearg(A_kro_B,Np,Na))
BxA = tom4.inv_p_rearg(P_t,Np,Na)
B_kro_A = np.kron(B,A)
"""
T_vol =np.random.random_integers(0,9,(3,3))
T_sol =np.random.random_integers(0,9,(3,3))
R_sol =np.random.random_integers(0,9,(3,3))
R_vol =np.random.random_integers(0,9,(3,3))
Na=3
Np=3
Ups = np.kron(R_sol,T_sol)+np.kron(R_vol,T_vol)
W = tom.UPS_to_MPMB(Ups)
E = np.diag(np.diag(W.copy())) #Matrice des coeffs diagonaux de E
W_norm = tom.normalize_MPMB2(W,Na)
R_t,C_t,_=tom.sm_separation(W_norm,Np,Na)
F= tom.power(np.diag(np.array([E[0,0],E[2,2], E[4,4]])),0.5)
print F.dot(C_t[1].dot(F))
print T_vol
def test_commutte_ejd():
A_t = np.random.random_integers(0,9,(3,3))
A_t = 1/2*(A_t+A_t.T.conj()) #hermitianisation de A_t
B_t = np.random.random_integers(0,9,(3,3))
B_t = 1/2*(B_t+B_t.T.conj()) #hermitianisation de B_t
D1,D2,A,LAMBDA_mat = tom.ejd2(A_t,B_t)
D1_p,D2_p,A_p,LAMBDA_mat_p = tom.ejd2(B_t,A_t)
print LAMBDA_mat
print LAMBDA_mat_p
return A_t,B_t,D1,D2,A,LAMBDA_mat,D1_p,D2_p,A_p,LAMBDA_mat_p
def test_ecart_angle_droite():
plt.close('all')
Np=3
Na=2
param = mb.param_rvog(Na)
A= [0.1,0.95]
E= [71,200]
k_z = [0.1]
param.k_z = [k_z[0]]
param.display()
#calcul pour plusieurs A et E pour differentes N (taille echant)
min_taille1 = 50
max_taille1 = 10000
nb_taille1 = 20
varia_taille_echant1 = np.floor(np.logspace(np.log10(min_taille1),\
np.log10(max_taille1),nb_taille1))
varia_taille_echant1 = varia_taille_echant1.astype(np.int64)
N_real = 5000
plot_hist0=0;save_hist0=0;plot_cohe0=0;save_data0=1
tom.ecart_angle_inclin_A_E(A,E,param,varia_taille_echant1,N_real,\
save_data0,plot_hist0,save_hist0,plot_cohe0)
sauve_plot_biais_variance = 1
pt.plot_bias_var_inclin_A_E(A,E,varia_taille_echant1,N_real,sauve_plot_biais_variance)
def test_angle_ff():
"""Calcul de differetens angle d'inclinaison
de matrice Upsilon non bruités et plot """
Np=3
Na=2
A = 0.1
E = 200
param = mb.param_rvog(Na)
param = mb.rvog_reduction(param,A,E)
Nb_k_z = 5
vec_k_z = np.linspace(0.1,2*np.pi/param.h_v,Nb_k_z)
print vec_k_z
theta = np.zeros((Nb_k_z,1))
for i,k_z in enumerate(vec_k_z):
param.k_z = [k_z]
Ups = param.get_upsilon()
omega = tom.polinsar_compute_omega12blanchi(Ups)
theta[i],_ = tom.polinsar_estime_droite(omega)
plt.hold(True)
tom.polinsar_plot_cu(Ups)
print theta*180/np.pi
def load_ups_theta():
A_test = [0.1,0.95]
E_test = [71,200]
for A in A_test:
for E in E_test:
date = '8_10/'
home_dir ='/home/capdessus/Python/Code_Pierre/'
folder_name = 'data/angle_inclinaison_droite/'+date
sub_folder_name ='A_{0}_E_{1}/'.format(A,E)
total_path = home_dir+folder_name+sub_folder_name
varia_taille_echant,theta_vrai,\
theta_pascale_moy,theta_pascale_var,\
theta_tebald_moy,theta_tebald_var,\
Ups= pt.load_data(total_path)
print 'A= {0} E ={1}\t theta_vrai {2}'.format(A,E,theta_vrai*180/np.pi)
print 'Ups'
bl.printm(Ups)
def test_matrice_antoine():
Na=2
Np=3
path= '/home/capdessus/Python/Code_Pierre/matrice_Ups_test_.txt'
path2= '/home/capdessus/Python/Code_Pierre/matrice_Ups_test_norm.txt'
Ups_antoine=bl.load_txt(path)
Ups_norm_antoine=bl.load_txt(path2)
A=0.1
E=71
param = mb.param_rvog(Na)
param = mb.rvog_reduction(param,A,E)
Ups_vrai = param.get_upsilon()
omega_vrai_blanc = tom.polinsar_compute_omega12blanchi(Ups_vrai)
theta_vrai,_ = tom.polinsar_estime_droite(omega_vrai_blanc)
omega_antoine = tom.polinsar_compute_omega12blanchi(Ups_antoine)
theta_antoine,_ = tom.polinsar_estime_droite(omega_antoine)
W_k=tom.UPS_to_MPMB(Ups_antoine,Na)
W_k_norm=tom.normalize_MPMB_PS_Tebald(W_k,Na)
#sm_separation
R_t,C_t,_ = tom.sm_separation(W_k_norm,Np,Na)
interv_a,interv_b,Cond,alpha =\
tom.search_space_definition(R_t,C_t,Na)
a=0; b=1
_,R1,R2,C1,C2=tom.value_R_C(R_t,C_t,a,b)
gamma1 = R1[0,1]; gamma2 = R2[0,1]
gamma = [gamma1,gamma2]
theta_tebald_antoine= bl.estime_line_svd(gamma,theta_vrai)
print '-------------------------------'
print 'Ups_antoine'
bl.printm(Ups_antoine)
print 'Ups_antoine_norm'
bl.printm(Ups_norm_antoine)
print 'Rtilde1'
bl.printm(R_t[0])
print 'Rtilde2'
bl.printm(R_t[1])
print 'Ctilde1'
bl.printm(C_t[0])
print 'Ctilde2'
bl.printm(C_t[1])
print 'R1'
bl.printm(R1)
print 'R2'
bl.printm(R2)
print 'C1'
bl.printm(C1)
print 'C2'
bl.printm(C2)
print 'theta_vrai {0}'.format(theta_vrai*180/np.pi)
print 'theta_antoine_FF {0}'.format(theta_antoine*180/np.pi)
print 'theta_antoine_Tebald {0}'.format(theta_tebald_antoine*180/np.pi)
tom.polinsar_plot_cu(tom.MPMB_to_UPS(W_k_norm,Na),title =' CU')
#tom.polinsar_plot_cu(Ups_norm_antoine,title =' CU')
print '------ Influcence normalisation ------------'
print 'Ups_antoine'
bl.printm(Ups_antoine)
print 'Ups_antoine_norm'
bl.printm(Ups_norm_antoine)
print 'Ups normalisé par Pierre à partir de Ups_antoine'
bl.printm(tom.MPMB_to_UPS(W_k_norm,Na))
return Ups_antoine,Ups_norm_antoine,tom.MPMB_to_UPS(W_k_norm,Na)
def test_estimaeur_dpctm_kz():
hv,sig,gt1,gt2,gt3,\
meanhv,varhv,meansig,varsig,\
meangt1,vargt1,meangt2,vargt2,\
meangt3,vargt3 = monte_carl_estim_dpct_kz(param_MB)
np.save('hv',hv)
np.save('sig',sig)
np.save('gt1',gt1)
np.save('gt2',gt2)
np.save('gt3',gt3)
Nb_N=15#nb de taille diff
vec_N = np.floor((np.logspace(2,5,Nb_N)))
P_real=100
pt.plot_biais_variance_err(vec_N,meanhv,varhv,P_real,\
'hv_moy','hv_var',param_MB.h_v)
pt.plot_biais_variance_err(vec_N,meansig,varsig,P_real,\
'sig_moy','sig_var',param_MB.sigma_v)
pt.plot_biais_variance_err(vec_N,meangt1,vargt1,P_real,\
'gt1_moy','gt1_var',param_MB.gammat[0,1])
pt.plot_biais_variance_err(vec_N,meangt2,vargt2,P_real,\
'gt2_moy','gt2_var',param_MB.gammat[0,2])
pt.plot_biais_variance_err(vec_N,meangt3,vargt3,P_real,\
'gt3_moy','gt3_var',param_MB.gammat[1,2])
def test_estim_ecart_ang_pol():
Na = 3
Np = 3
A = 0.95
E = 4000
k_z = [0.1,0.15]
#MB
param_MB = mb.param_rvog()
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z=k_z
param_MB.Na=len(param_MB.k_z)+1
param_MB.theta=45*np.pi/180
param_MB.sigma_v=0.0345
param_MB.h_v=30
if param_MB.h_v > np.min(2*np.pi/np.array(k_z)):print 'Attention h_v > Hamb'
param_MB.z_g = 0
#param_MB.gammat=np.array([[1,0.7,0.8],[1,1,0.8],[1,1,1]])
param_MB.gammat=np.ones((3,3))
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon_gt(),Na)
W_k=W_k_vrai_MB
W_k_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k,param_MB.Na)
R_t,C_t,_ = tom.sm_separation(W_k_norm,Np,param_MB.Na)
interv_a,interv_b,_,_ = tom.search_space_definition(R_t,C_t,Na)
interv_a,interv_b = tom.ground_selection_MB(R_t,interv_a,interv_b)
#choix du a et b
g_sol1 = interv_a[0][0]*R_t[0][0,1]+(1-interv_a[0][0])*R_t[1][0,1]
g_sol2 = interv_a[0][1]*R_t[0][0,1]+(1-interv_a[0][1])*R_t[1][0,1]
g_sol_possible = np.array([g_sol1,g_sol2])
a = interv_a[0][np.argmax(np.abs(g_sol_possible))]
b = (interv_b[0][0]+interv_b[0][1])/2
b_vrai = tom.b_true(R_t,param_MB)
_,Rg,Rv,Cg,Cv=tom.value_R_C(R_t,C_t,a,b_vrai)
e.estim_ecart_ang_pol(W_k,param_MB)
def test_estim_ecart_ang():
Na = 3
Np = 3
A = 0.95
E = 200
k_z = [0.1,0.15]
#MB
param_MB = mb.param_rvog()
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z=k_z
param_MB.Na=len(param_MB.k_z)+1
param_MB.sigma_v=0.0345
param_MB.theta=45*np.pi/180
param_MB.h_v=30
if param_MB.h_v > np.min(2*np.pi/np.array(k_z)):print 'Attention h_v > Hamb'
param_MB.z_g = 0
param_MB.gammat=np.array([[1,0.7,0.8],[1,1,0.8],[1,1,1]])
param_MB.N=100
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon_gt(),Na)
nb_echant=10**3
data_synt=tom.TomoSARDataSet_synth(param_MB.Na,param_MB)
W_k_bruit=data_synt.get_W_k_rect(param_MB,int(nb_echant),param_MB.Na)
W_k=W_k_vrai_MB
W_k_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k,param_MB.Na)
R_t,C_t,_ = tom.sm_separation(W_k_vrai_MB,Np,param_MB.Na)
interv_a,interv_b,_,_ = tom.search_space_definition(R_t,C_t,Na)
#*interv_a,interv_b = tom.ground_selection_MB(R_t,interv_a,interv_b)
#choix du a et b
g_sol1 = interv_a[0][0]*R_t[0][0,1]+(1-interv_a[0][0])*R_t[1][0,1]
g_sol2 = interv_a[0][1]*R_t[0][0,1]+(1-interv_a[0][1])*R_t[1][0,1]
g_sol_possible = np.array([g_sol1,g_sol2])
a = interv_a[0][np.argmax(np.abs(g_sol_possible))]
b = (interv_b[0][0]+interv_b[0][1])/2
b_vrai = tom.b_true(R_t,param_MB)
_,Rg,Rv,Cg,Cv=tom.value_R_C(R_t,C_t,a,b_vrai)
vec_gm = tom.gamma_from_Rv(Rv)
vec_gt = np.array([param_MB.gammat[0,1],param_MB.gammat[0,2],param_MB.gammat[1,2]])
vec_kz = param_MB.get_kzlist()
costheta=np.cos(param_MB.theta)
sigmin=0.01
sigmax=0.1
hvmin=5.
hvmax=2.*np.pi/np.max(vec_kz)#le min des hauteurs d'ambiguité
estim=0
if estim:
J,J2,Ressemb,ErrQM,\
vec_hv,vec_sig,vec_b,\
hv_J,hv_J2,hv_MV,hv_EQM,\
sig_J,sig_J2,sig_MV,sig_EQM,\
vec_gt_J,vec_gt_J2,vec_gt_MV,\
vec_gt_EQM = e.estim_ecart_ang(W_k,param_MB)
#pdb.set_trace()
load=1
if(load):
path = 'D:/PIERRE CAPDESSUS/Python/Code_Pierre/sauv_data_estimation/Test4/'
J=np.load(path+'J.npy')
J2=np.load(path+'J2.npy')
#ErrQM = np.load(path+'EQM.npy')
Ressemb=np.load(path+'Ressemb.npy')
vec_hv=np.load(path+'vec_hv.npy')
vec_sig=np.load(path+'vec_sig.npy',)
vec_b=np.load(path+'vec_b.npy',)
hv_J=np.load(path+'hv_J.npy')
hv_J2=np.load(path+'hv_J2.npy')
hv_MV=np.load(path+'hv_MV.npy')
hv_EQM=np.load(path+'hv_EQM.npy')
sig_J=np.load(path+'sig_J.npy')
sig_J2=np.load(path+'sig_J2.npy')
sig_MV=np.load(path+'sig_MV.npy')
sig_EQM=np.load(path+'sig_EQM.npy')
save =0
if(save):
np.save('J',J)
np.save('J2',J2)
np.save('Ressemb',Ressemb)
np.save('ErrQM',EQM)
np.save('vec_hv',vec_hv)
np.save('vec_sig',vec_sig)
np.save('vec_b',vec_b)
np.save('hv_J',hv_J)
np.save('hv_J2',hv_J2)
np.save('hv_MV',hv_MV)
np.save('hv_EQM',hv_EQM)
np.save('sig_J',sig_J)
np.save('sig_J2',sig_J2)
np.save('sig_MV',sig_MV)
np.save('sig_EQM',sig_EQM)
np.save('vec_gt_J',vec_gt_J)
np.save('vec_gt_J2',vec_gt_J2)
np.save('vec_gt_MV',vec_gt_MV)
np.save('vec_gt_EQM',vec_gt_EQM)
#calcul de la valeur de critere J sur les hv/sigb selectionnés sur
#pour chaque b
minJ = np.zeros(vec_b.size,dtype='double')
minJ2 = np.zeros(vec_b.size,dtype='double')
minV=np.zeros(vec_b.size)
minEQM=np.zeros(vec_b.size)
for idxb,b in enumerate(vec_b):
idx_hvJ = np.argmin(np.abs(hv_J[idxb]-vec_hv))
idx_sigJ = np.argmin(np.abs(sig_J[idxb]-vec_sig))
idx_hvMV = np.argmin(np.abs(hv_MV[idxb]-vec_hv))
idx_sigMV = np.argmin(np.abs(sig_MV[idxb]-vec_sig))
#idx_hvEQM = np.argmin(np.abs(hv_EQM[idxb]-vec_hv))
#idx_sigEQM = np.argmin(np.abs(sig_EQM[idxb]-vec_sig))
minJ[idxb] = J[idxb,idx_hvJ,idx_sigJ]
minJ2[idxb] = J2[idxb,idx_hvJ,idx_sigJ]
minV[idxb] = Ressemb[idxb,idx_hvMV,idx_sigMV]
#minEQM[idxb] = ErrQM[idxb,idx_hvEQM,idx_sigEQM]
b_vrai=tom.b_true(R_t,param_MB)
idx_bvrai=np.argmin(np.abs(vec_b-b_vrai))
b_vrai_num=vec_b[idx_bvrai]
print 'b_vrai: {0}'.format(b_vrai)
print 'b_vrai echantillonné: {0} deltab:{1}'.format(b_vrai_num,vec_b[1]-vec_b[0])
print 'b minimisant minJ: {0}'.format(vec_b[np.argmin(minJ)])
print 'b minimisant minMV: {0}'.format(vec_b[np.argmin(minV)])
print 'b minimisant minEQM: {0}'.format(vec_b[np.argmin(minEQM)])
plt.close('all')
pt.plot_cu_sm_possible(tom.MPMB_to_UPS(W_k,3),R_t,interv_a,interv_b,\
0,1,title='CU')
plt.hold(True)
plt.polar([np.angle(param_MB.get_gamma_v_gt(0,1)),
np.angle(param_MB.get_gamma_v(0,1))],
[np.abs(param_MB.get_gamma_v_gt(0,1)),
np.abs(param_MB.get_gamma_v(0,1))],'--ko')
plt.draw()
ib=idx_bvrai
idxminJ = zip(*np.where(J[ib,:,:]==np.nanmin(J[ib,:,:])))
idxminJ2 = zip(*np.where(J2[ib,:,:]==np.nanmin(J2[ib,:,:])))
idxminMV = zip(*np.where(Ressemb[ib,:,:]==np.nanmin(Ressemb[ib,:,:])))
#idxminEQM = zip(*np.where(ErrQM[ib,:,:]==np.nanmin(ErrQM[ib,:,:])))
idxminminJ = zip(*np.where(minJ==np.nanmin(minJ)))
idxminminJ2 = zip(*np.where(minJ2==np.nanmin(minJ2)))
idxminminV = zip(*np.where(minV==np.nanmin(minV)))
print 'b={0}'.format(vec_b[idx_bvrai])
print 'sigmav_MV={0}'.format(vec_sig[idxminMV[0][0]])
print 'hv_MV={0}'.format(vec_hv[idxminMV[0][1]])
print '----------------------------------------'
print 'sigmav_J={0}'.format(vec_sig[idxminJ[0][0]])
print 'hv_J={0}'.format(vec_hv[idxminJ[0][1]])
print '----------------------------------------'
print 'sigmav_J2={0}'.format(vec_sig[idxminJ2[0][0]])
print 'hv_J2={0}'.format(vec_hv[idxminJ2[0][1]])
print 'b={0}'.format(vec_b[idx_bvrai])
print 'sigmav_MV={0}'.format(sig_MV[np.argmin(minV)])
print 'hv_MV={0}'.format(hv_MV[np.argmin(minV)])
print '----------------------------------------'
print 'sigmav_J={0}'.format(sig_J[np.argmin(minJ)])
print 'hv_J={0}'.format(hv_J[np.argmin(minJ)])
print '----------------------------------------'
print 'sigmav_J2={0}'.format(sig_J2[np.argmin(minJ2)])
print 'hv_J2={0}'.format(hv_J2[np.argmin(minJ)])
plt.figure()
plt.imshow(J[1,:,:])
plt.title('ib=1')
plt.colorbar()
plt.draw()
plt.figure()
plt.imshow(J[-1,:,:])
plt.title('ib=-1')
plt.colorbar()
plt.draw()
plt.figure()
levels=np.logspace(np.log10(np.min(Ressemb[ib,:,:])),
np.log10(np.max(Ressemb[ib,:,:])),25)
plt.imshow(Ressemb[ib,:,:],origin='lower')
idx_hv=idxminMV[0][0]
idx_sig=idxminMV[0][1]
plt.plot(idx_sig,idx_hv,'or',label='min MV')
plt.colorbar()
plt.legend()
plt.axis('tight')
plt.hold(True)
plt.contour(Ressemb[ib,:,:],levels,linewidths=2,colors='Black')
plt.title('Ressemb ib='+str(ib))
plt.draw()
"""EQM
plt.figure()
levelsErrQM=np.logspace(np.log10(np.min(ErrQM[ib,:,:])),
np.log10(np.max(ErrQM[ib,:,:])),25)
plt.imshow(ErrQM[ib,:,:],origin='lower')
idx_hv=idxminEQM[0][0]
idx_sig=idxminEQM[0][1]
plt.plot(idx_sig,idx_hv,'or',label='min ErrQM')
plt.colorbar()
plt.legend()
plt.axis('tight')
plt.hold(True)
plt.contour(ErrQM[ib,:,:],levelsErrQM,linewidths=2,colors='Black')
plt.title('ErrQM ib='+str(ib))
plt.draw()
"""
font = {'family': 'sans-serif',
'weight': 'bold',
'size': 25
}
#plt.rc('font',**font)
plt.rc('lines',linewidth=2)
plt.rcParams['lines.markersize']=9
plt.rcParams['axes.labelsize']=25
#plt.rcParams['axes.labelsize']=18
plt.rcParams['font.size']=20
plt.figure()
plt.plot(vec_b,hv_J,'b.-',label='J')
plt.plot(vec_b,hv_J2,'g.-',label='J2')
#plt.plot(vec_b,hv_MV,'r.-',label='MV')
#plt.plot(vec_b,hv_EQM,'c.-',label='EQM')
#plt.plot(vec_b,param_MB.h_v*np.ones(vec_b.size),'k--',label='hv vrai')
hv_num = vec_hv[np.argmin(np.abs(vec_hv-param_MB.h_v))]
plt.plot(vec_b,hv_num*np.ones(vec_b.size),'r--',label='hv vrai')
plt.plot([b_vrai_num,b_vrai_num],
[hv_num,hv_num],'ok')
plt.xlabel('b')
plt.ylabel('hv')
plt.grid()
plt.title('Estimation de hv pour chaque b')
plt.legend(loc='best')
plt.draw()
plt.figure()
plt.plot(vec_b,sig_J,'b.-',label='J')
plt.plot(vec_b,sig_J2,'g.-',label='J2')
#plt.plot(vec_b,sig_MV,'r.-',label='MV')
#plt.plot(vec_b,sig_EQM,'c.-',label='EQM')
sig_num = vec_sig[np.argmin(np.abs(vec_sig-param_MB.sigma_v))]
plt.plot(vec_b,sig_num*np.ones(vec_b.size),'k--',label='sig vrai (num)')
plt.plot([b_vrai_num,b_vrai_num],
[sig_num,sig_num],'ok')
plt.xlabel('b')
plt.ylabel('sigmav')
plt.grid()
plt.legend(loc='best')
plt.draw()
plt.figure()
plt.plot(vec_b,minJ,'b.-',label='J')
plt.plot(vec_b,minJ2,'r.-',label='J2')
plt.plot(vec_b,(minV),'g.-',label='-logV-med(-logV)')
plt.axvline(x=b_vrai_num,ymin=0,ymax=1,alpha=.7,linestyle='--',color='k',
lw=3)
plt.title('Variation critere en fonction de b')
plt.xlabel('b')
plt.grid()
plt.legend(loc='best')
plt.draw()
plt.figure()
plt.semilogy(vec_b,minJ-np.min(minJ),'b.-',label='J')
plt.semilogy(vec_b,minJ2-np.min(minJ2),'r.-',label='J2')
plt.semilogy(vec_b,(minV)-np.min(minV),'g.-',label='-logV-med(-logV)')
plt.axvline(x=b_vrai_num,ymin=0,ymax=1,alpha=.7,linestyle='--',color='k',
lw=3)
plt.title('Variation critere en fonction de b. (x-min(x))')
plt.grid()
plt.xlabel('b')
plt.legend(loc='best')
plt.draw()
plt.figure()
plt.plot(vec_b,(minJ-np.min(minJ)),'b.-',label='J')
plt.plot(vec_b,(minJ2-np.min(minJ2)),'r.-',label='J2')
plt.plot(vec_b,minV-np.min(minV),'g.-',label='MV')
#plt.plot(vec_b,(minEQM-np.mi(minEQM))/np.std(minEQM),'c.-',label='EQM')
plt.axvline(x=b_vrai_num,ymin=0,ymax=1,alpha=.7,linestyle='--',color='k',
lw=3)
plt.xlabel('b')
plt.ylabel('')
plt.title('Variation critere en fonction de b. (x-min(x))')
plt.grid()
plt.legend(loc='best')
plt.draw()
def test_estim_ecart_ang_reestim_b():
Na = 3
Np = 3
A = 0.95
E = 200
k_z = [0.1,0.15]
#MB
param_MB = mb.param_rvog(Na)
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z=k_z
param_MB.sigma_v=0.0345
param_MB.h_v=30
if param_MB.h_v > np.min(2*np.pi/np.array(k_z)):print 'Attention h_v > Hamb'
param_MB.z_g = 0
#param_MB.gammat=np.array([[1,0.7,0.8],[1,1,0.8],[1,1,1]])
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon_gt(),Na)
W_k_vrai_MB_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k_vrai_MB,param_MB.Na)
nb_echant=10**5
data_synt=tom.TomoSARDataSet_synth(param_MB.Na,param_MB)
W_k_bruit=data_synt.get_W_k_rect(param_MB,int(nb_echant),param_MB.Na)
W_k=W_k_bruit
W_k_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k,param_MB.Na)
R_t,C_t,_ = tom.sm_separation(W_k_norm,Np,Na)
interv_a,interv_b,_,_ = tom.search_space_definition(R_t,C_t,Na)
interv_a,interv_b = tom.ground_selection_MB(R_t,interv_a,interv_b)
R_t_vrai,_,_=tom.sm_separation(W_k_vrai_MB_norm,Np,Na)
hvJ,hvJ2,hvV,\
sigJ,sigJ2,sigV,\
gt_J,gt_J2,gt_V,\
X_minJ,X_minJ2,X_minV,\
minJ,minJ2,minV,\
bminJ,bminJ2,bminV,\
vec_b,vec_br=e.estim_ecart_ang_reestim_b(W_k,param_MB)
idx_sort=np.argsort(vec_br)
vec_brs = np.sort(vec_br)
minJsort=minJ[idx_sort]
bvrai=tom.b_true2(R_t_vrai,param_MB)
ant1,ant2=(0,1)
gvgtij = param_MB.get_gamma_v_gt(ant1,ant2)
gvij = param_MB.get_gamma_v(ant1,ant2)
gvb = bvrai*R_t[0][ant1,ant2]+(1-bvrai)*R_t[1][ant1,ant2]
gvbJ = bminJ*R_t[0][ant1,ant2]+(1-bminJ)*R_t[1][ant1,ant2]
pt.plot_cu_sm_possible(tom.UPS_to_MPMB(W_k,3),R_t,interv_a,interv_b,ant1,ant2)
plt.hold(True)
plt.polar(np.angle(gvgtij),np.abs(gvgtij),'ok',label='gvgt vrai')
plt.polar(np.angle(gvij),np.abs(gvij),'sk',label='gv vrai')
plt.polar(np.angle(gvb),np.abs(gvb),'or',
label='gv(bvrai) vrai b={0}'.format(bvrai))
plt.polar(np.angle(gvbJ),np.abs(gvbJ),'oc',
label='gv(bminJ) b={0}'.format(bminJ))
plt.legend()
plt.hold(False)
plt.figure()
plt.plot(np.linspace(vec_b[0]-0.05,vec_b[-1]+0.05),
np.polyval(np.polyfit(vec_b,vec_br,1),np.linspace(vec_b[0]-0.05,vec_b[-1]+0.05)),
label='fit')
plt.plot(np.linspace(vec_b[0]-0.05,vec_b[-1]+0.05),
np.linspace(vec_b[0]-0.05,vec_b[-1]+0.05),
'k--',label='Id')
plt.plot(vec_b,vec_br,'ko-')
plt.plot(tom.b_true2(R_t,param_MB),tom.b_true2(R_t_vrai,param_MB),'or',label='bvrai')
plt.legend()
plt.xlabel('vec_b')
plt.ylabel('vec_br')
plt.grid(True)
plt.figure()
plt.hold(True)
plt.plot(vec_b,minJ,'*-r',label='b echant')
plt.plot(vec_brs,minJsort,'sb-',label='b recalc')
plt.axvline(x=bvrai,
ymin=0,ymax=1,alpha=.7,linestyle='--',color='k',
lw=3,label='bvrai={0}'.format(bvrai))
plt.axvline(x=bminJ,
ymin=0,ymax=1,alpha=.7,linestyle='--',color='r',
lw=3,label='bminJ={0}'.format(bminJ))
plt.hold(False)
plt.grid(True)
plt.legend()
plt.xlabel('b')
plt.ylabel('Critere')
plt.yscale('log')
plt.title('Critere =f(b) (echelle log)')
plt.figure()
plt.hold(True)
plt.plot(vec_b,minJ,'*-r',label='b echant')
plt.plot(vec_brs,minJsort,'sb-',label='b recalc')
plt.axvline(x=bvrai,
ymin=0,ymax=1,alpha=.7,linestyle='--',color='k',
lw=3,label='bvrai={0}'.format(bvrai))
plt.axvline(x=bminJ,
ymin=0,ymax=1,alpha=.7,linestyle='--',color='r',
lw=3,label='bminJ={0}'.format(bminJ))
plt.hold(False)
plt.grid(True)
plt.legend()
plt.xlabel('b')
plt.ylabel('Critere')
plt.title('Critere =f(b)')
#pdb.set_trace()
def test_estim_ecart_ang_opt_2():
Na = 3
Np = 3
A = 0.95
E = 200
k_z = [0.1,0.15]
#MB
param_MB = mb.param_rvog(Na)
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z=k_z
param_MB.sigma_v=0.0345
param_MB.h_v=10
if param_MB.h_v > np.min(2*np.pi/np.array(k_z)):print 'Attention h_v > Hamb'
param_MB.z_g = 0
param_MB.gammat=np.array([[1,0.7,0.8],[1,1,0.8],[1,1,1]])
#param_MB.gammat=np.array([[1,1,1],[1,1,1],[1,1,1]])
nb_echant=10
data_synt=tom.TomoSARDataSet_synth(param_MB.Na,param_MB)
W_k=data_synt.get_W_k_rect(param_MB,int(nb_echant),param_MB.Na)
hvJ,hvJ2,hvV,\
sigJ,sigJ2,sigV,\
gt_J,gt_J2,gt_V,\
X_minJ,X_minJ2,X_minV,\
minJ,minJ2,minV,\
vec_b = e.estim_ecart_ang_opt2(W_k,param_MB)
return hvJ,hvJ2,hvV,\
sigJ,sigJ2,sigV,\
gt_J,gt_J2,gt_V,\
X_minJ,X_minJ2,X_minV,\
minJ,minJ2,minV,\
vec_b
def test_estim_ecart_ang_tot():
Na = 3
Np = 3
A = 0.95
E = 200
k_z = [0.1,0.15]
#MB
param_MB = mb.param_rvog(Na)
param_MB = mb.rvog_reduction(param_MB,A,E)
param_MB.k_z=k_z
param_MB.sigma_v=0.0345
param_MB.h_v=30
if param_MB.h_v > np.min(2*np.pi/np.array(k_z)):print 'Attention h_v > Hamb'
param_MB.z_g = 0
param_MB.gammat=np.array([[1,0.7,0.8],[1,1,0.8],[1,1,1]])
W_k_vrai_MB = tom.UPS_to_MPMB(param_MB.get_upsilon_gt(),Na)
W_k=W_k_vrai_MB
W_k_norm,_ = tom.normalize_MPMB_PS_Tebald(W_k,param_MB.Na)
R_t,C_t,_ = tom.sm_separation(W_k_norm,Np,param_MB.Na)
interv_a,interv_b,_,_ = tom.search_space_definition(R_t,C_t,Na)
interv_a,interv_b = tom.ground_selection_MB(R_t,interv_a,interv_b)
#choix du a et b
g_sol1 = interv_a[0][0]*R_t[0][0,1]+(1-interv_a[0][0])*R_t[1][0,1]
g_sol2 = interv_a[0][1]*R_t[0][0,1]+(1-interv_a[0][1])*R_t[1][0,1]
g_sol_possible = np.array([g_sol1,g_sol2])
a = interv_a[0][np.argmax(np.abs(g_sol_possible))]
b = (interv_b[0][0]+interv_b[0][1])/2
b_vrai = tom.b_true(R_t,param_MB)
_,Rg,Rv,Cg,Cv=tom.value_R_C(R_t,C_t,a,b)
vec_gt = np.array([param_MB.gammat[0,1],param_MB.gammat[0,2],param_MB.gammat[1,2]])
q = e.estim_ecart_ang_tot(W_k,param_MB)
print 'yo bvrai {0} hv_vrai {1} sigvrai {2}'.format(b_vrai,param_MB.h_v,
param_MB.sigma_v)
return 'vive les petits lapins'
def test_estim_ecart_ang_scal():
Np=3
param=lp.load_param(name='DB_1')
W_k_vrai = tom.UPS_to_MPMB(param.get_upsilon_gt())
data = tom.TomoSARDataSet_synth(param)
Wnoise = data.get_W_k_rect(param,10**6)
#W = W_k_vrai
W = Wnoise
W_norm,_ = tom.normalize_MPMB_PS_Tebald(W,param.Na)
bvrai=tom.b_true_from_param(param)
hv,sigv,vec_gt,bopt = e.estim_ecart_ang_scal(W,param,
critere='J2',
zg_connu=param.z_g,
U0=np.array([param.h_v,param.sigma_v]),
b0=bvrai)
print 'b_vrai {0} b {1}'.format(bvrai,bopt)
print 'hv_vrai {0} hv {1}'.format(param.h_v,hv)
print 'sig_vrai {0} sig {1}'.format(param.sigma_v,sigv)
print 'vec_gt_vrai {0}\n vec_gt {1}'.format(param.get_gtlist(),vec_gt)
def test_V_scal():
"""Test du criètre de vraissemblance V optimisé par rapport à b"""