<s> """<STR_LIT>""" <EOL> import json <EOL> import math <EOL> from matplotlib import cm <EOL> from matplotlib . ticker import MaxNLocator <EOL> import matplotlib . pyplot as plt <EOL> from mpl_toolkits . mplot3d import proj3d <EOL> import os <EOL> import sys <EOL> sys . path . append ( os . path . abspath ( os . path . dirname ( os . path . dirname ( __file__ ) ) ) ) <EOL> from utils . data_paths import RESULTS_DIR_PATH <EOL> def main ( ) : <EOL> rmse_file_paths = sys . argv [ <NUM_LIT:1> : ] <EOL> info = get_info ( rmse_file_paths ) <EOL> points = get_points ( rmse_file_paths ) <EOL> graph_all_surfaces ( info , points ) <EOL> plt . show ( ) <EOL> def get_info ( rmse_file_paths ) : <EOL> combined_info_dict = { } <EOL> infos = [ ] <EOL> for rmse_file_path in rmse_file_paths : <EOL> result = Result ( rmse_file_path ) <EOL> infos . append ( result . info ) <EOL> for info in infos : <EOL> for key , value in info . __dict__ . items ( ) : <EOL> if key not in combined_info_dict : <EOL> combined_info_dict [ key ] = [ value ] <EOL> elif value not in combined_info_dict [ key ] : <EOL> combined_info_dict [ key ] . append ( value ) <EOL> for key , value in combined_info_dict . items ( ) : <EOL> if len ( value ) == <NUM_LIT:1> : <EOL> combined_info_dict [ key ] = value [ <NUM_LIT:0> ] <EOL> else : <EOL> value . sort ( ) <EOL> combined_info_dict [ key ] = '<STR_LIT>' . join ( <EOL> [ '<STR_LIT:U+002CU+0020>' . join ( str ( v ) for v in value [ : - <NUM_LIT:1> ] ) , <EOL> str ( value [ - <NUM_LIT:1> ] ) ] <EOL> ) <EOL> return ResultInfo ( combined_info_dict ) <EOL> def get_points ( rmse_file_paths ) : <EOL> points = [ ] <EOL> for rmse_file_path in rmse_file_paths : <EOL> result = Result ( rmse_file_path ) <EOL> with open ( rmse_file_path ) as rmse_file : <EOL> for epoch , line in enumerate ( rmse_file ) : <EOL> points . append ( Point ( epoch = epoch + <NUM_LIT:1> , <EOL> feature = result . info . num_features , <EOL> learn_rate = result . info . learn_rate , <EOL> rmse = float ( line . strip ( ) ) ) ) <EOL> return points <EOL> class Result : <EOL> def __init__ ( self , rmse_file_path ) : <EOL> self . rmse_file_path = rmse_file_path <EOL> self . info_file_path = rmse_file_path . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with open ( self . info_file_path , '<STR_LIT:r>' ) as info_file : <EOL> info_dict = json . load ( info_file ) <EOL> self . info = ResultInfo ( info_dict ) <EOL> def __repr__ ( self ) : <EOL> return self . rmse_file_path <EOL> class ResultInfo : <EOL> def __init__ ( self , info_dict ) : <EOL> self . num_epochs = info_dict [ '<STR_LIT>' ] <EOL> self . num_features = info_dict [ '<STR_LIT>' ] <EOL> self . learn_rate = info_dict [ '<STR_LIT>' ] <EOL> self . train_set_name = info_dict [ '<STR_LIT>' ] <EOL> self . test_set_name = info_dict [ '<STR_LIT>' ] <EOL> class Point : <EOL> def __init__ ( self , epoch , feature , learn_rate , rmse ) : <EOL> self . epoch = epoch <EOL> self . feature = feature <EOL> self . learn_rate = learn_rate <EOL> self . rmse = rmse <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' <EOL> . format ( e = self . epoch , f = self . feature , lr = self . learn_rate , <EOL> r = self . rmse ) ) <EOL> def graph_all_surfaces ( info , points ) : <EOL> figure_e_vs_f , axes_e_vs_f = get_figure_and_axes_for_epoch_vs_feature ( info ) <EOL> figure_e_vs_l , axes_e_vs_l = get_figure_and_axes_for_epoch_vs_learn ( info ) <EOL> figure_f_vs_l , axes_f_vs_l = get_figure_and_axes_for_feature_vs_learn ( info ) <EOL> epochs = [ point . epoch for point in points ] <EOL> features = [ point . feature for point in points ] <EOL> learns = [ point . learn_rate for point in points ] <EOL> rmses = [ point . rmse for point in points ] <EOL> graph_surface ( figure_e_vs_f , axes_e_vs_f , epochs , features , rmses ) <EOL> graph_surface ( figure_e_vs_l , axes_e_vs_l , epochs , learns , rmses ) <EOL> graph_surface ( figure_f_vs_l , axes_f_vs_l , features , learns , rmses ) <EOL> figure_e_vs_f . savefig ( os . path . join ( RESULTS_DIR_PATH , <EOL> '<STR_LIT>' ) ) <EOL> figure_e_vs_l . savefig ( os . path . join ( RESULTS_DIR_PATH , <EOL> '<STR_LIT>' ) ) <EOL> figure_f_vs_l . savefig ( os . path . join ( RESULTS_DIR_PATH , <EOL> '<STR_LIT>' ) ) <EOL> def get_figure_and_axes_for_epoch_vs_feature ( info ) : <EOL> title = ( '<STR_LIT>' <EOL> . format ( train = info . train_set_name , <EOL> test = info . test_set_name , <EOL> lr = info . learn_rate ) ) <EOL> figure = plt . figure ( ) <EOL> figure . canvas . set_window_title ( title ) <EOL> axes = figure . add_subplot ( <NUM_LIT> , projection = '<STR_LIT>' ) <EOL> axes . get_xaxis ( ) . set_major_locator ( MaxNLocator ( integer = True ) ) <EOL> axes . get_yaxis ( ) . set_major_locator ( MaxNLocator ( integer = True ) ) <EOL> axes . set_title ( title ) <EOL> axes . set_xlabel ( '<STR_LIT>' ) <EOL> axes . set_ylabel ( '<STR_LIT>' ) <EOL> axes . set_zlabel ( '<STR_LIT>' ) <EOL> return figure , axes <EOL> def get_figure_and_axes_for_epoch_vs_learn ( info ) : <EOL> title = ( '<STR_LIT>' <EOL> . format ( train = info . train_set_name , <EOL> test = info . test_set_name , <EOL> f = info . num_features ) ) <EOL> figure = plt . figure ( ) <EOL> figure . canvas . set_window_title ( title ) <EOL> axes = figure . add_subplot ( <NUM_LIT> , projection = '<STR_LIT>' ) <EOL> axes . get_xaxis ( ) . set_major_locator ( MaxNLocator ( integer = True ) ) <EOL> axes . set_title ( title ) <EOL> axes . set_xlabel ( '<STR_LIT>' ) <EOL> axes . set_ylabel ( '<STR_LIT>' ) <EOL> axes . set_zlabel ( '<STR_LIT>' ) <EOL> return figure , axes <EOL> def get_figure_and_axes_for_feature_vs_learn ( info ) : <EOL> title = ( '<STR_LIT>' <EOL> . format ( train = info . train_set_name , <EOL> test = info . test_set_name , <EOL> e = info . num_epochs ) ) <EOL> figure = plt . figure ( ) <EOL> figure . canvas . set_window_title ( title ) <EOL> axes = figure . add_subplot ( <NUM_LIT> , projection = '<STR_LIT>' ) <EOL> axes . get_xaxis ( ) . set_major_locator ( MaxNLocator ( integer = True ) ) <EOL> axes . set_title ( title ) <EOL> axes . set_xlabel ( '<STR_LIT>' ) <EOL> axes . set_ylabel ( '<STR_LIT>' ) <EOL> axes . set_zlabel ( '<STR_LIT>' ) <EOL> return figure , axes <EOL> def graph_surface ( figure , axes , xs , ys , rmse_values ) : <EOL> xs , ys , rmse_values = sorted_minima ( xs , ys , rmse_values ) <EOL> min_rmse_value = min ( rmse_values ) <EOL> min_rmse_index = rmse_values . index ( min_rmse_value ) <EOL> min_rmse_x_value = xs [ min_rmse_index ] <EOL> min_rmse_y_value = ys [ min_rmse_index ] <EOL> min_rmse_color = '<STR_LIT>' <EOL> only_one_x_value = len ( set ( xs ) ) == <NUM_LIT:1> <EOL> only_one_y_value = len ( set ( ys ) ) == <NUM_LIT:1> <EOL> if only_one_x_value : <EOL> axes . plot ( xs , ys , rmse_values ) <EOL> axes . set_xlim ( get_one_below_and_one_above ( xs [ <NUM_LIT:0> ] ) ) <EOL> elif only_one_y_value : <EOL> axes . plot ( xs , ys , rmse_values ) <EOL> axes . set_ylim ( get_one_below_and_one_above ( ys [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> axes . set_xlim ( min ( xs ) , max ( xs ) ) <EOL> axes . set_ylim ( min ( ys ) , max ( ys ) ) <EOL> try : <EOL> axes . plot_trisurf ( xs , ys , rmse_values , cmap = cm . CMRmap , linewidth = <NUM_LIT:0> ) <EOL> except ValueError : <EOL> axes . plot ( xs , ys , rmse_values ) <EOL> xlim = axes . get_xlim ( ) <EOL> ylim = axes . get_ylim ( ) <EOL> zlim = axes . get_zlim ( ) <EOL> axes . plot ( [ min_rmse_x_value , min_rmse_x_value ] , <EOL> ylim , <EOL> zs = [ zlim [ <NUM_LIT:0> ] , zlim [ <NUM_LIT:0> ] ] , <EOL> color = min_rmse_color , ls = '<STR_LIT::>' ) <EOL> axes . plot ( xlim , <EOL> [ min_rmse_y_value , min_rmse_y_value ] , <EOL> zs = [ zlim [ <NUM_LIT:0> ] , zlim [ <NUM_LIT:0> ] ] , <EOL> color = min_rmse_color , ls = '<STR_LIT::>' ) <EOL> axes . plot ( [ min_rmse_x_value , min_rmse_x_value ] , <EOL> [ min_rmse_y_value , min_rmse_y_value ] , <EOL> zs = [ zlim [ <NUM_LIT:0> ] , min_rmse_value ] , <EOL> color = min_rmse_color , ls = '<STR_LIT::>' ) <EOL> annotate_point ( figure , axes , <EOL> min_rmse_x_value , min_rmse_y_value , min_rmse_value , <EOL> min_rmse_color ) <EOL> def sorted_minima ( xs , ys , zs ) : <EOL> points = zip ( xs , ys , zs ) <EOL> unique_points = set ( points ) <EOL> minimum_points = [ ] <EOL> for new_point in unique_points : <EOL> for old_index , old_point in enumerate ( minimum_points ) : <EOL> if old_point [ : <NUM_LIT:2> ] == new_point [ : <NUM_LIT:2> ] : <EOL> if new_point [ <NUM_LIT:2> ] < old_point [ <NUM_LIT:2> ] : <EOL> minimum_points [ old_index ] = new_point <EOL> break <EOL> else : <EOL> minimum_points . append ( new_point ) <EOL> sorted_minimum_points = sorted ( minimum_points ) <EOL> xs , ys , zs = zip ( * sorted_minimum_points ) <EOL> return xs , ys , zs <EOL> def get_one_below_and_one_above ( x ) : <EOL> delta = math . pow ( <NUM_LIT:10> , math . floor ( math . log10 ( x ) ) ) <EOL> return x - delta , x + delta <EOL> def annotate_point ( figure , axes , x , y , z , color ) : <EOL> xp1 , yp1 , _ = proj3d . proj_transform ( x , y , z , axes . get_proj ( ) ) <EOL> label = axes . annotate ( <EOL> '<STR_LIT>' . format ( z ) , xy = ( xp1 , yp1 ) , xytext = ( - <NUM_LIT:20> , <NUM_LIT> ) , <EOL> textcoords = '<STR_LIT>' , ha = '<STR_LIT:right>' , va = '<STR_LIT>' , <EOL> bbox = dict ( boxstyle = '<STR_LIT>' , fc = color , alpha = <NUM_LIT:0.5> ) , <EOL> arrowprops = dict ( arrowstyle = '<STR_LIT>' , connectionstyle = '<STR_LIT>' , <EOL> color = color ) ) <EOL> def update_position ( _ ) : <EOL> xp2 , yp2 , _ = proj3d . proj_transform ( x , y , z , axes . get_proj ( ) ) <EOL> label . xy = xp2 , yp2 <EOL> label . update_positions ( figure . canvas . renderer ) <EOL> figure . canvas . draw ( ) <EOL> figure . canvas . mpl_connect ( '<STR_LIT>' , update_position ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
