The mathematics behind Artificial Intelligence can be challenging to understand. It is essential to comprehend them to apply machine learning algorithms properly. The interpretation of the results also requires an understanding of mathematics and statistics. This post explains the learning problem of neural networks from a mathematical point of view. In particular, from the perspective of functional analysis and variational calculus.
Preliminaries
First, we will define some mathematical concepts.
Function
A function is a binary relation between two sets that associates each element of the first set to exactly one element of the second set.
$$\begin{align*}
y \colon X &\to Y\\
x &\mapsto y(x)
\end{align*}$$
Function space
A function space is a normed vector space whose elements are functions. For example, $C^1(X, Y)$ is the space of continuously differentiable functions, or $P^3(X, Y)$ is the space of all polynomials of order 3.
Optimization problem
An optimization problem consists of finding a vector that minimizes a function.
For example, let’s look at the function $f(x)=x^2$.

In this case, the minimum is at $x=0$.
Functional
A functional correspondence assigns a number to each function belonging to some class.
$$\begin{align*}
F \colon V &\to R\\
y(x) &\mapsto F[y(x)]
\end{align*}$$
Variational problem
A variational problem consists of finding a function that minimizes a functional.
For example, given two points $A$ and $B$, we consider the functional of length.

The function $y^*(x)$ that minimizes the length between the two points is a straight line.
Neural network
A neural network is a biologically inspired computational model consisting of a network architecture composed of artificial neurons. Neural networks are a powerful technique for solving approximation, classification, and forecasting problems.

This diagram shows a neural network with four inputs and two outputs.
Learning problem
Training a neural network means choosing, among all the functions that the network can represent, the one that performs a given task best. To make “best” precise, we need a functional: a rule that assigns a number to every candidate function, measuring how badly it does the job. In machine learning, this functional is the loss index; for a regression model it can be the mean squared error over the data, and for a classifier, the cross-entropy. Learning then becomes a variational problem: find the function for which the loss index is smallest.
Here is the activity diagram.

We will explain each of the steps one by one.
Neural network
A neural network spans a function space, which we will call $V$. It is the space of all the functions that the neural network can produce.
$$\begin{align*}
y \colon X \subset R^n &\to Y \subset R^m\\
x &\mapsto y(x;\theta)
\end{align*}$$
This structure contains a set of parameters. The training strategy will then adjust the parameters to perform specific tasks.
Each function depends on a vector of free parameters $theta$. The dimension of $V$ is the number of parameters in the neural network.
For example, here, we have a neural network. It has a hidden layer with a hyperbolic tangent activation function and an output layer with a linear activation function. The dimension of the function space is 7, the number of parameters in this neural network.

The elements of the function space are of the following form.
$$y(x;theta)=b_1^{(2)}+w_{1,1}^{(2)}tanh(b_1^{(1)}+w_{1,1}^{(1)}x)+w_{2,1}^{(2)}tanh(b_2^{(1)}+w_{1,2}^{(1)}x)$$
Here, we have different examples of elements of the function space.

They both have the same structure but different values for the parameters.
Loss index
The loss index turns the task into a number. It receives a function produced by the neural network and returns how far that function is from the desired behavior, so it encodes what the network has to learn, and the right choice depends on the type of model. For a data set of $k$ samples $(x_i,y_i)$ and a candidate function $y(x;\theta)$, two common choices are:
- Mean squared error: $E[y(x;theta)] = frac{1}{k} sum_{i=1}^k (y(x_i;theta)-y_i)^2$
- Cross-entropy error: $E[y(x;theta)] = – frac{1}{k} sum_{i=1}^k y(x_i;theta) log(y_i)$
We formulate the variational problem, which is the learning task of the neural network. We look for the function $y^*(x;theta^*) in V$ for which the functional $F[y(x;theta)]$ gives a minimum value. In general, we approximate the solution with direct methods.
Let’s see an example of a variational problem. Consider the function space of the previous neural network. Find the element $y^*(x;theta)$ such that the mean squared error functional, $MSE$, is minimized. We have a series of points, and we are looking for a function that will fit them.

We have taken a random function $y(x;theta)=-x$ for now, the functional $MSE[y(x;theta)]=1.226$ is not minimized yet.
Next, we will study a method to solve this problem.
Optimization algorithm
Once the architecture is fixed, every function in $V$ is completely determined by its parameter vector $\theta$. Evaluating the loss index on $y(x;\theta)$ therefore gives an ordinary function of the parameters, the loss function $f$:
$$\begin{align*}
f \colon \Theta \subset R^d &\to R\\
\theta &\mapsto f(\theta)
\end{align*}$$
This step replaces the search over functions with a search over $d$ real numbers: the variational problem becomes a function optimization problem. If $\theta^*$ minimizes $f$, then $y(x;\theta^*)$ is the function of $V$ for which the loss index is smallest.
Solving that problem is the job of the optimization algorithm. Most algorithms start from random parameters and improve them step by step using the gradient of $f$: gradient descent and adaptive moment estimation (Adam) use first derivatives only, while the quasi-Newton and Levenberg-Marquardt methods also approximate the curvature of $f$. Our post on five algorithms to train a neural network compares them.
Back to the example: the data points are the same, but the unknown is now the vector of seven parameters. Starting from the initial function, the optimization algorithm updates $\theta$ iteration after iteration, lowering the mean squared error each time, until it reaches a minimum.

After finding this vector $theta^*=(−1.16,−1.72, 0.03,2.14,−1.67,−1.72, 1.24)$, for which $mse(theta^*)=0.007$,
we obtain the function $y^*(x;theta^*)=−1.16−1.72tanh(0.03+2.14x)−1.67tanh(−1.72+1.24x)$ that minimizes the functional. This is the solution to the problem.
Conclusions
We have explained neural networks from the perspective of variational calculus.
The neural network spans a parameterized function space. In this space, we formulate the variational problem. We must minimize a functional to solve it. To do so, we reduce it to a function optimization problem. This is solved with an optimization algorithm, and we obtain the function we sought.
Video
Watch this video to understand the learning problem in neural networks better.


