Added notebook to sample from predictions and load model
This commit is contained in:
@@ -11,7 +11,9 @@ Eerst literatuur bekijken ofdat probleem al voorkomt
|
||||
- Training data -> 2 tresholds (1 voor charging, 1 voor discharging) (Volledig chargen / dischargen)
|
||||
- 2 Mwh -> 8 kwartieren
|
||||
|
||||
- 1000 generaties voor 1 dag -> 1000 prijzen reconstrueren -> tresholds bepalen (logische tresholds) -> 2 tresholds voor 1 dag en toepassen op volledige test set
|
||||
2 MWh -> 0.25 MW per kwartier -> charge cycle: 4 MWh -> 16 kwartieren iets doen -> dan charge cycle (max 400 per jaar voor later)
|
||||
|
||||
- 1000 generaties voor 1 dag uit test set -> 1000 prijzen reconstrueren -> tresholds bepalen (logische tresholds) -> 2 tresholds voor 1 dag en toepassen op de echte prijzen van de dag
|
||||
|
||||
- [x] Learning rate non autoregressive
|
||||
|
||||
@@ -28,6 +30,38 @@ Eerst literatuur bekijken ofdat probleem al voorkomt
|
||||
|
||||
- [ ] Diffusion vs Variable Selection Network
|
||||
|
||||
- [x] Bid ladder van gisteren
|
||||
- [ ] Plot van reconstucted prices with real bid ladder + bid ladder from yersterday against real reconstructed prices
|
||||
|
||||
|
||||
Presentatie:
|
||||
- Korte motivatie -> op dit moment: veel batterijen op simpele manier zoals onze baseline
|
||||
- Policy per dag afhankelijk van generation model (policy word day ahead vastgelegd)
|
||||
|
||||
~~- NRV -> resultaten van verschillende resultaten (verder werken met autoregresive om te kunnen samplen)
|
||||
-> ook overconfidence tonen van de quantiles (met die histogram)~~
|
||||
|
||||
~~- Quantile regreession + figuur van CDF
|
||||
Resultaten van de autoregression modellen~~
|
||||
|
||||
- Plot van CRPS (kijk teams)
|
||||
|
||||
~~- Prijs reconstructie + momenteel bid ladders geplubliceerd door Elia momenteel. (paar plotjes)~~
|
||||
|
||||
~~- Baseline Policy voor batterij~~
|
||||
|
||||
- (Resultaten van nieuwe methode met samplen)
|
||||
|
||||
~~- Volgende stappen:~~
|
||||
~~3 mogelijkheden:~~
|
||||
~~- bid ladders (niet echt doen)~~
|
||||
~~- Generaties beter van NRV -> quantile regression + overconfidence fixen (+ betere modellen)
|
||||
Diffusion model is er een van en niet probleem van autoregressive~~
|
||||
|
||||
~~- Betere RL modellen (policies)~~
|
||||
|
||||
(mag 20 minuten zijn)
|
||||
|
||||
# Different Model Architectures (For Quantile Regression)
|
||||
## Baseline
|
||||
The baseline just calculates the values for the given quantiles using the training data.
|
||||
|
||||
@@ -10,72 +10,57 @@ Determining 2 thresholds for battery charging and discharging. Charging when the
|
||||
Training data: 01-01-2020 - 31-12-2022
|
||||
Test data: 01-01-2023 - 12-12-2023
|
||||
|
||||
| Charging threshold (€/MWh) | Discharge threshold (€/MWh) | Profit (€) | Charge Cycles |
|
||||
------------------:|---------------------:|---------------:|----------------:|
|
||||
| 150 | 100 | 366406 | 2658 |
|
||||
| 150 | 50 | 366406 | 2658 |
|
||||
| 150 | 0 | 366406 | 2658 |
|
||||
| 150 | 150 | 365999 | 2639 |
|
||||
| 100 | 150 | 364905 | 2306 |
|
||||
| 100 | 100 | 364483 | 2886 |
|
||||
| 100 | 0 | 364376 | 2896 |
|
||||
| 100 | 50 | 364376 | 2896 |
|
||||
| 200 | 150 | 352953 | 2416 |
|
||||
| 200 | 100 | 352953 | 2416 |
|
||||
| 200 | 50 | 352953 | 2416 |
|
||||
| 200 | 0 | 352953 | 2416 |
|
||||
| 200 | 200 | 352811 | 2413 |
|
||||
| 150 | 200 | 350975 | 2243 |
|
||||
| 100 | 200 | 345855 | 1929 |
|
||||
| 50 | 50 | 341569 | 3864 |
|
||||
| 50 | 100 | 341421 | 2357 |
|
||||
| 50 | 0 | 341202 | 3865 |
|
||||
| 200 | 250 | 337567 | 1996 |
|
||||
| 50 | 150 | 330189 | 1815 |
|
||||
| 150 | 250 | 329684 | 1835 |
|
||||
| 200 | 300 | 329343 | 1610 |
|
||||
| 250 | 250 | 323456 | 2089 |
|
||||
| 250 | 0 | 322692 | 2103 |
|
||||
| 250 | 150 | 322692 | 2103 |
|
||||
| 250 | 50 | 322692 | 2103 |
|
||||
| 250 | 100 | 322692 | 2103 |
|
||||
| 250 | 200 | 322692 | 2103 |
|
||||
| 250 | 300 | 321378 | 1685 |
|
||||
| 100 | 250 | 319651 | 1554 |
|
||||
| 150 | 300 | 319089 | 1462 |
|
||||
| 300 | 250 | 314776 | 1752 |
|
||||
| 300 | 50 | 314776 | 1752 |
|
||||
| 300 | 100 | 314776 | 1752 |
|
||||
| 300 | 150 | 314776 | 1752 |
|
||||
| 300 | 200 | 314776 | 1752 |
|
||||
| 300 | 0 | 314776 | 1752 |
|
||||
| 50 | 200 | 313685 | 1476 |
|
||||
| 300 | 300 | 313469 | 1749 |
|
||||
| 100 | 300 | 309773 | 1236 |
|
||||
| 200 | 350 | 306832 | 1341 |
|
||||
| 250 | 350 | 302349 | 1411 |
|
||||
| 150 | 350 | 295917 | 1202 |
|
||||
| 300 | 350 | 290570 | 1466 |
|
||||
| 50 | 250 | 290097 | 1195 |
|
||||
| 350 | 300 | 284856 | 1507 |
|
||||
| 350 | 250 | 284856 | 1507 |
|
||||
| 350 | 150 | 284856 | 1507 |
|
||||
| 350 | 100 | 284856 | 1507 |
|
||||
| 350 | 50 | 284856 | 1507 |
|
||||
| 350 | 0 | 284856 | 1507 |
|
||||
| 350 | 200 | 284856 | 1507 |
|
||||
| 100 | 350 | 284323 | 996 |
|
||||
| 50 | 300 | 280922 | 954 |
|
||||
| 350 | 350 | 279834 | 1496 |
|
||||
| 0 | 150 | 277863 | 1243 |
|
||||
| 0 | 100 | 276435 | 1477 |
|
||||
| 0 | 200 | 270056 | 1080 |
|
||||
| 0 | 50 | 269265 | 1914 |
|
||||
| 50 | 350 | 259569 | 787 |
|
||||
| 0 | 250 | 258282 | 908 |
|
||||
| 0 | 300 | 250679 | 741 |
|
||||
| 0 | 0 | 248357 | 2065 |
|
||||
| 0 | 350 | 233775 | 624 |
|
||||
| | Charge treshold | Discharge treshold | Charging Cost | Discharging Profit | Total Profit | Charge cycles | Mean charging price | Mean discharging price |
|
||||
|---:|------------------:|---------------------:|----------------:|---------------------:|---------------:|----------------:|----------------------:|-------------------------:|
|
||||
| 0 | 150 | 100 | 184072 | 1.03303e+06 | 848962 | 1884.62 | 32.4889 | 332.002 |
|
||||
| 0 | 150 | 0 | 184072 | 1.03303e+06 | 848962 | 1884.62 | 32.4889 | 332.002 |
|
||||
| 0 | 150 | -100 | 184072 | 1.03303e+06 | 848962 | 1884.62 | 32.4889 | 332.002 |
|
||||
| 0 | 150 | -50 | 184072 | 1.03303e+06 | 848962 | 1884.62 | 32.4889 | 332.002 |
|
||||
| 0 | 150 | 50 | 184072 | 1.03303e+06 | 848962 | 1884.62 | 32.4889 | 332.002 |
|
||||
| 0 | 150 | 150 | 182152 | 1.02598e+06 | 843824 | 1860.12 | 32.4889 | 333.447 |
|
||||
| 0 | 200 | 150 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | 100 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | 50 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | 0 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | -50 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | -100 | 248326 | 1.0773e+06 | 828976 | 1695.5 | 42.9038 | 367.058 |
|
||||
| 0 | 200 | 200 | 247560 | 1.07529e+06 | 827727 | 1690 | 42.9038 | 367.44 |
|
||||
| 0 | 150 | 200 | 151145 | 937599 | 786454 | 1514.88 | 32.4889 | 367.44 |
|
||||
| 0 | 100 | -100 | 85591.8 | 865530 | 779938 | 1978.12 | 19.9739 | 283.851 |
|
||||
| 0 | 100 | 50 | 85591.8 | 865530 | 779938 | 1978.12 | 19.9739 | 283.851 |
|
||||
| 0 | 100 | 0 | 85591.8 | 865530 | 779938 | 1978.12 | 19.9739 | 283.851 |
|
||||
| 0 | 100 | -50 | 85591.8 | 865530 | 779938 | 1978.12 | 19.9739 | 283.851 |
|
||||
| 0 | 100 | 100 | 84872.7 | 864043 | 779171 | 1966.62 | 19.9739 | 284.61 |
|
||||
| 0 | 100 | 150 | 63807.1 | 802437 | 738630 | 1502.5 | 19.9739 | 333.447 |
|
||||
| 0 | 50 | 50 | -35789.2 | 689455 | 725244 | 2831 | -9.65396 | 204.943 |
|
||||
| 0 | 50 | -100 | -35776.3 | 688933 | 724710 | 2833.88 | -9.65396 | 204.79 |
|
||||
| 0 | 50 | 0 | -35776.3 | 688933 | 724710 | 2833.88 | -9.65396 | 204.79 |
|
||||
| 0 | 50 | -50 | -35776.3 | 688933 | 724710 | 2833.88 | -9.65396 | 204.79 |
|
||||
| 0 | 100 | 200 | 49469.3 | 721380 | 671911 | 1196.12 | 19.9739 | 367.44 |
|
||||
| 0 | 50 | 100 | -46110.5 | 592694 | 638805 | 1417.5 | -9.65396 | 284.61 |
|
||||
| 0 | 50 | 150 | -45858.6 | 531472 | 577330 | 1007.5 | -9.65396 | 333.447 |
|
||||
| 0 | 50 | 200 | -43738 | 473478 | 517216 | 779.25 | -9.65396 | 367.44 |
|
||||
| 0 | 0 | 100 | -97804.3 | 341072 | 438876 | 761.5 | -73.2011 | 284.61 |
|
||||
| 0 | 0 | 50 | -121468 | 314671 | 436139 | 993.625 | -73.2011 | 204.943 |
|
||||
| 0 | 0 | 150 | -85919 | 341046 | 426964 | 635.75 | -73.2011 | 333.447 |
|
||||
| 0 | 0 | 200 | -75822.2 | 328188 | 404010 | 541.25 | -73.2011 | 367.44 |
|
||||
| 0 | 0 | 0 | -135954 | 259915 | 395869 | 1110.12 | -73.2011 | 146.436 |
|
||||
| 0 | 0 | -100 | -136936 | 251758 | 388694 | 1117.5 | -73.2011 | 145.226 |
|
||||
| 0 | 0 | -50 | -136936 | 251758 | 388694 | 1117.5 | -73.2011 | 145.226 |
|
||||
| 0 | -50 | 150 | -97889.1 | 219525 | 317414 | 409.312 | -127.845 | 333.447 |
|
||||
| 0 | -50 | 100 | -108274 | 208273 | 316548 | 458.312 | -127.845 | 284.61 |
|
||||
| 0 | -50 | 200 | -87698.7 | 223235 | 310933 | 363.625 | -127.845 | 367.44 |
|
||||
| 0 | -50 | 50 | -124664 | 184027 | 308691 | 525.688 | -127.845 | 204.943 |
|
||||
| 0 | -50 | 0 | -131679 | 158118 | 289797 | 551.188 | -127.845 | 146.436 |
|
||||
| 0 | -50 | -50 | -138246 | 126218 | 264464 | 576.5 | -127.845 | 136.356 |
|
||||
| 0 | -50 | -100 | -138429 | 125059 | 263488 | 577.625 | -127.845 | 136.262 |
|
||||
| 0 | -100 | 200 | -76499.7 | 137174 | 213674 | 219.625 | -179.829 | 367.44 |
|
||||
| 0 | -100 | 150 | -82202.7 | 128215 | 210418 | 237.125 | -179.829 | 333.447 |
|
||||
| 0 | -100 | 100 | -86319.5 | 117325 | 203645 | 250.25 | -179.829 | 284.61 |
|
||||
| 0 | -100 | 50 | -94055.9 | 99443.5 | 193499 | 269.875 | -179.829 | 204.943 |
|
||||
| 0 | -100 | 0 | -95713.7 | 87279.5 | 182993 | 274.625 | -179.829 | 146.436 |
|
||||
| 0 | -100 | -50 | -97722.9 | 71560.6 | 169283 | 280.375 | -179.829 | 136.356 |
|
||||
| 0 | -100 | -100 | -101133 | 45851.2 | 146985 | 289.375 | -179.829 | 130.542 |
|
||||
|
||||
## Optimal policy
|
||||
Charge threshold: 150 €/MWh \
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import torch
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
import pandas as pd
|
||||
@@ -29,7 +30,6 @@ class NrvDataset(Dataset):
|
||||
range(len(dataframe) - self.sequence_length - self.predict_sequence_length)
|
||||
)
|
||||
self.valid_indices = sorted(list(total_indices - set(self.samples_to_skip)))
|
||||
print(len(self.valid_indices))
|
||||
|
||||
self.history_features = []
|
||||
if self.data_config.LOAD_HISTORY:
|
||||
@@ -69,7 +69,9 @@ class NrvDataset(Dataset):
|
||||
self.time_feature = None
|
||||
|
||||
self.nrv = torch.tensor(dataframe["nrv"].values).float().reshape(-1)
|
||||
self.datetime = dataframe["datetime"]
|
||||
|
||||
print(dataframe.columns)
|
||||
self.history_features, self.forecast_features = self.preprocess_data(dataframe)
|
||||
|
||||
def skip_samples(self, dataframe):
|
||||
@@ -203,3 +205,6 @@ class NrvDataset(Dataset):
|
||||
return None, torch.stack(targets)
|
||||
|
||||
return torch.stack(features), torch.stack(targets)
|
||||
|
||||
def get_idx_for_date(self, date: datetime.date):
|
||||
return self.datetime[self.datetime.dt.date == date].index[0]
|
||||
File diff suppressed because one or more lines are too long
@@ -187,22 +187,56 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ClearML Task: created new task id=6b50442e1cec4bf9b3bd5a34077b4217\n",
|
||||
"ClearML results page: http://192.168.1.182:8080/projects/2e46d4af6f1e4c399cf9f5aa30bc8795/experiments/6b50442e1cec4bf9b3bd5a34077b4217/output/log\n",
|
||||
"151780\n",
|
||||
"ClearML Task: created new task id=d19c767120a24f97b3231f0e8ac9f2b5\n",
|
||||
"ClearML results page: http://192.168.1.182:8080/projects/2e46d4af6f1e4c399cf9f5aa30bc8795/experiments/d19c767120a24f97b3231f0e8ac9f2b5/output/log\n",
|
||||
"151780\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).\n",
|
||||
"\u0000Exception ignored in: <function _MultiProcessingDataLoaderIter.__del__ at 0x7f37044039a0>\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
" File \"/opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py\", line 1478, in __del__\n",
|
||||
" self._shutdown_workers()\n",
|
||||
" File \"/opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py\", line 1442, in _shutdown_workers\n",
|
||||
" w.join(timeout=_utils.MP_STATUS_CHECK_INTERVAL)\n",
|
||||
" File \"/opt/conda/lib/python3.10/multiprocessing/process.py\", line 149, in join\n",
|
||||
" res = self._popen.wait(timeout)\n",
|
||||
" File \"/opt/conda/lib/python3.10/multiprocessing/popen_fork.py\", line 40, in wait\n",
|
||||
" if not wait([self.sentinel], timeout):\n",
|
||||
" File \"/opt/conda/lib/python3.10/multiprocessing/connection.py\", line 931, in wait\n",
|
||||
" ready = selector.select(timeout)\n",
|
||||
" File \"/opt/conda/lib/python3.10/selectors.py\", line 416, in select\n",
|
||||
" fd_event_list = self._selector.poll(timeout)\n",
|
||||
" File \"/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/signal_handling.py\", line 66, in handler\n",
|
||||
" _error_if_any_worker_fails()\n",
|
||||
"RuntimeError: DataLoader worker (pid 326715) is killed by signal: Bus error. It is possible that dataloader's workers are out of shared memory. Please try to raise your shared memory limit.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"151780\n",
|
||||
"24979\n",
|
||||
"151780\n",
|
||||
"24979\n",
|
||||
"151780\n",
|
||||
"24979\n",
|
||||
"Using get_plot_error\n",
|
||||
"Using get_plot_error\n",
|
||||
"Using get_plot_error\n",
|
||||
"Using get_plot_error\n",
|
||||
"Early stopping triggered\n",
|
||||
"151780\n",
|
||||
"24979\n"
|
||||
@@ -210,7 +244,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"task = clearml_helper.get_task(task_name=\"Autoregressive Non Linear Quantile Regression + Quarter + DoW\")\n",
|
||||
"task = clearml_helper.get_task(task_name=\"Autoregressive Non Linear Quantile Regression + Quarter + DoW + Net\")\n",
|
||||
"data_config = task.connect(data_config, name=\"data_features\")\n",
|
||||
"\n",
|
||||
"#### Hyperparameters ####\n",
|
||||
@@ -227,8 +261,8 @@
|
||||
" quantiles = eval(quantiles)\n",
|
||||
"\n",
|
||||
"model_parameters = {\n",
|
||||
" \"learning_rate\": 0.0001,\n",
|
||||
" \"hidden_size\": 512,\n",
|
||||
" \"learning_rate\": 0.0002,\n",
|
||||
" \"hidden_size\": 1024,\n",
|
||||
" \"num_layers\": 3,\n",
|
||||
" \"dropout\": 0.2,\n",
|
||||
" \"time_feature_embedding\": 2,\n",
|
||||
@@ -256,7 +290,7 @@
|
||||
" [PinballLoss(quantiles), MSELoss(), L1Loss(), CRPSLoss(quantiles)]\n",
|
||||
")\n",
|
||||
"trainer.early_stopping(patience=10)\n",
|
||||
"trainer.plot_every(15)\n",
|
||||
"trainer.plot_every(25)\n",
|
||||
"trainer.train(task=task, epochs=epochs, remotely=False)"
|
||||
]
|
||||
},
|
||||
|
||||
454
src/policies/policy_tester.ipynb
Normal file
454
src/policies/policy_tester.ipynb
Normal file
File diff suppressed because one or more lines are too long
@@ -17,32 +17,18 @@ class Battery:
|
||||
self.power = power
|
||||
self.charge_cycles = 0
|
||||
|
||||
self.charging = False
|
||||
self.discharging = False
|
||||
|
||||
def simulate(self):
|
||||
"""
|
||||
Simulate the battery for one time step (one quarter of an hour)
|
||||
"""
|
||||
if self.charging:
|
||||
return self.charge()
|
||||
elif self.discharging:
|
||||
return self.discharge()
|
||||
return 0
|
||||
|
||||
def discharge(self):
|
||||
"""
|
||||
Discharge the battery by one time step (one quarter of an hour)
|
||||
"""
|
||||
if self.current_charge == 0:
|
||||
return 0
|
||||
self.discharging = True
|
||||
self.current_charge -= self.power / 4
|
||||
|
||||
self.charge_cycles += 1/16
|
||||
|
||||
if self.current_charge <= 0:
|
||||
self.current_charge = 0
|
||||
self.discharging = False
|
||||
self.charge_cycles += 1
|
||||
|
||||
return self.power / 4
|
||||
|
||||
@@ -52,12 +38,12 @@ class Battery:
|
||||
"""
|
||||
if self.current_charge == self.capacity:
|
||||
return 0
|
||||
self.charging = True
|
||||
self.current_charge += self.power / 4
|
||||
|
||||
self.charge_cycles += 1/16
|
||||
|
||||
if self.current_charge >= self.capacity:
|
||||
self.current_charge = self.capacity
|
||||
self.charging = False
|
||||
|
||||
return self.power / 4
|
||||
|
||||
@@ -89,7 +75,7 @@ class BaselinePolicy():
|
||||
imbalance_prices = imbalance_prices.loc[imbalance_prices['DateTime'].dt.year >= 2020]
|
||||
else:
|
||||
imbalance_prices = imbalance_prices.loc[imbalance_prices['DateTime'].dt.year == 2023]
|
||||
imbalance_prices = imbalance_prices.sort_values(by=['DateTime'])
|
||||
imbalance_prices = imbalance_prices.sort_values(by=['DateTime'], ascending=True)
|
||||
return imbalance_prices
|
||||
|
||||
def get_train_score(self, charge_treshold, discharge_treshold):
|
||||
@@ -98,42 +84,53 @@ class BaselinePolicy():
|
||||
def get_test_score(self, charge_treshold, discharge_treshold):
|
||||
return self.get_score(self.test_data, charge_treshold, discharge_treshold)
|
||||
|
||||
# if price is below treshold -> charge battery: total_profit -= charge * price
|
||||
# if price is below charging treshold (cheap charging) -> charge battery: total_profit -= charge * price
|
||||
# if price is above treshold -> discharge battery: total_profit += discharge * price
|
||||
def get_score(self, df, charge_treshold, discharge_treshold):
|
||||
self.battery.reset()
|
||||
total_profit = 0
|
||||
total_charging_cost = 0
|
||||
total_discharging_profit = 0
|
||||
mean_charging_price = 0
|
||||
mean_discharging_price = 0
|
||||
number_of_charges = 0
|
||||
number_of_discharges = 0
|
||||
|
||||
for index, row in df.iterrows():
|
||||
if self.battery.charging:
|
||||
total_profit -= self.battery.simulate() * row['Positive imbalance price']
|
||||
elif self.battery.discharging:
|
||||
total_profit += self.battery.simulate() * row['Positive imbalance price']
|
||||
else:
|
||||
if row['Positive imbalance price'] < charge_treshold:
|
||||
total_profit -= self.battery.charge() * row['Positive imbalance price']
|
||||
elif row['Positive imbalance price'] > discharge_treshold:
|
||||
total_profit += self.battery.discharge() * row['Positive imbalance price']
|
||||
if row['Positive imbalance price'] < charge_treshold:
|
||||
total_charging_cost += self.battery.charge() * row['Positive imbalance price']
|
||||
mean_charging_price += row['Positive imbalance price']
|
||||
number_of_charges += 1
|
||||
elif row['Positive imbalance price'] > discharge_treshold:
|
||||
total_discharging_profit += self.battery.discharge() * row['Positive imbalance price']
|
||||
mean_discharging_price += row['Positive imbalance price']
|
||||
number_of_discharges += 1
|
||||
|
||||
return total_profit, self.battery.charge_cycles
|
||||
return total_charging_cost, total_discharging_profit, self.battery.charge_cycles, mean_charging_price / number_of_charges, mean_discharging_price / number_of_discharges
|
||||
|
||||
def treshold_scores(self, charge_tresholds, discharge_tresholds):
|
||||
df = pd.DataFrame(columns=["Charge treshold", "Discharge treshold", "Total Profit", "Charge cycles"])
|
||||
|
||||
df = pd.DataFrame(columns=["Charge treshold", "Discharge treshold", "Charging Cost", "Discharging Profit", "Total Profit", "Charge cycles", "Mean charging price", "Mean discharging price"])
|
||||
df_test = pd.DataFrame(columns=["Charge treshold", "Discharge treshold", "Charging Cost", "Discharging Profit", "Total Profit", "Charge cycles", "Mean charging price", "Mean discharging price"])
|
||||
for charge_treshold, discharge_treshold in tqdm(itertools.product(charge_tresholds, discharge_tresholds)):
|
||||
total_profit, charge_cycles = self.get_train_score(charge_treshold, discharge_treshold)
|
||||
df = pd.concat([df, pd.DataFrame([[charge_treshold, discharge_treshold, total_profit, charge_cycles]], columns=["Charge treshold", "Discharge treshold", "Total Profit", "Charge cycles"])])
|
||||
total_charging_cost, total_discharge_profit, charge_cycles, mean_charging_price, mean_discharging_price = self.get_train_score(charge_treshold, discharge_treshold)
|
||||
df = pd.concat([df, pd.DataFrame([[charge_treshold, discharge_treshold, total_charging_cost, total_discharge_profit, total_discharge_profit - total_charging_cost, charge_cycles, mean_charging_price, mean_discharging_price]], columns=["Charge treshold", "Discharge treshold", "Charging Cost", "Discharging Profit", "Total Profit", "Charge cycles", "Mean charging price", "Mean discharging price"])])
|
||||
|
||||
total_charging_cost, total_discharge_profit, charge_cycles, mean_charging_price, mean_discharging_price = self.get_test_score(charge_treshold, discharge_treshold)
|
||||
df_test = pd.concat([df_test, pd.DataFrame([[charge_treshold, discharge_treshold, total_charging_cost, total_discharge_profit, total_discharge_profit - total_charging_cost, charge_cycles, mean_charging_price, mean_discharging_price]], columns=["Charge treshold", "Discharge treshold", "Charging Cost", "Discharging Profit", "Total Profit", "Charge cycles", "Mean charging price", "Mean discharging price"])])
|
||||
|
||||
df = df.sort_values(by=['Total Profit'], ascending=False)
|
||||
return df
|
||||
|
||||
return df, df_test
|
||||
|
||||
|
||||
battery = Battery(2, 1)
|
||||
policy = BaselinePolicy(battery)
|
||||
|
||||
# charge_tresholds = [0, 50, 100, 150, 200, 250, 300, 350]
|
||||
# discharge_tresholds = [0, 50, 100, 150, 200, 250, 300, 350]
|
||||
# df = policy.treshold_scores(charge_tresholds, discharge_tresholds)
|
||||
# print(df.to_markdown())
|
||||
charge_tresholds = np.arange(-100, 250, 50)
|
||||
discharge_tresholds = np.arange(-100, 250, 50)
|
||||
|
||||
print(policy.get_test_score(150, 100))
|
||||
df, df_test = policy.treshold_scores(charge_tresholds, discharge_tresholds)
|
||||
print(df.to_markdown())
|
||||
|
||||
print(df_test.to_markdown())
|
||||
|
||||
# print(policy.get_test_score(150, 100))
|
||||
@@ -1,16 +1,12 @@
|
||||
from src.models.lstm_model import LSTMModel, GRUModel
|
||||
from src.models.lstm_model import GRUModel
|
||||
from src.data import DataProcessor, DataConfig
|
||||
from src.trainers.quantile_trainer import AutoRegressiveQuantileTrainer, NonAutoRegressiveQuantileRegression
|
||||
from src.trainers.probabilistic_baseline import ProbabilisticBaselineTrainer
|
||||
from src.trainers.autoregressive_trainer import AutoRegressiveTrainer
|
||||
from src.trainers.quantile_trainer import AutoRegressiveQuantileTrainer
|
||||
from src.trainers.trainer import Trainer
|
||||
from src.utils.clearml import ClearMLHelper
|
||||
from src.models import *
|
||||
from src.losses import *
|
||||
import torch
|
||||
import numpy as np
|
||||
from torch.nn import MSELoss, L1Loss
|
||||
from datetime import datetime
|
||||
import torch.nn as nn
|
||||
from src.models.time_embedding_layer import TimeEmbedding
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,8 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Given lists of quantiles and their corresponding probabilities
|
||||
quantiles = [-0.23013, -0.19831, -0.15217, -0.13654, -0.05726,
|
||||
0.011687, 0.015129, 0.043187, 0.047704]
|
||||
probs = [0.025, 0.05, 0.1, 0.15, 0.5, 0.85, 0.9, 0.95, 0.975]
|
||||
|
||||
@@ -83,8 +83,8 @@ class ImbalancePriceCalculator:
|
||||
fig.add_trace(go.Scatter(x=x_dec_interpolated, y=y_dec_interpolated, mode='lines+markers', name="dec"))
|
||||
fig.update_layout(
|
||||
title='Bid ladder',
|
||||
xaxis_title='Volume',
|
||||
yaxis_title='Price',
|
||||
xaxis_title='Volume [MWh]',
|
||||
yaxis_title='Price [EUR/MWh]',
|
||||
hovermode='x unified'
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user