What is a neural network?
A neural network is a computational model of connected layers of nodes. Its layered structure is similar to the network of neurons in the brain. It learns from data, so it can be trained to recognize patterns, classify data, and predict future events.
A neural network breaks an input into several layers of abstraction. Trained on many examples, it can recognize a pattern as speech or as an image, in a way similar to the brain. Its behavior is set by how its elements are connected and by the strength, or weight, of those connections. During training, the weights are adjusted automatically by a learning rule until the network performs the required task.
Why do neural networks matter?
Neural networks are especially suited topattern recognition, for identifying and classifying objects or signals in speech, vision, and control systems. They can also be used for time-series prediction and modeling.
A few examples:
A power company forecasts the load on its grid, so supply stays reliable and the generators it runs are used efficiently.
An ATM accepts a bank deposit by reading the account number and the amount on a check.
A pathologist uses a cancer-detection application to classify a tumor as benign or malignant from the uniformity of cell size, clump density, mitosis, and other factors.
Deep learning
A neural network that works with two or three connected layers of neurons is called ashallow neural network. A deep-learning network can have many layers, even hundreds. Both are machine-learning techniques that learn directly from input data.
Deep learning is receiving a great deal of attention, and for good reason. It is achieving results that were not possible before.
Deep learning is especially suited to difficult recognition tasks, such as face recognition, text translation, and speech recognition. It is also a key technique in advanced driver-assistance systems and tasks, including lane classification and traffic-sign recognition.
How does a neural network work?
Inspired by biological nervous systems, a neural network combines several processing layers by running simple elements in parallel. It has an input layer, one or more hidden layers, and an output layer. The layers are connected by nodes, or neurons, and each layer uses the output of the previous layer as its input.

A typical neural-network architecture.
Techniques used with neural networks
Common machine-learning techniques for neural-network applications include supervised and unsupervised learning, classification, regression, pattern recognition, and clustering.
Supervised learning
Train a supervised neural network to produce the required output for sample inputs, so the network is suited to modeling and control of dynamic systems, classification of noisy data, and prediction of future events. Deep Learning Toolbox™ includes four supervised networks: feedforward, radial basis, dynamic, and learning vector quantization.
Classification
Classification is supervised machine learning in which an algorithm learns, from labeled examples, to classify a new observation.
Regression
A regression model describes the relationship between one response, the output, and one or more predictors, the inputs.
Pattern recognition
Pattern recognition is an important part of neural-network applications in computer vision, radar processing, speech recognition, and text classification. It classifies input data into objects or classes from key features, by supervised or unsupervised classification.
In computer vision, for example, supervised pattern recognition is used for optical character recognition (OCR), face detection, face recognition, object detection, and object classification. In image processing and computer vision, unsupervised pattern recognition is used for object detection and image segmentation.
Unsupervised learning
An unsupervised network is trained by letting it keep adjusting to new inputs. It draws inferences from input data that has no labeled responses. It can be used to find natural distributions, categories, and relationships in the data.
Deep Learning Toolbox includes two unsupervised networks: competitive layers and self-organizing maps.
Clustering
Clustering is unsupervised learning in which a neural network explores data to find hidden patterns or groups. Data are grouped by similarity. Uses include gene-sequence analysis, market research, and object recognition.
Developing shallow neural networks with MATLAB
With tools and functions for large data sets, MATLAB® provides specialized toolboxes for machine learning, neural networks, deep learning, computer vision, and automated driving.
With a few lines of MATLAB code, a neural network can be developed without first becoming a specialist. You can start quickly, create and visualize a model, and deploy it to a server or an embedded device.
With MATLAB, the result can be brought into an existing application. MATLAB can deploy a neural network automatically to an enterprise system, a cluster, the cloud, or an embedded device.
A typical workflow for designing a neural network
Every application is different, but development usually follows these steps:
Access and prepare the data
Create the neural network
Configure the inputs and outputs
Adjust the network parameters (weights and biases) to improve performance
Train the network
Validate the results
Integrate the network into a production system
Classification and clustering with shallow networks
MATLAB and Deep Learning Toolbox provide command-line functions and apps for creating, training, and simulating shallow neural networks. The apps make it straightforward to build a network for classification, regression (including time-series regression), and clustering. After the network is created, MATLAB code can be generated so the work can be repeated.
Preprocessing, postprocessing, and improvement
Preprocessing the inputs and targets makes training of a shallow network more efficient, and it makes the performance easier to analyze. MATLAB and Simulink® provide tools for the following:
Reduce the dimension of the input vector with principal component analysis
Run a regression between the network response and the corresponding target
Scale inputs and targets so that they lie in the range [−1, 1]
Normalize the training set by its mean and standard deviation
Use automatic data preprocessing and data division when the network is created
Better generalization helps prevent overfitting, a common problem in neural-network design. Overfitting happens when the network has memorized the training set but has not learned to generalize to new inputs. The error on the training set is then relatively small, but the error is larger when new data is presented.
Two ways to improve generalization:
RegularizationModify the performance function, the error measure that training minimizes. By including the size of the weights and biases, regularization produces a network that performs well on the training data and more smoothly on new data.
Early stoppingUse two data sets. The training set updates the weights and biases. The validation set stops training when the network starts to overfit.

Preprocessing plots for analyzing network performance, including root-mean-square error on the validation set across training epochs (upper left), an error histogram (upper right), and confusion matrices for training, validation, and test (bottom).
Code generation and deployment
With Deep Learning Toolbox together with MATLAB Coder™, GPU Coder™, and MATLAB Compiler™, a trained network can be deployed to an embedded system or integrated into a wide range of production environments. MATLAB Coder can generate C and C++ code for a trained network, so the network can be simulated on PC hardware and then deployed to an embedded system. MATLAB Compiler and MATLAB Compiler SDK™ can deploy a trained network as a C/C++ shared library, a Microsoft® .NET assembly, a Java® class, and a Python® package from a MATLAB program. A network model can also be trained inside a deployed application or component.
Simulink support
Deep Learning Toolbox provides a block set for building shallow neural networks in Simulink. The blocks are compatible with Simulink Coder™. They are grouped in four libraries:
Transfer-function blocks, which take a network input vector and produce a corresponding output vector.
Net-input function blocks, which take weighted input vectors, layer-output vectors, and a bias vector, and return a net-input vector.
Weight-function blocks, which apply a neuron's weight vector to an input vector (or a layer output vector) to get the neuron's weighted input.
Data-preprocessing blocks, which map input and output data into the range that a neural network can process directly.
Alternatively, the network can be created and trained in MATLAB, and a Simulink block can be generated to simulate it. This also lets you view the network graphically.