Session 2 - From Linear Models to the Perceptron

From Linear Models to the Perceptron

Christian Cabrera Jojoa

Assistant Research Professor

Department of Computer Science and Technology

University of Cambridge

chc79@cam.ac.uk

Session 2 - From Linear Models to the Perceptron

Last Time

Session 2 - From Linear Models to the Perceptron

Last Time

Machine Learning Pipeline
Data Science Process
Session 2 - From Linear Models to the Perceptron

Regression Models

Session 2 - From Linear Models to the Perceptron

Supervised Learning


Given a training set of example input-output pairs



Each pair was generated by an unknown function



The goal is to discover a function that approximates the true function .

Session 2 - From Linear Models to the Perceptron

Regression Models

The regression problem involves predicting a continuous numerical value. Regression models approximate a function that maps input features to a continuous output.

Session 2 - From Linear Models to the Perceptron

Regression Models

The hypotheses space includes linear functions of continuous-valued inputs and outputs.

Session 2 - From Linear Models to the Perceptron

Regression Models

The hypotheses space includes linear functions of continuous-valued inputs and outputs.


The simplest example is "fitting a straight line". The model learns the coefficients


Session 2 - From Linear Models to the Perceptron

Regression Models

The hypotheses space includes linear functions of continuous-valued inputs and outputs.


The simplest example is "fitting a straight line". The model learns the coefficients


Hypothesis Space for Regression
Example functions described using a linear model.
Session 2 - From Linear Models to the Perceptron

Regression Models

Hypothesis Space for Regression
Example functions described using a linear model.
Training Data Set
Training dataset.
Regression Fit
Linear regression fit.
Session 2 - From Linear Models to the Perceptron

Regression Models

The simplest example is "fitting a straight line". The model learns the coefficients



Finding the that best fits the data is called linear regression.


Session 2 - From Linear Models to the Perceptron

Regression Models

The simplest example is "fitting a straight line". The model learns the coefficients



Finding the that best fits the data is called linear regression.



Finding the values of the weights and that minimise the empirical loss (Squared Error).

Session 2 - From Linear Models to the Perceptron

Regression Models

Given the


We want to find

Session 2 - From Linear Models to the Perceptron

Regression Models

Given the


We want to find


We know that the loss is minimised when its partial derivatives with respect to and are zero.


Session 2 - From Linear Models to the Perceptron

Regression Models

We know that the loss is minimised when its partial derivatives with respect to and are zero.




Session 2 - From Linear Models to the Perceptron

Regression Models

We know that the loss is minimised when its partial derivatives with respect to and are zero.




Solving the partial derivatives


Session 2 - From Linear Models to the Perceptron

Regression Models

Convex Function
Weights Space - Convex Loss Function.
Session 2 - From Linear Models to the Perceptron

Regression Models

Convex Function
Weights Space - Convex Loss Function.
Non Convex Function
Non Convex Function - Zachary kaplan, CC BY-SA 4.0 , via Wikimedia Commons.
Session 2 - From Linear Models to the Perceptron

Regression Models

Convex Function
Weights Space - Convex Loss Function.
Non Convex Function
Non Convex Function - Zachary kaplan, CC BY-SA 4.0 , via Wikimedia Commons.
Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.
Session 2 - From Linear Models to the Perceptron

Regression Models

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

We choose any starting point and then compute an estimate of the gradient and move a small amount in the steepest downhill direction, repeating until we converge on a point in the weight space with (local) minima loss.


Gradient Descent Algorithm:
Initialize w randomly
repeat
    for each w[i] in w
        Compute gradient: g = ∇Loss(w[i])
        Update weight:   w[i] = w[i] - α * g
until convergence

The size of the step is given by the parameter , which regulates the behaviour of the gradient descent algorithm. This is a hyperparameter of the regression model we are training, usually called learning rate.

Session 2 - From Linear Models to the Perceptron

Regression Models

Following with our "straight line" example, the update rule for and is


Session 2 - From Linear Models to the Perceptron

Regression Models

Following with our "straight line" example, the update rule for and is


The loss function is represented as a composition of functions.


Session 2 - From Linear Models to the Perceptron

Regression Models

Following with our "straight line" example, the update rule for and is


The loss function is represented as a composition of functions.


We need to differentiate the loss function step by step using the chain rule to compute the gradients.


Session 2 - From Linear Models to the Perceptron

Regression Models

Applying the chain rule to the loss function



Session 2 - From Linear Models to the Perceptron

Regression Models

Applying the chain rule to the loss function



Applying this to and


Session 2 - From Linear Models to the Perceptron

Regression Models

The update rule for each weight in the "straight line" example is (folding 2 into )


Session 2 - From Linear Models to the Perceptron

Regression Models

The update rule for each weight in the "straight line" example is (folding 2 into )


For training examples

These updates constitute the batch gradient descent. For the "straight line", this gradient descent is deterministic.


An epoch is defined as one complete pass through the entire dataset during the training process. Multiple epochs are needed for the model to converge to an optimal solution. Not enough epochs could generate underfitting. Too many epochs could generate overfitting. Another hyperparameter for the model.

Session 2 - From Linear Models to the Perceptron

Regression Models

Batch Gradient Descent

The algorithm updates using the entire dataset in each iteration.

import numpy as np
def batch_gradient_descent(X, y, alpha=0.01, epochs=1000):
    """
    X: numpy array of shape (n_samples, n_features)
    y: numpy array of shape (n_samples,)
    alpha: learning rate
    epochs: number of passes over the data
    Returns: w (numpy array of shape (n_features,))
    """
    n_samples, n_features = X.shape
    w = np.zeros(n_features)
    for epoch in range(epochs):
        grad = [0] * len(w)
        for i in range(n_samples):
            x_i = X[i]
            y_i = y[i]
            prediction = dot(w, x_i)
            error = prediction - y_i
            for j in range(len(w)):
                grad[j] += error * x_i[j]
        for j in range(len(w)):
            grad[j] /= len(n_samples)
            w[j] -= alpha * grad[j]
    return w
Session 2 - From Linear Models to the Perceptron

Regression Models

Stochastic Gradient Descent

The algorithm updates after computing the gradient for each training example.

import numpy as np
def stochastic_gradient_descent(X, y, alpha=0.01, epochs=1000):
    """
    X: numpy array of shape (n_samples, n_features)
    y: numpy array of shape (n_samples,)
    alpha: learning rate
    epochs: number of passes over the data
    Returns: w (numpy array of shape (n_features,))
    """
    n_samples, n_features = X.shape
    w = np.zeros(n_features)
    for epoch in range(epochs):
        for i in range(n_samples):
            x_i = X[i]
            y_i = y[i]
            prediction = np.dot(w, x_i)
            error = prediction - y_i
            for j in range(n_features):
                w[j] -= alpha * error * x_i[j]
    return w
Session 2 - From Linear Models to the Perceptron

Regression Models

Mini-batch Gradient Descent

The algorithm updates after computing the gradient for a small batch of training examples (batch size ). The batch size is another hyperparameter.

import numpy as np
def mini_batch_gradient_descent(X, y, alpha=0.01, epochs=1000, batch_size=32):
    """
    X: numpy array of shape (n_samples, n_features)
    y: numpy array of shape (n_samples,)
    alpha: learning rate
    epochs: number of passes over the data
    batch_size: number of samples per batch
    Returns: w (numpy array of shape (n_features,))
    """
    n_samples, n_features = X.shape
    w = np.zeros(n_features)
    for epoch in range(epochs):
        indices = np.arange(n_samples)
        np.random.shuffle(indices)
        X_shuffled = X[indices]
        y_shuffled = y[indices]
        for start in range(0, n_samples, batch_size):
            end = start + batch_size
            X_batch = X_shuffled[start:end]
            y_batch = y_shuffled[start:end]
            y_pred = X_batch @ w
            error = y_pred - y_batch
            grad = X_batch.T @ error / len(X_batch)
            w -= alpha * grad
    return w
Session 2 - From Linear Models to the Perceptron

Regression Models

Regression Fit
Linear regression fit.

Linear Regression

Training Dataset

Hypothesis Space: All possible linear functions of continuous-valued inputs and outputs.

Hypothesis:

Loss Function:

Cost Function:

Session 2 - From Linear Models to the Perceptron

Regression Models

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

Linear Regression

Analytical Solution:

Gradient Descent Algorithm:


Initialize w randomly
repeat
    for each w[i] in w
        Compute gradient: g = ∇Loss(w[i])
        Update weight:   w[i] = w[i] - α * g
until convergence

Hyperparameters: Learning rate, number of epochs, and batch size.

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression

Multivariate regression extends the simple linear model to handle multiple input features. The model learns a function that maps multiple input variables to a continuous output.

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


In these problems, each example is a n-element vector. The hypotheses space now includes linear functions of multiple continuous-valued inputs and a single continuous output.


Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


In these problems, each example is a n-element vector. The hypotheses space now includes linear functions of multiple continuous-valued inputs and a single continuous output.



We want to find the that best fits the data.

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


In these problems, each example is a n-element vector. The hypotheses space now includes linear functions of multiple continuous-valued inputs and a single continuous output.



We want to find the that best fits the data.


In vector notation:


Where is the feature vector, is the parameters vector, and is a bias term.

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


The loss function for multivariate regression is:


Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


The loss function for multivariate regression is:



In matrix notation:



Where is the target vector, is the feature matrix, and is the weight vector.

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


Given the Loss function:

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


Given the Loss function:


We want to find

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


Given the Loss function:


We want to find


Taking the derivative with respect to and setting to zero:

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression


Given the Loss function:


We want to find


Taking the derivative with respect to and setting to zero:


This leads to the normal equation:

Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

Gradient Descent for Multivariate Regression

The gradient of the loss function is:


Session 2 - From Linear Models to the Perceptron

Multivariate Linear Regression

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

Gradient Descent for Multivariate Regression

The gradient of the loss function is:



Update rule for :



Where is the learning rate.

Session 2 - From Linear Models to the Perceptron

Supervised Learning

Underfitted Model
Underfitted Model - AAStein, CC BY-SA 4.0 , via Wikimedia Commons

Underfitting occurs when our hypothesis space is too simple to capture the true function


Even the best hypothesis in will have high error because:



where is some small positive number.

Session 2 - From Linear Models to the Perceptron

Supervised Learning

Overfitting
Overfitting - ThirdOrderLogic, CC BY 4.0 , via Wikimedia Commons

Overfitting occurs when our hypothesis space is too complex, leading to:


Low empirical loss but high generalisation loss:



The hypothesis memorizes the training examples instead of learning the true function .

Session 2 - From Linear Models to the Perceptron

Supervised Learning

Overfitting
Overfitting - ThirdOrderLogic, CC BY 4.0 , via Wikimedia Commons

Regularisation transforms the loss function into a cost function that penalizes complexity to avoid overfitting


Choosing the complexity function depends on the hypotheses space . A good example for polynomials will be a function that returns the sum of the squares of coefficients.

Session 2 - From Linear Models to the Perceptron

Supervised Learning

Given the new cost function



The best hypothesis is the one that minimises the cost:


where is a hyperparameter that controls the trade-off between fitting the data and model complexity and serves as a conversion rate.


Alternatives to mitigate overfitting are feature selection, hyperparameter tuning, splitting dataset in training, validation, and test data (e.g., cross validation algorithm).

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Linear classifiers are models that separate data into classes using a linear decision boundary. These classifiers are functions that can decide if an input (i.e., vectors of numbers) belong to a specific class or not.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

SVM Separating Hyperplanes
SVM Separating Hyperplanes - Cyc, Public domain, via Wikimedia Commons.

A decision boundary is a line (or a surface in higher dimensions) that separates data into classes.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

SVM Separating Hyperplanes
SVM Separating Hyperplanes - Cyc, Public domain, via Wikimedia Commons.

A decision boundary is a line (or a surface in higher dimensions) that separates data into classes.


The hypothesis is the result of passing a linear function through a threshold function:


Session 2 - From Linear Models to the Perceptron

Linear Classifiers

SVM Separating Hyperplanes
SVM Separating Hyperplanes - Cyc, Public domain, via Wikimedia Commons.

A decision boundary is a line (or a surface in higher dimensions) that separates data into classes.


The hypothesis is the result of passing a linear function through a threshold function:


Regression Fit
Threshold Function.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


The optimal hypothesis is the one that minimises the loss function:



Where is the hypothesis space.

Regression Fit
Threshold Function.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


The optimal hypothesis is the one that minimises the loss function:



Where is the hypothesis space.


Partial derivatives and gradient methods do not work. Instead, we apply perceptron learning rule.

Regression Fit
Threshold Function.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


Perceptron update rule:



The rule is applied one example at a time, choosing examples at random (as in stochastic gradient descent).

Regression Fit
Threshold Function.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


An alternative to the discrete threshold function is the logistic function, which is smooth and differentiable.

Regression Fit
Threshold Function.
Logistic Curve
Logistic Curve - Qef, Public domain, via Wikimedia Commons.
Session 2 - From Linear Models to the Perceptron

Linear Classifiers


An alternative to the discrete threshold function is the logistic function, which is smooth and differentiable.

Logistic Curve
Logistic Curve - Qef, Public domain, via Wikimedia Commons.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


An alternative to the discrete threshold function is the logistic function, which is smooth and differentiable. The process of finding the optimal hypothesis is called logistic regression.




Where is the hypothesis space.

Logistic Curve
Logistic Curve - Qef, Public domain, via Wikimedia Commons.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers


An alternative to the discrete threshold function is the logistic function, which is smooth and differentiable. The process of finding the optimal hypothesis is called logistic regression.




Where is the hypothesis space.

Logistic Curve
Logistic Curve - Qef, Public domain, via Wikimedia Commons.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Following the gradient descent algorithm, the update rule is:


Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Following the gradient descent algorithm, the update rule is:



The loss function is represented as a composition of functions:


Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Following the gradient descent algorithm, the update rule is:



The loss function is represented as a composition of functions:



We need to differentiate the loss function using the chain rule to compute the gradients:


Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Following the gradient descent algorithm, the update rule is:


Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Following the gradient descent algorithm, the update rule is:



The resulting update rule after solving the partial derivatives:



The gradient descent algorithm is applied using this update rule.

Session 2 - From Linear Models to the Perceptron

Linear Classifiers

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

Gradient Descent for Logistic Regression

The gradient of the loss function is:



Update rule for :



Where is the learning rate.

Session 2 - From Linear Models to the Perceptron

The Perceptron

Session 2 - From Linear Models to the Perceptron

The Perceptron

The perceptron is one of the earliest and simplest artificial neural network models for binary classification.

Session 2 - From Linear Models to the Perceptron

The Perceptron

1940 1950 1960 1970 1980 1990 2000 2010 2020 2030 First AI Winter (1974-1980) Second AI Winter (1987-1994) Big Data (2000-2012) Artificial Neuron (McCulloch & Pitts, 1943) Information Theory (Shannon, 1948) Cybernetics (Wiener, 1948) Updating Rule (Hebbian, 1949) Computing Machinery and Intelligence (Turing, 1950) SNARC (Minsky, 1951) AI Term (Dartmouth Workshop, 1956) GPS (Newell & Simon, 1957) Advice Taker (McCharty, 1958) Back-Propagation (Kelley, 1960) Perceptrons (Rosenblant, 1962) ELIZA (MIT, 1966) ALPAC Report (USA, 1966) The DENDRAL (Buchanan, 1969) Perceptrons Book (Minsky & Papert, 1969) PROLOG (1972) MYCIN (Stanford, 1972) Lighthill Report (UK, 1973) FRAMES (1975) Hopfield net (1982) R1 (McDermott, 1982) Parallel Distributed Processing (Rumerlhart & McClelland, 1986) Bayesian Networks (Pearls, 1988) Reinforcement Learning (Sutton, 1988) Image Recognition (LeCun et al., 1990) Deep Blue beats Kasparov (IBM, 1997) Deep Learning (Hinton, 2006) Watson wins Jeopardy (2011) AlexNet (Krizhevsky, 2012) GANs (Goodfellow, 2014) AlphaGo beats Lee Sedol (DeepMind, 2016) Transformer (Vaswani, 2017) AlphaFold (DeepMind, 2018) GPT-1 (OpenAI, 2020) BERT (Google, 2019) Chinchilla (DeepMind, 2022) ChatGPT (OpenAI, 2022) LLaMA (Meta AI, 2023) Claude 2 (Anthropic, 2023) phi-3 (Microsoft, 2024) Gemini 1.5 (Google DeepMind, 2024) Qwen3 (Alibaba, 2025) R1 (DeepSeek) 2025)
Session 2 - From Linear Models to the Perceptron

The Perceptron

Rosenblatt
Dr. Frank Rosenblatt and the Mark I - National Museum of the U.S. Navy, Public domain, via Wikimedia Commons.

The perceptron was simulated by Frank Rosenblatt in 1957 on an IBM 704 machine as a model for biological neural networks. The neural network was invented in 1943 by McCulloch & Pitts.

Session 2 - From Linear Models to the Perceptron

The Perceptron

Rosenblatt
Dr. Frank Rosenblatt and the Mark I - National Museum of the U.S. Navy, Public domain, via Wikimedia Commons.

The perceptron was simulated by Frank Rosenblatt in 1957 on an IBM 704 machine as a model for biological neural networks. The neural network was invented in 1943 by McCulloch & Pitts.


By 1962 Rosenblatt published the "Principles of Neurodynamics: Perceptrons and the Theory of Brain Mechanisms".

Session 2 - From Linear Models to the Perceptron

The Perceptron

Rosenblatt
Dr. Frank Rosenblatt and the Mark I - National Museum of the U.S. Navy, Public domain, via Wikimedia Commons.

The perceptron was simulated by Frank Rosenblatt in 1957 on an IBM 704 machine as a model for biological neural networks. The neural network was invented in 1943 by McCulloch & Pitts.


By 1962 Rosenblatt published the "Principles of Neurodynamics: Perceptrons and the Theory of Brain Mechanisms".


The Perceptron machine is named Mark I. It is a special-purpose hardware that implemented the perceptron supervised learning for image recognition.

Session 2 - From Linear Models to the Perceptron

The Perceptron

Rosenblatt
Dr. Frank Rosenblatt and the Mark I - National Museum of the U.S. Navy, Public domain, via Wikimedia Commons.

The Perceptron machine is named Mark I. It is a special-purpose hardware that implemented the perceptron supervised learning for image recognition.

Session 2 - From Linear Models to the Perceptron

The Perceptron

Mark I
Mark I Perceptron - John C. Hay, Albert E. Murray, Public domain, via Wikimedia Commons

The Perceptron machine is named Mark I. It is a special-purpose hardware that implemented the perceptron supervised learning for image recognition.


  • Input layer: An array of 400 photocells (20x20 grid) named "sensory units" or "input retina".
  • Hidden Layer: 512 perceptrons named "association units" or "A-units".
  • Output Layer: 8 perceptrons named "response units" or "R-units".
Session 2 - From Linear Models to the Perceptron

The Perceptron

Mark I
Mark I - (Bishop, 2006).
Session 2 - From Linear Models to the Perceptron

The Perceptron

Biological Brain vs Perceptron - Rosenblatt, F., Public domain, via Wikimedia Commons
Biological Brain vs Perceptron
Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Architecture
Perceptron Architecture.

The perceptron is a linear classifier model (i.e., linear discriminant), with hypothesis space defined by all the functions of the form:

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Architecture
Perceptron Architecture.

The perceptron is a linear classifier model (i.e., linear discriminant), with hypothesis space defined by all the functions of the form:


The function is similar to the function previously defined. is given by a step function of the form:

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Architecture
Perceptron Architecture.

The perceptron is a linear classifier model (i.e., linear discriminant), with hypothesis space defined by all the functions of the form:


The function is similar to the function previously defined. is given by a step function of the form:


We want to find :

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Step Function
Perceptron Step Function.

The perceptron step function is not differentiable and the gradient is zero almost everywhere:

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Step Function
Perceptron Step Function.

The perceptron step function is not differentiable and the gradient is zero almost everywhere:


We need to derive the perceptron criterion. We know we are seeking parameters vector such that features in in class :


And for features in in class :

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Step Function
Perceptron Step Function.

The perceptron step function is not differentiable and the gradient is zero almost everywhere:


Using , all features will satisfy:

Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Loss Function
Perceptron Loss Function.

The perceptron step function is not differentiable and the gradient is zero almost everywhere:


Using , all features will satisfy:


The loss function is:

Session 2 - From Linear Models to the Perceptron

The Perceptron


Perceptron Loss Function
The loss function is:

Session 2 - From Linear Models to the Perceptron

The Perceptron


Perceptron Loss Function
The loss function is:


The update rule for a missclassified input is:


Session 2 - From Linear Models to the Perceptron

The Perceptron


The perceptron learning algorithm is similar to the stochastic gradient descent.



Initialise weights w randomly
repeat
    for each training example (x, y)
        Compute prediction: y_pred = f(w·Φ(x))
        if y_pred ≠ y then
            Update weights: w = w + αΦ(x)y
until no misclassifications or max iterations
Session 2 - From Linear Models to the Perceptron

The Perceptron

import numpy as np

class Perceptron:
    def __init__(self, learning_rate=0.01, max_iterations=1000):
        self.learning_rate = learning_rate
        self.max_iterations = max_iterations
        self.weights = None
        self.bias = None
    def fit(self, X, y):
        n_samples, n_features = X.shape
        self.weights = np.zeros(n_features)
        self.bias = 0
        for _ in range(self.max_iterations):
            misclassified = 0
            for i in range(n_samples):
                prediction = self.predict(X[i])
                if prediction != y[i]:
                    self.weights += self.learning_rate * (y[i] - prediction) * X[i]
                    self.bias += self.learning_rate * (y[i] - prediction)
                    misclassified += 1
            if misclassified == 0:
                break
    def predict(self, x):
        return 1 if np.dot(self.weights, x) + self.bias >= 0 else 0

Python Implementation

Session 2 - From Linear Models to the Perceptron

The Perceptron

XOR Problem
XOR Problem - Andreas Maier, CC BY 4.0 , via Wikimedia Commons

XOR Problem:


The perceptron cannot learn the XOR function because it's not linearly separable.

(Minsky & Papert, 1969)


Other limitations:

  • Only binary classification
  • No probabilistic output
  • The step function is not differentiable
  • May oscillate for non-separable data
Session 2 - From Linear Models to the Perceptron

The Perceptron

1940 1950 1960 1970 1980 1990 2000 2010 2020 2030 First AI Winter (1974-1980) Second AI Winter (1987-1994) Big Data (2000-2012) Artificial Neuron (McCulloch & Pitts, 1943) Information Theory (Shannon, 1948) Cybernetics (Wiener, 1948) Updating Rule (Hebbian, 1949) Computing Machinery and Intelligence (Turing, 1950) SNARC (Minsky, 1951) AI Term (Dartmouth Workshop, 1956) GPS (Newell & Simon, 1957) Advice Taker (McCharty, 1958) Back-Propagation (Kelley, 1960) Perceptrons (Rosenblant, 1962) ELIZA (MIT, 1966) ALPAC Report (USA, 1966) The DENDRAL (Buchanan, 1969) Perceptrons Book (Minsky & Papert, 1969) PROLOG (1972) MYCIN (Stanford, 1972) Lighthill Report (UK, 1973) FRAMES (1975) Hopfield net (1982) R1 (McDermott, 1982) Parallel Distributed Processing (Rumerlhart & McClelland, 1986) Bayesian Networks (Pearls, 1988) Reinforcement Learning (Sutton, 1988) Image Recognition (LeCun et al., 1990) Deep Blue beats Kasparov (IBM, 1997) Deep Learning (Hinton, 2006) Watson wins Jeopardy (2011) AlexNet (Krizhevsky, 2012) GANs (Goodfellow, 2014) AlphaGo beats Lee Sedol (DeepMind, 2016) Transformer (Vaswani, 2017) AlphaFold (DeepMind, 2018) GPT-1 (OpenAI, 2020) BERT (Google, 2019) Chinchilla (DeepMind, 2022) ChatGPT (OpenAI, 2022) LLaMA (Meta AI, 2023) Claude 2 (Anthropic, 2023) phi-3 (Microsoft, 2024) Gemini 1.5 (Google DeepMind, 2024) Qwen3 (Alibaba, 2025) R1 (DeepSeek) 2025)
Session 2 - From Linear Models to the Perceptron

The Perceptron

Perceptron Overview
Perceptron Overview - Andreas Maier, CC BY 4.0 , via Wikimedia Commons
Session 2 - From Linear Models to the Perceptron

Machine Learning Pipeline

Data Assess Pipeline
Session 2 - From Linear Models to the Perceptron

Hyperparameters

Gradient Descent Algorithm
Gradient Descent Algorithm - Jacopo Bertolotti, CC0, via Wikimedia Commons.

Hyperparameters defined in this lecture

  • Learning rate : size of each gradient descent step

  • Epochs: number of complete passes through the dataset

  • Batch size : training examples per mini-batch update

  • Regularisation strength : weight of the complexity penalty in the cost function

  • Max iterations: stopping limit for the perceptron learning algorithm

Session 2 - From Linear Models to the Perceptron

Conclusions

Overview

  • Linear and logistic baselines
  • Hypothesis space, loss function, weights, update rule, gradient descent
  • The perceptron and linear separability
  • Hyperparameters

Next Time

  • Neural networks
  • Activation functions
  • Back-propagation
  • Networks architectures
Session 2 - From Linear Models to the Perceptron

Many Thanks!

chc79@cam.ac.uk

_script: true

This script will only execute in HTML slides

_script: true