Designing Machine Learning ApplicationsDesigning Machine Learning Applications
Home
Discus
Home
Discus
  • Contents
  • Preface

    • About the Author
    • About DMLA
  • Mathematical Foundations

    • Linear Algebra

      • Vector Basics
      • Matrix Basics
    • Calculus

      • Limits, Derivatives, and Differentials
      • Multivariate Functions and Composite Function Differentiation
    • Statistics and Probability

      • Probability Basics
      • Statistical Inference
  • Classical Statistical Learning

    • Linear Models

      • Linear Regression
      • Logistic Regression
      • Regularization and Generalized Linear Models
    • Bayesian Methods

      • Naive Bayes
      • Bayesian Network
      • EM Algorithm
    • Support Vector Machines

      • Support Vector Machine
      • Kernel Trick
    • Decision Trees and Ensembles

      • Decision Trees
      • Random Forest
      • Boosting
    • Unsupervised Learning

      • Clustering
      • Dimensionality Reduction
  • Neural Networks and Deep Learning

    • Neural Network Architectures

      • Fundamentals of Neural Networks
      • Linear Perceptron
      • Multi-Layer Perceptron
      • Forward Propagation
      • Backpropagation
      • Activation Functions and Loss Functions
    • Optimization

      • Gradient Descent
      • Adaptive Optimizers
    • Deep Network Stability

      • Weight Initialization
      • Dropout Regularization
      • Batch Normalization
    • Convolutional Neural Networks

      • CNN Basics
      • AlexNet and the CNN Revival
      • VGG and GoogLeNet
      • ResNet Residual Network
      • Lab: AlexNet Image Classification
    • Generative Models

      • Variational Autoencoder
      • Generative Adversarial Network
      • Lab: DCGAN Image Generation
    • Sequence Models

      • Word Embedding and Representation Learning
      • RNN Fundamentals
      • LSTM and GRU Gating Mechanisms
      • Seq2Seq Sequence Mapping
      • Lab: LSTM Poetry Generation
  • The Language Model Singularity

    • Transformer Architecture

      • Transformer Fundamentals
      • Transformer Evolution and Variants
      • Language Models and Tokenization
      • Lab: Transformer Model Training
    • Pretraining and Fine-Tuning

      • Pretraining Data Engineering
      • Scaling Laws
      • Distributed Training Infrastructure
      • Supervised Fine-Tuning
      • Lab: SFT Model Conversation
    • Alignment Training

      • Reinforcement Learning from Human Feedback
      • Evolution of Alignment Methods
      • Lab: DPO Alignment Training
    • Reasoning Capabilities

      • Chain of Thought and Reasoning Models
      • Test-Time Compute Scaling
      • Inference Efficiency Optimization
      • Lab: LLM Inference Optimization
    • Multimodal Fusion and Safety

      • Multimodal Large Language Models
      • Model Evaluation and Safety
      • Lab: VLM Training
  • AI Infrastructure and Engineering

    • Model Serving

      • Inference Service Architecture
      • Request Scheduling and Batching
      • GPU Resource Management
      • Lab: Deploying LLM Inference Service
    • MLOps Practices

      • Data Versioning
      • Experiment Tracking and Model Registry
      • Hyperparameter Optimization
      • Model Performance Monitoring
      • Drift Detection
  • Agentic Application Systems

    • Vector Retrieval and RAG

      • Embedding and Vector Retrieval
      • Retrieval Quality Evaluation and Optimization
      • Retrieval-Augmented Generation
      • Lab: Building a Knowledge Base Q&A System
    • Building Agent Applications

      • From LLM to Agent
      • Tool Use
      • Planning and Reasoning
      • Memory Systems
      • Agent Collaboration and Communication
      • Orchestration and Fault Tolerance
      • Lab: Research Agent Collaboration System
  • Appendix

    • Building the Sandbox Environment
    • NumPy Practice

      • Data Processing Practice
      • Calculus Computation Practice
      • Probability and Statistics Practice

Linear Perceptron

In the previous chapter, we mentioned that the 1969 book Perceptrons sharply criticized the perceptron, pointing out its inability to solve the XOR problem. This criticism plunged neural network research into a decade-long trough. However, the criticism itself precisely revealed the essential characteristic of the perceptron — Linear Separability. Understanding this property not only helps grasp how the perceptron works, but also provides readers with deep insight into the inner logic of the evolution from single-layer to multi-layer neural networks.

The Perceptron, proposed by psychologist Frank Rosenblatt in 1957, was the world's first neural network model capable of learning from data. It introduced a learning algorithm based on the M-P model, enabling automatic weight adjustment to perform pattern recognition and classification tasks. The advent of the perceptron marked the transition of neural network research from theoretical study to practical application, sparking the first wave of neural network research. This chapter will detail the model structure, geometric interpretation, learning algorithm, and convergence theorem of the perceptron, and experimentally verify its learning capabilities and limitations.

Perceptron Model

The perceptron is a single-layer neural network consisting of an input layer and an output layer, with no hidden layers. The entire perceptron structure includes the input vector x=(x1,x2,…,xn)T\mathbf{x} = (x_1, x_2, \ldots, x_n)^Tx=(x1​,x2​,…,xn​)T, the weight vector w=(w1,w2,…,wn)T\mathbf{w} = (w_1, w_2, \ldots, w_n)^Tw=(w1​,w2​,…,wn​)T, and the bias bbb. The final output is a binary result {+1,−1}\{+1, -1\}{+1,−1}. The perceptron structure is illustrated in the following figure, and its output calculation proceeds in two steps:

  • First step Linear Combination: Compute the weighted sum of inputs plus bias z=wTx+b=∑i=1nwixi+bz = \mathbf{w}^T \mathbf{x} + b = \sum_{i=1}^{n} w_i x_i + bz=wTx+b=∑i=1n​wi​xi​+b
  • Second step Activation Function: Convert the linear output to a binary output via a threshold function (a simple sign function) y={1if z≥0−1if z<0y = \begin{cases} 1 & \text{if } z \geq 0 \\ -1 & \text{if } z < 0 \end{cases}y={1−1​if z≥0if z<0​

Perceptron Structure

Figure: Structure of the Perceptron

The perceptron uses the sign function sign(z)\text{sign}(z)sign(z) as its activation function, with output values {1,−1}\{1, -1\}{1,−1}. In this context, the activation function transforms the continuous linear output into discrete class labels, enabling classification decisions. The bias bbb can be understood as the negative of the threshold θ\thetaθ. In the M-P model from the previous chapter, the threshold condition was ∑wixi≥θ\sum w_i x_i \geq \theta∑wi​xi​≥θ. Moving the threshold to the left side gives ∑wixi−θ≥0\sum w_i x_i - \theta \geq 0∑wi​xi​−θ≥0, which yields b=−θb = -\thetab=−θ. This form is mathematically more convenient because the decision boundary can be uniformly written as wTx+b=0\mathbf{w}^T \mathbf{x} + b = 0wTx+b=0.

For ease of derivation, it is customary to incorporate the bias bbb into the weight vector. Define the augmented input vector x~=(x1,x2,…,xn,1)T\tilde{\mathbf{x}} = (x_1, x_2, \ldots, x_n, 1)^Tx~=(x1​,x2​,…,xn​,1)T and the augmented weight vector w~=(w1,w2,…,wn,b)T\tilde{\mathbf{w}} = (w_1, w_2, \ldots, w_n, b)^Tw~=(w1​,w2​,…,wn​,b)T. The perceptron output can then be concisely expressed as y=sign(w~Tx~)y = \text{sign}(\tilde{\mathbf{w}}^T \tilde{\mathbf{x}})y=sign(w~Tx~). This representation treats the bias as the weight corresponding to a constant input of 1, simplifying the mathematical formulation. In the following discussion, unless otherwise specified, we use the augmented vector form and omit the augmentation notation, simply writing w\mathbf{w}w and x\mathbf{x}x.

The decision boundary of the perceptron is the hyperplane equation wTx=0\mathbf{w}^T \mathbf{x} = 0wTx=0. In two-dimensional space, the decision boundary is a straight line; in three or higher dimensions, it is a hyperplane. This hyperplane partitions the input space into two regions: wTx≥0\mathbf{w}^T \mathbf{x} \geq 0wTx≥0 outputs y=1y = 1y=1 (positive class), and wTx<0\mathbf{w}^T \mathbf{x} < 0wTx<0 outputs y=−1y = -1y=−1 (negative class). The position and orientation of the decision boundary are determined by the weight vector w\mathbf{w}w. The direction of the weight vector is perpendicular to the decision boundary, since w\mathbf{w}w is the normal vector of the hyperplane. The magnitude of the weight vector determines the "steepness" of the boundary, as shown in the figure below.

Perceptron Hyperplane Diagram

Figure: Decision boundary (hyperplane) of the perceptron. The normal vector w\mathbf{w}w is perpendicular to the decision boundary, partitioning the space into positive and negative regions

In our earlier discussion of linear models, we extensively used the concept of Linearly Separable, which refers to the existence of a hyperplane that can completely separate two classes of data points, with all positive samples on one side and all negative samples on the other. Given a training dataset D={(xi,yi)}i=1ND = \{(\mathbf{x}_i, y_i)\}_{i=1}^{N}D={(xi​,yi​)}i=1N​, where xi∈Rn\mathbf{x}_i \in \mathbb{R}^nxi​∈Rn and yi∈{1,−1}y_i \in \{1, -1\}yi​∈{1,−1}, dataset DDD is linearly separable if there exists a weight vector w\mathbf{w}w such that yi⋅(wTxi)>0y_i \cdot (\mathbf{w}^T \mathbf{x}_i) > 0yi​⋅(wTxi​)>0 for all samples.

A typical example of linear separability is the AND logical operation. The truth table for AND has four cases: (0,0)→0(0, 0) \rightarrow 0(0,0)→0 (negative class), (0,1)→0(0, 1) \rightarrow 0(0,1)→0 (negative class), (1,0)→0(1, 0) \rightarrow 0(1,0)→0 (negative class), (1,1)→1(1, 1) \rightarrow 1(1,1)→1 (positive class). On a two-dimensional plane, the three negative points (0,0)(0,0)(0,0), (0,1)(0,1)(0,1), (1,0)(1,0)(1,0) and the one positive point (1,1)(1,1)(1,1) can be separated by a straight line. The decision boundary x1+x2=1.5x_1 + x_2 = 1.5x1​+x2​=1.5 (or x1+x2−1.5=0x_1 + x_2 - 1.5 = 0x1​+x2​−1.5=0) separates the positive point from the others.

A typical example of linear non-separability is the XOR logical operation. The truth table for XOR is: (0,0)→0(0, 0) \rightarrow 0(0,0)→0 (negative class), (0,1)→1(0, 1) \rightarrow 1(0,1)→1 (positive class), (1,0)→1(1, 0) \rightarrow 1(1,0)→1 (positive class), (1,1)→0(1, 1) \rightarrow 0(1,1)→0 (negative class). On a two-dimensional plane, the four points exhibit a "diagonal distribution": positive points lie on the diagonal (0,1)−(1,0)(0,1) - (1,0)(0,1)−(1,0), while negative points lie on the other diagonal (0,0)−(1,1)(0,0) - (1,1)(0,0)−(1,1). Any straight line either passes through the positive points or passes through the negative points; it cannot separate them, as shown in the figure below.

Linear Separability and XOR Problem

Figure: Comparison of linear separability (AND) and linear non-separability (XOR)

Perceptron Learning Algorithm

The perceptron directly inherits the design philosophy of the M-P model: weighted summation, threshold decision, and binary output. The key difference is that the perceptron possesses learning ability. While the M-P model requires manual setting of weights and thresholds, the perceptron introduces a learning algorithm that can automatically adjust weights and biases based on training data. This capability stems from the Hebbian learning rule, which states that weights can be adjusted according to neural activity. The perceptron evolved Hebbian correlation learning into error-driven learning: weights are updated only when a prediction is wrong, and the direction of the update moves the next prediction closer to the correct result. The algorithm steps are quite straightforward, with three steps:

  • First step Initialization: The weight vector w\mathbf{w}w is initialized to a zero vector or small random values.
  • Second step Iterative Training: Iterate over the training data. For each sample (xi,yi)(\mathbf{x}_i, y_i)(xi​,yi​), compute the predicted value y^i=sign(wTxi)\hat{y}_i = \text{sign}(\mathbf{w}^T \mathbf{x}_i)y^​i​=sign(wTxi​). If the prediction is wrong (y^i≠yi\hat{y}_i \neq y_iy^​i​=yi​), update the weights w←w+η⋅yi⋅xi\mathbf{w} \leftarrow \mathbf{w} + \eta \cdot y_i \cdot \mathbf{x}_iw←w+η⋅yi​⋅xi​, where η>0\eta > 0η>0 is the learning rate that controls the update step size. When updating weights:
    • If the true label yi=1y_i = 1yi​=1 but the prediction is −1-1−1 (wTxi<0\mathbf{w}^T \mathbf{x}_i < 0wTxi​<0), the sample xi\mathbf{x}_ixi​ lies on the wrong side of the decision boundary. The update rule w←w+η⋅xi\mathbf{w} \leftarrow \mathbf{w} + \eta \cdot \mathbf{x}_iw←w+η⋅xi​ moves the weight vector toward the sample, increasing wTxi\mathbf{w}^T \mathbf{x}_iwTxi​ and making it more likely to become positive.
    • Similarly, if the true label yi=−1y_i = -1yi​=−1 but the prediction is 111 (wTxi>0\mathbf{w}^T \mathbf{x}_i > 0wTxi​>0), the update rule w←w−η⋅xi\mathbf{w} \leftarrow \mathbf{w} - \eta \cdot \mathbf{x}_iw←w−η⋅xi​ moves the weight vector away from the sample, decreasing wTxi\mathbf{w}^T \mathbf{x}_iwTxi​ and making it more likely to become negative.
  • Third step Termination Condition: Stop when all samples are correctly classified or the maximum number of iterations is reached.

Rosenblatt proved an important theorem: if the training dataset is linearly separable, the perceptron learning algorithm will converge in a finite number of steps, correctly classifying all samples. The proof also shows that if the data is non-linearly separable, the algorithm may fail to converge, with weights updating indefinitely and misclassified samples always present. This conclusion reveals the necessity of multi-layer networks: because the perceptron performs linear processing directly on raw inputs, it lacks the ability to combine features. Taking the XOR problem as an example, its essence is determining "whether exactly one input is 1." This requires the classifier to simultaneously detect the combined features of two inputs, rather than processing each input independently. The solution is to add a hidden layer: first extract combined features, then make decisions based on the extracted features — this enables solving the XOR problem. Rosenblatt himself was likely aware of this, but was constrained by the inability to train multi-layer networks, an issue that was not resolved until the backpropagation algorithm was proposed in the 1980s.

The following code provides a complete implementation of the perceptron learning algorithm and verifies its learning capability on both linearly separable (AND problem) and non-linearly separable (XOR problem) data.

import numpy as np
import matplotlib.pyplot as plt

class Perceptron:
    """
    Perceptron Implementation
    
    Uses error-driven weight update rule:
    w = w + eta * y * x (when prediction is wrong)
    """
    def __init__(self, learning_rate=1.0, max_iterations=1000):
        self.lr = learning_rate
        self.max_iter = max_iterations
        self.w = None  # weight vector (including bias)
        self.errors_history = []  # error count per iteration
    
    def fit(self, X, y):
        """
        Train perceptron
        
        Parameters:
        X : ndarray, shape (n_samples, n_features)
            Input feature matrix
        y : ndarray, shape (n_samples,)
            Label vector, values in {1, -1}
        """
        n_samples, n_features = X.shape
        
        # Augmented vector: add constant 1 column (for bias)
        X_aug = np.column_stack([X, np.ones(n_samples)])
        
        # Initialize weights to zero vector
        self.w = np.zeros(n_features + 1)
        
        # Training loop
        for iteration in range(self.max_iter):
            errors = 0
            for i in range(n_samples):
                # Compute prediction
                prediction = np.sign(self.w @ X_aug[i])
                if prediction == 0:
                    prediction = 1  # sign function boundary case (z=0 outputs 1, consistent with the text)
                
                # If prediction is wrong, update weights
                if prediction != y[i]:
                    self.w += self.lr * y[i] * X_aug[i]
                    errors += 1
            
            self.errors_history.append(errors)
            
            # Early termination if all samples correctly classified
            if errors == 0:
                print(f"Converged after {iteration + 1} iterations")
                break
        
        return self
    
    def predict(self, X):
        """
        Predict
        
        Parameters:
        X : ndarray, shape (n_samples, n_features)
        
        Returns:
        predictions : ndarray, shape (n_samples,)
            Predicted labels {1, -1}
        """
        n_samples = X.shape[0]
        X_aug = np.column_stack([X, np.ones(n_samples)])
        predictions = np.sign(X_aug @ self.w)
        predictions[predictions == 0] = 1
        return predictions
    
    def score(self, X, y):
        """Calculate accuracy"""
        predictions = self.predict(X)
        return np.mean(predictions == y)


# Experiment 1: Linearly Separable Data
print("=" * 50)
print("Experiment 1: Linearly Separable Data (AND Logic)")
print("=" * 50)

# AND data: three negative samples, one positive sample
X_and = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_and = np.array([-1, -1, -1, 1])  # Use -1 for class 0

model_and = Perceptron(learning_rate=1.0, max_iterations=100)
model_and.fit(X_and, y_and)

print(f"Learned weights: w1={model_and.w[0]:.2f}, w2={model_and.w[1]:.2f}, b={model_and.w[2]:.2f}")
print(f"Decision boundary: {model_and.w[0]:.2f}*x1 + {model_and.w[1]:.2f}*x2 + {model_and.w[2]:.2f} = 0")
print(f"Training accuracy: {model_and.score(X_and, y_and):.2%}")

# Experiment 2: Non-linearly Separable Data (XOR Logic)
print("\n" + "=" * 50)
print("Experiment 2: Non-linearly Separable Data (XOR Logic)")
print("=" * 50)

# XOR data
X_xor = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_xor = np.array([-1, 1, 1, -1])  # XOR: outputs 0 when both are 0 or both are 1, otherwise outputs 1

model_xor = Perceptron(learning_rate=1.0, max_iterations=100)
model_xor.fit(X_xor, y_xor)

print(f"Training accuracy: {model_xor.score(X_xor, y_xor):.2%}")
print(f"Note: XOR is non-linearly separable, perceptron cannot converge to correct solution")

# Visualization
fig, axes = plt.subplots(1, 3, figsize=(15, 5))

# Figure 1: Decision boundary for AND problem
def plot_decision_boundary(ax, X, y, model, title):
    # Plot data points
    colors = ['blue' if label == 1 else 'red' for label in y]
    ax.scatter(X[:, 0], X[:, 1], c=colors, s=100, edgecolors='k', linewidth=2)
    
    # Plot decision boundary
    w1, w2, b = model.w
    if w2 != 0:
        x_line = np.linspace(-0.5, 1.5, 100)
        y_line = -(w1 * x_line + b) / w2
        ax.plot(x_line, y_line, 'g-', linewidth=2, label='Decision boundary')
    
    ax.set_xlim(-0.5, 1.5)
    ax.set_ylim(-0.5, 1.5)
    ax.set_xlabel('x1')
    ax.set_ylabel('x2')
    ax.set_title(title)
    # ax.legend()
    ax.grid(True, alpha=0.3)

plot_decision_boundary(axes[0], X_and, y_and, model_and, 'AND (Linearly Separable)')
plot_decision_boundary(axes[1], X_xor, y_xor, model_xor, 'XOR (Non-linearly Separable)')

# Figure 3: Convergence comparison
axes[2].plot(model_and.errors_history, 'b-', linewidth=2, label='AND (Converged)')
axes[2].plot(model_xor.errors_history, 'r-', linewidth=2, label='XOR (Not converged)')
axes[2].set_xlabel('Iteration')
axes[2].set_ylabel('Number of errors')
axes[2].set_title('Convergence Comparison')
axes[2].legend()
axes[2].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()
plt.close()
Click Run to execute code. Click the code area to edit.

Summary

This chapter provides a detailed introduction to Rosenblatt's perceptron model, including its structure, geometric interpretation, learning algorithm, and convergence theorem. In 1958, Rosenblatt implemented the first learnable neural network on the Mark I perceptron at the Cornell Aeronautical Laboratory. Its core contribution is the error-driven learning mechanism: when a classification error occurs, the model automatically adjusts its weights until the correct decision boundary is found. The decision boundary of a perceptron is a linear hyperplane, which limits its expressive power to linearly separable classification problems and implies inevitable failure on non-linearly separable data. In 1969, the book Perceptrons rigorously proved the limitations of single-layer perceptrons, a conclusion that plunged neural network research into nearly a decade of winter. But the predicament also pointed the way forward: add hidden layers, build multi-layer networks, and let the model first extract combined features before making decisions. The key issue is how to train multi-layer networks, which will be discussed in the next chapter on Multilayer Perceptrons and resolved in the subsequent chapter on the backpropagation algorithm.

Exercises

  1. Prove that the perceptron weight update rule w←w+η⋅yi⋅xi\mathbf{w} \leftarrow \mathbf{w} + \eta \cdot y_i \cdot \mathbf{x}_iw←w+η⋅yi​⋅xi​ moves the predicted value of a misclassified sample in the correct direction. That is, prove that after the update, yi⋅(wnewTxi)>yi⋅(woldTxi)y_i \cdot (\mathbf{w}_{new}^T \mathbf{x}_i) > y_i \cdot (\mathbf{w}_{old}^T \mathbf{x}_i)yi​⋅(wnewT​xi​)>yi​⋅(woldT​xi​).

    Reference Answer

    Let the weight before the update be w\mathbf{w}w, and the sample (xi,yi)(\mathbf{x}_i, y_i)(xi​,yi​) be misclassified, i.e., yi⋅(wTxi)<0y_i \cdot (\mathbf{w}^T \mathbf{x}_i) < 0yi​⋅(wTxi​)<0.

    The updated weight is wnew=w+η⋅yi⋅xi\mathbf{w}_{new} = \mathbf{w} + \eta \cdot y_i \cdot \mathbf{x}_iwnew​=w+η⋅yi​⋅xi​.

    Compute the predicted value after the update:

    wnewTxi=(w+η⋅yi⋅xi)Txi=wTxi+η⋅yi⋅xiTxi\mathbf{w}_{new}^T \mathbf{x}_i = (\mathbf{w} + \eta \cdot y_i \cdot \mathbf{x}_i)^T \mathbf{x}_i = \mathbf{w}^T \mathbf{x}_i + \eta \cdot y_i \cdot \mathbf{x}_i^T \mathbf{x}_iwnewT​xi​=(w+η⋅yi​⋅xi​)Txi​=wTxi​+η⋅yi​⋅xiT​xi​

    Note that xiTxi=∥xi∥2>0\mathbf{x}_i^T \mathbf{x}_i = \|\mathbf{x}_i\|^2 > 0xiT​xi​=∥xi​∥2>0 (assuming the sample is not the zero vector), and η>0\eta > 0η>0.

    Therefore:

    yi⋅(wnewTxi)=yi⋅(wTxi)+η⋅yi2⋅∥xi∥2y_i \cdot (\mathbf{w}_{new}^T \mathbf{x}_i) = y_i \cdot (\mathbf{w}^T \mathbf{x}_i) + \eta \cdot y_i^2 \cdot \|\mathbf{x}_i\|^2yi​⋅(wnewT​xi​)=yi​⋅(wTxi​)+η⋅yi2​⋅∥xi​∥2

    Since yi2=1y_i^2 = 1yi2​=1 (labels are ±1\pm 1±1), ∥xi∥2>0\|\mathbf{x}_i\|^2 > 0∥xi​∥2>0, and η>0\eta > 0η>0, we have:

    yi⋅(wnewTxi)=yi⋅(wTxi)+η⋅∥xi∥2>yi⋅(wTxi)y_i \cdot (\mathbf{w}_{new}^T \mathbf{x}_i) = y_i \cdot (\mathbf{w}^T \mathbf{x}_i) + \eta \cdot \|\mathbf{x}_i\|^2 > y_i \cdot (\mathbf{w}^T \mathbf{x}_i)yi​⋅(wnewT​xi​)=yi​⋅(wTxi​)+η⋅∥xi​∥2>yi​⋅(wTxi​)

    This proves that after the update, yi⋅(wnewTxi)y_i \cdot (\mathbf{w}_{new}^T \mathbf{x}_i)yi​⋅(wnewT​xi​) increases by η⋅∥xi∥2\eta \cdot \|\mathbf{x}_i\|^2η⋅∥xi​∥2 compared to before the update. With enough updates, yi⋅(wTxi)y_i \cdot (\mathbf{w}^T \mathbf{x}_i)yi​⋅(wTxi​) will eventually become positive, and the sample will be correctly classified.

    Key Insight: Each update moves the predicted value in the correct direction by a fixed step η⋅∥xi∥2\eta \cdot \|\mathbf{x}_i\|^2η⋅∥xi​∥2. This is the essence of "error-driven learning": only correct errors, do not optimize correct predictions.

  2. Design a two-layer perceptron to solve the OR logical operation, write down the weight and threshold settings for each layer's neurons, and verify its correctness. OR operation definition: (0,0)→0(0,0)\rightarrow 0(0,0)→0, (0,1)→1(0,1)\rightarrow 1(0,1)→1, (1,0)→1(1,0)\rightarrow 1(1,0)→1, (1,1)→1(1,1)\rightarrow 1(1,1)→1.

    Reference Answer Consider the perceptron model y=sign(w1x1+w2x2+b)y = \text{sign}(w_1 x_1 + w_2 x_2 + b)y=sign(w1​x1​+w2​x2​+b). Choose weights w1=1,w2=1,b=−0.5w_1 = 1, w_2 = 1, b = -0.5w1​=1,w2​=1,b=−0.5.

    Verification:

    • (0,0)(0,0)(0,0): 0+0−0.5=−0.5<00 + 0 - 0.5 = -0.5 < 00+0−0.5=−0.5<0, output −1-1−1 (class 0) ✓
    • (0,1)(0,1)(0,1): 0+1−0.5=0.5>00 + 1 - 0.5 = 0.5 > 00+1−0.5=0.5>0, output 111 ✓
    • (1,0)(1,0)(1,0): 1+0−0.5=0.5>01 + 0 - 0.5 = 0.5 > 01+0−0.5=0.5>0, output 111 ✓
    • (1,1)(1,1)(1,1): 1+1−0.5=1.5>01 + 1 - 0.5 = 1.5 > 01+1−0.5=1.5>0, output 111 ✓

    The decision boundary x1+x2=0.5x_1 + x_2 = 0.5x1​+x2​=0.5 is a straight line that separates the origin (class 0) from the other three points (class 1). OR data is linearly separable, so a single-layer perceptron is sufficient.

Words: 2,606
Updated 2026-08-07
Last Updated:
Contributors: icyfenix, Claude
Prev
Fundamentals of Neural Networks
Next
Multi-Layer Perceptron