-
Notifications
You must be signed in to change notification settings - Fork 1
/
TOPODATA__VISUALiZATION_V1.2.py
2566 lines (2227 loc) · 105 KB
/
TOPODATA__VISUALiZATION_V1.2.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 Thu Nov 5 16:06:46 2015
Copyright (2007-2017) Pierre Baudot, Daniel Bennequin, Jean-Marc Goaillard, Monica Tapia
The terms of the licence GNU GPL is reproduced in the file "COPYING" of INFOTOPO distribution.
This file is part of INFOTOPO.
INFOTOPO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
INFOTOPO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with INFOTOPO. If not, see <http://www.gnu.org/licenses/>.
@author: Pierre Baudot, Daniel Bennequin, Jean-Marc Goaillard, Monica Tapia
GENERAL PHILOSOPHY AND AUTORS REQUEST:
Giving the authorization of free use of this program also gives you the responsibility
of its use: we trust you. Every tool can be used to make things better for all, but also worse.
We ask any users of the present program to use and develop it such that it profits to the
sustainable development of all, societies and environment and avoid development
in selfish interest, conflict involvement, or individual freedom restrictions or survey.
As a Human in the world, please be conscious of what you do, of its consequence on others, and try to make it better.
This tools comes from mathematic and pertain to it, mathematic do not pertain to anybody in particular
and according to its original developments promotes harmony and sustainable developments on short
and long time and space scales, please respect this ancestral tradition, old as humanity, and develop it in this respect.
More information on the practical use and mathematical framework and bibliographic citations:
http://www.biorxiv.org/content/early/2017/07/26/168740
http://www.mdpi.com/1099-4300/17/5/3253
and README file.
Baudot wrote the code and participated to theorems and algorithms, Bennequin participated to the theory and main theorems that the algorithm implement,
Goaillard and Tapia participated to the development of the algorithms and program.
For any requests, questions, improvements, developments (etc.) contact pierre.baudot [at] gmail.com
Friendly ergonomic interface will be developped afterward, sorry, please see the README file and/or contact me for use.
INFOTOPO has been developed since 2007 thanks to grants-fundings-hosting of:
_ Institut de Mathématiques de Jussieu-Paris Rive Gauche (IMJ-PRG) (2006-2010)
_ ISC-PIF (Complex system institute Paris Ile de France) (2007-2013)
_ Max Planck Institute for Mathematic in the Sciences (MPI-MIS, Leipzig) (2013-2015)
_ Inserm Unis 1072 - ERC channelomics (2015-2017)
We thank those public and non-profit scientific organization for their support.
"""
# ************************************************************
# Reading of datafiles (specific of .CSV files or XLS file)
#csvkit manual: http://csvkit.readthedocs.org/en/latest/cli.html
# ************************************************************
import math
from math import *
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.colors import SymLogNorm
import numpy as np
import os
from openpyxl import Workbook
from openpyxl import load_workbook
from tkinter import *
from tkinter.messagebox import *
from tkinter import filedialog
import pickle
import itertools
from operator import itemgetter
from collections import OrderedDict
import networkx as nx
#################################################################
#################################################################
#################################################################
### THE INPUT PARAMETERS OF THE PROGRAM #######################
#################################################################
#################################################################
#################################################################
#in order to use this program read the comments in grey
#Give the path of the file where the .xlsx file and .plk files are
directory_path = os.path.abspath("/home/baudot/LABOMARSEILLE/RESULTAT ANALYSE PCR/ACTUAL RESEARCH/ANALYSE 21RNA MARS/CLUSTER_10_10SHUFFLE/")
#directory_path = os.path.abspath("/home/baudot/LABOMARSEILLE/RESULTAT ANALYSE PCR/ACTUAL RESEARCH/ANALYSE 21RNA MARS/DOPA_n=8_oct2017SHUFFLE/")
#give the name of the .xlsx worksheet on which the data are :
Name_worksheet="DOPA"
# the number of different values that can take each random variable, the resampling scale.
Nb_bins=8
# Nb var is the number n used for the computation of n-tuple information,
# it is the number n of random variable: the total dimension of the data space.
Nb_var=20
# Nb var tot is the total number m of variable used for the computation of n-tuple information
# we have necessarily m>n
Nb_var_tot=20
#Shuffle are making a derangement permutation of all the rows values of the data matrix, rows by rows, and then compute all informations functions on the randomiszed sample
# if you computed shuffles of the data and whish to realize significance test of independence choose True
compute_shuffle = False
# the Shuffle can be made nb_of_shuffle times, with each time computing informations
nb_of_shuffle=17
# p value is the significiativity of the test of independence computed using the shuffles
# p_value=0.05 means 5 percent of the shuffled independent distribution of the Ik values
p_value=0.05
#number of bins in the histograms of info values (between max and min)
resultion_histo=50
##################################################################
# Choose the file .plk to load. By default choose True for all load_results_and false for compute_different_
##################################################################
# add a number in the name of the .plk file to load
# compute_different_m will compute all entropie and mutualinfo for different values of Nb_trials=m (SAMPLE SIZE m)
compute_different_m = False
Nb_of_m = 10 # the number of Nb_trials_max used ranges from Nb_trials_max to int(Nb_trials_max/(Nb_of_m)) with stepps of int(Nb_trials_max/(Nb_of_m))
#Nb_trials =Nb_trials_max- k*int(Nb_trials_max/(Nb_of_m))
#ex: if Nb_of_m=10 and Nb_trials_max=111, the program will run for Nb_trials=111,100,89,78,67,56,45,34,23,12
# compute_different_N will compute all entropie and mutualinfo for a value of Nb_bins=N (GRAINING SIZE N )
# with Nb_bins=number_load+2
compute_different_N = False
Nb_of_N = 17
choose_number_load = False
number_load=0
load_results_MATRIX = False
load_results_ENTROPY = True
load_results_ENTROPY_ORDERED = True
load_results_INFOMUT = True
load_results_ENTROPY_SUM = True
load_results_INFOMUT_ORDERED = True
load_results_INFOMUT_SUM = True
###########################
# Choose the type of data analysis and representation (figure)
###########################
# Computes and display various entropies, means, efficiencies etc...
SHOW_results_ENTROPY = False
# Computes and display various infomut, means, etc...
SHOW_results_INFOMUT = False
# Computes and display cond infomut, cond infomut landscape, etc...
SHOW_results_COND_INFOMUT = False
# Computes and display HISTOGRAMS ENTROPY, ENTROPY landscape, etc...
SHOW_results_ENTROPY_HISTO = False
# Computes and display INFOMUT HISTOGRAMS , INFOMUT landscape, etc...
SHOW_results_INFOMUT_HISTO = False
# Computes and display INFOMUT PATHS, etc...
SHOW_results_INFOMUT_path = False
# Computes and display SCAFFOLDS (RING representation) of mutual info
# currently only for I2 ( pairwise infomut...), Ik to be developped soon
SHOW_results_SCAFOLD = False
# Computes and display INFOMUT-ENTROPY-k landscape (ENERGY VS. ENTROPY) ...
SHOW_results_INFO_entropy_landscape = True
# Computes the mean Ik as a function os the binning graining N and dim k ..
SHOW_results_INFOMUT_Normed_per_bins = False
# Computes the mean Ik as a function os the sample size m and dim k ..
SHOW_results_INFOMUT_Normed_per_samplesize = False
# Reload the information landscapes saved in pkl file
SHOW_results_RELOAD_LANDSCAPES = False
# print data saved in pkl file
SHOW_results_PRINT_PLK_file = False
degree_to_print= 4
variable_x=4 -1
variable_y=12 -1
SHOW_HARD_DISPLAY= False
SHOW_HARD_DISPLAY_medium= False
#display_figure = True
display_figure = True
#matplotlib.use('agg')
#matplotlib.use('svg')
Format_SVG_SAVE_Figure = False
save_results = False
save_landscape_object = True
#save_results = False
#################################################################
### Procedure for saving and loading objects ####################
### Procedure for saving FIGURES ####################
#################################################################
def save_obj(obj, name ):
# with open('obj/'+ name + '.pkl', 'wb') as f:
with open(directory_path + '/' + name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
print('File loaded: ', directory_path + '/' + name + '.pkl')
with open(directory_path + '/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
def save_FIGURE(num_fig2, name, Format_SVG_SAVE_Fig ):
# with open('obj/'+ name + '.pkl', 'wb') as f:
# mng = plt.get_current_fig_manager(num_fig2)
# mng.window.showMaximized(num_fig2)
plt.tight_layout(num_fig2)
if Format_SVG_SAVE_Fig == False:
plt.savefig(os.path.join(directory_path,name), format="png")
if Format_SVG_SAVE_Fig == True:
plt.savefig(os.path.join(directory_path,name), format="svg")
#################################################################
### dialog open file XLS DATA FILE ##############################
#################################################################
root = Tk()
root.filename = filedialog.askopenfilename(initialdir = directory_path,title = "choose your file",filetypes = (("xls files","*.xlsx"),("all files","*.*")))
root.destroy()
workbook_data = load_workbook(root.filename)
########################################################################
### Tools to manipulate WORKBOOK ######################################
# https://openpyxl.readthedocs.org/en/2.3.3/index.html #################
########################################################################
#Name_worksheet="NONDOPA_MONICA_SIMONE"
print(workbook_data.get_sheet_names())
d = workbook_data[Name_worksheet].cell(row = 2, column = 5)
print(d.value)
c = workbook_data[Name_worksheet]['B1':'B239']
print(c)
###############################################################
### procedure for resampling and displaying ##################
### probability distributions ##################
###############################################################
Nb_column=1
for i in range(2,10000):
if workbook_data[Name_worksheet].cell(row = 1, column = i).value == None:
Nb_column=i-2
break
Nb_trials=Nb_column
Nb_trials_max=Nb_trials
# compute_different_m will compute all entropie and mutualinfo for different values of Nb_trials=m (SAMPLE SIZE m)
if compute_different_m == True :
Nb_trials =Nb_trials_max- number_load*int(Nb_trials_max/(Nb_of_m))
print('the number of column (or trials n) is: ', Nb_trials)
#ex: if Nb_of_m=10 and Nb_trials_max=111, the program will run for Nb_trials=111,100,89,78,67,56,45,34,23,12
if compute_different_N == True :
Nb_bins=(number_load+2)
print('the number of bins in the GRAINING is: ', Nb_bins)
#We put the XLSSheet into a numpy matrix nparray #############
# Variables (RNA) are the lines #
# Trials are the columns #
# Matrix_data contains the RAW DATA
# Matrix_data contains the DATA resampled and rescaled
Matrix_data = np.zeros((Nb_var_tot,Nb_trials))
Matrix_data2 = np.zeros((Nb_var_tot,Nb_trials))
# WE PUT ALL THE 0 value to nan #
for col in range(Nb_trials):
for row in range(Nb_var_tot):
if workbook_data[Name_worksheet].cell(row = (row+2), column = (col+2)).value == 0:
Matrix_data[row,col] = np.nan
else:
Matrix_data[row,col] = workbook_data[Name_worksheet].cell(row = (row+2), column = (col+2)).value
Min_matrix = np.nanmin(Matrix_data, axis=1)
Max_matrix = np.nanmax(Matrix_data, axis=1)
Max_matrix = Max_matrix + ((Max_matrix - Min_matrix)/100000)
Ampl_matrix = Max_matrix - Min_matrix
# WE RESCALE ALL MATRICES AND SAMPLE IT into Nb_bins (Parameter N Graining) #
for col in range(Nb_trials):
for row in range(Nb_var_tot):
if np.isnan(Matrix_data[row,col]):
Matrix_data[row,col] = 0
Matrix_data2[row,col] = 0
workbook_data["DOPA_SAMPLED"].cell(row = (row+2), column = (col+2)).value = 0
else:
if Ampl_matrix[row] !=0 :
Matrix_data2[row,col] = int(((Matrix_data[row,col]-Min_matrix[row])*(Nb_bins))/(Ampl_matrix[row]))+1
else:
Matrix_data2[row,col] = 0
workbook_data["DOPA_SAMPLED"].cell(row = (row+2), column = (col+2)).value = Matrix_data2[row,col]
###############################################################
######## SOME FUNCTIONS USEFULLS ##########
### AT ALL ORDERS On SET OF SUBSETS #########
###############################################################
# Fonction factorielle
def factorial(x):
if x < 2:
return 1
else:
return x * factorial(x-1)
# Fonction coeficient binomial (nombre de combinaison de k elements dans [1,..,n])
def binomial(n,k):
return factorial(n)/(factorial(k)*factorial(n-k))
def compute_Ninfomut_cond(Nentropie_input):
# Ninfomut={}
for x,y in Nentropie_input.items():
for k in range(1, len(x)+1):
for subset in itertools.combinations(x, k):
# print(subset)
Ninfomut[x]=Ninfomut.get(x,0)+ ((-1)**(len(subset)+1))*Nentropie_input[subset]
return (Ninfomut)
###############################################################
### AFFICHAGE ET ENREGISTREMENT DES DATA RESAMPLEES ##########
### ET RESCALEES ##################
###############################################################
num_fig=0
workbook_data.save(os.path.join(directory_path,"Sampled_DATA.xlsx"))
#plt.figure(1)
num_fig=num_fig+1
plt.matshow(Matrix_data, cmap='autumn')
if save_results == True:
if Format_SVG_SAVE_Figure == False:
plt.savefig(os.path.join(directory_path,'Matrix_RAW_VALUE'), format="png")
if Format_SVG_SAVE_Figure == True:
plt.savefig(os.path.join(directory_path,'Matrix_RAW_VALUE'), format="svg")
#plt.figure(2)
plt.matshow(Matrix_data2, cmap='autumn')
num_fig=num_fig+1
if save_results == True:
if Format_SVG_SAVE_Figure == False:
plt.savefig(os.path.join(directory_path,'Matrix_RESCALED_VALUE'), format="png")
if Format_SVG_SAVE_Figure == True:
plt.savefig(os.path.join(directory_path,'Matrix_RESCALED_VALUE'), format="svg")
num_fig=num_fig+1
plt.figure(num_fig)
hist, bin_edges = np.histogram(Matrix_data2, bins = Nb_bins,range=(0,Nb_bins+1))
plt.bar(bin_edges[:-1], hist, width = 1)
plt.xlim(min(bin_edges), max(bin_edges))
if display_figure == True:
plt.show()
if save_results == True:
if Format_SVG_SAVE_Figure == False:
plt.savefig(os.path.join(directory_path,'histogram_RESCALED_VALUE'), format="png")
if Format_SVG_SAVE_Figure == True:
plt.savefig(os.path.join(directory_path,'histogram_RESCALED_VALUE'), format="svg")
num_fig=num_fig+1
plt.figure(num_fig)
hist, bin_edges = np.histogram(Matrix_data, bins = 52,range=(0,26))
plt.bar(bin_edges[:-1], hist, width = 0.5)
plt.xlim(min(bin_edges), max(bin_edges))
if display_figure == True:
plt.show()
if save_results == True:
if Format_SVG_SAVE_Figure == False:
plt.savefig(os.path.join(directory_path,'histogram_RAW_VALUE'), format="png")
if Format_SVG_SAVE_Figure == True:
plt.savefig(os.path.join(directory_path,'histogram_RAW_VALUE'), format="svg")
###############################################################
### LOAD SAVED FILE ##################
### ##################
###############################################################
if load_results_MATRIX == True:
name_object= 'Matrix_data2'
if choose_number_load :
name_object= name_object+str(number_load)
Matrix_data2 = load_obj(name_object)
if load_results_ENTROPY == True:
name_object= 'ENTROPY'
if choose_number_load :
name_object= name_object+str(number_load)
Nentropie = load_obj(name_object)
if load_results_ENTROPY_ORDERED == True:
name_object= 'ENTROPY_ORDERED'
if choose_number_load :
name_object= name_object+str(number_load)
Nentropy_per_order_ordered = load_obj(name_object)
if load_results_INFOMUT == True:
name_object= 'INFOMUT'
if choose_number_load :
name_object= name_object+str(number_load)
Ninfomut = load_obj(name_object)
if load_results_ENTROPY_SUM == True:
name_object= 'ENTROPY_SUM'
if choose_number_load :
name_object= name_object+str(number_load)
entropy_sum_order = load_obj(name_object)
if load_results_INFOMUT_ORDERED == True:
name_object= 'INFOMUT_ORDERED'
if choose_number_load :
name_object= name_object+str(number_load)
Ninfomut_per_order_ordered = load_obj(name_object)
name_object= 'INFOMUT_ORDEREDList'
if choose_number_load :
name_object= name_object+str(number_load)
infomut_per_order = load_obj(name_object)
if load_results_INFOMUT_SUM == True:
name_object= 'INFOMUT_SUM'
if choose_number_load :
name_object= name_object+str(number_load)
infomut_sum_order = load_obj(name_object)
if load_results_INFOMUT_SUM == True:
name_object= 'INFOMUT_SUM'
if choose_number_load :
name_object= name_object+str(number_load)
infomut_sum_order = load_obj(name_object)
###############################################################
### LOAD SHUFFLES ##################
### AND SHUFFLE ANALYSIS ##################
###############################################################
'''
if compute_shuffle == True:
for k in range(nb_of_shuffle):
if load_results_MATRIX == True:
name_object= 'Matrix_data2'+str(k)
Matrix_data2 = load_obj(name_object)
if load_results_ENTROPY == True:
name_object= 'ENTROPY'
Nentropie = load_obj(name_object)
if load_results_ENTROPY_ORDERED == True:
name_object= 'ENTROPY_ORDERED'+str(k)
Nentropy_per_order_ordered = load_obj(name_object)
if load_results_INFOMUT == True:
name_object= 'INFOMUT'+str(k)
Ninfomut = load_obj(name_object)
if load_results_ENTROPY_SUM == True:
name_object= 'ENTROPY_SUM'+str(k)
entropy_sum_order = load_obj(name_object)
if load_results_INFOMUT_ORDERED == True:
name_object= 'INFOMUT_ORDERED'+str(k)
Ninfomut_per_order_ordered = load_obj(name_object)
name_object= 'INFOMUT_ORDEREDList'+str(k)
infomut_per_order = load_obj(name_object)
if load_results_INFOMUT_SUM == True:
name_object= 'INFOMUT_SUM'+str(k)
infomut_sum_order = load_obj(name_object)'''
###############################################################
### PRINT infomut_sum_order ##################
### EXAMPLE ##################
###############################################################
#(infomut_sum_order_abs,infotot_absbis) = compute_infomut_sum_order_abs(Ninfomut)
#for x in range(0,(2**Nb_var_tot)-1):
# print('les infos mutuelles à ', x ,'sont:')
# print(Ninfomut_per_order_ordered[x])
#print('la somme des val abs de toutes le infomut est:')
#print(infotot_absbis)
#print('les valeur abs(info mutuelles) sommées par ordre sont:')
#print(infomut_sum_order_abs)
#print('les info mutuelles sommées par ordre sont:')
#print(infomut_sum_order)
#########################################################################
#########################################################################
#########################################################################
#########################################################################
###### GRAPHICS AND DISPLAY ##############################
#########################################################################
#########################################################################
#########################################################################
#########################################################################
# Visualisation Graphique Distribution des valeurs
#########################################################################
#########################################################################
###### JOINT ENTROPIES VARIOUS calculus #########################
###### FIGURE 1 #########################
#########################################################################
#########################################################################
#########################################################################
###### JOINT ENTROPIES Values #########################
#########################################################################
if SHOW_results_ENTROPY == True:
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
if SHOW_HARD_DISPLAY_medium== True:
for x,y in Nentropie.items():
plt.plot(len(x), y, 'ro')
if y>maxordonnee:
maxordonnee=y
if y<minordonnee:
minordonnee=y
# xp = np.linspace(minordonnee-((maxordonnee-minordonnee)*0.03), maxordonnee+((maxordonnee-minordonnee)*0.03), 100)
# plt.plot(len(x), y, 'ro',xp, polyn_fit(xp), '-')
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Entropy')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'DIAGRAM_ENTROPY', Format_SVG_SAVE_Figure )
#########################################################################
###### Sum of Joint-ENtropy Values per degrees n ######################
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in entropy_sum_order.items():
plt.plot(x, y, 'ro',x, y, 'b-')
if y>maxordonnee:
maxordonnee=y
if y<minordonnee:
minordonnee=y
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(bits)')
plt.title('Sum entropy per order')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'DIAGRAM_ENTROPY', Format_SVG_SAVE_Figure )
#########################################################################
###### Average Entropy rate ######################
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in entropy_sum_order.items():
rate=y/x
plt.plot(x, rate, 'ro',x, y, 'b-')
if rate>maxordonnee:
maxordonnee=rate
if rate<minordonnee:
minordonnee=rate
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits/symbols)')
plt.title('Average Entropy Rate')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Average Entropy Rate', Format_SVG_SAVE_Figure )
#########################################################################
########### MEAN ENTROPY ###########
###### Average entropy normalised by Binomial coefficients ###########
########### (MEASURE OF CONTRIBUTION PER ORDER) ###########
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
average_entropy=[]
for x,y in entropy_sum_order.items():
rate=y/binomial(Nb_var,x)
plt.plot(x, rate, linestyle='--', marker='o', color='b')
average_entropy.append(rate)
# plt.plot(x, rate, 'ro',x, y, 'b-')
if rate>maxordonnee:
maxordonnee=rate
if rate<minordonnee:
minordonnee=rate
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits/symbols)')
plt.title('Average entropy normalised by Binomial coef')
plt.grid(True)
print('Average entropy normalised by Binomial coef')
print(average_entropy)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Average entropy normalised by Binomial coef', Format_SVG_SAVE_Figure )
#########################################################################
###### Entropy rate ######################
#########################################################################
#plt.subplot(323)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Nentropie.items():
# rate=y/len(x)
# plt.plot(len(x), rate, 'ro')
# if rate>maxordonnee:
# maxordonnee=rate
# if rate<minordonnee:
# minordonnee=rate
#plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
#plt.ylabel('(Bits/symbols)')
#plt.title('Entropy Rate')
#plt.grid(True)
# Sum of Joint-entropy values per degrees n
# MULTI-INFO
#plt.subplot(324)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Nentropie.items():
# SumH1=0.00
## print 'le code de sequence encours est:', x
# for v in range(0,len(x)):
# Mierda=(x[v],)
# print 'les composantes marg :', x[v]
# print 'lentropy de la marg :', Nentropie[Mierda]
# SumH1=SumH1+Nentropie[Mierda]
# print 'la somme tot des H1 :',SumH1
# print 'lentropy tot de sequence en cours :',y
# multiInfo=SumH1-y
# plt.plot(len(x), multiInfo, 'ro')
# if multiInfo>maxordonnee:
# maxordonnee=multiInfo
# if multiInfo<minordonnee:
# minordonnee=multiInfo
#plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
#plt.ylabel('(bits)')
#plt.title('MultiInfo = sumH(1)-Htot')
#plt.grid(True)
#########################################################################
###### Order Entropy Duality: H(n-k)-H(k) ############
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in entropy_sum_order.items():
dualdiff=entropy_sum_order.get(Nb_var-x+1,0)-y
plt.plot(x, dualdiff, 'ro')
if dualdiff>maxordonnee:
maxordonnee=dualdiff
if dualdiff<minordonnee:
minordonnee=dualdiff
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(bits)')
plt.title('Order Entropy Duality: H(n-k)-H(k)')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Order Entropy Duality: H(n-k)-H(k)', Format_SVG_SAVE_Figure )
#########################################################################
###### AVERAGE MEAN INFORMATION EFFICIENCY ############
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in entropy_sum_order.items():
# Hmax is = nlog(nb_bin) ...
redundancy=1-(y/(binomial(Nb_var,x)*x*math.log(Nb_bins)/math.log(2) ) )
plt.plot(x,redundancy, 'ro')
if redundancy>maxordonnee:
maxordonnee=redundancy
if redundancy<minordonnee:
minordonnee=redundancy
plt.axis([0, Nb_var+1,minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('[0,1]')
plt.title('Mean Efficiency - Redundancy')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Mean Efficiency - Redundancy', Format_SVG_SAVE_Figure )
# INFORMATION EFFICIENCY
#plt.subplot(323)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Nentropie.items():
# Hmax is = nlog(nb_bin) ...
# redundancy=1-(y/(len(x)*math.log(Nb_bins)/math.log(2) ) )
# plt.plot(len(x),redundancy, 'ro')
# if redundancy>maxordonnee:
# maxordonnee=redundancy
# if redundancy<minordonnee:
# minordonnee=redundancy
#plt.axis([0, Nb_var+1,minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
#plt.ylabel('[0,1]')
#plt.title('Efficiency - Redundancy')
#plt.grid(True)
#########################################################################
#########################################################################
###### MUTUAL INFORMATIONS VARIOUS calculus #####################
###### FIGURE 2 #########################
#########################################################################
#########################################################################
#########################################################################
###### MUTUAL INFORMATIONS ############
#########################################################################
if SHOW_results_INFOMUT == True:
num_fig=num_fig+1
plt.figure(num_fig)
if SHOW_HARD_DISPLAY_medium== True:
import matplotlib as mpl
mpl.rcParams['agg.path.chunksize'] = 3000000
maxordonnee=-1000000.00
minordonnee=1000000.00
x_absss = np.array([])
y_absss = np.array([])
for x,y in Ninfomut.items():
if len(x)>0:
# print(len(x))
# print(y)
x_absss=np.append(x_absss,[len(x)])
y_absss=np.append(y_absss,[y])
# plt.plot(len(x), y, 'ro',len(x), y, 'b-',len(x),0,'r-')
if y>maxordonnee:
maxordonnee=y
if y<minordonnee:
minordonnee=y
# plt.plot(x_absss, y_absss, 'ro',len(x), y, 'b-',len(x),0,'r-')
# plt.plot(x_absss, y_absss, 'ro',alpha=(-1.8*x_absss)/(Nb_var-2)+(Nb_var-0.2)/(Nb_var-2))
plt.scatter(x_absss, y_absss, marker= "_", s= 1000)
# print(x_absss)
# print(y_absss)
plt.draw()
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Mutual Information')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'DIAGRAM_INFOMUT', Format_SVG_SAVE_Figure )
#########################################################################
###### SUM OF MUTUAL INFORMATIONS Per degrees ############
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in infomut_sum_order.items():
if x>1:
plt.plot(x, y, 'ro',x, y, 'b-',x, 0, 'r-')
if y>maxordonnee:
maxordonnee=y
if y<minordonnee:
minordonnee=y
plt.axis([1, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Sum Mutual Information per Order')
plt.grid(True)
# print('tamerenslip-2')
# if display_figure == True:
# plt.show(num_fig)
# print('tamerenslip-1')
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Sum Mutual Information per Order', Format_SVG_SAVE_Figure )
#########################################################################
###### Average MUTUAL INFORMATIONS RATE Per degrees ############
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in infomut_sum_order.items():
rate=y/x
if x>0:
plt.plot(x, rate, 'ro',x, y, 'b-',x, 0, 'r-')
if rate>maxordonnee:
maxordonnee=rate
if rate<minordonnee:
minordonnee=rate
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Averaged Mutual Information rate')
plt.grid(True)
print('tamerenslip0')
# if display_figure == True:
# plt.show(num_fig)
# print('tamerenslip1')
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Averaged Mutual Information rate', Format_SVG_SAVE_Figure )
#########################################################################
###### Average MUTUAL INFORMATIONS NORMALISED Per degrees ###########
#########################################################################
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
normed_informut={}
for x,y in infomut_sum_order.items():
rate=y/binomial(Nb_var,x)
normed_informut[x]=y/binomial(Nb_var,x)
if x>0:
plt.plot(x, rate, 'ro',x, y, 'b-',x, 0, 'r-')
if rate>maxordonnee:
maxordonnee=rate
if rate<minordonnee:
minordonnee=rate
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Averaged Mutual Information Normalised by Binomial coef')
plt.grid(True)
plt.show(num_fig)
# if display_figure == True:
# plt.show(num_fig)
# print('tamerenslip')
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Averaged Mutual Information Normalised by Binomial coef', Format_SVG_SAVE_Figure )
save_obj(normed_informut,'normed_informut'+str(Nb_bins))
#########################################################################
###### INFORMATION DISTANCE and n-VOLUME: d= H-I ###########
#########################################################################
# Information distance-pseudovol d= H-I
if SHOW_HARD_DISPLAY== True:
num_fig=num_fig+1
plt.figure(num_fig)
maxordonnee=-1000000.00
minordonnee=1000000.00
for x,y in Ninfomut.items():
dist=Nentropie[x]-Ninfomut[x]
if len(x)>0:
plt.plot(len(x), dist, 'ro',len(x), dist, 'b-',len(x),0,'r-')
if dist>maxordonnee:
maxordonnee=dist
if dist<minordonnee:
minordonnee=dist
plt.axis([0, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
plt.ylabel('(Bits)')
plt.title('Info 2-Distance - n-Volume')
plt.grid(True)
# if display_figure == True:
# plt.show(num_fig)
# else: plt.close(num_fig)
if save_results == True:
save_FIGURE(num_fig, 'Info 2-Distance - n-Volume', Format_SVG_SAVE_Figure )
#plt.show()
#########################################################################
###### VARIOUS KEPT FOR MEMORY ###########
#########################################################################
#plt.subplot(323)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Ninfomut.items():
# if len(x)>1:
# percent=100*math.fabs(y)/infomut_sum_order_abs[len(x)]
# plt.plot(len(x), percent, 'ro')
# if percent>maxordonnee:
# maxordonnee=percent
# if percent<minordonnee:
# minordonnee=percent
#plt.axis([1, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
#plt.ylabel('(%)')
#plt.title('InfoMut(n)/SumInfomutOrder(n)')
#plt.grid(True)
# Calcul de Ninfomut_contrib:
# % de participation de |In| par rapport a la somme de
# toutes les |Ik| (k=<n) avec les mêmes variables internes
#Ninfomut_contrib={}
#for x,y in Ninfomut.items():
# Denominator=0.00
# for w,z in Ninfomut.items():
# test_in=0
# for v in range(0,len(w)):
# if w[v] in x:
# test_in= test_in+0
# else:
# test_in= test_in+1
# if test_in!= 0 :
# Denominator=Denominator
# Ninfomut[x]=Ninfomut.get(x,0)
# I suppose the last lign was not very useful pass?
# else:
# Denominator=Denominator+math.fabs(Ninfomut[w])
# Ninfomut[x]=Ninfomut.get(x,0)+ ((-1)**(len(w)+1))*Nentropie[w]
# if Denominator!=0.00:
# Ninfomut_contrib[x]=math.fabs(Ninfomut[x])/Denominator
#plt.subplot(324)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Ninfomut_contrib.items():
# if len(x)>1:
# plt.plot(len(x), y, 'ro')
# if y>maxordonnee:
# maxordonnee=y
# if y<minordonnee:
# minordonnee=y
#plt.axis([1, Nb_var+1, minordonnee-((maxordonnee-minordonnee)*0.07),maxordonnee+((maxordonnee-minordonnee)*0.07)])
#plt.ylabel('(%)')
#plt.title('abs(InfoMut(n))/Sum_abs(InfomutOrder)(1->n)')
#plt.grid(True)
#plt.subplot(325)
#maxordonnee=-1000000.00
#minordonnee=1000000.00
#for x,y in Ninfomut.items():
# if len(x)>1:
# percent=100*math.fabs(y)/infotot_absbis
# plt.plot(len(x), percent, 'ro')
# if percent>maxordonnee:
# maxordonnee=percent
# if percent<minordonnee:
# minordonnee=percent