From b0048c1f7fdb0df18d1b1009792943633039003e Mon Sep 17 00:00:00 2001 From: MiZuii Date: Sun, 15 Dec 2024 21:13:42 +0100 Subject: [PATCH] minifix --- measurements/loss_vs_time_plot.py | 74 +++++++++++++++++++++++++++++++ src/config.yaml | 4 +- src/generator/hull_generator.py | 4 +- src/main.py | 5 ++- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 measurements/loss_vs_time_plot.py diff --git a/measurements/loss_vs_time_plot.py b/measurements/loss_vs_time_plot.py new file mode 100644 index 0000000..dc0ec02 --- /dev/null +++ b/measurements/loss_vs_time_plot.py @@ -0,0 +1,74 @@ +import pandas as pd +import matplotlib.pyplot as plt + +def plot_optimization_graph(csv_file_path): + # Load the data from a CSV file, splitting columns by the semicolon delimiter + data = pd.read_csv(csv_file_path, sep=';') + + # Rename the columns for clarity + data.columns = ['source_data', 'config_id', 'out_data', 'time', 'Loss'] + + # Ensure the required columns ('time', 'config_id', 'Loss') are present + required_columns = {'time', 'config_id', 'Loss'} + if not required_columns.issubset(data.columns): + raise ValueError(f"CSV file must contain the following columns: {required_columns}") + + # Create a new column 'OptimizationType' by formatting the 'config_id' column + # Replace underscores with spaces and capitalize each word + data['OptimizationType'] = data['config_id'].str.replace('_', ' ').str.title() + + # Convert 'time' and 'Loss' columns to numeric, coercing errors to NaN + data['time'] = pd.to_numeric(data['time'], errors='coerce') + data['Loss'] = pd.to_numeric(data['Loss'], errors='coerce') + + # Begin plotting with matplotlib + plt.figure(figsize=(10, 6)) # Set the figure size + + # Iterate through each unique optimization type to plot them separately + for opt_type, color in zip(data['OptimizationType'].unique(), ['orange', 'blue', 'green']): + # Filter the data for the current optimization type + subset = data[data['OptimizationType'] == opt_type] + + # Scatter plot for the current optimization type + plt.scatter( + subset['time'], # X-axis: time + subset['Loss'], # Y-axis: loss + label=opt_type, # Legend label + s=100, # Marker size + color=color + ) + + # Calculate mean and variance for each optimization type + mean_loss = subset['Loss'].mean() + + # Plot the mean as a horizontal line + plt.axhline( + y=mean_loss, # Horizontal line at mean loss + color=color, linestyle='solid', linewidth=1, label=f"{opt_type} Mean" + ) + + # Set both axes to a logarithmic scale + plt.xscale('log') + plt.yscale('log') + + # Add titles and labels to the plot + plt.title("Loss vs Time by Optimization Type", fontsize=16) # Plot title + plt.xlabel("Time (log scale)", fontsize=14) # X-axis label + plt.ylabel("Loss (log scale)", fontsize=14) # Y-axis label + + # Add a legend to distinguish optimization types and their statistics, fixed in the top-right corner + plt.legend(fontsize=12, title_fontsize=13, + loc='center left', + bbox_to_anchor=(1, 0.5), + borderaxespad=0.5) + + # Adjust layout for better spacing + plt.tight_layout() + + # Display the plot + plt.show() + +# Example usage +# Replace 'data.csv' with the path to your CSV file +csv_file_path = 'measurements/results_dual_annealing_main.csv' # Update with your actual file path +plot_optimization_graph(csv_file_path) diff --git a/src/config.yaml b/src/config.yaml index 85fc436..f9ab17a 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,5 +1,5 @@ global: - nothing: nothing + generate_hulls: True editor: # initial frame size (the data is normalized to -100, 100 on wider axis) @@ -153,7 +153,7 @@ labels_generator: no_local_search: True global: - generate_greedy_x0: True + generate_greedy_x0: False maxiter: 1500 visit: 4 initial_temp: 7230 diff --git a/src/generator/hull_generator.py b/src/generator/hull_generator.py index d1c7ee3..2f14f87 100644 --- a/src/generator/hull_generator.py +++ b/src/generator/hull_generator.py @@ -743,6 +743,8 @@ def calc_one_hull(hull_name, def parse_solution_to_editor_hull(hulls: dict, state: dict) -> dict: state["hulls_data"]["hulls"] = {} state["hulls_data"]['self_drawn'] = [] + state["hulls_data"]["change"] = {} + state["hulls_data"]["undraw"] = set() for i in hulls.keys(): # state['hulls_data'][i] = { # 'name': hulls[i]['name'], @@ -759,8 +761,6 @@ def parse_solution_to_editor_hull(hulls: dict, state: dict) -> dict: "gathering_radius": hulls[i]["gathering_radius"], "artist": None } - state["hulls_data"]["change"] = {} - state["hulls_data"]["undraw"] = set() state["hulls_data"][hulls[i]["name"]] = dict() state["hulls_data"][hulls[i]["name"]]["hull_line"] = dict() diff --git a/src/main.py b/src/main.py index a659913..5bd4da4 100644 --- a/src/main.py +++ b/src/main.py @@ -157,7 +157,10 @@ def draw_maps(raw_data: Union[str, Experiment], domain_expansion=1.5, closest_points_radius=2) - hulls = calc_hull(normalized_data, 0.1, 20, 20) + if Configuration['global']['generate_hulls']: + hulls = calc_hull(normalized_data, 0.1, 20, 20) + else: + hulls = {} state_dict = parse_solution_to_editor_hull(hulls, state_dict) state_dict["hulls_data"]['line_size'] = 1.0