Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions measurements/loss_vs_time_plot.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions src/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global:
nothing: nothing
generate_hulls: True

editor:
# initial frame size (the data is normalized to -100, 100 on wider axis)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/generator/hull_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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()

Expand Down
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading