Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ramp rate #86

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pvnet/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,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 = {}

Expand All @@ -343,6 +345,18 @@ def _calculate_common_losses(self, y, y_hat):
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
# the mean across the batch?
Expand All @@ -352,6 +366,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,
}
)

Expand Down