-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_approximation.py
More file actions
43 lines (32 loc) · 1.31 KB
/
plot_approximation.py
File metadata and controls
43 lines (32 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd
import matplotlib.pyplot as plt
import sys
# Get the hidden size from command line argument
if len(sys.argv) < 2:
print("Usage: python plot_approximation.py <hidden_size>")
sys.exit(1)
hidden_size = sys.argv[1]
file_path = f'prediction_data_h{hidden_size}.csv'
try:
df = pd.read_csv(file_path)
except FileNotFoundError:
print(f"Error: {file_path} not found. Please ensure the C++ program generated it.")
sys.exit(1)
plt.figure(figsize=(12, 7))
plt.plot(df['x'], df['y_true'], label='True Function', color='black', linestyle='--', linewidth=2)
plt.plot(df['x'], df['y_standard_pred'], label='Standard Model Prediction', alpha=0.8)
plt.plot(df['x'], df['y_optimized_pred'], label='Optimized Model Prediction', alpha=0.8)
plt.plot(df['x'], df['y_openmp_pred'], label='OpenMP Model Prediction', alpha=0.8)
plt.title(f'Neural Model Approximation for Hidden Size: {hidden_size}')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
# --- Save and show the plot ---
try:
plt.savefig('three_models_verification.png', dpi=300) # Save with higher resolution
print("Plot successfully saved as 'three_models_verification.png'")
except Exception as e:
print(f"Error encountered while saving the plot: {e}")
plt.show()
print(f"Approximation plot for hidden size {hidden_size} displayed.")