Adding baseline policy evaluator
This commit is contained in:
@@ -35,10 +35,14 @@ class PolicyEvaluator:
|
|||||||
]
|
]
|
||||||
return imbalance_prices_day["Positive imbalance price"].values
|
return imbalance_prices_day["Positive imbalance price"].values
|
||||||
|
|
||||||
def evaluate_for_date(self, date, idx_samples, test_loader):
|
def evaluate_for_date(
|
||||||
charge_thresholds = np.arange(-100, 250, 25)
|
self,
|
||||||
discharge_thresholds = np.arange(-100, 250, 25)
|
date,
|
||||||
|
idx_samples,
|
||||||
|
test_loader,
|
||||||
|
charge_thresholds=np.arange(-100, 250, 25),
|
||||||
|
discharge_thresholds=np.arange(-100, 250, 25),
|
||||||
|
):
|
||||||
idx = test_loader.dataset.get_idx_for_date(date.date())
|
idx = test_loader.dataset.get_idx_for_date(date.date())
|
||||||
|
|
||||||
print("Evaluated for idx: ", idx)
|
print("Evaluated for idx: ", idx)
|
||||||
@@ -95,7 +99,6 @@ class PolicyEvaluator:
|
|||||||
def evaluate_test_set(self, idx_samples, test_loader):
|
def evaluate_test_set(self, idx_samples, test_loader):
|
||||||
self.profits = []
|
self.profits = []
|
||||||
try:
|
try:
|
||||||
print(self.dates)
|
|
||||||
for date in tqdm(self.dates):
|
for date in tqdm(self.dates):
|
||||||
self.evaluate_for_date(date, idx_samples, test_loader)
|
self.evaluate_for_date(date, idx_samples, test_loader)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
73
src/policies/baselines/BaselinePolicyEvaluator.py
Normal file
73
src/policies/baselines/BaselinePolicyEvaluator.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
from clearml import Task
|
||||||
|
from src.policies.simple_baseline import BaselinePolicy
|
||||||
|
from src.policies.PolicyEvaluator import PolicyEvaluator
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
from tqdm import tqdm
|
||||||
|
import torch
|
||||||
|
|
||||||
|
|
||||||
|
class BaselinePolicyEvaluator(PolicyEvaluator):
|
||||||
|
def __init__(self, baseline_policy: BaselinePolicy, task: Task = None):
|
||||||
|
super(baseline_policy, task)
|
||||||
|
self.dates = baseline_policy.train_data["DateTime"].dt.date.unique()
|
||||||
|
self.dates = pd.to_datetime(self.dates)
|
||||||
|
self.penalties = [0, 100, 300, 500, 800, 1000, 1500]
|
||||||
|
self.profits = []
|
||||||
|
|
||||||
|
def determine_thresholds_for_date(self, date):
|
||||||
|
charge_thresholds = np.arange(-100, 250, 25)
|
||||||
|
discharge_thresholds = np.arange(-100, 250, 25)
|
||||||
|
|
||||||
|
real_imbalance_prices = self.get_imbanlance_prices_for_date(date.date())
|
||||||
|
|
||||||
|
for penalty in self.penalties:
|
||||||
|
found_charge_thresholds, found_discharge_thresholds = (
|
||||||
|
self.baseline_policy.get_optimal_thresholds(
|
||||||
|
torch.tensor([real_imbalance_prices]),
|
||||||
|
charge_thresholds,
|
||||||
|
discharge_thresholds,
|
||||||
|
penalty,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
best_charge_threshold = found_charge_thresholds.item()
|
||||||
|
best_discharge_threshold = found_discharge_thresholds.item()
|
||||||
|
|
||||||
|
simulated_profit, simulated_charge_cycles = self.baseline_policy.simulate(
|
||||||
|
torch.tensor([[real_imbalance_prices]]),
|
||||||
|
torch.tensor([best_charge_threshold]),
|
||||||
|
torch.tensor([best_discharge_threshold]),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.profits.append(
|
||||||
|
[
|
||||||
|
date,
|
||||||
|
penalty,
|
||||||
|
simulated_profit[0][0].item(),
|
||||||
|
simulated_charge_cycles[0][0].item(),
|
||||||
|
best_charge_threshold.item(),
|
||||||
|
best_discharge_threshold.item(),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def determine_best_thresholds(self):
|
||||||
|
self.profits = []
|
||||||
|
try:
|
||||||
|
for date in tqdm(self.dates):
|
||||||
|
self.determine_thresholds_for_date(date)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.profits = pd.DataFrame(
|
||||||
|
self.profits,
|
||||||
|
columns=[
|
||||||
|
"Date",
|
||||||
|
"Penalty",
|
||||||
|
"Profit",
|
||||||
|
"Charge Cycles",
|
||||||
|
"Charge Threshold",
|
||||||
|
"Discharge Threshold",
|
||||||
|
],
|
||||||
|
)
|
||||||
16
src/policies/baselines/global_threshold_baseline.py
Normal file
16
src/policies/baselines/global_threshold_baseline.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from src.utils.clearml import ClearMLHelper
|
||||||
|
|
||||||
|
#### ClearML ####
|
||||||
|
clearml_helper = ClearMLHelper(project_name="Thesis/NrvForecast")
|
||||||
|
task = clearml_helper.get_task(task_name="Global Thresholds Baselien")
|
||||||
|
task.execute_remotely(queue_name="default", exit_process=True)
|
||||||
|
|
||||||
|
from src.policies.baselines.BaselinePolicyEvaluator import BaselinePolicyEvaluator
|
||||||
|
from src.policies.simple_baseline import BaselinePolicy, Battery
|
||||||
|
|
||||||
|
### Policy Evaluator ###
|
||||||
|
battery = Battery(2, 1)
|
||||||
|
baseline_policy = BaselinePolicy(battery, data_path="")
|
||||||
|
policy_evaluator = BaselinePolicyEvaluator(baseline_policy, task)
|
||||||
|
|
||||||
|
policy_evaluator.determine_best_thresholds()
|
||||||
Reference in New Issue
Block a user