1. Home
  2. Explore
  3. Computer Science
  4. Neural Network Pattern Recognition

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Neural Network Pattern Recognition

Neural Networks: Pattern Recognition, Layers, and Training

1. Neural Networks as Pattern-Recognition Systems

Neural networks are computational systems designed to learn patterns from input data. They are useful when the relationship between inputs and desired outputs is too complicated to express through simple rules.

A small example uses a camera with only four black-and-white pixels. The network must classify each image as one of four possible patterns:

  • Solid white or solid dark

  • Vertical line

  • Diagonal line

  • Horizontal line

Although the image is extremely small, classification is not always straightforward. Two different images may both represent horizontal lines even though different pixels are bright in each image. A rule based only on the brightness of a particular pixel would therefore be unreliable.

The neural network solves this by combining the pixel values in multiple ways rather than examining them with isolated, fixed rules.

Neural networks learn useful combinations of input features by adjusting the strengths of connections between computational units.


2. Representing Inputs with Neurons

Each pixel is represented by an input neuron. The brightness of a pixel is converted into a numerical value:

  • +1+1+1: completely white

  • 000: gray or halfway between black and white

  • −1-1−1: completely black

For a four-pixel image, the input can be represented as a list of four numbers:

x=[x1,x2,x3,x4]\mathbf{x} = [x_1, x_2, x_3, x_4]x=[x1​,x2​,x3​,x4​]

This list is called an input vector or input array. It is a numerical representation of the current input image.

For example, an image with two dark pixels and two light pixels might be represented by values such as:

[−1,+1,−1,+1][-1, +1, -1, +1][−1,+1,−1,+1]

The exact arrangement of values matters. A neural network must learn not only how much brightness exists overall, but also how brightness is distributed across the pixels.


3. Receptive Fields

A neuron’s receptive field is the set of input features that makes that neuron most active.

For an input neuron, the receptive field is simple:

  • Each input neuron is associated with one pixel.

  • The neuron reaches its maximum value when that pixel is completely white.

  • The neuron reaches its minimum value when that pixel is completely black.

  • Other pixels have no effect on that input neuron.

For neurons in later layers, receptive fields become more complex. A later neuron may respond strongly to:

  • Two specific pixels being white

  • One pixel being white and another being black

  • A particular arrangement of several pixels

  • A larger pattern spread across the whole image

The receptive field therefore describes what pattern a neuron has learned to detect.


4. The Basic Operation of a Neuron

A neuron performs two main operations:

  1. It calculates a weighted sum of its inputs.

  2. It applies an activation function to that sum.

4.1 Weighted Inputs

Each connection between neurons has a numerical weight. A weight controls how strongly one neuron influences another.

  • A positive weight strengthens the contribution of an input.

  • A negative weight reverses the contribution of an input.

  • A weight of zero effectively ignores the input.

  • Larger magnitudes indicate stronger influence.

If the inputs are x1,x2,…,xnx_1, x_2, \ldots, x_nx1​,x2​,…,xn​ and the corresponding weights are w1,w2,…,wnw_1, w_2, \ldots, w_nw1​,w2​,…,wn​, the weighted sum is:

z=∑i=1nwixiz = \sum_{i=1}^{n} w_i x_iz=∑i=1n​wi​xi​

A weight of −1-1−1 turns an input into its negative. For example:

(−1)(+1)=−1(-1)(+1) = -1(−1)(+1)=−1

A weight of zero contributes nothing:

0⋅xi=00 \cdot x_i = 00⋅xi​=0

The weighted sum allows the neuron to recognize combinations of inputs rather than responding to only one input at a time.

4.2 Graphical Representation of Weights

Weights can be represented visually:

  • White links represent positive weights.

  • Black links represent negative weights.

  • Thicker lines represent weights with larger magnitudes.

  • Missing links may represent weights of zero in simplified diagrams.

In a real neural network, weights are generally continuous values rather than only −1-1−1, 000, or +1+1+1.


5. Activation Functions

After calculating the weighted sum, the neuron applies an activation function. This transforms the raw sum into the neuron's output value.

Activation functions are important because they:

  • Limit or reshape neuron values

  • Introduce nonlinear behavior

  • Allow networks to learn complicated patterns

  • Help keep computations stable

Two activation functions discussed are the sigmoid function and the rectified linear unit.


6. The Sigmoid Activation Function

A sigmoid function has an S-shaped curve. It receives a numerical input and produces an output between −1-1−1 and +1+1+1 in the version described here.

For an input such as 0.50.50.5, the sigmoid output is slightly below 0.50.50.5. As the input becomes larger, the output also increases, but progressively more slowly.

The function has the following general behavior:

  • Large positive inputs produce values close to +1+1+1.

  • Large negative inputs produce values close to −1-1−1.

  • Inputs near zero produce outputs near the middle of the range.

  • The output never exceeds the bounded range.

The neuron’s output can be written as:

a=σ(z)a = \sigma(z)a=σ(z)

where:

  • zzz is the weighted sum

  • σ\sigmaσ is the sigmoid function

  • aaa is the activated output

The sigmoid ensures that neuron values remain bounded, which helps maintain numerical stability during computation.

A sigmoid neuron first calculates a weighted sum and then compresses that sum into a limited output range.

For example, a weighted sum may be transformed into an output of approximately 0.7460.7460.746. The exact output depends on the chosen sigmoid definition and the value of the weighted sum.


7. Layers in a Neural Network

A neural network contains groups of neurons called layers.

7.1 Input Layer

The input layer contains one neuron for each input feature. In the four-pixel example, it contains four input neurons.

The input layer does not usually perform a complex transformation. It holds the numerical representation of the image.

7.2 Hidden Layers

A hidden layer receives values from the previous layer, combines them using weighted connections, and produces new values.

The output of one layer becomes the input to the next:

Layer 1 output→Layer 2 input\text{Layer 1 output} \rightarrow \text{Layer 2 input}Layer 1 output→Layer 2 input

A network may contain:

  • One hidden layer

  • Several hidden layers

  • Hundreds or even more layers in large systems

A network with many layers is described as a deep neural network.

7.3 Output Layer

The final layer contains neurons corresponding to the classifications or predictions of interest. In the pixel example, the output layer has four neurons:

  • Solid

  • Vertical

  • Diagonal

  • Horizontal

The output neuron with the strongest activation indicates the network’s prediction.


8. Increasingly Complex Receptive Fields

The first hidden layer may detect simple relationships between pairs or small groups of pixels. For example, one neuron may combine:

  • The upper-left pixel

  • The lower-left pixel

If both connections have positive weights, the neuron becomes highly active when both pixels are bright.

Another neuron might connect to:

  • The upper-right pixel with a positive weight

  • The lower-right pixel with a negative weight

That neuron becomes most active when the upper-right pixel is bright and the lower-right pixel is dark.

Its receptive field therefore represents a specific contrast pattern rather than simple brightness.

As information moves through additional layers, receptive fields become increasingly complex:

  1. Input neurons represent individual pixels.

  2. Early hidden neurons represent combinations of pixels.

  3. Later hidden neurons represent arrangements involving larger portions of the image.

  4. Output neurons represent complete categories such as horizontal or diagonal lines.

This hierarchical structure allows a neural network to build complicated concepts from simpler components.

Deeper layers combine the patterns detected by earlier layers into increasingly abstract and global representations.


9. Fully Connected Layers and Simplified Diagrams

In a fully connected network, every neuron in one layer is connected to every neuron in the previous layer.

If one layer contains mmm neurons and the previous layer contains nnn neurons, the layer may contain:

m×nm \times nm×n

individual connections.

Many diagrams omit connections whose weights are zero or very small to keep the illustration readable. However, in an actual fully connected network, every possible connection may exist and have a weight between negative and positive values.

A simplified diagram may show only a few positive and negative links, but the complete network can contain many more connections.


10. The Rectified Linear Unit

Another activation function is the rectified linear unit, commonly abbreviated as ReLU.

It is defined by:

ReLU⁡(a)={0,a<0a,a≥0\operatorname{ReLU}(a) = \begin{cases} 0, & a < 0 \\ a, & a \geq 0 \end{cases}ReLU(a)={0,a,​a<0a≥0​

The operation is simple:

  • Negative values become zero.

  • Positive values remain unchanged.

For example:

ReLU⁡(−3)=0\operatorname{ReLU}(-3) = 0ReLU(−3)=0

and

ReLU⁡(2.5)=2.5\operatorname{ReLU}(2.5) = 2.5ReLU(2.5)=2.5

Compared with the sigmoid function, the rectified linear unit does not compress positive values into a fixed upper bound. It simply removes the negative portion.

ReLU is popular because it is:

  • Easy to compute

  • Effective in practical neural networks

  • Associated with useful stability properties

  • Able to create sparse activations, since many negative inputs become exactly zero

Because some incoming weights may be positive and others negative, ReLU neurons can respond to particular patterns and also to their opposites.


11. Forward Propagation Through the Network

Forward propagation is the process of sending an input through the network from the input layer to the output layer.

The general process is:

  1. Convert the input image into numerical pixel values.

  2. Place those values in the input neurons.

  3. Calculate weighted sums in the first hidden layer.

  4. Apply the relevant activation function.

  5. Pass the resulting values to the next layer.

  6. Repeat the weighted-sum and activation operations.

  7. Produce the final output values.

11.1 Example: Recognizing a Horizontal Line

Suppose the top pixels of the image are dark and the bottom pixels are light.

The input values reflect this arrangement:

  • Top pixels have values near −1-1−1.

  • Bottom pixels have values near +1+1+1.

In the first hidden layer, different neurons combine these values in different ways.

One neuron may combine a dark pixel and a light pixel with positive weights:

(−1)+(+1)=0(-1) + (+1) = 0(−1)+(+1)=0

This produces a neutral activation.

Another neuron may combine a dark pixel with a light pixel using a negative weight:

(−1)+(−1)(+1)=−2(-1) + (-1)(+1) = -2(−1)+(−1)(+1)=−2

This result is strongly negative. If the neuron uses a sigmoid, its output is near the negative end of its range. If it uses ReLU, the result becomes zero.

This behavior matches the neuron’s receptive field. If the neuron expects the opposite arrangement of pixel colors, the actual input should make that neuron weakly active.

As the signal moves through later layers:

  • Some values remain zero.

  • Negative values may become zero through ReLU.

  • Positive combinations become stronger.

  • Features corresponding to a horizontal arrangement accumulate.

At the output layer, the horizontal-line neuron produces the strongest positive value, while the solid, vertical, and diagonal outputs remain near zero. The network therefore predicts that the image contains a horizontal line.


12. Truth, Predictions, and Error

A neural network’s output is not guaranteed to be exactly correct. The desired answer is called the truth, target, or ground-truth output.

For a horizontal-line image, the desired output might be:

[0,0,0,1][0, 0, 0, 1][0,0,0,1]

where the four positions correspond to:

  1. Solid

  2. Vertical

  3. Diagonal

  4. Horizontal

The network may instead produce an approximate result such as:

[0.1,0.0,0.2,0.8][0.1, 0.0, 0.2, 0.8][0.1,0.0,0.2,0.8]

The error measures the difference between the target and the network’s prediction.

If the error for each output is represented by EiE_iEi​, the total error may be obtained by combining the individual errors:

Etotal=∑iEiE_{\text{total}} = \sum_i E_iEtotal​=∑i​Ei​

The exact method of calculating error depends on the chosen loss function. The central objective remains the same:

Training adjusts the weights so that the network’s predictions become closer to the truth and its total error becomes smaller.


13. Training as Weight Adjustment

Training begins with a network whose weights are usually assigned random values. At this point, the network produces arbitrary predictions.

The training process then repeatedly performs the following steps:

  1. Provide an input whose correct answer is known.

  2. Propagate the input forward through the network.

  3. Compare the output with the known truth.

  4. Calculate the error.

  5. Determine how each weight should change.

  6. Adjust the weights slightly in the direction that reduces the error.

  7. Repeat with many additional examples.

After thousands or millions of repetitions, the weights gradually settle into values that produce accurate predictions for many inputs.

The weights can be viewed as a point in a very high-dimensional space:

  • Each dimension corresponds to one weight.

  • The error determines the height of a location in that space.

  • Training attempts to move the network toward a low-error region.

This can be imagined as rolling downhill into a valley. With a very small network, the valley may be easy to visualize. With a large network, there may be thousands or millions of dimensions, making direct exploration impractical.


14. Slopes and Gradients

To reduce error efficiently, the network needs to know how changing each weight affects the error.

The relevant quantity is the slope, or derivative, of the error with respect to a weight:

dEdW\frac{dE}{dW}dWdE​

This means:

The amount by which the error changes when a weight changes.

If increasing a weight by 111 causes the error to decrease by 222, then the slope is:

ΔEΔW=−21=−2\frac{\Delta E}{\Delta W} = \frac{-2}{1} = -2ΔWΔE​=1−2​=−2

A negative slope indicates that increasing the weight tends to reduce the error. A positive slope indicates that increasing the weight tends to increase the error, so decreasing the weight may be beneficial.

For a simple error function:

E=W2E = W^2E=W2

the derivative is:

dEdW=2W\frac{dE}{dW} = 2WdWdE​=2W

At W=−1W = -1W=−1:

dEdW=2(−1)=−2\frac{dE}{dW} = 2(-1) = -2dWdE​=2(−1)=−2

The derivative therefore provides both:

  • The direction in which the weight should move

  • Information about the size of the adjustment

The collection of slopes for all weights is called the gradient.


15. Why Direct Weight Testing Is Impractical

One possible training strategy would be to change one weight, run the entire network again, and observe how the error changes. This would have to be repeated for every weight.

For a large network, this is extremely expensive because each trial requires:

  • Recomputing the weighted sums

  • Reapplying activation functions

  • Propagating values through every layer

  • Recalculating the final error

A network with many weights would require an enormous number of full computations. A more efficient method calculates the necessary slopes by working backward through the already-computed operations.

This method is called backpropagation.


16. Backpropagation and the Chain Rule

Backpropagation efficiently calculates how the error depends on each weight.

It uses the chain rule from calculus. The chain rule states that the rate of change across a sequence of operations can be found by multiplying the derivatives of the individual steps.

16.1 A Simple Two-Weight Network

Consider a network with:

  • Input XXX

  • First weight W1W_1W1​

  • Intermediate value YYY

  • Second weight W2W_2W2​

  • Error-related output EEE

Suppose:

Y=XW1Y = XW_1Y=XW1​

and:

E=YW2E = YW_2E=YW2​

The derivative of YYY with respect to W1W_1W1​ is:

dYdW1=X\frac{dY}{dW_1} = XdW1​dY​=X

The derivative of EEE with respect to YYY is:

dEdY=W2\frac{dE}{dY} = W_2dYdE​=W2​

By the chain rule:

dEdW1=dEdYdYdW1=W2X\frac{dE}{dW_1} = \frac{dE}{dY} \frac{dY}{dW_1} = W_2XdW1​dE​=dYdE​dW1​dY​=W2​X

This is equivalent to differentiating the complete expression:

E=XW1W2E = XW_1W_2E=XW1​W2​

with respect to W1W_1W1​.

16.2 Application to Deep Networks

In a deep network, the same principle is applied repeatedly:

  1. Start with the error at the output.

  2. Calculate the derivative for the final operation.

  3. Multiply by the derivative for the previous operation.

  4. Continue backward through each layer.

  5. Continue until reaching the weight of interest.

Instead of recomputing the entire network separately for every weight, backpropagation reuses intermediate calculations and efficiently propagates derivative information backward.

Backpropagation calculates the effect of each weight on the final error by chaining together local derivatives across the network.


17. Backpropagation Through Common Operations

A neural network is built from repeated types of operations. Backpropagation must know how to calculate the derivative for each one.

17.1 Weighted Connections

Suppose neuron BBB receives a value from neuron AAA through weight WWW:

B=AWB = AWB=AW

The derivative of BBB with respect to AAA is:

dBdA=W\frac{dB}{dA} = WdAdB​=W

If the change in error with respect to BBB is already known, multiplying by WWW transfers the error gradient back to AAA.

17.2 Summation

Suppose a neuron forms a sum:

Z=A+B+CZ = A + B + CZ=A+B+C

The derivative of the sum with respect to any one input is:

dZdA=1\frac{dZ}{dA} = 1dAdZ​=1

This is intuitive: increasing one input by 111 increases the total sum by $1, assuming the other inputs remain unchanged.

The same applies to every input:

dZdB=1\frac{dZ}{dB} = 1dBdZ​=1

and

dZdC=1\frac{dZ}{dC} = 1dCdZ​=1

17.3 Sigmoid Activation

For the sigmoid operation:

B=σ(A)B = \sigma(A)B=σ(A)

the derivative has a useful form:

dBdA=B(1−B)\frac{dB}{dA} = B(1-B)dAdB​=B(1−B)

Thus, once the sigmoid output BBB has been calculated, its derivative can be found without reconstructing the entire function.

This makes sigmoid backpropagation straightforward.

17.4 Rectified Linear Unit

For the rectified linear unit:

B={A,A>00,A≤0B = \begin{cases} A, & A > 0 \\ 0, & A \leq 0 \end{cases}B={A,0,​A>0A≤0​

the derivative is:

dBdA={1,A>00,A≤0\frac{dB}{dA} = \begin{cases} 1, & A > 0 \\ 0, & A \leq 0 \end{cases}dAdB​={1,0,​A>0A≤0​

A positive input passes its gradient backward unchanged. A negative input has been turned into zero, so its derivative is zero.


18. Complete Training Procedure

A basic neural-network training procedure can be summarized as follows:

  1. Create the network

    • Choose the number of layers and neurons.

    • Connect the layers.

    • Initialize the weights with random values.

  2. Supply a labeled input

    • Provide an image or other input.

    • Provide the correct target output.

  3. Perform forward propagation

    • Calculate weighted sums.

    • Apply activation functions.

    • Produce the network’s prediction.

  4. Calculate the error

    • Compare the prediction with the target.

    • Combine the differences using an error or loss function.

  5. Perform backpropagation

    • Compute local derivatives.

    • Chain the derivatives backward.

    • Determine how each weight contributed to the error.

  6. Update the weights

    • Adjust every weight slightly in the direction that reduces the error.

  7. Repeat

    • Use many additional training examples.

    • Continue until the network performs sufficiently well.

Through repeated updates, the weights move toward a low-error region in the network’s high-dimensional parameter space.


19. Learned Representations

After training, the network develops internal representations of the input patterns.

In an especially interpretable result:

  • Some neurons may respond to simple pixel arrangements.

  • Other neurons may respond to combinations of those arrangements.

  • Later neurons may respond to complete shapes or categories.

  • Most unnecessary connections may have small values close to zero.

This is called a sparse representation, because only a relatively small number of connections or activations may be strongly involved in representing a particular input.

However, training does not guarantee that the resulting network will be easy for humans to understand. A network may achieve good performance while developing complicated or unintuitive receptive fields.

The important guarantee is not interpretability. Rather, training attempts to find a representation that produces predictions as close as possible to the correct answers across the training examples.


20. Important Extensions

Several additional concepts are commonly used when developing practical neural networks.

20.1 Biased Neurons

A bias is an additional adjustable value added to a neuron’s weighted sum. It allows the activation function to shift independently of the input values.

A neuron with a bias can be written as:

z=∑i=1nwixi+bz = \sum_{i=1}^{n} w_i x_i + bz=∑i=1n​wi​xi​+b

where bbb is the bias.

Biases increase the flexibility of neurons because the neuron does not have to produce an activation centered around zero input.

20.2 Dropout

Dropout is a training technique in which some neuron outputs are temporarily ignored during particular training passes.

It helps reduce overreliance on individual neurons and can improve generalization to new data. Because the network must continue working when some units are unavailable, it is encouraged to develop more robust internal representations.

20.3 Practical Network Design

Successful neural-network development often requires attention to:

  • Network architecture

  • Activation functions

  • Weight initialization

  • Training data

  • Error functions

  • Learning rates

  • Regularization methods

  • The balance between model complexity and generalization

The fundamental principles remain the same: weighted combinations, nonlinear activation, error measurement, gradient calculation, and repeated weight adjustment.


Key Takeaways

Neural networks learn patterns by combining numerical inputs through weighted connections and nonlinear activation functions.

  • An input vector represents the input as a list of numerical values.

  • A neuron calculates a weighted sum and applies an activation function.

  • A neuron’s receptive field is the input pattern that makes it most active.

  • Early layers detect simple combinations, while deeper layers combine them into complex patterns.

  • Sigmoid activation compresses values into a bounded range.

  • ReLU converts negative values to zero and preserves positive values.

  • The output layer represents the possible predictions or categories.

  • The error measures the difference between the network’s prediction and the desired truth.

  • Training adjusts weights to reduce that error.

  • Backpropagation uses the chain rule to calculate how each weight affects the final error.

  • Repeated gradient-based adjustments allow a randomly initialized network to learn useful representations of data.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent