Updated thesis
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -841,9 +841,11 @@ class NonAutoRegressiveQuantileRegression(Trainer):
|
||||
self.data_processor.inverse_transform(samples),
|
||||
)
|
||||
|
||||
samples = samples.unsqueeze(0)
|
||||
samples = self.data_processor.inverse_transform(samples).unsqueeze(0)
|
||||
|
||||
targets = targets.squeeze(-1)
|
||||
targets = targets[0].unsqueeze(0)
|
||||
targets = self.data_processor.inverse_transform(targets)
|
||||
|
||||
samples = samples.to(self.device)
|
||||
|
||||
@@ -851,48 +853,59 @@ class NonAutoRegressiveQuantileRegression(Trainer):
|
||||
|
||||
crps_from_samples_metric.append(crps[0].mean().item())
|
||||
|
||||
task.get_logger().report_scalar(
|
||||
title="CRPS_from_samples",
|
||||
series="test",
|
||||
value=np.mean(crps_from_samples_metric),
|
||||
iteration=epoch,
|
||||
)
|
||||
|
||||
# using the policy evaluator, evaluate the policy with the generated samples
|
||||
if self.policy_evaluator is not None:
|
||||
optimal_penalty, profit, charge_cycles = (
|
||||
self.policy_evaluator.optimize_penalty_for_target_charge_cycles(
|
||||
idx_samples=generated_samples,
|
||||
test_loader=dataloader,
|
||||
initial_penalty=500,
|
||||
target_charge_cycles=283,
|
||||
initial_learning_rate=2,
|
||||
max_iterations=100,
|
||||
tolerance=1,
|
||||
if epoch is not None and task is not None:
|
||||
task.get_logger().report_scalar(
|
||||
title="CRPS_from_samples",
|
||||
series="val",
|
||||
value=np.mean(crps_from_samples_metric),
|
||||
iteration=epoch,
|
||||
)
|
||||
|
||||
# using the policy evaluator, evaluate the policy with the generated samples
|
||||
if self.policy_evaluator is not None and epoch != -1:
|
||||
optimal_penalty, profit, charge_cycles = (
|
||||
self.policy_evaluator.optimize_penalty_for_target_charge_cycles(
|
||||
idx_samples=generated_samples,
|
||||
test_loader=dataloader,
|
||||
initial_penalty=900,
|
||||
target_charge_cycles=58 * 400 / 356,
|
||||
initial_learning_rate=5,
|
||||
max_iterations=100,
|
||||
tolerance=1,
|
||||
iteration=epoch,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
print(
|
||||
f"Optimal Penalty: {optimal_penalty}, Profit: {profit}, Charge Cycles: {charge_cycles}"
|
||||
)
|
||||
print(
|
||||
f"Optimal Penalty: {optimal_penalty}, Profit: {profit}, Charge Cycles: {charge_cycles}"
|
||||
)
|
||||
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Penalty",
|
||||
series="test",
|
||||
value=optimal_penalty,
|
||||
iteration=epoch,
|
||||
)
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Penalty",
|
||||
series="val",
|
||||
value=optimal_penalty,
|
||||
iteration=epoch,
|
||||
)
|
||||
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Profit", series="test", value=profit, iteration=epoch
|
||||
)
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Profit", series="val", value=profit, iteration=epoch
|
||||
)
|
||||
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Charge Cycles",
|
||||
series="test",
|
||||
value=charge_cycles,
|
||||
iteration=epoch,
|
||||
)
|
||||
task.get_logger().report_scalar(
|
||||
title="Optimal Charge Cycles",
|
||||
series="val",
|
||||
value=charge_cycles,
|
||||
iteration=epoch,
|
||||
)
|
||||
|
||||
return (
|
||||
np.mean(crps_from_samples_metric),
|
||||
profit,
|
||||
charge_cycles,
|
||||
optimal_penalty,
|
||||
generated_samples,
|
||||
)
|
||||
|
||||
def plot_quantile_percentages(
|
||||
self,
|
||||
|
||||
@@ -2,9 +2,7 @@ from src.utils.clearml import ClearMLHelper
|
||||
|
||||
#### ClearML ####
|
||||
clearml_helper = ClearMLHelper(project_name="Thesis/NrvForecast")
|
||||
task = clearml_helper.get_task(
|
||||
task_name="AQR: Non-Linear (4 - 512) + Load + Wind + PV + QE + NP"
|
||||
)
|
||||
task = clearml_helper.get_task(task_name="AQR: Linear + All")
|
||||
task.execute_remotely(queue_name="default", exit_process=True)
|
||||
|
||||
from src.policies.PolicyEvaluator import PolicyEvaluator
|
||||
@@ -46,7 +44,7 @@ data_config.NOMINAL_NET_POSITION = True
|
||||
|
||||
data_config = task.connect(data_config, name="data_features")
|
||||
|
||||
data_processor = DataProcessor(data_config, path="", lstm=False)
|
||||
data_processor = DataProcessor(data_config, path="", lstm=True)
|
||||
data_processor.set_batch_size(512)
|
||||
data_processor.set_full_day_skip(False)
|
||||
|
||||
@@ -69,8 +67,8 @@ else:
|
||||
|
||||
model_parameters = {
|
||||
"learning_rate": 0.0001,
|
||||
"hidden_size": 512,
|
||||
"num_layers": 4,
|
||||
"hidden_size": 256,
|
||||
"num_layers": 2,
|
||||
"dropout": 0.2,
|
||||
"time_feature_embedding": 5,
|
||||
}
|
||||
@@ -91,17 +89,17 @@ time_embedding = TimeEmbedding(
|
||||
# dropout=model_parameters["dropout"],
|
||||
# )
|
||||
|
||||
non_linear_model = NonLinearRegression(
|
||||
time_embedding.output_dim(inputDim),
|
||||
len(quantiles),
|
||||
hiddenSize=model_parameters["hidden_size"],
|
||||
numLayers=model_parameters["num_layers"],
|
||||
dropout=model_parameters["dropout"],
|
||||
)
|
||||
# non_linear_model = NonLinearRegression(
|
||||
# time_embedding.output_dim(inputDim),
|
||||
# len(quantiles),
|
||||
# hiddenSize=model_parameters["hidden_size"],
|
||||
# numLayers=model_parameters["num_layers"],
|
||||
# dropout=model_parameters["dropout"],
|
||||
# )
|
||||
|
||||
# linear_model = LinearRegression(time_embedding.output_dim(inputDim), len(quantiles))
|
||||
linear_model = LinearRegression(time_embedding.output_dim(inputDim), len(quantiles))
|
||||
|
||||
model = nn.Sequential(time_embedding, non_linear_model)
|
||||
model = nn.Sequential(time_embedding, linear_model)
|
||||
|
||||
model.output_size = 1
|
||||
optimizer = torch.optim.Adam(model.parameters(), lr=model_parameters["learning_rate"])
|
||||
@@ -128,7 +126,7 @@ trainer.add_metrics_to_track(
|
||||
)
|
||||
trainer.early_stopping(patience=6)
|
||||
trainer.plot_every(4)
|
||||
trainer.train(task=task, epochs=epochs, remotely=False)
|
||||
trainer.train(task=task, epochs=epochs, remotely=True)
|
||||
|
||||
### Policy Evaluation ###
|
||||
idx_samples = trainer.test_set_samples
|
||||
|
||||
@@ -2,151 +2,18 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>DateTime</th>\n",
|
||||
" <th>Quality status</th>\n",
|
||||
" <th>Resolution code</th>\n",
|
||||
" <th>Net regulation volume</th>\n",
|
||||
" <th>System imbalance</th>\n",
|
||||
" <th>Alpha</th>\n",
|
||||
" <th>Marginal incremental price</th>\n",
|
||||
" <th>Marginal decremental price</th>\n",
|
||||
" <th>Strategic reserve price</th>\n",
|
||||
" <th>Positive imbalance price</th>\n",
|
||||
" <th>Negative imbalance price</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>2023-12-12 06:45:00+00:00</td>\n",
|
||||
" <td>Not Validated</td>\n",
|
||||
" <td>PT15M</td>\n",
|
||||
" <td>64.621</td>\n",
|
||||
" <td>-92.402</td>\n",
|
||||
" <td>0.00</td>\n",
|
||||
" <td>153.12</td>\n",
|
||||
" <td>-248.86</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>153.12</td>\n",
|
||||
" <td>153.12</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>2023-12-12 06:30:00+00:00</td>\n",
|
||||
" <td>Not Validated</td>\n",
|
||||
" <td>PT15M</td>\n",
|
||||
" <td>39.672</td>\n",
|
||||
" <td>-73.985</td>\n",
|
||||
" <td>0.00</td>\n",
|
||||
" <td>153.29</td>\n",
|
||||
" <td>-147.29</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>153.29</td>\n",
|
||||
" <td>153.29</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>2023-12-12 06:15:00+00:00</td>\n",
|
||||
" <td>Not Validated</td>\n",
|
||||
" <td>PT15M</td>\n",
|
||||
" <td>80.030</td>\n",
|
||||
" <td>-103.795</td>\n",
|
||||
" <td>0.00</td>\n",
|
||||
" <td>152.00</td>\n",
|
||||
" <td>-90.69</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>152.00</td>\n",
|
||||
" <td>152.00</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>2023-12-12 06:00:00+00:00</td>\n",
|
||||
" <td>Not Validated</td>\n",
|
||||
" <td>PT15M</td>\n",
|
||||
" <td>9.882</td>\n",
|
||||
" <td>10.054</td>\n",
|
||||
" <td>0.00</td>\n",
|
||||
" <td>234.00</td>\n",
|
||||
" <td>-516.96</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>-516.96</td>\n",
|
||||
" <td>-516.96</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>2023-12-12 05:45:00+00:00</td>\n",
|
||||
" <td>Not Validated</td>\n",
|
||||
" <td>PT15M</td>\n",
|
||||
" <td>198.887</td>\n",
|
||||
" <td>-250.889</td>\n",
|
||||
" <td>5.06</td>\n",
|
||||
" <td>234.00</td>\n",
|
||||
" <td>-390.57</td>\n",
|
||||
" <td>NaN</td>\n",
|
||||
" <td>239.06</td>\n",
|
||||
" <td>239.06</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" DateTime Quality status Resolution code \\\n",
|
||||
"0 2023-12-12 06:45:00+00:00 Not Validated PT15M \n",
|
||||
"1 2023-12-12 06:30:00+00:00 Not Validated PT15M \n",
|
||||
"2 2023-12-12 06:15:00+00:00 Not Validated PT15M \n",
|
||||
"3 2023-12-12 06:00:00+00:00 Not Validated PT15M \n",
|
||||
"4 2023-12-12 05:45:00+00:00 Not Validated PT15M \n",
|
||||
"\n",
|
||||
" Net regulation volume System imbalance Alpha Marginal incremental price \\\n",
|
||||
"0 64.621 -92.402 0.00 153.12 \n",
|
||||
"1 39.672 -73.985 0.00 153.29 \n",
|
||||
"2 80.030 -103.795 0.00 152.00 \n",
|
||||
"3 9.882 10.054 0.00 234.00 \n",
|
||||
"4 198.887 -250.889 5.06 234.00 \n",
|
||||
"\n",
|
||||
" Marginal decremental price Strategic reserve price \\\n",
|
||||
"0 -248.86 NaN \n",
|
||||
"1 -147.29 NaN \n",
|
||||
"2 -90.69 NaN \n",
|
||||
"3 -516.96 NaN \n",
|
||||
"4 -390.57 NaN \n",
|
||||
"\n",
|
||||
" Positive imbalance price Negative imbalance price \n",
|
||||
"0 153.12 153.12 \n",
|
||||
"1 153.29 153.29 \n",
|
||||
"2 152.00 152.00 \n",
|
||||
"3 -516.96 -516.96 \n",
|
||||
"4 239.06 239.06 "
|
||||
]
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
"ename": "",
|
||||
"evalue": "",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31mRunning cells with 'Python 3.12.3' requires the ipykernel package.\n",
|
||||
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
|
||||
"\u001b[1;31mCommand: '/opt/homebrew/bin/python3 -m pip install ipykernel -U --user --force-reinstall'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
@@ -160,7 +27,7 @@
|
||||
"# read imbalance prices\n",
|
||||
"imbalance_prices = pd.read_csv('../../data/imbalance_prices.csv', sep=';')\n",
|
||||
"imbalance_prices[\"DateTime\"] = pd.to_datetime(imbalance_prices['DateTime'], utc=True)\n",
|
||||
"imbalance_prices.head()"
|
||||
"imbalance_prices.head()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -170,7 +37,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ipc_1 = ImbalancePriceCalculator(method=1)\n",
|
||||
"ipc_2 = ImbalancePriceCalculator(method=2)"
|
||||
"ipc_2 = ImbalancePriceCalculator(method=2)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -320,7 +187,7 @@
|
||||
" \n",
|
||||
"\n",
|
||||
"print(\"Total error for method 1: \", error_1)\n",
|
||||
"print(\"Total error for method 2: \", error_2)"
|
||||
"print(\"Total error for method 2: \", error_2)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -508,7 +375,7 @@
|
||||
" plt.legend()\n",
|
||||
" # save plt\n",
|
||||
" # plt.savefig(f'../../Result-Reports/imbalance_prices_images/method_1/imbalance_price_reconstruction_{dt.strftime(\"%d-%m-%Y\")}.png', dpi=300)\n",
|
||||
" plt.show()"
|
||||
" plt.show()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -591,7 +458,7 @@
|
||||
"print(\"MAE NRV | Today Bid Ladder:: \", error_2)\n",
|
||||
"\n",
|
||||
"print(\"MAE SI | Yesterday Bid Ladder: \", error_3)\n",
|
||||
"print(\"MAE NRV | Yesterday Bid Ladder: \", error_4)"
|
||||
"print(\"MAE NRV | Yesterday Bid Ladder: \", error_4)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -776,7 +643,7 @@
|
||||
" plt.legend()\n",
|
||||
" # save plt\n",
|
||||
" # plt.savefig(f'../../Result-Reports/imbalance_prices_images/method_1/imbalance_price_reconstruction_{dt.strftime(\"%d-%m-%Y\")}.png', dpi=300)\n",
|
||||
" plt.show()"
|
||||
" plt.show()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -803,7 +670,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.11"
|
||||
"version": "3.undefined.undefined"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -85,7 +85,9 @@ class ImbalancePriceCalculator:
|
||||
|
||||
|
||||
def plot(self, datetime):
|
||||
print(self.bid_ladder.index)
|
||||
row = self.bid_ladder.loc[self.bid_ladder.index == datetime]
|
||||
print(row)
|
||||
dec_bids = row["bid_ladder_dec"].values[0]
|
||||
inc_bids = row["bid_ladder_inc"].values[0]
|
||||
|
||||
@@ -109,6 +111,15 @@ class ImbalancePriceCalculator:
|
||||
hovermode='x unified'
|
||||
)
|
||||
|
||||
# figure size figsize=(10, 6)
|
||||
|
||||
fig.update_layout(
|
||||
autosize=False,
|
||||
width=800,
|
||||
height=600,
|
||||
)
|
||||
|
||||
|
||||
fig.show()
|
||||
|
||||
def get_imbalance_prices_2023_for_date_vectorized(self, date, NRV_predictions_matrix):
|
||||
@@ -178,4 +189,4 @@ def calculate_imbalance_price(SI_PREV, SI, MIP, MDP):
|
||||
imbalance_price[SI > 0] = neg_imbalance_price[SI > 0]
|
||||
imbalance_price[SI == 0] = (pos_imbalance_price[SI == 0] + neg_imbalance_price[SI == 0]) / 2
|
||||
|
||||
return alpha, imbalance_price
|
||||
return alpha, imbalance_price
|
||||
|
||||
Reference in New Issue
Block a user