Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mamunm committed Mar 28, 2024
1 parent 705f412 commit c500397
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 18 deletions.
16 changes: 16 additions & 0 deletions experiments/mu_G/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
import sys

import matplotlib.pyplot as plt
import pandas as pd

sys.path.append(str(Path(__file__).parents[2]))

from src.utils import plot_results

df = pd.read_csv("mu_G_results.csv")
fig = plot_results(df, ["mu", "G_free_energy"], [True, False])
fig.tight_layout()
# plt.savefig("mu_G_results.png")
plt.show()

Binary file modified experiments/mu_G/mu_G_results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions experiments/mu_G/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
import sys

import matplotlib.pyplot as plt
import pandas as pd

sys.path.append(str(Path(__file__).parents[2]))

from src.utils import plot_results

df = pd.read_csv("mu_G_results.csv")
fig = plot_results(df, ["mu", "G_free_energy"], [True, False])
fig.tight_layout()
plt.savefig("mu_G_results.png")
plt.show()

Binary file modified experiments/mu_gap/mu_gap_results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions experiments/mu_gap/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
import sys

import matplotlib.pyplot as plt
import pandas as pd

sys.path.append(str(Path(__file__).parents[2]))

from src.utils import plot_results

df = pd.read_csv("mu_gap_results.csv")
fig = plot_results(df, ["mu", "gap"], [True, False])
fig.tight_layout()
plt.savefig("mu_gap_results.png")
plt.show()

36 changes: 18 additions & 18 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def plot_results(df, targets, target_bool):
fig, ax = plt.subplots(2, 2, figsize=(20,10))
ax = ax.flatten()
global_values = torch.tensor(df[targets].values)
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
global_values[:, mask] *= -1
global_values[:, i] *= -1
global_pareto_idx = is_non_dominated(global_values)
global_pareto_front = global_values[global_pareto_idx]
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
global_pareto_front[:, mask] *= -1
global_pareto_front[:, i] *= -1
ref_point = global_values.min(0)[0]
hv = DominatedPartitioning(ref_point=ref_point, Y=global_values)
global_hv = hv.compute_hypervolume().item()
Expand All @@ -40,9 +40,9 @@ def plot_results(df, targets, target_bool):
for iter_no in range(max_iterations + 1):
current_data = df[df[f'iteration_{acq}'] <= iter_no]
local_values = torch.tensor(current_data[targets].values)
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
local_values[:, mask] *= -1
local_values[:, i] *= -1
hv = DominatedPartitioning(ref_point=ref_point, Y=local_values)
hv_iterations[acq].append(hv.compute_hypervolume().item())
ax[0].plot(np.array(hv_iterations["qEHVI"]) / global_hv * 100, marker='o', label="qEHVI")
Expand All @@ -57,14 +57,14 @@ def plot_results(df, targets, target_bool):
max_iterations = int(df['iteration_qEHVI'].max())
current_data = df[df['iteration_qEHVI'] <= max_iterations]
qEHVI_values = torch.tensor(current_data[targets].values)
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
qEHVI_values[:, mask] *= -1
qEHVI_values[:, i] *= -1
qEHVI_pareto_idx = is_non_dominated(qEHVI_values)
qEHVI_pareto_front = qEHVI_values[qEHVI_pareto_idx]
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
qEHVI_pareto_front[:, mask] *= -1
qEHVI_pareto_front[:, i] *= -1
ax[1].scatter(qEHVI_pareto_front[:, 0], qEHVI_pareto_front[:, 1],
color='red', label="qEHVI Pareto Front", marker="*", s=100)
ax[1].scatter(df[targets[0]], df[targets[1]], alpha=0.3)
Expand All @@ -79,14 +79,14 @@ def plot_results(df, targets, target_bool):
max_iterations = int(df['iteration_qNEHVI'].max())
current_data = df[df['iteration_qNEHVI'] <= max_iterations]
qNEHVI_values = torch.tensor(current_data[targets].values)
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
qNEHVI_values[:, mask] *= -1
qNEHVI_values[:, i] *= -1
qNEHVI_pareto_idx = is_non_dominated(qNEHVI_values)
qNEHVI_pareto_front = qNEHVI_values[qNEHVI_pareto_idx]
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
qNEHVI_pareto_front[:, mask] *= -1
qNEHVI_pareto_front[:, i] *= -1
ax[2].scatter(qNEHVI_pareto_front[:, 0], qNEHVI_pareto_front[:, 1],
color='red', label="qNEHVI Pareto Front", marker="*", s=100)
ax[2].scatter(df[targets[0]], df[targets[1]], alpha=0.3)
Expand All @@ -101,14 +101,14 @@ def plot_results(df, targets, target_bool):
max_iterations = int(df['iteration_random'].max())
current_data = df[df['iteration_random'] <= max_iterations]
random_values = torch.tensor(current_data[targets].values)
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
random_values[:, mask] *= -1
random_values[:, i] *= -1
random_pareto_idx = is_non_dominated(random_values)
random_pareto_front = random_values[random_pareto_idx]
for mask in target_bool:
for i, mask in enumerate(target_bool):
if not mask:
random_pareto_front[:, mask] *= -1
random_pareto_front[:, i] *= -1
ax[3].scatter(random_pareto_front[:, 0], random_pareto_front[:, 1],
color='red', label="Random Pareto Front", marker="*", s=100)
ax[3].scatter(df[targets[0]], df[targets[1]], alpha=0.3)
Expand Down

0 comments on commit c500397

Please sign in to comment.