Spaces:
Sleeping
Sleeping
Commit
·
a77475c
1
Parent(s):
6a2352e
Update app.py
Browse files
app.py
CHANGED
@@ -56,17 +56,17 @@ lr = float(st.text_input('Learning rate', value=0.5))
|
|
56 |
|
57 |
prob_A = float(st.text_input('Click probability of ad A', value=0.3))
|
58 |
|
59 |
-
prob_B = float(st.text_input('Click probability of ad B', value=0.
|
60 |
|
61 |
-
|
62 |
|
63 |
-
information_for_plotting = np.zeros((
|
64 |
|
65 |
if st.button('Run the ad campaign and display the results'):
|
66 |
|
67 |
with st.spinner('Simulating the ad campaign may take a few seconds ...'):
|
68 |
|
69 |
-
for
|
70 |
|
71 |
# The neural network is used to choose the action
|
72 |
# To display the learning progress, we also record the
|
@@ -98,16 +98,16 @@ if st.button('Run the ad campaign and display the results'):
|
|
98 |
model.trainable_variables[1].assign(
|
99 |
model.trainable_variables[1]-lr*grads_adjusted[1])
|
100 |
|
101 |
-
information_for_plotting[
|
102 |
-
information_for_plotting[
|
103 |
-
information_for_plotting[
|
104 |
-
information_for_plotting[
|
105 |
-
information_for_plotting[
|
106 |
-
information_for_plotting[
|
107 |
-
information_for_plotting[
|
108 |
-
information_for_plotting[
|
109 |
-
information_for_plotting[
|
110 |
-
information_for_plotting[
|
111 |
|
112 |
# Plot the results
|
113 |
titles = ['Model Output', 'Action', 'Loss', 'Gradients', 'Rewards',
|
@@ -132,7 +132,7 @@ if st.button('Run the ad campaign and display the results'):
|
|
132 |
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
|
133 |
plt.ylabel(titles[i])
|
134 |
|
135 |
-
plt.xlabel('
|
136 |
plt.show()
|
137 |
|
138 |
# Sum of the total clicks obtained
|
|
|
56 |
|
57 |
prob_A = float(st.text_input('Click probability of ad A', value=0.3))
|
58 |
|
59 |
+
prob_B = float(st.text_input('Click probability of ad B', value=0.4))
|
60 |
|
61 |
+
steps = int(st.text_input('Number of ad impressions (steps)', value=1000))
|
62 |
|
63 |
+
information_for_plotting = np.zeros((steps, 10))
|
64 |
|
65 |
if st.button('Run the ad campaign and display the results'):
|
66 |
|
67 |
with st.spinner('Simulating the ad campaign may take a few seconds ...'):
|
68 |
|
69 |
+
for step in range(steps):
|
70 |
|
71 |
# The neural network is used to choose the action
|
72 |
# To display the learning progress, we also record the
|
|
|
98 |
model.trainable_variables[1].assign(
|
99 |
model.trainable_variables[1]-lr*grads_adjusted[1])
|
100 |
|
101 |
+
information_for_plotting[step, 0] = output.numpy()[0]
|
102 |
+
information_for_plotting[step, 1] = action.numpy()[0].astype(int)
|
103 |
+
information_for_plotting[step, 2] = loss
|
104 |
+
information_for_plotting[step, 3] = grads[0]
|
105 |
+
information_for_plotting[step, 4] = grads[1]
|
106 |
+
information_for_plotting[step, 5] = reward
|
107 |
+
information_for_plotting[step, 6] = grads_adjusted[0]
|
108 |
+
information_for_plotting[step, 7] = grads_adjusted[1]
|
109 |
+
information_for_plotting[step, 8] = copy.deepcopy(model.trainable_variables[0])
|
110 |
+
information_for_plotting[step, 9] = copy.deepcopy(model.trainable_variables[1])
|
111 |
|
112 |
# Plot the results
|
113 |
titles = ['Model Output', 'Action', 'Loss', 'Gradients', 'Rewards',
|
|
|
132 |
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.2f'))
|
133 |
plt.ylabel(titles[i])
|
134 |
|
135 |
+
plt.xlabel('Step')
|
136 |
plt.show()
|
137 |
|
138 |
# Sum of the total clicks obtained
|