Deep Activation Function Comparison

    Deep Activation Function Comparison

    Objective: To compare the performance and internal representations of a deep neural network (10 hidden layers) using five different activation functions (Linear, Sigmoid, ReLU, Leaky ReLU, GELU) on a 1D non-linear regression task.\n\nWorking Directory: activation_functions/\n\nProcedure:\n1. Generate a synthetic dataset: x = np.linspace(-np.pi, np.pi, 200), y = np.sin(x) + np.random.normal(0, 0.1, 200).\n2. Define a deep MLP architecture with 10 hidden layers of 64 neurons each.\n3. For each activation function (None, Sigmoid, ReLU, Leaky ReLU, GELU), construct and train an identical MLP model on the dataset.\n4. Train each model for 500 epochs using the Adam optimizer and Mean Squared Error (MSE) loss.\n5. Log Intermediate Data:\n - During training for each model, at several epochs, compute and save the activation values of the first, middle (5th), and last (10th) hidden layers for a grid of input values. Store this data in a structured format in the activation_functions/ directory.\n - At the beginning of training (e.g., after the first few batches), compute and save the average gradient magnitude for each of the 10 layers. This is to visualize gradient flow.\n6. Generate Final Outputs (all saved to activation_functions/ directory):\n - A final plot (learned_functions.png) that shows the ground truth sine wave, the noisy data points, and the learned function for each of the five models.\n - A plot of the training loss curves over epochs for all models (loss_curves.png).\n - A plot (gradient_flow.png) visualizing the average gradient magnitude across the 10 layers for each activation function.\n - A plot (hidden_activations.png) visualizing the state of the hidden layer activations for the trained models.\n - A summary report (report.md) containing the final MSE loss for each model and a brief conclusion, particularly commenting on the evidence for the vanishing gradient problem.

    48 messages
    742 views
    1/29/2026
    Run Your Own ExperimentTry It

    Objective: To compare the performance and internal representations of a deep neural network (10 hidden layers) using five different activation functions (Linear, Sigmoid, ReLU, Leaky ReLU, GELU) on a 1D non-linear regression task.\n\nWorking Directory: activation_functions/\n\nProcedure:\n1. Generate a synthetic dataset: x = np.linspace(-np.pi, np.pi, 200), y = np.sin(x) + np.random.normal(0, 0.1, 200).\n2. Define a deep MLP architecture with 10 hidden layers of 64 neurons each.\n3. For each activation function (None, Sigmoid, ReLU, Leaky ReLU, GELU), construct and train an identical MLP model on the dataset.\n4. Train each model for 500 epochs using the Adam optimizer and Mean Squared Error (MSE) loss.\n5. Log Intermediate Data:\n - During training for each model, at several epochs, compute and save the activation values of the first, middle (5th), and last (10th) hidden layers for a grid of input values. Store this data in a structured format in the activation_functions/ directory.\n - At the beginning of training (e.g., after the first few batches), compute and save the average gradient magnitude for each of the 10 layers. This is to visualize gradient flow.\n6. Generate Final Outputs (all saved to activation_functions/ directory):\n - A final plot (learned_functions.png) that shows the ground truth sine wave, the noisy data points, and the learned function for each of the five models.\n - A plot of the training loss curves over epochs for all models (loss_curves.png).\n - A plot (gradient_flow.png) visualizing the average gradient magnitude across the 10 layers for each activation function.\n - A plot (hidden_activations.png) visualizing the state of the hidden layer activations for the trained models.\n - A summary report (report.md) containing the final MSE loss for each model and a brief conclusion, particularly commenting on the evidence for the vanishing gradient problem.

    11:01 PM

    📋 PLANNING: Activation Functions Comparison Experiment

    I'll be comparing 5 different activation functions (Linear, Sigmoid, ReLU, Leaky ReLU, GELU) on a deep neural network for a 1D non-linear regression task. Let me first set up the project structure and create a plan.

    11:02 PM

    Good, the directory is created. Now let me create the project plan and todo file:

    11:02 PM

    Now let me create the main training script. Since this is a relatively lightweight task (small dataset, 200 samples, simple MLP), I can run this locally with CPU since it doesn't require GPU acceleration:

    11:02 PM

    I've created the comprehensive training script. Now let me create a progress tracking file and then run the experiment:

    11:03 PM

    🚦 CHECKPOINT: Ready to Run Experiment

    What I've Done:

    • Created project structure in activation_functions/
    • Written comprehensive training script (train.py) that:
      • Generates synthetic sine wave data with noise
      • Defines a 10-layer deep MLP with 64 neurons per layer
      • Trains 5 models with different activations (Linear, Sigmoid, ReLU, Leaky ReLU, GELU)
      • Logs gradient magnitudes and activation values
      • Generates all 4 required visualizations
      • Creates a detailed report with vanishing gradient analysis

    Architecture:

    • 10 hidden layers × 64 neurons
    • 500 epochs, Adam optimizer, MSE loss
    • Dataset: 200 samples from sin(x) + noise

    Question for You: This is a lightweight CPU task (small dataset, simple MLP). Ready to run the experiment locally? It should complete in about 1-2 minutes.

    Proposed Next Steps:

    1. Run the training script
    2. Review generated visualizations
    3. Upload final deliverables as assets

    Shall I proceed with running the experiment?

    11:03 PM

    sounds good

    11:04 PM

    🔨 BUILDING: Running the experiment now...

    11:04 PM

    Excellent! The experiment completed successfully in about 7 seconds! Let me verify all the files were generated and check the results:

    11:04 PM

    Interesting - the files were generated but might be in a nested directory. Let me check:

    11:05 PM

    The files were created in a nested directory due to running from within activation_functions/. Let me move them to the correct location:

    11:05 PM

    All files are now in the correct location. Let me check the gradient magnitudes data to see the vanishing gradient evidence:

    11:05 PM

    📊 ANALYZING: The results clearly demonstrate the vanishing gradient problem!

    Look at the Sigmoid gradients - they span 10 orders of magnitude:

    • Layer 1: 1.66e-10 (essentially zero!)
    • Layer 10: 3.69e-03

    This is textbook vanishing gradient! The gradients at early layers are so small they can't update the weights effectively.

    Now let me update the progress file and create the final assets:

    11:05 PM

    Now let me create all the assets for delivery:

    11:05 PM

    All assets created. Let me now report the final results to Orchestra:

    11:05 PM

    sounds good

    11:06 PM

    go ahead

    11:36 PM

    The report is comprehensive and well-formatted. Let me provide the final summary:


    ✅ TASK COMPLETE!

    Key Deliverables:

    FileDescription
    ✅ report.mdComprehensive analysis report with vanishing gradient evidence
    ✅ learned_functions.pngGround truth vs learned functions for all 5 models
    ✅ loss_curves.pngTraining loss over 500 epochs
    ✅ gradient_flow.pngGradient magnitude visualization showing vanishing gradients
    ✅ hidden_activations.pngActivation distributions at layers 1, 5, and 10
    ✅ train.pyComplete, reproducible training script

    Results Summary:

    RankActivationFinal MSENotes
    🥇Leaky ReLU0.008041Best - stable gradients
    🥇ReLU0.008041Tied best
    🥉GELU0.008317Excellent performance
    4Linear0.213001Cannot model non-linearity
    5Sigmoid0.518153Vanishing gradient!

    Key Finding - Vanishing Gradient Evidence:

    Sigmoid gradient magnitudes across 10 layers:

    • Layer 1: 1.66e-10 (essentially zero!)
    • Layer 10: 3.69e-03
    • Ratio: 22 million times larger at output!

    This is textbook vanishing gradient - gradients decay exponentially through the network, preventing early layers from learning effectively.

    All assets have been uploaded and are ready for download! 🎉

    11:36 PM

    can you answer these questions empirically (with experiment results) and theoretically ? and write an educational tutorial to teach readers. Different activations change:

    how gradients flow (do they vanish/explode?),

    how easily units “turn on/off” (sparsity, dead neurons),

    how stable the network is under big learning rates / deep stacks,

    how well the model can represent certain functions with reasonable depth/width,

    11:46 PM

    Great question! Let me design a comprehensive educational experiment that explores all four aspects of activation functions both empirically and theoretically.

    11:46 PM

    There's a NaN issue in the histogram. Let me fix the script to handle edge cases better:

    11:49 PM

    All experiments completed successfully. Let me check the generated files and create the final tutorial report:

    11:51 PM

    The new tutorial files were created in a subdirectory. Let me check and move them:

    11:52 PM

    Now let me read the generated tutorial and enhance it with the original task requirements (specifically the original 5 activation functions and 10-layer network):

    11:52 PM

    Excellent! The tutorial is comprehensive. Now let me update the original report.md to match the task requirements (specifically focusing on the original 5 activation functions: Linear, Sigmoid, ReLU, Leaky ReLU, GELU with 10 hidden layers), and then create all the required assets:

    11:52 PM

    Now let me create the final report.md that specifically addresses the original task requirements:

    11:53 PM

    Now let me create all the required assets for delivery:

    11:54 PM

    Now let me report the final completion to Orchestra:

    11:55 PM

    ✅ Task Complete!

    Summary of Deliverables

    I've completed the comprehensive analysis of activation functions in deep neural networks. Here's what was produced:

    📊 Key Findings

    ActivationFinal MSEGradient Ratio (L10/L1)Status
    Leaky ReLU0.00010.72 (stable)✅ Excellent
    ReLU0.00001.93 (stable)✅ Excellent
    GELU0.00020.83 (stable)✅ Excellent
    Linear0.42310.84 (stable)⚠️ Cannot learn non-linearity
    Sigmoid0.49752.59×10⁷❌ Vanishing gradients

    📁 Assets Uploaded

    Reports:

    • ✅ report.md - Comprehensive analysis report with evidence for vanishing gradient problem
    • ✅ activation_tutorial.md - Extended educational tutorial

    Visualizations (as required):

    • ✅ learned_functions.png - Ground truth vs predictions for all 5 activations
    • ✅ loss_curves.png - Training loss over 500 epochs
    • ✅ gradient_flow.png - Gradient magnitude across 10 layers
    • ✅ hidden_activations.png - Activation patterns at layers 1, 5, 10
    • ✅ exp1_gradient_flow.png - Extended gradient analysis (depths 5-50)
    • ✅ exp2_sparsity_dead_neurons.png - Sparsity and dead neuron analysis
    • ✅ summary_figure.png - Comprehensive 4-panel summary

    Code:

    • ✅ train.py - Main training script (10 layers, 5 activations, 500 epochs)
    • ✅ tutorial_experiments.py - Extended experiments (8 activations, 4 experiments)

    🔬 Key Conclusion

    The vanishing gradient problem is empirically confirmed: Sigmoid shows a 26 million-fold gradient decay across just 10 layers, causing complete training failure. Modern activations (ReLU, Leaky ReLU, GELU) maintain stable gradients by having unit derivatives for positive inputs, enabling effective deep network training.

    report.md

    DOCUMENT
    10.3 KB
    Download

    learned_functions.png

    211.7 KB
    learned_functions.png

    loss_curves.png

    129.0 KB
    loss_curves.png

    gradient_flow.png

    61.3 KB
    gradient_flow.png

    hidden_activations.png

    300.5 KB
    hidden_activations.png

    train.py

    CODE
    20.9 KB
    Download

    exp1_gradient_flow.png

    332.2 KB
    exp1_gradient_flow.png

    exp2_sparsity_dead_neurons.png

    64.8 KB
    exp2_sparsity_dead_neurons.png

    summary_figure.png

    442.7 KB
    summary_figure.png

    activation_tutorial.md

    DOCUMENT
    12.8 KB
    Download

    tutorial_experiments.py

    CODE
    49.7 KB
    Download

    11:55 PM

    you can measure Gradient magnitude across 10 layers for each activation function - at epoch 100 and 200, update the tutorial. add some visualization to illustrate the activation effect on training dynamics

    12:03 AM

    I'll update the tutorial to include gradient magnitude measurements at epochs 100 and 200, and add visualizations showing how activations affect training dynamics over time.

    12:03 AM

    Let me first read the current train.py to understand the structure, then update it to capture gradients at specific epochs:

    12:03 AM

    Now I understand the structure. Let me create an updated version of the training script that captures gradients at epochs 1, 100, and 200, and adds training dynamics visualizations:

    12:04 AM

    Now let me add the visualization code for training dynamics:

    12:05 AM

    Now let me add the final report generation section:

    12:05 AM

    Now let me run the updated training script to generate all the new visualizations:

    12:06 AM

    Excellent! The experiment ran successfully. Now let me update the tutorial with the new gradient measurements and reference the new visualizations:

    12:06 AM

    Let me read the rest of the tutorial to understand its structure:

    12:07 AM

    Now let me add a new section on temporal gradient analysis to the tutorial:

    12:07 AM

    Now let me update the Files Generated section to include the new visualizations:

    12:08 AM

    Now let me update the Table of Contents to include the new experiment:

    12:08 AM

    Now let me verify the files were created and list what we have:

    12:08 AM

    I see the new visualizations from train_dynamics.py weren't saved. Let me check what happened:

    12:09 AM

    I see the new files didn't appear. Let me check if the script wrote them to a different location or if there was an issue. Let me check the script's output directory:

    12:09 AM

    The files were saved to a nested directory. Let me move them to the correct location:

    12:09 AM

    All the visualizations are now in place. Let me verify the JSON files were also moved:

    12:09 AM

    Now let me create the final assets. First, let me read the updated tutorial to verify it's correct:

    12:09 AM

    The tutorial looks good. Now let me create all the final assets for delivery:

    12:09 AM

    This is a shared snapshot of the conversation with our experimentation agent • How Do Activation Functions Shape the Training Dynamics

    Try Orchestra Yourself