Added plots thresholds densities
This commit is contained in:
@@ -124,6 +124,9 @@ def get_next_day_profits_for_date(model, data_processor, test_loader, date, ipc,
|
||||
predicted_nrv_profits_cycles = {i: [0, 0] for i in penalties}
|
||||
baseline_profits_cycles = {i: [0, 0] for i in penalties}
|
||||
|
||||
_charge_thresholds = {}
|
||||
_discharge_thresholds = {}
|
||||
|
||||
initial, nrvs, target = predict_NRV(model, date, data_processor, test_loader)
|
||||
|
||||
initial = np.repeat(initial, nrvs.shape[0])
|
||||
@@ -139,6 +142,10 @@ def get_next_day_profits_for_date(model, data_processor, test_loader, date, ipc,
|
||||
|
||||
for penalty in penalties:
|
||||
found_charge_thresholds, found_discharge_thresholds = baseline_policy.get_optimal_thresholds(reconstructed_imbalance_prices, charge_thresholds, discharge_thresholds, penalty)
|
||||
|
||||
_charge_thresholds[penalty] = found_charge_thresholds
|
||||
_discharge_thresholds[penalty] = found_discharge_thresholds
|
||||
|
||||
next_day_charge_threshold = found_charge_thresholds.mean(axis=0)
|
||||
next_day_discharge_threshold = found_discharge_thresholds.mean(axis=0)
|
||||
yesterday_charge_thresholds, yesterday_discharge_thresholds = baseline_policy.get_optimal_thresholds(yesterday_imbalance_prices, charge_thresholds, discharge_thresholds, penalty)
|
||||
@@ -153,23 +160,29 @@ def get_next_day_profits_for_date(model, data_processor, test_loader, date, ipc,
|
||||
baseline_profits_cycles[penalty][0] += yesterday_profit.item()
|
||||
baseline_profits_cycles[penalty][1] += yesterday_charge_cycles.item()
|
||||
|
||||
return predicted_nrv_profits_cycles, baseline_profits_cycles
|
||||
return predicted_nrv_profits_cycles, baseline_profits_cycles, _charge_thresholds, _discharge_thresholds
|
||||
|
||||
def next_day_test_set(model, data_processor, test_loader, ipc, predict_NRV: callable):
|
||||
penalties = [0, 10, 50, 150, 300, 500, 600, 800, 1000, 1500, 2000, 2500]
|
||||
predicted_nrv_profits_cycles = {i: [0, 0] for i in penalties}
|
||||
baseline_profits_cycles = {i: [0, 0] for i in penalties}
|
||||
|
||||
charge_thresholds = {}
|
||||
discharge_thresholds = {}
|
||||
|
||||
# get all dates in test set
|
||||
dates = baseline_policy.test_data["DateTime"].dt.date.unique()
|
||||
|
||||
# dates back to datetime
|
||||
dates = pd.to_datetime(dates)
|
||||
|
||||
for date in tqdm(dates):
|
||||
for date in tqdm(dates[:10]):
|
||||
try:
|
||||
new_predicted_nrv_profits_cycles, new_baseline_profits_cycles = get_next_day_profits_for_date(model, data_processor, test_loader, date, ipc, predict_NRV, penalties)
|
||||
new_predicted_nrv_profits_cycles, new_baseline_profits_cycles, new_charge_thresholds, new_discharge_thresholds = get_next_day_profits_for_date(model, data_processor, test_loader, date, ipc, predict_NRV, penalties)
|
||||
|
||||
charge_thresholds[date] = new_charge_thresholds
|
||||
discharge_thresholds[date] = new_discharge_thresholds
|
||||
|
||||
for penalty in penalties:
|
||||
predicted_nrv_profits_cycles[penalty][0] += new_predicted_nrv_profits_cycles[penalty][0]
|
||||
predicted_nrv_profits_cycles[penalty][1] += new_predicted_nrv_profits_cycles[penalty][1]
|
||||
@@ -179,15 +192,15 @@ def next_day_test_set(model, data_processor, test_loader, ipc, predict_NRV: call
|
||||
|
||||
except Exception as e:
|
||||
# print(f"Error for date {date}")
|
||||
continue
|
||||
raise e
|
||||
|
||||
return predicted_nrv_profits_cycles, baseline_profits_cycles
|
||||
return predicted_nrv_profits_cycles, baseline_profits_cycles, charge_thresholds, discharge_thresholds
|
||||
|
||||
def main():
|
||||
clearml_helper = ClearMLHelper(project_name="Thesis/NrvForecast")
|
||||
task = clearml_helper.get_task(task_name="Policy Test")
|
||||
|
||||
task.execute_remotely(queue_name="default", exit_process=True)
|
||||
# task.execute_remotely(queue_name="default", exit_process=True)
|
||||
|
||||
configuration, model, data_processor, test_loader = load_model(args.task_id)
|
||||
|
||||
@@ -205,7 +218,69 @@ def main():
|
||||
|
||||
ipc = ImbalancePriceCalculator(data_path="")
|
||||
|
||||
predicted_nrv_profits_cycles, baseline_profits_cycles = next_day_test_set(model, data_processor, test_loader, ipc, predict_NRV)
|
||||
predicted_nrv_profits_cycles, baseline_profits_cycles, charge_thresholds, discharge_thresholds = next_day_test_set(model, data_processor, test_loader, ipc, predict_NRV)
|
||||
# the charge_thresholds is a dictionary with date as key. The values of the dictionary is another dictionary with keys as penalties and values as the charge thresholds
|
||||
# create density plot that shows a density plot of the charge thresholds for each penalty (use seaborn displot) (One plot with a different color for each penalty)
|
||||
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
charge_thresholds_for_penalty = {}
|
||||
for d in charge_thresholds.values():
|
||||
for penalty, thresholds in d.items():
|
||||
if penalty not in charge_thresholds_for_penalty:
|
||||
charge_thresholds_for_penalty[penalty] = []
|
||||
charge_thresholds_for_penalty[penalty].extend(thresholds)
|
||||
|
||||
discharge_thresholds_for_penalty = {}
|
||||
for d in discharge_thresholds.values():
|
||||
for penalty, thresholds in d.items():
|
||||
if penalty not in discharge_thresholds_for_penalty:
|
||||
discharge_thresholds_for_penalty[penalty] = []
|
||||
discharge_thresholds_for_penalty[penalty].extend(thresholds)
|
||||
|
||||
### Plot charge thresholds distribution ###
|
||||
data_to_plot = []
|
||||
for penalty, values in charge_thresholds_for_penalty.items():
|
||||
for value in values:
|
||||
data_to_plot.append({'Penalty': penalty, 'Value': value.item()})
|
||||
df = pd.DataFrame(data_to_plot)
|
||||
print(df.head())
|
||||
palette = sns.color_palette("bright", len(charge_thresholds.keys()))
|
||||
fig = sns.displot(data=df, x="Value", hue="Penalty", kind="kde", palette=palette)
|
||||
plt.title('Density of Charge Thresholds by Penalty')
|
||||
plt.xlabel('Charge Threshold')
|
||||
plt.ylabel('Density')
|
||||
plt.legend(title='Penalty')
|
||||
task.get_logger().report_matplotlib_figure(
|
||||
"Policy Results",
|
||||
"Charge Thresholds",
|
||||
iteration=0,
|
||||
figure=fig
|
||||
)
|
||||
plt.close()
|
||||
|
||||
### Plot discharge thresholds distribution ###
|
||||
data_to_plot = []
|
||||
for penalty, values in discharge_thresholds_for_penalty.items():
|
||||
for value in values:
|
||||
data_to_plot.append({'Penalty': penalty, 'Value': value.item()})
|
||||
df = pd.DataFrame(data_to_plot)
|
||||
palette = sns.color_palette("bright", len(discharge_thresholds.keys()))
|
||||
fig = sns.displot(data=df, x="Value", hue="Penalty", kind="kde", palette=palette)
|
||||
plt.title('Density of Charge Thresholds by Penalty')
|
||||
plt.xlabel('Charge Threshold')
|
||||
plt.ylabel('Density')
|
||||
plt.legend(title='Penalty')
|
||||
task.get_logger().report_matplotlib_figure(
|
||||
"Policy Results",
|
||||
"Discharge Thresholds",
|
||||
iteration=0,
|
||||
figure=fig
|
||||
)
|
||||
plt.close()
|
||||
|
||||
|
||||
|
||||
# create dataframe with columns "name", "penalty", "profit", "cycles"
|
||||
df = pd.DataFrame(columns=["name", "penalty", "profit", "cycles"])
|
||||
|
||||
@@ -10,6 +10,6 @@ class ClearMLHelper:
|
||||
Task.ignore_requirements("torchvision")
|
||||
Task.ignore_requirements("tensorboard")
|
||||
task = Task.init(project_name=self.project_name, task_name=task_name, continue_last_task=False)
|
||||
task.set_base_docker(f"docker.io/clearml/pytorch-cuda-gcc:2.0.0-cuda11.7-cudnn8-runtime --env GIT_SSL_NO_VERIFY=true --env CLEARML_AGENT_GIT_USER=VictorMylle --env CLEARML_AGENT_GIT_PASS=Voetballer1" )
|
||||
task.set_base_docker(f"docker.io/clearml/pytorch-cuda-gcc:2.0.0-cuda11.7-cudnn8-runtime")
|
||||
task.set_packages("requirements.txt")
|
||||
return task
|
||||
Reference in New Issue
Block a user