Archana731 commited on
Commit
99d526b
Β·
verified Β·
1 Parent(s): 48d07fb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Set Streamlit page config
6
+ st.set_page_config(page_title="Sigmoid Curve Visualizer", page_icon="πŸ“ˆ")
7
+
8
+ # Title
9
+ st.title("πŸ“ˆ Sigmoid Activation Function Visualizer")
10
+
11
+ st.write("""
12
+ The **sigmoid function** is defined as:
13
+ \[
14
+ \sigma(z) = \frac{1}{1 + e^{-z}}
15
+ \]
16
+ It smoothly maps any real number to a value between 0 and 1, making it useful for **probability outputs** in neural networks.
17
+ """)
18
+
19
+ # Sidebar controls
20
+ st.sidebar.header("βš™οΈ Controls")
21
+ min_z = st.sidebar.slider("Minimum z value", -20, 0, -10)
22
+ max_z = st.sidebar.slider("Maximum z value", 0, 20, 10)
23
+ points = st.sidebar.slider("Number of points", 50, 1000, 400)
24
+
25
+ # Sigmoid function
26
+ def sigmoid(z):
27
+ return 1 / (1 + np.exp(-z))
28
+
29
+ # Generate values
30
+ z = np.linspace(min_z, max_z, points)
31
+ sig = sigmoid(z)
32
+
33
+ # Plot
34
+ fig, ax = plt.subplots(figsize=(6,4))
35
+ ax.plot(z, sig, label=r'$\sigma(z) = \frac{1}{1+e^{-z}}$', color='blue')
36
+ ax.axhline(0.5, color='gray', linestyle='--', linewidth=0.8)
37
+ ax.axvline(0, color='gray', linestyle='--', linewidth=0.8)
38
+ ax.set_title("Sigmoid Activation Function", fontsize=14)
39
+ ax.set_xlabel("z (Weighted Sum)")
40
+ ax.set_ylabel("Output (Probability)")
41
+ ax.grid(True, linestyle='--', alpha=0.6)
42
+ ax.legend()
43
+
44
+ st.pyplot(fig)
45
+
46
+ # Example interpretation
47
+ st.subheader("πŸ” Interpretation Example")
48
+ z_input = st.number_input("Enter a z value:", value=0.0, step=0.1)
49
+ probability = sigmoid(z_input)
50
+ st.write(f"Sigmoid({z_input}) = **{probability:.4f}** β†’ This means {probability*100:.2f}% probability.")
51
+