sarithamiryala5 commited on
Commit
a51e3be
1 Parent(s): 630a236

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import math
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ plt.style.use('seaborn-white')
6
+ import pandas as pd
7
+ from matplotlib import animation, rc
8
+ import torch.nn.functional as F
9
+ import torch
10
+ import torch.nn as nn
11
+ import torch.optim as optim
12
+ plt.rcParams.update({'pdf.fonttype': 'truetype'})
13
+ import pickle
14
+ pc2 = pickle.load(open('price.pkl','rb'))
15
+ def to_tensor(x):
16
+ return torch.from_numpy(np.array(x).astype(np.float32))
17
+ def prediction(price_max,price_step,policy_net):
18
+ price_grid = np.arange(price_step, price_max, price_step)
19
+ sample_state = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \
20
+ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]
21
+ Q_s = policy_net(to_tensor(sample_state))
22
+ a_opt = Q_s.max(0)[1].detach()
23
+ print(f'Optimal price action {price_grid[a_opt]}')
24
+ plt.figure(figsize=(16, 5))
25
+ plt.xlabel("Price action ($)")
26
+ plt.ylabel("Q ($)")
27
+ plt.bar(price_grid, Q_s.detach().numpy(), color='crimson', width=6, alpha=0.8)
28
+ plt.show()
29
+ prediction(500,10,pc2)