Skip to content

Instantly share code, notes, and snippets.

@kmcelwee
Last active January 23, 2020 20:25
Show Gist options
  • Save kmcelwee/47574cb5f38a8f7169bd3ed83306449b to your computer and use it in GitHub Desktop.
Save kmcelwee/47574cb5f38a8f7169bd3ed83306449b to your computer and use it in GitHub Desktop.
from scipy.stats import norm
def peak_likelihood(hist=None,
tomorrow=None, tomorrow_std=None,
two_day=None, two_day_std=None,
three_day=None, three_day_std=None):
'''
Given the predictions and standard deviation of the three-day forecast, in
addition to the highest load so far this month, what is the likelihood that
a sample from tomorrow's distribution will be higher than the other three.
'''
# likelihood that tomorrow is lower than highest so far this month
A = norm(tomorrow, tomorrow_std).cdf(hist)
# likelihood that tomorrow is lower than than the two-day forecast
B = norm(0, 1).cdf(-(tomorrow - two_day) / ((tomorrow_std**2 + two_day_std**2)**.5))
# likelihood that tomorrow is lower than than the three-day forecast
C = norm(0, 1).cdf(-(tomorrow - three_day) / ((tomorrow_std**2 + three_day_std**2)**.5))
# likelihood tomorrow is (not A) AND (not B) AND (not C)
# in other words, what's the likelihood that tomorrow is local peak
return round((1 - A)*(1 - B)*(1 - C)*100, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment