2828import sys
2929import time
3030
31+ from MLC .arduino .protocol import ArduinoUserInterface
3132from MLC .mlc_parameters .mlc_parameters import Config
3233from PyQt5 .QtCore import Qt
3334
@@ -39,7 +40,7 @@ def individual_data(indiv):
3940
4041 config = Config .get_instance ()
4142 artificial_noise = config .getint ('EVALUATOR' , 'artificialnoise' )
42- y_with_noise = y + [random .random () - 0.5 for _ in xrange (SAMPLES )] + artificial_noise * 500
43+ y_with_noise = y + [random .random () / 2 - 0.25 for _ in xrange (SAMPLES )] + artificial_noise * 500
4344
4445 if isinstance (indiv .get_formal (), str ):
4546 formal = indiv .get_formal ().replace ('S0' , 'x' )
@@ -75,21 +76,41 @@ def cost(indiv):
7576
7677def show_best (index , generation , indiv , cost , block = True ):
7778 x , y , y_with_noise , b = individual_data (indiv )
78- cuadratic_error = np .sqrt ((y_with_noise - b )** 2 / (1 + np .absolute (x ** 2 )))
79+ mean_squared_error = np .sqrt ((y_with_noise - b )** 2 / (1 + np .absolute (x ** 2 )))
7980
80- fig = plt .figure ()
8181 # Put figure window on top of all other windows
82+ fig = plt .figure ()
8283 fig .canvas .manager .window .setWindowModality (Qt .ApplicationModal )
84+ fig .canvas .manager .window .setWindowTitle ("Best Individual" )
85+
86+ formal = None
87+ if type (indiv .get_formal ()) == list :
88+ formal = indiv .get_formal ()[0 ]
89+ else :
90+ formal = indiv .get_formal ()
8391
92+ plt .rc ('font' , family = 'serif' )
8493 plt .suptitle ("Generation N#{0} - Individual N#{1}\n "
8594 "Cost: {2}\n Formal: {3}" .format (generation ,
8695 index ,
8796 cost ,
88- indiv .get_formal ()))
97+ formal ),
98+ fontsize = 12 )
99+
89100 plt .subplot (2 , 1 , 1 )
90- plt .plot (x , y , x , y_with_noise , '*' , x , b )
101+ line1 , = plt .plot (x , y , color = 'r' , linewidth = 4 , label = 'Curve without noise' )
102+ line2 , = plt .plot (x , y_with_noise , 'g-.' , linewidth = 2 , label = 'Curve with noise' )
103+ line3 , = plt .plot (x , b , color = 'k' , linewidth = 2 , label = 'Control Law (Individual)' )
104+ plt .ylabel ('Functions' , fontsize = 12 , fontweight = 'bold' )
105+ plt .xlabel ('Samples' , fontsize = 12 , fontweight = 'bold' )
106+ plt .legend (handles = [line1 , line2 , line3 ], loc = 2 )
107+ plt .grid (True )
91108
92109 plt .subplot (2 , 1 , 2 )
93- plt .plot (x , cuadratic_error , '*r' )
110+ plt .plot (x , mean_squared_error , '*r' )
111+ plt .ylabel ('Mean Squared Error' , fontsize = 12 , fontweight = 'bold' )
112+ plt .xlabel ('Samples' , fontsize = 12 , fontweight = 'bold' )
113+ plt .grid (True )
94114 plt .yscale ('log' )
115+
95116 plt .show (block = block )
0 commit comments