forked from borea17/Notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot_choiceEpoch.py
More file actions
56 lines (46 loc) · 4.03 KB
/
Copy pathPlot_choiceEpoch.py
File metadata and controls
56 lines (46 loc) · 4.03 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
import numpy as np
import os
# === Font Configuration ===
font_path = "/usr/share/fonts/truetype/latin-modern/LMRoman10-Regular.ttf"
if os.path.exists(font_path):
prop = fm.FontProperties(fname=font_path)
plt.rcParams['font.family'] = prop.get_name()
plt.rcParams['font.size'] = 12
print(f"Using font: {prop.get_name()}")
else:
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.size'] = 12
print("Latin Modern Roman not found; using serif")
# === Data ===
steps = np.array([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, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150])
values = np.array([124.398376, 113.38092, 109.316605, 106.428513, 103.468819, 102.870964, 101.736839, 100.781998, 100.061897, 99.8131943, 99.2754669, 98.7917938, 98.1384583, 97.289711, 97.1026154, 96.6268997, 96.4066696, 96.5686417, 96.4910049, 96.2395477, 95.9286499, 95.6955261, 95.6449051, 95.7392807, 95.2529221, 95.2774353, 94.9942017, 95.3434219, 95.2180481, 95.0292816, 95.0391159, 94.7533112, 94.5438766, 94.6415405, 94.4554825, 94.7773056, 94.2029877, 94.2372589, 94.1403656, 94.3619537, 93.6135483, 93.651123, 93.1774826, 93.5091324, 93.4592743, 93.209404, 93.3338928, 93.2930832, 92.9828873, 92.903595, 93.1646347, 92.7620163, 92.8808517, 92.9212112, 92.9085617, 92.9332504, 92.7984009, 92.8603897, 92.6597748, 92.6281433, 92.709343, 92.6758423, 92.6846161, 92.5936661, 92.5417023, 92.4809647, 92.2701797, 92.4530487, 92.2653122, 92.6063309, 92.4805908, 92.293541, 92.4024811, 92.2332382, 92.2823563, 92.2173843, 92.3258896, 92.3851395, 92.1114883, 92.2687378, 92.0264359, 92.3604965, 92.2353745, 91.9741211, 92.0055847, 91.998848, 92.4637527, 91.9562607, 92.0611343, 91.9616013, 91.9653778, 91.9762878, 92.0574417, 91.9262009, 91.8298187, 91.8962326, 91.8986969, 92.1727295, 91.8513184, 91.7544022, 91.9544907, 91.7149658, 91.7689743, 91.9470749, 91.8275375, 91.7881241, 91.5932846, 91.7392426, 91.5721664, 91.8045502, 91.6445084, 91.6565247, 91.6507339, 91.4674454, 91.7379837, 91.8207703, 91.7146149, 91.5017471, 91.5608292, 91.7005463, 91.779686, 91.0041275, 91.0398636, 91.0897217, 91.1834335, 90.9731979, 91.0183411, 90.9784088, 91.0133591, 90.8155975, 90.7282867, 90.8960953, 91.2149582, 90.9112625, 90.9921799, 90.9364395, 90.7375259, 90.8013687, 90.8045654, 90.7888718, 90.9245224, 90.7507401, 90.8995743, 90.8698273, 90.9001312, 90.7203598, 90.8107529, 90.7000122, 90.6829758, 91.0214081])
# === Plot Setup ===
fig, ax = plt.subplots(figsize=(10, 6))
# === Line Plot ===
ax.plot(steps, values, linewidth=1.5, color='black')
# === Vertical Marker at Step 80 ===
ax.axvline(x=80, color='red', linestyle='--', linewidth=2)
# === Styling ===
ax.set_xlabel('Step')
ax.set_ylabel('Loss (NLL + KL)')
ax.grid(True, alpha=0.3, linestyle='-', linewidth=0.5)
ax.set_xlim(0, 150)
# Match the clean, minimal style from your original code
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# === Save and Show ===
plt.tight_layout()
plt.savefig('loss_plot.pdf', format='pdf', bbox_inches='tight')
plt.show()
# === Summary Stats ===
print("Summary Statistics:")
print("-" * 50)
print(f"Initial loss: {values[0]:.4f}")
print(f"Final loss: {values[-1]:.4f}")
print(f"Minimum loss: {np.min(values):.4f} at step {steps[np.argmin(values)]}")
print(f"Maximum loss: {np.max(values):.4f} at step {steps[np.argmax(values)]}")
print(f"Total reduction: {values[0] - values[-1]:.4f}")
print(f"Mean loss: {np.mean(values):.4f}")
print(f"Standard deviation: {np.std(values):.4f}")