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.")