Добавил инфу на графики
This commit is contained in:
23
lab1/gen.py
23
lab1/gen.py
@@ -314,10 +314,11 @@ def plot_generation_snapshot(
|
||||
plt.scatter(
|
||||
current_pop_x,
|
||||
current_pop_f,
|
||||
s=20,
|
||||
alpha=0.9,
|
||||
color="gray",
|
||||
label=f"Популяция поколения {generation}",
|
||||
s=50,
|
||||
alpha=0.8,
|
||||
color="black",
|
||||
label=f"Популяция поколения #{generation + 1}",
|
||||
zorder=10,
|
||||
)
|
||||
|
||||
# Лучшая особь красной точкой
|
||||
@@ -327,12 +328,13 @@ def plot_generation_snapshot(
|
||||
plt.scatter(
|
||||
[current_pop_x[best_idx]],
|
||||
[current_pop_f[best_idx]],
|
||||
s=60,
|
||||
s=100,
|
||||
color="red",
|
||||
marker="o",
|
||||
label=f"Лучшая особь поколения {generation}",
|
||||
label=f"Лучшая особь поколения #{generation + 1}",
|
||||
edgecolors="darkred",
|
||||
linewidth=1,
|
||||
zorder=10,
|
||||
)
|
||||
|
||||
# История лучших по поколениям (до текущего включительно)
|
||||
@@ -343,14 +345,19 @@ def plot_generation_snapshot(
|
||||
history_x_until_now,
|
||||
history_f_until_now,
|
||||
s=15,
|
||||
alpha=0.9,
|
||||
alpha=0.8,
|
||||
color="orange",
|
||||
label="Лучшие предыдущих поколений",
|
||||
zorder=10,
|
||||
)
|
||||
|
||||
plt.xlabel("x")
|
||||
plt.ylabel("f(x)")
|
||||
plt.title(f"Популяция поколения {generation}")
|
||||
plt.title(
|
||||
f"Поколение #{generation + 1}. "
|
||||
f"Лучшая особь: {history_best_f[generation]:.4f}. "
|
||||
f"Среднее значение: {np.mean(history_populations_f[generation]):.4f}"
|
||||
)
|
||||
plt.legend(loc="best")
|
||||
plt.grid(True, alpha=0.3)
|
||||
plt.tight_layout()
|
||||
|
||||
Reference in New Issue
Block a user