File size: 1,560 Bytes
99d526b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

# Set Streamlit page config
st.set_page_config(page_title="Sigmoid Curve Visualizer", page_icon="πŸ“ˆ")

# Title
st.title("πŸ“ˆ Sigmoid Activation Function Visualizer")

st.write("""
The **sigmoid function** is defined as:  
\[
\sigma(z) = \frac{1}{1 + e^{-z}}
\]  
It smoothly maps any real number to a value between 0 and 1, making it useful for **probability outputs** in neural networks.
""")

# Sidebar controls
st.sidebar.header("βš™οΈ Controls")
min_z = st.sidebar.slider("Minimum z value", -20, 0, -10)
max_z = st.sidebar.slider("Maximum z value", 0, 20, 10)
points = st.sidebar.slider("Number of points", 50, 1000, 400)

# Sigmoid function
def sigmoid(z):
    return 1 / (1 + np.exp(-z))

# Generate values
z = np.linspace(min_z, max_z, points)
sig = sigmoid(z)

# Plot
fig, ax = plt.subplots(figsize=(6,4))
ax.plot(z, sig, label=r'$\sigma(z) = \frac{1}{1+e^{-z}}$', color='blue')
ax.axhline(0.5, color='gray', linestyle='--', linewidth=0.8)
ax.axvline(0, color='gray', linestyle='--', linewidth=0.8)
ax.set_title("Sigmoid Activation Function", fontsize=14)
ax.set_xlabel("z (Weighted Sum)")
ax.set_ylabel("Output (Probability)")
ax.grid(True, linestyle='--', alpha=0.6)
ax.legend()

st.pyplot(fig)

# Example interpretation
st.subheader("πŸ” Interpretation Example")
z_input = st.number_input("Enter a z value:", value=0.0, step=0.1)
probability = sigmoid(z_input)
st.write(f"Sigmoid({z_input}) = **{probability:.4f}** β†’ This means {probability*100:.2f}% probability.")