Tuesday, August 4, 2026

Backpropagation vs. Gradient Descent in Linear and Logistic Regression


Note that the term "backpropagation" is technically not used for standard linear or logistic regression. Instead, we simply call the optimization process Gradient Descent.


Backpropagation is also related to vanishing gradient.  Vanishing gradient can occur only across multiple layers. Thus both backpropagation and vanishing gradient are related to multiple layers only, then are never used for single layer models.

Important Note

The word propagation implies a sequence of layers. Because linear regression and logistic regression contain only a single layer of weights, there is no sequence of layers through which errors can propagate backward.

What is Backpropagation?

Backpropagation is short for "backward propagation of errors." It is an algorithm specifically designed for multi-layer neural networks.

The Sequence

It uses the mathematical Chain Rule to calculate gradients. It starts at the final output layer, computes the error, and then passes (propagates) that error backward, layer by layer, to update the weights at the very beginning of the network.

During backpropagation, the error is propagated backward through multiple layers using the Chain Rule.

Why the Confusion in Linear and Logistic Regression?

You might hear people use the term loosely in linear or logistic regression for two main reasons:

1. Neural Network Equivalent

A logistic regression model is mathematically identical to a single-neuron neural network with a sigmoid activation function.

2. The "One-Step" Chain Rule

Even in logistic regression, you use a small version of the Chain Rule. To find how the loss changes with respect to the weights,

∂Loss / ∂W = (∂Loss / ∂Prediction) × (∂Prediction / ∂Score) × (∂Score / ∂W)

Because this calculation proceeds backward from the Loss to the Weights, some instructors casually refer to it as "backpropagation", even though it only spans a single layer.

Logistic regression applies the Chain Rule over a single layer rather than propagating errors through multiple layers.

Summary of Terms

Term Definition Used In
Gradient Descent The overall optimization algorithm used to update weights to minimize error. Linear regression, logistic regression, and neural networks.
Backpropagation The specific method used inside gradient descent to calculate gradients across multiple sequential layers. Multi-layer neural networks.
Key Takeaway

Gradient Descent is the optimization algorithm that updates model parameters to minimize the loss function. Backpropagation is the gradient-computation algorithm used within gradient descent for multi-layer neural networks. In standard linear regression and logistic regression, we typically refer only to Gradient Descent, since there are no multiple layers through which errors must propagate.

Monday, August 3, 2026

Mathematical Transformations

A mathematical transformation is a function T that maps elements from an initial set (domain) to another set (codomain), modifying inputs into outputs according to a strict mathematical rule.

In geometry and linear algebra, it maps vectors or points from one vector space to another, written as:

T : VW
Here V is the domain, W is the Codomain and T is the function that maps V to W.

2. Linear vs. Non-Linear Transformations

The fundamental division between transformations relies on two algebraic rules:

  • Additivity
    T(u + v) = T(u) + T(v)
  • Homogeneity
    T(cu) = cT(u)

Linear Transformations

Linear transformations satisfy both conditions.

  • They always map the origin to itself.
  • T(0) = 0
  • They map straight lines to straight lines.
  • They keep grid lines straight and parallel.
  • They can always be expressed as a matrix multiplication:
    T(x) = Ax

Non-Linear Transformations

Non-linear transformations fail at least one condition.

  • They curve the underlying space.
  • They warp grid lines.
  • They move the origin.
  • Examples include squaring coordinates:
    T(x, y) = (x2, y)
  • Or adding constants:
    T(x) = x + b
    (which is an affine transformation, not strictly linear).
Property Linear Transformation Non-Linear Transformation
Additivity ✔ Satisfied ✘ Violated
Homogeneity ✔ Satisfied ✘ Violated
Origin Preserved May Move
Grid Lines Remain Straight May Warp
Matrix Representation Always Possible Generally Not Possible

3. Standard 2D Linear Geometric Transformations

In a two-dimensional Cartesian plane, standard linear transformations alter the spatial properties of shapes and can be written using a 2 × 2 matrix:

[ x′ ]  =  [ a  b ] [ x ]
[ y′ ]      [ c  d ] [ y ]
Note

Use arrow keys to adjust value.

0:00 / 1:01

Audio made with Google AI. Image licensed by Google.

Scaling

Stretches or shrinks coordinates along axes.

sx 0
0 sy

Rotation

Rotates points counterclockwise around the origin by an angle θ.

cos θ − sin θ
sin θ cos θ

Shearing

Slants one coordinate axis parallel to another based on a factor k.

Horizontal Shear

1 k
0 1

Vertical Shear

1 0
k 1

Reflection

Flips the space across a line passing through the origin.

Across the x-axis:

1 0
0 −1
Note

Translation—sliding an object—is geometric but requires a 3 × 3 matrix with homogeneous coordinates to be handled linearly because it moves the origin.
Figure 3.1 — Examples of scaling, rotation, shearing, and reflection in two-dimensional space.

4. Non-Geometric Transformations

Non-geometric transformations modify the properties or data structures of elements rather than their spatial positions, shapes, or orientations.

Transformation Type Description Examples
Data Transformations Converting variable distributions in statistics. Logarithmic transformation (log(x)) or Z-score normalization.
Color Space Transformations Converting digital imagery pixels from one color representation to another. RGB → CMYK or YCbCr color spaces.
Domain Transformations Changing the functional domain of an equation. Fourier Transform or Laplace Transform for mapping time-domain signals to the frequency domain.
Cryptographic Transformations Permuting and substituting data bytes to encrypt plain text into ciphertext. Algorithms such as AES.
Important Note

Unlike geometric transformations, non-geometric transformations change the underlying data, representation, or mathematical domain without necessarily altering the physical position or shape of objects.

Prompt Engineering

Prompt Engineering Frameworks Comparison
Category Framework Components / Meaning Best Use Case
1. General & Professional Tasks
General & Professional Tasks RACE Role, Action, Context, Expectation 80% of daily professional tasks
General & Professional Tasks RTF Role, Task, Format Most minimalist and fastest framework to use
General & Professional Tasks TAG Task, Action, Goal Quick, objective-driven assignments
2. Marketing, Creative, & Communication
Marketing, Creative, & Communication CO-STAR Context, Objective, Style, Tone, Audience, Response Gold standard for high-stakes copywriting and content creation
Marketing, Creative, & Communication CRISPE Capacity/Role, Response, Insight, Scope, Personality, Experiment Developed internally by OpenAI circles for detailed outputs
Marketing, Creative, & Communication CREATE Context, Role, Explicit instructions, Attributes, Target audience, Execute Audience-centric copy and tailored messaging
3. Technical, Analytical, & Deep Research
Technical, Analytical, & Deep Research RISEN Role, Instructions, Steps, End goal, Narrowing constraints Project roadmaps or complex execution plans
Technical, Analytical, & Deep Research RTCROS Role, Task, Context, Resources, Output, Success criteria Production-grade AI features (matches with constraints, commands, resources, rules and performance evaluation) 
Technical, Analytical, & Deep Research CLEAR Context, Limits, Emphasis, Alignment, Review Strategic research and highly regulated topics
4. Advanced "Reasoning" Frameworks
Advanced "Reasoning" Frameworks Chain-of-Thought (CoT) Architectural behavioral method Forces the AI to show its step-by-step reasoning before outputting a final answer.
Advanced "Reasoning" Frameworks Tree-of-Thought (ToT) Architectural behavioral method Guides the AI to evaluate multiple different solution paths simultaneously, self-correcting as it goes.
Advanced "Reasoning" Frameworks ReAct Reasoning + Acting Prompts the AI to alternate between "thinking" about a problem and "acting" (e.g., searching the web, running code).

Prompt Components: Constraints, Commands, Resources, Rules, and Performance Evaluation

A prompt can consist of constraints, commands, resources, rules, and performance evaluation. While a basic prompt might only be a simple question, advanced prompt engineering frameworks frequently use these exact five components to obtain high-quality, predictable outputs from AI models.

Key Idea

Advanced prompt engineering frameworks extend beyond a simple instruction by defining what the AI should do, what limitations it must follow, what information it can use, what rules it must obey, and how the final output will be evaluated.

Component Breakdown

Component Description Example
Commands The core instruction telling the AI what to do. "Write," "Analyze," "Summarize"
Constraints The boundaries or limits placed on the output. "Under 500 words," "Do not use jargon," "Format as markdown"
Resources The background data, context, or examples provided to help the AI understand the task. "Based on the attached CSV file," "Use the following style guide"
Rules The logical guidelines or conditional policies the AI must follow while processing the request. "If the sentiment is negative, escalate to human tone," "Always verify facts before listing them"
Performance Evaluation The criteria or rubric used to tell the AI how its output will be judged, often used in iterative prompts. "Your output will be scored on clarity, accuracy, and conciseness from 1 to 5"
  • Commands:What to do 
  • Constraints: Limits 
  • Resources: Context 
  • Rules: Policies 
  • Performance Evaluation: Quality Criteria
Important Note

Although a simple prompt may contain only a question or instruction, advanced prompt engineering frameworks typically combine these five components to produce more accurate, consistent, and predictable AI responses.

Sunday, August 2, 2026

The Sigmoid Function: Definition, Properties, Applications, and Evolution

1. The Sigmoid Function: Definition, Properties, and Universality

Mathematical Definition

The standard logistic sigmoid function maps any real-valued number into a strict probability-like range between 0 and 1.

σ(x) = 1 1 + e-x

The Derivative

Using the quotient rule and the chain rule, the derivative simplifies into a remarkably elegant, self-referential expression where the slope is computed directly from the value of the sigmoid itself.

σ′(x) = σ(x) (1 − σ(x))

Why Euler's Number (e) is Used

While any exponential base (such as 2-x or 10-x) could theoretically be used, Euler's number (e ≈ 2.71828) is universally chosen for deep mathematical reasons.

The Natural Derivative

The derivative of ex is exactly ex. This unique property eliminates unwanted scaling constants such as ln(2) or ln(10), making the derivative beautifully simple and computationally efficient during backpropagation.

Information Theory & Physics

The base e naturally appears in the Boltzmann distribution in statistical physics and in log-odds (logits) in statistics. It represents the natural rate of continuous growth and maximum entropy, making it the mathematically preferred choice for probabilistic modeling.

Universal Significance of the Sigmoid Function

Why the Sigmoid Function Is So Widely Used

The sigmoid function is much more than just another mathematical equation. It possesses several unique properties that make it one of the most important functions in statistics, probability, machine learning, and deep learning.

  • Smooth Thresholding
    It acts as a continuous, differentiable alternative to a hard step function. Instead of abruptly switching from 0 to 1, it transitions smoothly, making gradient-based optimization possible.
  • Probability Mapping
    It transforms unconstrained real numbers ranging from
    −∞   to   +∞
    into valid probabilities between
    0   and   1
    making it ideal for probabilistic prediction.

2. Why the Derivative Is Not a True Parabola

The derivative of the sigmoid function is written as

σ′(x) = σ(x) (1 − σ(x))

At first glance, this expression resembles the quadratic form

σ − σ2

Since this resembles the familiar equation x − x2, many beginners assume the derivative must be a parabola. Although the algebraic form appears similar, the geometric behavior is completely different.

The Input Variable Matters

A true parabola is defined directly as a polynomial in the horizontal variable.

f(x) = x − x2

Here, the independent variable x appears directly as a polynomial. Consequently, the graph follows the familiar parabolic shape.

In contrast, the sigmoid derivative is ultimately a function of x through the exponential term e−x. Therefore, the horizontal axis is not related polynomially to the output.

The Exponential Constraint

Inside the sigmoid function, the input variable appears inside an exponential:

σ(x) = 1 1 + e−x

Because of this exponential dependence, the rate of change grows and decays exponentially rather than polynomially.

As a result, the derivative cannot produce the infinitely expanding shape associated with a geometric parabola.

The Geometric Result

Instead of expanding outward forever, the exponential terms continuously bend the curve inward.

The curve gradually flattens on both sides, producing a smooth, symmetric, bell-shaped distribution.

Mathematically, this curve is a hyperbolic secant squared function rather than a parabola.

Visual Comparison: Parabola vs. Sigmoid Derivative

True Parabola Sigmoid Derivative
Key Observation

Although the derivative contains an algebraic expression that resembles a quadratic function, its dependence on the exponential term e−x causes the graph to become a bounded bell-shaped curve rather than an unbounded parabola.

3. Core Applications: Logistic Regression and Neural Networks

Why the Sigmoid Function Became So Important

The sigmoid function became one of the most influential mathematical functions in Machine Learning because it naturally converts unrestricted real-valued numbers into probabilities.

This single property makes it extremely useful in both statistical machine learning and artificial neural networks.

Logistic Regression (Statistical Machine Learning)

In binary classification problems, an algorithm must predict a probability between 0 and 1.

Examples include determining whether:

  • Email → Spam or Not Spam
  • Patient → Disease Present or Healthy
  • Transaction → Fraudulent or Genuine
  • Student → Pass or Fail

Step 1 — Linear Model Produces a Raw Score

A linear model first computes a raw numerical score known as the logit.

z = β0 + β1x1 + β2x2 + ··· + βnxn

This value may lie anywhere between −∞ and +∞.

Step 2 — Apply the Sigmoid Function

The raw score is then passed through the sigmoid function.

P = 1 1 + e−z

The output is now guaranteed to lie between 0 and 1, allowing it to be interpreted as a probability.

Step 3 — Make the Final Prediction

A threshold is then applied.

  • If the probability is ≥ 0.5, predict Class 1.
  • If the probability is < 0.5, predict Class 0.

Logistic Regression Pipeline

Input Features Logit (z) Sigmoid Probability Class

Activation Functions in Neural Networks

Early neural networks adopted the sigmoid function because it provides a simple mathematical approximation of how biological neurons behave.

Biological Analogy

  • A biological neuron receives electrical signals from many other neurons.
  • It accumulates these incoming signals.
  • When the accumulated signal exceeds a threshold, the neuron fires.

Mathematical Interpretation

The sigmoid function acts as a smooth mathematical gate that determines how much information should pass from one layer of neurons to the next, depending on the strength of the incoming signal.

Sigmoid as an Activation Function

σ Activation Output

4. The Vanishing Gradient Problem and the Evolution of Activation Functions

The Vanishing Gradient Problem

Although the sigmoid function is mathematically elegant, it introduces a major difficulty when training deep neural networks.

The maximum value of the sigmoid derivative occurs at x = 0, where

σ′(0) = 0.25

As the input moves away from zero in either direction, the sigmoid curve gradually flattens and its derivative rapidly approaches zero.

During backpropagation, gradients from deeper layers are multiplied together while moving toward earlier layers.

Since each sigmoid derivative is at most 0.25, repeatedly multiplying these small values causes the gradient to shrink exponentially.

Result

By the time the gradient reaches the earliest layers of a deep network, it has effectively become zero. Consequently, those layers stop learning because their weights receive almost no updates.

Mathematical Intuition

Suppose a network contains several hidden layers. During backpropagation, the gradient reaching an early layer is roughly the product of all the derivatives encountered along the path.

Gradient = σ′1 × σ′2 × σ′3 × ··· × σ′n

If every derivative is smaller than 0.25, the product decreases exponentially as the number of layers increases.

Example of Gradient Shrinkage

Consider a simplified network in which each layer contributes a gradient of approximately 0.2.

Layer Approximate Gradient
Layer 4 0.20
Layer 3 0.04
Layer 2 0.008
Layer 1 Almost 0 (Vanished)

Gradient Flow Through a Deep Neural Network

Layer 4 Gradient ≈ 0.20 Layer 3 Gradient ≈ 0.04 Layer 2 Gradient ≈ 0.008 Layer 1 Vanished

Why Learning Stops

Neural networks learn by updating their weights using gradients computed during backpropagation.

If the gradient reaching a layer becomes extremely small, the weight updates become almost zero.

As a result, the earliest layers stop learning useful features even though the later layers continue to update.

Key Consequence

This inability to update the early layers severely limits the training of very deep neural networks and was one of the primary motivations for developing newer activation functions.

How Other Activation Functions Solve the Vanishing Gradient Problem

To overcome the vanishing gradient problem, modern deep learning relies on activation functions that preserve stronger gradients during backpropagation.

Instead of rapidly flattening like the sigmoid function, these activations maintain a larger derivative over a wider range of inputs, allowing information to propagate efficiently through very deep neural networks.

ReLU (Rectified Linear Unit)

The Rectified Linear Unit (ReLU) is defined as:

f(x) = max(0, x)

For any positive input, the derivative of ReLU is a constant 1.

Because a gradient of 1 does not shrink during multiplication, it can travel through hundreds of layers without vanishing, making ReLU the default activation function in many deep neural networks.

Tanh (Hyperbolic Tangent)

The hyperbolic tangent function scales inputs into the range:

−1    to    +1

Its maximum derivative is 1.0 (at x = 0), allowing gradients to flow more effectively than with the sigmoid function.

However, tanh still saturates for very large positive and negative inputs, so its gradients also become extremely small in those regions.

Activation Output Range Maximum Derivative Main Characteristic
Sigmoid 0 to 1 0.25 Good for probabilities but suffers from vanishing gradients.
Tanh −1 to 1 1.0 Improves gradient flow but still saturates.
ReLU 0 to ∞ 1.0 Fast training and excellent gradient propagation.

The Dying ReLU Problem

Although ReLU effectively prevents vanishing gradients for positive inputs, it introduces another limitation.

Whenever the input is negative, the output becomes 0 and the derivative is also exactly 0.

If a neuron continually receives negative inputs, it always produces zero output. Consequently, its gradient remains zero, its weights stop updating, and the neuron permanently stops contributing to the network.

Result

The neuron becomes permanently inactive, a phenomenon commonly known as the Dying ReLU Problem.

Solutions to the Dying ReLU Problem

Leaky ReLU

Instead of forcing every negative input to zero, Leaky ReLU assigns a small non-zero slope.

f(x) = 0.01x    for    x < 0

This ensures that a small gradient (approximately 0.01) always flows backward, allowing inactive neurons to recover during training.


GELU (Gaussian Error Linear Unit)

GELU combines the behavior of ReLU with a probabilistic weighting based on a Gaussian distribution.

Instead of introducing a sharp transition at zero, GELU provides a smoother activation function that has become the dominant choice in modern Transformer architectures and Large Language Models (LLMs).

Summary

The mathematical elegance of the sigmoid function relies on Euler's number (e) to create clean probabilistic outputs.

Although its derivative has an algebraic expression that resembles a parabola, the exponential nature of the sigmoid function causes the derivative to form a bell-shaped curve rather than a true parabola.

As neural networks became deeper, the sigmoid function's rapidly shrinking derivative led to the vanishing gradient problem, motivating the development of improved activation functions such as ReLU, Leaky ReLU, and GELU that maintain stronger gradients during training.

Backpropagation vs. Gradient Descent in Linear and Logistic Regression

Note that the term "backpropagation" is technically not used for standard linear or logistic regression. Instead, we simply c...