def plot_chart(experiment_root_folder, show_drift_times, show_sync_times, loss_function, plotBaseLines=True): envs = read_results_column(experiment_root_folder + RESULT_FILENAME, ENV_ID_COLUMN) labels = read_results_column(experiment_root_folder + RESULT_FILENAME, ENV_LABEL_COLUMN) index = -1 max_y = 0 max_x = 0 colors = ColorUtil().generateDistinctColors(len(envs)) for env in envs: if not plotBaseLines and "nosync" in env: print "skipped: ", env continue index += 1 metric = read_cumulative_error( experiment_root_folder + 'logs/prediction_%s.log' % (envs[index]), loss_function) xpoints, ypoints = metric max_env_x = max(xpoints) max_env_y = max(ypoints) if max_env_x > max_x: max_x = max_env_x if max_env_y > max_y: max_y = max_env_y #color = generate_color(index,len(envs)) color = colors[index] plt.plot(xpoints, ypoints, label=labels[index], color=color) if show_sync_times: plot_sync_times(experiment_root_folder, env, color, (xpoints, ypoints)) plt.xlim(0, max_x) plt.ylim(0, max_y * 1.05) if show_drift_times: plot_drift_times(experiment_root_folder)
def plot_chart(results_root_folder, show_drift_times, show_sync_times): envs=read_results_column(results_root_folder+RESULT_FILENAME,ENV_ID_COLUMN) labels=read_results_column(results_root_folder+RESULT_FILENAME,ENV_LABEL_COLUMN) index=-1 colors = ColorUtil().generateDistinctColors(len(envs)) for env in envs: index+=1 file_name=results_root_folder+'logs/communication_%s.log' % (env) if os.path.isfile(file_name): metric = read_cumulative_communication(file_name, read_number_of_rounds(results_root_folder+SUMMARY_FILENAME)) xpoints, ypoints = metric color = generate_color(index,len(envs)) color = colors[index] # if 'static-SGD' in labels[index]: # color = 'g' # if 'static-Kernel' in labels[index]: # color = 'c' # if 'dynamic-SGD' in labels[index]: # color = 'r' # if 'dynamic-Kernel' in labels[index]: # color = 'm' plt.plot(xpoints, ypoints, label = labels[index], color = color, linewidth=2.0) # if not "communication" in chart: if show_sync_times: plot_sync_times(results_root_folder, env, sync_times_marker, sync_times_size, color, xpoints, ypoints) if show_drift_times: plot_drift_times(results_root_folder)
def plot_chart(experiment_root_folder, show_drift_times, show_sync_times, loss_function): envs = read_results_column(experiment_root_folder + RESULT_FILENAME, ENV_ID_COLUMN) labels = read_results_column(experiment_root_folder + RESULT_FILENAME, ENV_LABEL_COLUMN) index = -1 max_y = 0 max_x = 0 for env in envs: index += 1 metric = read_average_error( experiment_root_folder + 'logs/prediction_%s.log' % (env), loss_function) write_metric(experiment_root_folder, metric) xpoints, ypoints = metric max_env_x = max(xpoints) max_env_y = max(ypoints) if max_env_x > max_x: max_x = max_env_x if max_env_y > max_y: max_y = max_env_y color = generate_color(index, len(envs)) plt.plot(xpoints, ypoints, label=labels[index], color=color) if show_sync_times: plot_sync_times(experiment_root_folder, env, color, (xpoints, ypoints)) plt.xlim(0, max_x) plt.ylim(0, max_y * 1.05) if show_drift_times: plot_drift_times(experiment_root_folder)
def read_metrics(envs, result_filename, predictive_performance_column): result = [] errors = read_results_column(result_filename, predictive_performance_column) communication = read_results_column(result_filename, ENV_COMM_MESSAGE_COLUMN) for i in xrange(len(envs)): result.append((float(communication[i]), float(errors[i]))) print envs print result print errors return result
def plot_baselines_annotation(envs, types, labels, result_file, predictive_performance_column): _, xmax, _, _ = plt.axis() x_annotation_position = 0.9 * xmax for i in xrange(len(envs)): env_type = types[i] if env_type == 'baseline': y = read_results_column(result_file, predictive_performance_column)[i] annotation = read_results_column(result_file, ENV_LABEL_COLUMN)[i] plt.annotate(annotation, xy=(x_annotation_position, y), xytext=(0, 15), textcoords='offset points', ha='right', va='top')
def plot_baselines(types, result_file, predictive_performance_column): baseline_markers = ['--', '-.', '-', ':', '--', '-.', '-', ':'] baseline_color = 'k' marker_index = 0 for i in xrange(len(types)): env_type = types[i] if env_type == 'baseline': marker = baseline_markers[marker_index] marker_index += 1 y = read_results_column(result_file, predictive_performance_column)[i] name = read_results_column(result_file, 1)[i] plt.axhline(y, color=baseline_color, linestyle=marker, label=r'' + name)
def generate(result_root_folder, predictive_performance_column=ENV_ERROR_COLUMN, plotBaseLines=True, loss_function=None): print "Plotting Performance" result_filename = result_root_folder + RESULT_FILENAME envs = read_results_column(result_filename, ENV_ID_COLUMN) labels = read_results_column(result_filename, ENV_LABEL_COLUMN) types = read_results_column(result_filename, ENV_TYPE_COLUMN) _ = read_results_column(result_filename, ENV_PARAM_COLUMN) values = read_metrics(envs, result_filename, predictive_performance_column) #if loss_function != None: # for index in xrange(len(envs)): # cumError = read_cumulative_error(result_root_folder+'logs/prediction_%s.log' % (envs[index]),loss_function) # values[index] = (values[index][0],cumError) # matplotlib.rcParams.update({'font.size': 16}) # matplotlib.rc('xtick', labelsize=12) # matplotlib.rc('ytick', labelsize=12) matplotlib.rcParams.update({'axes.labelsize': 14}) plot_points(values, labels, types, markers_size) if plotBaseLines: plot_baselines(types, result_filename, predictive_performance_column) # set_plot_axes(x_axis, y_axis) #plot_baselines_annotation(envs, types, labels,result_filename,predictive_performance_column) plt.title(title) x_label = "Cumulative Communication" y_label = "Cumulative Error" plt.xlabel(x_label) plt.ylabel(y_label) plt.ylim(-3000, 88000) #plt.legend(loc='upper left') fig = plt.gcf() fig.set_size_inches(*CHART_DIMENSIONS) # plt.savefig(result_root_folder+'charts/performance.%s' % (FILE_FORMAT), # format=FILE_FORMAT, dpi = CHART_DPI, bbox_inches='tight') save_chart(result_root_folder + 'charts/performance.%s' % (FILE_FORMAT)) plt.clf()