intelligent-environments-lab / CityLearn

Official reinforcement learning environment for demand response and load shaping
MIT License
453 stars 165 forks source link

fix: simple change to avoid division by zero in unserved_energy calc #89

Closed callumtilbury closed 9 months ago

callumtilbury commented 9 months ago

Description

Simple fix in the unserved energy cost calculation.

Issue

The problem lies in the normalized_unserved_energy function, in the line:

data.loc[data['power_outage']==0, ('unserved_energy', 'expected_energy')] = (0.0, 0.0)

where the expected_energy is set to 0.0 for when there isn't a power outage.

As a result, when there is NO power outage for a given time series (i.e. data['power_outage'].all() == True), all of data['expected_energy'] gets set to zero, which leads to a division by zero in:

data['unserved_energy'] = data['unserved_energy']/data['expected_energy'].sum()

Changes

Simple fix by only setting the unserved_energy to zero, and leaving the expected_energy as is:

data.loc[data['power_outage']==0, 'unserved_energy'] = 0.0

Screenshots

n/a

Checklist

Additional notes

As discussed on Discord with @kingsleynweye :)