From 6c65f0ae7275259680c4b27281bcfc3f11d7e804 Mon Sep 17 00:00:00 2001 From: James Fulton Date: Wed, 27 Sep 2023 12:25:27 +0000 Subject: [PATCH 1/3] add ramp rate --- pvnet/models/base_model.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index 74cadd39..fce05952 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -259,6 +259,8 @@ def _calculate_qauntile_loss(self, y_quantiles, y): def _calculate_common_losses(self, y, y_hat): """Calculate losses common to train, test, and val""" + # y (actual values) shape: [batch_size, time horizon] + # y_hat (predicted values) shape: [batch_size, time horizon, quantile] losses = {} @@ -273,6 +275,18 @@ def _calculate_common_losses(self, y, y_hat): # calculate mse, mae with exp weighted loss mse_exp = self.weighted_losses.get_mse_exp(output=y_hat, target=y) mae_exp = self.weighted_losses.get_mae_exp(output=y_hat, target=y) + + if self.use_quantile_regression: + # Take median value for remaining metric calculations + y_hat = self._quantiles_to_prediction(y_hat) + + # Ramp Rate - % of GSP capacity per hour + start_step = 1 + end_step = 3 + interval_hours = (end_step - start_step)/2 + ramp_rate = y[:, end_step] - y[:, start_step] / interval_hours + ramp_rate_hat = y_hat[:, end_step] - y_hat[:, start_step] / interval_hours + ramp_rate_mae = F.l1_loss(ramp_rate_hat, ramp_rate) # TODO: Compute correlation coef using np.corrcoef(tensor with # shape (2, num_timesteps))[0, 1] on each example, and taking @@ -283,6 +297,7 @@ def _calculate_common_losses(self, y, y_hat): "MAE": mae_loss, "MSE_EXP": mse_exp, "MAE_EXP": mae_exp, + "normalised_ramp_rate_MAE_60-120mins": ramp_rate_mae, } ) From 9f7eb154de707d1a103684f5446dbc02819b93dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:32:43 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pvnet/models/base_model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pvnet/models/base_model.py b/pvnet/models/base_model.py index fce05952..a167d43b 100644 --- a/pvnet/models/base_model.py +++ b/pvnet/models/base_model.py @@ -275,18 +275,18 @@ def _calculate_common_losses(self, y, y_hat): # calculate mse, mae with exp weighted loss mse_exp = self.weighted_losses.get_mse_exp(output=y_hat, target=y) mae_exp = self.weighted_losses.get_mae_exp(output=y_hat, target=y) - + if self.use_quantile_regression: # Take median value for remaining metric calculations y_hat = self._quantiles_to_prediction(y_hat) - + # Ramp Rate - % of GSP capacity per hour start_step = 1 end_step = 3 - interval_hours = (end_step - start_step)/2 + interval_hours = (end_step - start_step) / 2 ramp_rate = y[:, end_step] - y[:, start_step] / interval_hours ramp_rate_hat = y_hat[:, end_step] - y_hat[:, start_step] / interval_hours - ramp_rate_mae = F.l1_loss(ramp_rate_hat, ramp_rate) + ramp_rate_mae = F.l1_loss(ramp_rate_hat, ramp_rate) # TODO: Compute correlation coef using np.corrcoef(tensor with # shape (2, num_timesteps))[0, 1] on each example, and taking From 3852d40bef242285f1d28166dc0ad9d542a0ed8c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:27:01 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pvnet/models/multimodal/multimodal.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pvnet/models/multimodal/multimodal.py b/pvnet/models/multimodal/multimodal.py index 8ebe9e09..9b04a52d 100644 --- a/pvnet/models/multimodal/multimodal.py +++ b/pvnet/models/multimodal/multimodal.py @@ -58,22 +58,22 @@ def __init__( """Neural network which combines information from different sources. Notes: - In the args, where it says a module `m` is partially instantiated, it means that a + In the args, where it says a module `m` is partially instantiated, it means that a normal pytorch module will be returned by running `mod = m(**kwargs)`. In this library, - this partial instantiation is generally achieved using partial instantiation via hydra. - However, the arg is still valid as long as `m(**kwargs)` returns a valid pytorch module + this partial instantiation is generally achieved using partial instantiation via hydra. + However, the arg is still valid as long as `m(**kwargs)` returns a valid pytorch module - for example if `m` is a regular function. Args: - output_network: A partially instatiated pytorch Module class used to combine the 1D + output_network: A partially instatiated pytorch Module class used to combine the 1D features to produce the forecast. output_quantiles: A list of float (0.0, 1.0) quantiles to predict values for. If set to None the output is a single value. - nwp_encoder: A partially instatiated pytorch Module class used to encode the NWP data + nwp_encoder: A partially instatiated pytorch Module class used to encode the NWP data from 4D into an 1D feature vector. - sat_encoder: A partially instatiated pytorch Module class used to encode the satellite + sat_encoder: A partially instatiated pytorch Module class used to encode the satellite data from 4D into an 1D feature vector. - pv_encoder: A partially instatiated pytorch Module class used to encode the site-level + pv_encoder: A partially instatiated pytorch Module class used to encode the site-level PV data from 2D into an 1D feature vector. add_image_embedding_channel: Add a channel to the NWP and satellite data with the embedding of the GSP ID. @@ -83,9 +83,9 @@ def __init__( `None`. forecast_minutes: The amount of minutes that should be forecasted. history_minutes: The default amount of historical minutes that are used. - sat_history_minutes: Length of recent observations used for satellite inputs. Defaults + sat_history_minutes: Length of recent observations used for satellite inputs. Defaults to `history_minutes` if not provided. - min_sat_delay_minutes: Minimum delay with respect to t0 of the latest available + min_sat_delay_minutes: Minimum delay with respect to t0 of the latest available satellite image. nwp_forecast_minutes: Period of future NWP forecast data used as input. Defaults to `forecast_minutes` if not provided.