Nipun commited on
Commit
817aeb7
1 Parent(s): a22efa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -1,10 +1,53 @@
1
  import streamlit as st
2
-
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
5
-
6
  import numpy as np
7
  import matplotlib.pyplot as plt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  fig, ax = plt.subplots()
9
- ax.plot(np.random.randn(10, 5))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  st.pyplot(fig)
 
 
 
 
 
 
 
 
1
  import streamlit as st
 
 
 
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ import tensorflow as tf
7
+ import seaborn as sns
8
+ import tensorflow_probability as tfp
9
+ import pandas as pd
10
+ tfd = tfp.distributions
11
+
12
+ st.title("1 dimensional normal distribution")
13
+ mean = st.slider('Mean', -5, 5, 0)
14
+ std = st.slider('Scale', 0, 5, 1)
15
+
16
+ p = tfd.Normal(2, 1)
17
+
18
+
19
+ st.latex(f"\mu={mean}"+"\n\n"+f"\sigma={std}")
20
+
21
+
22
+ q = tfd.Normal(mean, std)
23
+ z_values = tf.linspace(-5, 5, 200)
24
+ z_values = tf.cast(z_values, tf.float32)
25
+ prob_values_p = p.prob(z_values)
26
+ prob_values_q = q.prob(z_values)
27
+
28
  fig, ax = plt.subplots()
29
+ ax.plot(z_values, prob_values_p, label=r'p', linestyle='--', lw=5, alpha=0.5)
30
+ ax.plot(z_values, prob_values_q, label=r'q')
31
+
32
+ ax.set_xlabel("x")
33
+ ax.set_ylabel("PDF(x)")
34
+ ax.legend()
35
+ ax.set_ylim((0, 1))
36
+
37
+ sns.despine()
38
+
39
+ kl = tfd.kl_divergence(q, p)
40
+ st.latex(f"D_{{KL}}(q||p) is : {kl:0.2f}")
41
+
42
+ #arr = np.random.normal(mean, std, size=10000)
43
+
44
+ ##ax.hist(arr, bins=20)
45
+ #sns.despine()
46
  st.pyplot(fig)
47
+ hide_streamlit_style = """
48
+ <style>
49
+ #MainMenu {visibility: hidden;}
50
+ footer {visibility: hidden;}
51
+ </style>
52
+ """
53
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)