44import pandas as pd
55from matplotlib import pyplot as plt
66
7- JSON_FP = Path ("." ).absolute ().parent / "tmp" / "experiment_results.json"
7+ JSON_FP = Path ("." ).absolute ().parent / "tmp" / "experiment_results_li.json"
8+ # JSON_FP = Path(".").absolute().parent / "tmp" / "experiment_results.json"
89
910
1011def replace_square_list (sl ):
@@ -27,10 +28,11 @@ def get_data():
2728 result = {
2829 'noise' : data ['config' ]['noise' ],
2930 'line_interrupt' : data ['config' ]['line_interrupt' ],
30- 'act_threshold ' : data ['config' ]['lateral_model' ]['l1_params' ]['act_threshold' ],
31+ 'act_bias ' : round ( data ['config' ]['lateral_model' ]['l1_params' ]['act_threshold' ]- 0.5 , 2 ) ,
3132 'square_factor' : replace_square_list (data ['config' ]['lateral_model' ]['l1_params' ]['square_factor' ]),
3233 'noise_reduction' : data ['noise_reduction' ],
3334 'avg_line_recon_accuracy_meter' : data ['avg_line_recon_accuracy_meter' ],
35+ 'avg_line_recon_accuracy_meter_2' : (data ['avg_line_recon_accuracy_meter' ]- 0.75 )/ 0.25 ,
3436 'recon_accuracy' : data ['recon_accuracy' ],
3537 'recon_recall' : data ['recon_recall' ],
3638 'recon_precision' : data ['recon_precision' ],
@@ -46,24 +48,28 @@ def feature_noise_to_location_noise(feature_noise, round_=False):
4648 result = np .round (result , 2 )
4749 return result
4850
49- def plot_line (data , x_key , x_label , y_key , y_label , z_key , z_label , plot_key , plot_label , x2_func = None , x2_label = None ):
51+ def plot_line (data , x_key , x_label , y_key , y_label , z_key , z_label , plot_key , plot_label , ymin = None ,
52+ x2_func = None , x2_label = None ):
5053
51- fig , axs = plt .subplots (ncols = len (data [plot_key ].unique ()), figsize = (18 , 6 ), dpi = 100 )
54+ fig , axs = plt .subplots (ncols = len (data [plot_key ].unique ()), figsize = (13 , 3 ), dpi = 100 )
5255
53- for ax , pk in zip (axs , data [plot_key ].unique ()):
56+ for ax , pk in zip (axs , sorted ( data [plot_key ].unique () )):
5457 data_ = data [data [plot_key ] == pk ]
5558
5659 z_values = list (data_ [z_key ].unique ())
5760 z_values = sorted (z_values )
5861
5962 for zv in z_values :
6063 z = data_ [data_ [z_key ] == zv ]
61- ax .plot (z [x_key ].values , z [y_key ].values , label = "{} = {}" .format (z_label , zv ))
64+ ax .plot (z [x_key ].values , z [y_key ].values , label = "{}{}" .format (z_label , zv ))
6265
63- ax .set_title ("{} = {}" .format (plot_label , pk ))
66+ ax .set_title ("{}{}" .format (plot_label , pk ))
6467 ax .set_xlabel (x_label )
6568 ax .set_ylabel (y_label )
6669
70+ if ymin is not None :
71+ ax .set_ylim (ymax = 1.0 + 0.02 , ymin = ymin - 0.02 )
72+
6773 if x2_func is not None :
6874 ax2 = ax .twiny ()
6975 ax2 .set_xlim (ax .get_xlim ())
@@ -74,6 +80,7 @@ def plot_line(data, x_key, x_label, y_key, y_label, z_key, z_label, plot_key, pl
7480 ax .legend ()
7581 ax .grid ()
7682
83+ plt .tight_layout ()
7784 plt .show ()
7885
7986
@@ -85,26 +92,31 @@ def plot(data):
8592 # plot noise only
8693 data_1 = data [data ['line_interrupt' ] == 0 ]
8794 plot_line (data_1 , x_key = "noise" , x_label = "Feature Noise" , y_key = "noise_reduction" , y_label = "Noise Reduction Rate" ,
88- z_key = 'act_threshold ' , z_label = 'Act. Threshold ' , plot_key = 'square_factor' , plot_label = 'Square Factor' ,
89- x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
95+ z_key = 'act_bias ' , z_label = 'Act. Bias b = ' , plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' ,
96+ ymin = 0.4 , x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
9097
9198 plot_line (data_1 , x_key = "noise" , x_label = "Feature Noise" , y_key = "recon_recall" , y_label = "Recall" ,
92- z_key = 'act_threshold ' , z_label = 'Act. Threshold ' , plot_key = 'square_factor' , plot_label = 'Square Factor' ,
93- x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
99+ z_key = 'act_bias ' , z_label = 'Act. Bias b = ' , plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' ,
100+ ymin = 0.2 , x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
94101
95102 plot_line (data_1 , x_key = "noise" , x_label = "Feature Noise" , y_key = "recon_precision" , y_label = "Precision" ,
96- z_key = 'act_threshold ' , z_label = 'Act. Threshold ' , plot_key = 'square_factor' , plot_label = 'Square Factor' ,
97- x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
103+ z_key = 'act_bias ' , z_label = 'Act. Bias b = ' , plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' ,
104+ ymin = 0.1 , x2_func = feature_noise_to_location_noise , x2_label = "Spatial Noise" )
98105
99106 # plot line interrupt only
100107 data_1 = data [data ['noise' ] == 0.0 ]
101108 plot_line (data_1 , x_key = "line_interrupt" , x_label = "Line Interrupt" , y_key = "avg_line_recon_accuracy_meter" ,
102- y_label = "Feature Reconstruction Rate" ,
103- z_key = 'act_threshold' , z_label = 'Act. Threshold' , plot_key = 'square_factor' , plot_label = 'Square Factor' )
109+ y_label = "Feature Reconstruction Rate" , z_key = 'act_bias' , z_label = 'Act. Bias b = ' ,
110+ plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' , ymin = 0.0 )
111+ # plot_line(data_1, x_key="line_interrupt", x_label="Line Interrupt", y_key="avg_line_recon_accuracy_meter_2",
112+ # y_label="Feature Reconstruction Rate 2", z_key='act_bias', z_label='Act. Bias b = ',
113+ # plot_key='square_factor', plot_label='Power Factor γ = ', ymin=0.0)
104114 plot_line (data_1 , x_key = "line_interrupt" , x_label = "Line Interrupt" , y_key = "recon_recall" , y_label = "Recall" ,
105- z_key = 'act_threshold' , z_label = 'Act. Threshold' , plot_key = 'square_factor' , plot_label = 'Square Factor' )
115+ z_key = 'act_bias' , z_label = 'Act. Bias b = ' , plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' ,
116+ ymin = 0.5 )
106117 plot_line (data_1 , x_key = "line_interrupt" , x_label = "Line Interrupt" , y_key = "recon_precision" , y_label = "Precision" ,
107- z_key = 'act_threshold' , z_label = 'Act. Threshold' , plot_key = 'square_factor' , plot_label = 'Square Factor' )
118+ z_key = 'act_bias' , z_label = 'Act. Bias b = ' , plot_key = 'square_factor' , plot_label = 'Power Factor γ = ' ,
119+ ymin = 0.6 )
108120
109121
110122if __name__ == '__main__' :
0 commit comments