Spaces:
Runtime error
Runtime error
File size: 1,141 Bytes
3380ee9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
"""Script that generates, pickles and stores posterior data"""
import pickle
import numpy as np
import config as cfg
from scripts.posterior import PosteriorGenerator
np.random.seed(42)
if __name__ == '__main__':
demo_prices = np.concatenate([np.repeat(10,10), np.repeat(7.5,25), np.repeat(11,15)])
possible_prices = np.linspace(0,20,100)
for el in [x/100 for x in range(5,100,5)]:
demo_demands = np.exp(
np.random.normal(
loc=-el*demo_prices+cfg.LATENT_SHAPE,
scale=cfg.LATENT_STDEV,
)
)
ts = PosteriorGenerator(prices=demo_prices, demands=demo_demands)
posterior = ts.calc_posterior(samples=5000)
post_demand_samples = []
for idx in range(len(posterior)):
elas = posterior.get_values("elas")[idx]
shape = posterior.get_values("shape")[idx]
post_demand_sample = np.exp(elas*possible_prices + shape)
post_demand_samples.append(post_demand_sample)
with open(f"assets/precalc_results/posterior_{el}.pkl", 'wb') as f:
pickle.dump(post_demand_samples, f)
|