Last active
February 28, 2019 20:03
-
-
Save ikatsov/0162520bfea60f04d0d9a2a75f662cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = 24 * 1 # time step is one hour, flash offering for 1 day | |
m = 4 # not more than 4 price updates | |
def logx(x, n): # iterative logarithm function | |
for i in range(0, n): x = math.log(x) if x > 0 else 0 | |
return x | |
def intervals(m, T, scale): # generate a price schedule vector | |
mask = [] | |
for i in range(1, m): | |
mask.extend( np.full(scale * math.ceil(logx(T, m - i)), i - 1) ) | |
return np.append(mask, np.full(T - len(mask), m - 1)) | |
tau = 0 # start time of the current interval | |
p = h_vec[0]['p_opt'] # initial price | |
t_mask = intervals(m, T, 2) | |
h_vec = demand_hypotheses(...) | |
hist_d = [] | |
for t in range(0, T - 1): # simulation loop | |
realized_d = sample_actual_demand(p) | |
hist_d.append(realized_d) | |
if( t_mask[t] != t_mask[t + 1] ): # end of the interval | |
interval_mean_d = np.mean( hist_d[tau : t + 1] ) | |
min_dist = float("inf") | |
for h in h_vec: # search for the best hypothesis | |
dist = abs(interval_mean_d - h['d'](p)) | |
if(dist < min_dist): | |
min_error = error | |
h_opt = h | |
p = h_opt['p_opt'] # set price for the next interval | |
tau = t + 1 # switch to the next interval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment