This article presents a new methodology called deep Theory of FunctionalConnections (TFC) that estimates the solutions of partial differentialequations (PDEs) by combining neural networks with TFC. TFC is used totransform PDEs with boundary conditions into unconstrained optimizationproblems by embedding the boundary conditions into a "constrained expression."In this work, a neural network is chosen as the free function, and used tosolve the now unconstrained optimization problem. The loss function is taken asthe square of the residual of the PDE. Then, the neural network is trained inan unsupervised manner to solve the unconstrained optimization problem. Thismethodology has two major differences when compared with popular methods usedto estimate the solutions of PDEs. First, this methodology does not need todiscretize the domain into a grid, rather, this methodology randomly samplespoints from the domain during the training phase. Second, after training, thismethodology represents a closed form, analytical, differentiable approximationof the solution throughout the entire training domain. In contrast, otherpopular methods require interpolation if the estimated solution is desired atpoints that do not lie on the discretized grid. The deep TFC method forestimating the solution of PDEs is demonstrated on four problems with a varietyof boundary conditions.
Quick Read (beta)
Deep Theory of Functional Connections: A New Method for Estimating the Solutions of PDEs
This article presents a new methodology called deep Theory of Functional Connections (TFC) that estimates the solutions of partial differential equations (PDEs) by combining neural networks with TFC. TFC is used to transform PDEs with boundary conditions into unconstrained optimization problems by embedding the boundary conditions into a “constrained expression.” In this work, a neural network is chosen as the free function, and used to solve the now unconstrained optimization problem. The loss function is taken as the square of the residual of the PDE. Then, the neural network is trained in an unsupervised manner to solve the unconstrained optimization problem. This methodology has two major differences when compared with popular methods used to estimate the solutions of PDEs. First, this methodology does not need to discretize the domain into a grid, rather, this methodology randomly samples points from the domain during the training phase. Second, after training, this methodology represents a closed form, analytical, differentiable approximation of the solution throughout the entire training domain. In contrast, other popular methods require interpolation if the estimated solution is desired at points that do not lie on the discretized grid. The deep TFC method for estimating the solution of PDEs is demonstrated on four problems with a variety of boundary conditions.
Partial differential equations are a powerful mathematical tool that is used to model physical phenomena, and their solutions are used in the design and verification processes of a variety of systems. For example, the solution of PDEs may be used to verify that the loads experienced by a beam throughout its lifetime will not cause the beam to fail. Many methods exist to approximate the solutions of PDEs. The most famous of these methods is the finite element method (FEM) [FEA1, FEA2, FEA3]. FEM has been incredibly successful in approximating the solution to PDEs in a variety of fields including structures, fluids, and acoustics. However, FEM does have some drawbacks.
FEM discretizes the domain into elements. This works well for low-dimensional cases, but the number of elements grows exponentially with the number of dimensions. Therefore, the discretization becomes prohibitive as the number of dimensions increases. Another issue is that FEM solves the PDE at discrete nodes, but if the solution is needed at locations different than these nodes, an interpolation scheme must be used.
Reference [ModernPDE] explored the use of neural networks to solve PDEs, and showed that the use of neural networks avoids these problems. Rather than discretizing the entire domain into a number of elements that grows exponentially with the dimension, neural networks can sample points randomly from the domain. Moreover, once the neural network is trained, it is a closed form, analytical, differentiable approximation of the PDE. Therefore, no interpolation scheme is needed when estimating the solution at points that did not appear during training, and further analytical manipulation of the solution can be done with ease. Furthermore, Ref. [ModernPDE] compared the neural network method with FEM on a set of test points that did not appear during training (i.e. points that were not the nodes in the FEM solution), and showed that the solution obtained by the neural network generalized well to points outside of the training data. In fact, the maximum error on the test set of data was never more than the maximum error on the training set of data. In contrast, the FEM had more error on the test set than on the training set. In one case, the test set had approximately 3 orders of magnitude more error than the training set.
Reference [ModernPDE] is not the first article to explore the use of neural networks to solve PDEs. One of the early papers on the topic was Ref. [OrigOdePde]. Although Ref. [ModernPDE] improved what was presented in [OrigOdePde] in almost every way, one item that was missing was exact satisfaction of the boundary constraints. The solution for PDEs presented by Ref. [OrigOdePde] used a method similar to the Coon’s Patch [CoonsPatch] to satisfy the boundary constraints exactly.
Exact boundary constraint satisfaction is of interest for a variety of problems, especially when the boundary value information is known to a high degree of precision. This is especially useful for physics informed problems. Take for example, using the heat equation to describe the temperature within a rod. If the temperature on the edges of the rod is know to a high degree of precision, and the heat equation is being used to estimate the temperature inside the rod, then the only information that is known for sure a priori is the boundary conditions. Hence, it is desired to have the boundary conditions of the rod met exactly. Moreover, embedding the boundary conditions means that the neural network only needs to sample points from the interior of the domain, not the domain and the boundary. Thus, a method for embedding boundary conditions for PDEs of arbitrary dimension is desired. Luckily, a framework for embedding constraints into machine learning algorithms has already been invented: the Theory of Functional Connections (TFC) [SVM-TFC]. In Ref. [SVM-TFC], TFC was used to embed constraints into support vector machines, but left embedding constraints into neural networks to future work. This research shows how to embed constraints into neural networks, and leverages this technique to numerically estimate the solutions of PDEs.
TFC is a framework that is able to satisfy many types of boundary conditions while maintaining a function that can be freely chosen. This free function can be chosen, for example, to minimize the residual of a differential equation. TFC has already been used to solve differential equations with initial value constraints, boundary value constraints, relative constraints, integral constraints, and infinite constraints [TFC, LDE, NDE, TFCInt]. Recently, the framework was extended to dimensions [M-TFC] for constraints on the value and flux of dimensional manifolds. This means the framework can now generate constrained expressions that satisfy the boundary constraints of multidimensional PDEs [M-TFC-PDE].
2 Theory of Functional Connections
The Theory of Functional Connections (TFC) is a mathematical framework designed to turn constrained problems into unconstrained problems. This is accomplished through the use of the constrained expression, which is a mathematical expression that represents the family of all possible functions that satisfy the problem’s constraints. This technique is especially useful when solving PDEs, as it transforms the PDE into an unconstrained optimization problem. TFC has two major steps: 1) embed the boundary conditions of the problem into the constrained expression 2) solve the now unconstrained optimization problem. The paragraphs that follow will explain these steps in more detail.
The TFC framework is easiest to understand when explained via an example, like a simple harmonic oscillator. Equation (1) gives an example of a simple harmonic oscillator problem.
Step one of the TFC framework is to build the constrained expression. The constrained expression consists of two parts; the first part is a function that satisfies the boundary constraints, and the second part projects the free-function, , onto the hyper-surface of functions that are equal to zero at the boundaries. For problems with boundary and derivative constraints, the constrained expression can be written compactly using Eq. (2).
where x is a vector of the independent variables, , is an -th order tensor containing the boundary conditions , are vectors whose elements are functions of the independent variables, is the free-function that can be chosen to be anything11 1 More specifically, the free function can be chosen to be any function as long as that function is defined at the constraints., and is the constrained expression. The first term in satisfies the boundary conditions, and the final two terms project the free-function, , onto the space of functions that vanish at the constraints.
For one dimension with independent variable on the domain and for boundary and first-derivative constraints only, has the following form,
The values of that are unused are eliminated, and the vector, , is created afterwards with the appropriate size. For the one dimensional simple harmonic oscillator, and are given by Eq. (3).
where and are functions that need to be solved for. Substituting everything into the constrained expression, , and simplifying yields Eq. (4).
The functions and are solved for by setting the constrained expression, , equal to the boundary constraints at the boundaries. For the simple harmonic oscillator this yields the set of simultaneous equations given by Eqs. (5) and (6).
Equation (5) shows that and , and Eq. (6) shows that and . One solution to this set of simultaneous equations is and . Substituting these results back into the constrained expression and substituting and yields Eq. (7).
Notice that for any function , the boundary conditions will always be satisfied exactly. Therefore, solving the differential equation has now become an unconstrained optimization problem. This unconstrained optimization problem could be cast in the following way. Let the function to be minimized, , be equal to the square of the residual of the differential equation,
This function is to be minimized by varying the function . One way to do this is to make a linear combination of a series of basis functions, and minimize the coefficients that multiply those basis functions via least-squares or some other optimization technique. For an example of this implementation via Chebyshev Orthogonal Polynomials see [LDE]. Also, [NDE] shows how this can be done using non-linear least squares for non-linear ODEs.
2.1 -Dimensional Constrained Expressions
The previous example derived the constrained expression by creating and solving a series of simultaneous algebraic equations. This technique works well for constrained expressions in one dimension; however, a different, more mechanized formalism exists that is useful for deriving these expression in dimensions for constraints on the value and flux of dimensional manifolds [M-TFC]. This formalism shows how to construct the two portions of the constrained expression shown in Eq. (2): 1) -th order tensor 2) the vectors, .
Before discussing how to build the tensor and vectors, let’s introduce some mathematical notation. Let be an index used to denote the -th dimension. Let be the constraint specified by taking the -th derivative of the constraint function, , evaluated at the hyperplane. Further, let be the vector of constraints defined at the hyperplanes with derivative orders of , where and . In addition, let’s define a boundary condition operator that takes the -th derivative with respect to of a function, and then evaluates that function at the hyperplane. Mathematically,
This mathematical notation will be used to introduce a step-by-step method for building the tensor. This step-by-step process will be be illustrated via a 3-dimensional example that has Dirichlet boundary conditions in and initial conditions in and on the domain . The tensor is constructed using the following three rules.
The element .
The first order sub-tensor of specified by keeping one dimension’s index free and setting all other dimension’s indices to 1 consists of the value and the boundary conditions for that dimension. Mathematically,
Using the example boundary conditions,
The remaining elements of the tensor are those with at least two indices different from one. These elements are the geometric intersection of the boundary condition elements of the first order tensors given in Eq. (2), plus a sign ( or ) that is determined by the number of elements being intersected. Mathematically this can be written as,
where is the number of indices different than one. Using the example boundary conditions we give three examples:
A simple procedure also exists for constructing the vectors. The vectors have a standard form:
where are linearly independent functions. The simplest set of linearly independent functions, and those most often used in the TFC constrained expressions, are monomials, . The coefficients, , can be computed by matrix inversion,
Using the example boundary conditions, let’s derive the vector using the linearly independent functions and .
For more examples and a proof that these procedures for generating the tensor and vectors form a constrained expression see Ref. [M-TFC].
2.2 Two-Dimensional Example
This subsection will give an in depth example for a two-dimensional TFC case. The example is originally from [OrigOdePde] problem 5, and is one of the PDE problems analyzed in this article. The problem is shown in Eq. (9).
Following the step-by-step procedure given in the previous section we will construct the tensor:
The first element is .
The first order sub-tensors of are:
The remaining elements of are the geometric intersection of elements from the first order sub-tensors.
Hence, the tensor is,
Following the step-by-step procedure given in the previous section we will construct the vectors. For let’s choose the linearly independent functions and .
For let’s choose the linearly indpendent functions and .
Now, we use the constrained expression form given in Eq. (2) to finish building the constrained expression.
Notice, that Eq. (10) will always satisfy the boundary conditions of the problem regardless of the value of . Thus, the problem has been transformed into an unconstrained optimization problem where the cost function, , is the square of the residual of the PDE,
For one-dimensional ODEs, the minimization of the cost function was accomplished by making the summation of orthogonal polynomials, and performing least-squares or some other optimization technique to find the coefficients that multiply those orthogonal polynomials. For two dimensions, one could make the product of two sums of these orthogonal polynomials, calculate all of the cross-terms, and then solve for the coefficients that multiply all terms and cross-terms using least-squares or non-linear least-squares. However, this will become prohibitive as the dimension increases. An alternative solution, and the one explored in this article, is to make the free function, , a neural network.
3 PDE Solution Methodology
As with the previous section, the easiest way to describe the methodology is with an example. The example used throughout this section will be the PDE given in Eq. (9).
As mentioned in the previous section, deep TFC approximates solutions to PDEs by finding the constrained expression for the PDE and choosing a neural network as the free function. For all of the problems analyzed in this article, a simple, fully connected neural network was used. These networks consist of non-linear activation functions composed with affine transformations of the form , where are neuron weights, are neuron biases, and is a vector of inputs from the previous layer (or the inputs to the neural network if it is the first layer). The weights and biases of the entire neural network make up the tunable parameters, . In this article, neural networks will be represented with the symbol . For example, a neural network with inputs and would be given as . Thus, the constrained expression, given originally in Eq. (10), now has the form given in Eq. (11).
In order to estimate the solution to the PDE, the parameters of the neural network have to be optimized to minimize the loss function, which is taken to be the square of the residual of the PDE. For this example,
The attentive reader will notice that training the neural network will require, for this example, taking two second order partial derivatives of to calculate , and then taking gradients of with respect to the neural network parameters, , in order to train the neural network.
To take these higher order derivatives, TensorFlow’s™ gradients function was used [tensorflowWhitepaper]. This function uses automatic differentiation [AD] to compute these derivatives. However, one must be conscientious when using the gradients function to ensure they get the correct gradients.
When taking the gradient of a vector, , with respect to another vector, , TensorFlow™ computes,
where is a vector of the same size as . The only place where this may be an issue in the example used in this section is when computing . The desired output of this calculation is the following vector,
where has the same size as and is the pair used to generate . TensorFlow’s™ gradients function will compute the following vector,
However, because only depends on and the derivative operator commutes with the sum operator, TensorFlow’s™ gradients function will compute the desired vector. Moreover, the size of the output vector will be correct because the input vectors, and , have the same size as .
3.1 Training the Neural Network
Three methods were tried when optimizing the parameters of the neural networks:
Adam optimizer [Adam]
Broyden-–Fletcher–-Goldfarb-–Shanno (BFGS) optimizaion algorithm [OrigTrainMethod]
The first method, Adam, is a variant of stochastic gradient descent (SGD) that combines the advantages of two other popular SGD variants: AdaGrad [AdaGrad] and RMSProp [RMSProp].
The second method, BFGS, is a quasi-Newton method designed for solving unconstrained, non-linear optimization problems. This method was chosen based on its performance when optimizing neural network parameters to estimate PDE solutions in Ref. [OrigOdePde]. The hybrid method uses both methods in series. For all four problems shown in this article, the BFGS optimizer gave the best results.
This section compares the estimated solution found using deep TFC with with the analytical solution. Four PDE problems are analyzed. The first is the example PDE given in Eq. (9), and the second is the wave equation. The third and fourth PDEs are simple solutions to the incompressible Navier-Stokes equations.
4.1 Problem 1
The first problem analyzed was the PDE given by Eq. (9), copied below for the readers’ convenience.
The neural network used to estimate the solution to this PDE was a fully connected neural network with five hidden layers and 30 neurons per layer. The non-linear activation function used was the hyperbolic tangent. Other neural network sizes and non-linear activation functions were tried, but this size and activation function combination did the best. The biases of the neural network were all initialized as zeros, and the weights were initialized using TensorFlow’s™ implementation of the Xavier initialization with uniform random initialization [Init]. Training pairs, , were created for this problem by sampling and as independent and identically distributed (IID) random variables on the uniform distribution on . The network was trained using the BFGS method on a batch size of 10,000 training pairs.
Figure 1 shows the difference between the analytical solution and the estimated solution using deep TFC on a grid of 100 evenly distributed points (10 per independent variable). This grid represents the test set.
The maximum error on the test set was meters and the average error was meters. The maximum error is relatively low, five orders of magnitude lower than the solution values, which are on the order of meters. However, the maximum solution error using deep TFC is not as low as the maximum solution error obtained in [OrigOdePde], which was on the order of meters. Although there are many possible explanations for this discrepancy, for example, different implementations of the optimizer or different weight initialization functions, the author was concerned that it may be the assumed solution form, , that was causing the increase in estimated solution error. The solution form created using deep TFC is more complex both in the number of terms and the number of times the neural network appears within the assumed solution form.
To investigate, a comparison was made between the solution form posed in [OrigOdePde] and the solution form posed in this article, while keeping all other variables constant. For this comparison, the neural network architecture consisted of one hidden layer with 10 neurons, and the non-linear activation function used was the hyperbolic tangent function22 2 The sigmoid function was also tried, which is what is used in [OrigOdePde]; however, the average error and maximum error for both solution forms, deep TFC and [OrigOdePde], was almost doubled compared to using the hyperbolic tangent function.. The neural network was trained using the BFGS optimizer. The training pairs were created by randomly sampling 10,000 point pairs where and are IID random variables on the uniform distribution . The test set was a grid of 100 evenly distributed points (10 per independent variable).
Figure 2 was created using the solution form posed in [OrigOdePde]. The maximum error on the test set was meters and the average error on the test set was meters.
Figure 3 was created using the deep TFC solution form. The maximum error on the test set was meters and the average error on the test set was meters.
Comparing Figs. 2 and 3 shows that the solution form from [OrigOdePde] does slightly better in terms of average error and maximum error for this problem, but the difference is not significant. However, neither of the tests conducted here is able to reduce the error to the level reported in [OrigOdePde]. Thus, there must be some other factor, initialization, optimizer method, etc., that is causing this difference. One important take-away from this comparison is that despite the more complex solution form created using deep TFC, which can easily be applied to higher dimensions, the final solution accuracy is very similar to the simpler solution form that was designed for lower-dimensional problems.
4.2 Problem 2
The second problem analyzed was the wave equation, shown in Eq. (12).
where the constant, , was chosen to be 1. The constrained expression for this problem is shown in Eq. (13).
The neural network used to estimate the solution to this PDE was a fully connected neural network with two hidden layers and 30 neurons per layer. The non-linear activation function used was the hyperbolic tangent. The biases and weights were initialized using the same method as problem 1. The training points, , were created by sampling and IID from the uniform distribution on . The network was trained using the BFGS method on a batch size of 10,000 training pairs.
Figure 4 shows the difference between the analytical solution and the estimated solution using deep TFC on a grid of 100 evenly distributed points (10 per independent variable). This grid represents the test set.
The maximum error on the test set was meters and the average error on the test set was meters. The error of this solution is larger than in the problem one, while the solution values are on the same order of magnitude, meters, as in problem one. The larger relative error in problem two is most likely due to the more oscillatory nature of the solution.
4.3 Problem 3
The third problem analyzed was a known solution to the incompressible Navier-Stokes equations, called Poiseuille flow. The problem solves the flow velocity in a two-dimensional pipe in steady-state with a constant pressure gradient applied in the longitudinal axis. Equation (14) shows the associated equations and boundary conditions.
where and are velocities in the and directions respectively, is the height of the channel, is the pressure, is the density, and is the viscosity. For this problem, the values m, kg/m, Pas, and N/m were chosen. The constrained expressions for the -velocity, , and -velocity, , are shown in Eq. (15).
The neural network used to estimate the solution to this PDE was a fully connected neural network with four hidden layers and 30 neurons per layer. The non-linear activation function used was the sigmoid. The biases and weights were initialized using the same method as problem 1. The training points, , were created by sampling , , and IID from the a uniform distribution that spanned the range of the associated independent variable. For , the range was . For , the range was , and for , the range was . The network was trained using the BFGS method on a batch size of 1,000 training pairs. The loss function used was the sum of the squares of the residuals of the three PDEs in Eq. (14).
For one particular run33 3 All errors are given in meters per second., the maximum error in the -velocity was , the average error in the -velocity was , the maximum error in the -velocity was , and the average error in the -velocity was . The maximum error and average error for this problem are much lower than in problems 1 and 2. However, the constrained expression for this problem essentially encodes the solution, because the initial flow condition at time zero is the same as the flow condition throughout the spatial domain at any time. Thus, if the neural network outputs a value of zero for all inputs, the problem will be solved exactly. Although the neural network does output a very small value for all inputs, it is interesting to note that none of the layers have weights or biases that are at or near zero.
4.4 Problem 4
The fourth problem is another solution to the Navier-Stokes equations, and is very similar to the third. The only difference is that in this case, the fluid is not in steady state, it starts from rest. Equation (16) shows the associated equations and boundary conditions.
This problem was created to avoid encoding the solution to the problem into the constrained expression, as was the case in the previous problem. The constrained expressions for the -velocity, , and -velocity, , are shown in Eq. (17).
The neural network used in this problem is exactly the same as the neural network used in problem three. Problem 4 used 2,000 training points that were selected the same way as in problem three, except the new ranges for the independent variables were for , for , and for .
Figures 7 through 7 show the -velocity of the fluid throughout the domain at three different times. Qualitatively, the solution should look as follows. The solution should be symmetric about the line , and the solution should develop spatially and temporally such that after a period of time and sufficiently far from the inlet, , the -velocity will be equal or very close to the steady state -velocity of problem 3. Qualitatively, the -velocity field looks correct at all points. Quantitatively, the -velocity at from Fig. 7 was compared with the known steady state -velocity, and had a maximum error of meters per second and an average error of meters per second.
This article demonstrated how to combine neural networks with the Theory of Functional Connections into a new methodology, called deep TFC, that was used to estimate the solutions of PDEs. Results on four problems were presented that display how accurately relatively simple neural networks can approximate the solutions to some well known PDEs. The difficulty of the PDEs in these problems ranged from linear, two-dimensional PDEs to coupled, non-linear, three-dimensional PDEs. Moreover, while the focus of this article was on PDEs, the capability to embed constraints into neural networks is useful for many other applications as well.
Future work should investigate the performance of different neural network architectures on the estimated solution error. For example, Ref. [ModernPDE] suggests a neural network architecture where the hidden layers contain element-wise multiplications and sums of sub-layers. The sub-layers are more standard neural network layers like the fully connected layers used in the neural networks of this article.
Another topic for investigation is reducing the estimated solution error by sampling the training points based on the loss function values for the training points of the previous iteration. For example, one could create batches where half of the new batch consists of half of the points in the previous batch that had the largest loss function value and the other half are randomly sampled from the domain. This should consistently give training points that are in portions of the domain where the estimated solution is farthest from the real solution.