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