{'fraction_non_alphanumeric': 0.03247857656832603, 'fraction_numerical': 0.007915222084123765, 'mean_word_length': 4.461772061450518, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deep Learning for the Approximation of a Shape Functional

Artificial Neuronal Networks are models widely used for many scientific tasks. One of the well-known field of application is the approximation of high-dimensional problems via Deep Learning. In the present paper we investigate the Deep Learning techniques applied to Shape Functionals, and we start from the so--called Torsional Rigidity. Our aim is to feed the Neuronal Network with digital approximations of the planar domains where the Torsion problem (a partial differential equation problem) is defined, and look for a prediction of the value of Torsion. Dealing with images, our choice fell on Convolutional Neural Network (CNN), and we train such a network using reference solutions obtained via Finite Element Method. Then, we tested the network against some well-known properties involving the Torsion as well as an old standing conjecture. In all cases, good approximation properties and accuracies occurred.


Introduction
By "Shape Functional" one usually denotes any abstract functional defined on some class of subsets of R d . The Volume and the Perimeter are probably the most common examples of shape functionals. More sophisticated examples coming from physics include: drag force of a solid moving into a fluid, the electrostatic capacity of a conductor body in vacuum space, the effectiveness of the thermal insulation around a thermally conductor body etc. Very often (as in the examples above), there is some region (say Ω) to which we associate a certain scalar value (say F (Ω)).
Shape optimization is nowadays a very active field of research, ranging from abstract mathematics to applied physics and engineers. In a very broad sense, it aims at finding sets (called optimal sets) that minimize or maximize some shape functional, possibly under feasible geometrical constraints.
In many cases, in order to determine the value of a functional shape, one has to solve a differential problem: partial differential equation (PDE) or systems of PDEs.
Depending on the problem, the determination of the numerical solution can sometimes be very time-consuming. In addition, the class of domains in which one looks for the optimal sets is at best (unless one introduces some severe restrictions) infinite-dimensional, and there is no general method allowing us to find the optimal domain in a straightforward and reliable way.
In this paper, we investigate the possibility to train a Neural Network (NN) to approximate a shape functional. It can be considered as a first step toward the ultimate goal of a general implementation of NNs in shape optimization.
We warn the reader that the use of NNs is not meant to replace numerical methods, such as finite elments or finite difference schemes. Classical methods are still by far more accurate. They are actually used to train the network, since in absence of an analytical computation, they provide the only reference values. Neural Network can be used to support, to reinforce or to validate a numerical investigation. At the same time NNs are extremely efficient in terms of computational time. Some of the problems arising in shape optimization, expecially those involving a free boundary problem, are so complicated that classical numerical schemes are sometimes very difficult to implement and very time consuming. There is a good chance that a Deep Learning approach could be succesful in providing quick answers, which are very welcome, even at the risk of being suboptimal.
As a first attempt, we have chosen a functional called Torsion (or Torsional Rigidity). As we will see later (and as the name suggests), it is related to the mechanical response of an elastic body under Torsion. To determine its value, one has to solve a Poisson problem in a planar set Ω. The geometry of Ω uniquely determines the value of the functional. Torsional rigidity has the great advantage of having been intensively investigated in the last decades. Many theoretical results, as well as some long standing conjecture, provide reliable tests to check the accuracy of the neural network. However, no matter how large is the training set, there is no way it could be a good representative of the large class of open subset of the plane. Our ultimate test was to check the ability of the NN to extrapolate information on unseen cases, those with topological properties significantly different from the set used during the training.
For the reader not accustomed to the NNs, the naive idea beyond our approach can be easily summarized as follows. Take any planar bounded set enclosed in a box. Such a set can be represented by an digital b/w image: a square matrix of zeros and ones. The value 1 corresponds conventionally to a point inside the planar set and the value 0 corresponds to a point outside the set. We aim at an unknown function, Target Function, (which certainly exists even though it may be extremely complicated) that takes all these ones and zeros and provides the real value corresponding to the torsional rigidity of our input set. We want to approximate the target function and a NN is indeed a good candidate to do this job. How?
The building brick of a neural networks is the "neuron". A neuron itself is a function. It takes as input real values x j (j = 1, 2, ..., K) and makes a linear combination z defined as follows Here w j are called weights, and b is called bias. The output is then passed to a nonlinear activation function g. When we have the so-called sigmoid neuron. Weights and bias have to be fixed, and they are called trainable parameters of the neuron. A different activation function provides a different type of neuron. For instance the well-known RELU (Rectified Linear Unit) has the following activation function g(z) = max{0, z}.
All neurons share the common feature of taking a certain number of inputs and providing an output. However, a single Neuron is "just" a simple function; in order to extract complex information from the input, it is necessary to combine multiple neurons, in such a way that the output of a neuron can become the input of other neurons and so on. Each weight then represent the strenght of the connection between two neurons, reminiscent of our brain neuronal structure. What in general is done is to organize the neurons in structures, called layers, to augment the ability to extract patterns of data and then concatenate layers to elaborate these patterns. Such an architecture, composed of many connected neurons, when fully connected, is called Deep Neural Network (DNN). At the end, the output of this structure is a composition of neurons' functions, whose distance to the "target function" is measured by a "loss function". The structure which we consider is classified as feedforward neural network. The layers are ordered and the information flows from the input layer, to the output layer. No loop is formed between the neurons.
In a NN, weights and bias have to be changed to minimize the loss function. Such an operation is the most delicate, but there are some standard procedures for the optimization, including a particular gradient descent procedure called backpropagation [1]. This learning procedure provides an automatic strategy for updating the trainable parameters (weights and bias) to obtain a good fitting model for the considered input data.
The interested reader should look for Universal Approximation Theorems [2] which justify the use of NN to "represent" a wide variety of unknown nonlinear functions.
Over the years several types of NNs have become very popular. Among the others, important examples are the Convolutional Neural Networks (CNN), which are widely used to extract spatial information from data taking advantage of the property of space invariance of the Convolution operation. In particular, CNNs are mostly desiged to deal with images.
We shall see that a trained CNN can approximate very well our dataset. In particular, we gain good approximation error -thus accuracy -with a computational cost of evaluating Torsion that is orders of magnitude lower when compared to the standard resolution. The cost of the overall approximation is moved to the training of the CNN that is done only once and in advance. The resulting CNN is able to compute the Torsion in real-time. The paper is organized as follows. In Section 2 we present the formal mathematical definition of Torsional Rigidity together with some known theoretical results. In Section 3 we describe the construction of the training data set. We first present the routine used for the random generation of planar domains and then, the numerical approach (Galerkin method) for solving the PDE problem on such domains. In Section 4 we describe the Deep Neural Network that mimes the torsional rigidity. The accuracy of the DNN on training, validation and test set is discussed in Section 5. We then focus on polygonal domains and we show that, with a fairly good accuracy, the NN "agrees" with a long standing conjecture. Finally, in Section 6 we test the NN on some complicated examples which are topologically different from the training images. First we ask the NN to guess the Torsion on disconnected domains. Then we try out the tricky case of multiple connected sets. In both cases the results are very satisfactory. The paper ends (Section 7) with some conclusions and perspectives.

The considered problem
In Mathematical Analysis the Torsional Rigidity T (Ω) of a bounded open set Ω ⊂ R d is defined as It is named after the physical interpretation, in case Ω is a planar set (d = 2), of representing, in the framework of elasticity, the torsional rigidity of a prismatic bar of cross section Ω.
A minimizer u of (2.1) is provided by the unique solution to the following problem The function u is the so-called Torsion Function (or Prandtl stress function, see [17]) and the torsional rigidity becomes (using equations (2.2)-(2.1) together with the divergence theorem) The Torsional Rigidity (or just Torsion), is uniquely determined by the geometry of Ω and it is one of the most simple examples of so-called Shape Funcional. The dependence of the functional from the set Ω is provided by the solution to a partial differential equation and therefore non trivially deductible from the geometrical properties of Ω. The Torsion has been intensively investigated and although explicit solutions are known only in very few cases, a large number of known properties can be found in the literature. We summarize here the most important features.
• (Scaling) Under scaling the Torsion changes according to a power law: when the set Ω is replaced by an omothetic copy t Ω (for some t > 0), then T (tΩ) = t 4 T (Ω).

• (Additivity) Torsion is additive when acting on unions of disjoint open sets:
T (Ω) = T (Ω 1 ) + T (Ω 2 ) whenever Ω 1 and Ω 2 are open, disjoint and such that Ω 1 ∪ Ω 2 = Ω. • (Monotonicity) As a trivial consequence of the maximum principle for Poisson problem, the Torsion is monotone by inclusion: The Torsion of a set Ω is always smaller then the one of a ball having same volume. The first four properties follow trivially from the definition. The fifth one is named after Saint-Venant, who first conjectured it back in 1856. It was proved by Pólya in 1948 (see [13,14]). It means that among beams with constant cross sectional area, the maximal Torsional Rigidity is achieved by circular cylinders. Observe that, from property (Scaling), denoting by A(Ω) the area of an open set Ω, then A −2 (Ω)T (Ω) turns out to be scaling invariant. Indeed, in the following sections, we will often plot the Torsion T against A 2 .
Moreover, if D denotes any disk, then Property (Saint-Venant) reads The elementary form of the solution u to (2.2) is known only for very few domains. Amog the others: (the constants A and B are determinated by the conditions u(R) = u(r) = 0) and For equilateral triangles it is possible to write down an explicit solution but already for rectangle, the solution can at best be expressed as a series of elementary functions and the value of the Torsion as well requires the summation of a series [17]. Already for general polyogns the solutions in closed elementary form are out of question. A famous conjecture reads as follows Conjecture 1. Among all pentagons of given area the regular pentagon achieves the maximal Torsional rigidity Actually the original conjecture has been stated for the Laplace eigenvalue (see forn instance [3]), but it is generally tacitally assumed to refer also to the Torsional rigidity. Similar conjectures stand still unsolved for any number of sides (greater than 5). For triangles and quadrilaterals it is easy to prove that the property holds true ( [3]).

Model the Torsion approximation
In this section we describe the model used to predict T (Ω) by means of a trained DNN. More specifically, in Subsection 3.1 we discuss how to construct a training dataset and in Subsection 3.2 we describe the ML methodology employed to approximate the functional T (·). Starting from the open set Ω ⊂ R 2 and the matematical problem (subfigure 1), such problem is numerically solved by means of a Galerkin method (subfigure 2). These procedure is repeated for different sets Ω in order to populate a reference database. Conversely, a DL approximation model to compute the Torsion is identified (sub- figure 3) by adopting a supervised approach from a binary imageΩ of Ω. Through the DL model, we obtain the approximated Torsion value ofΩ (subfigure 4) 3.1. Training dataset via Galerkin method. The first step was the construction of different instances of Ω. More specifically {Ω j , j = 1, 2, ..., M } will denote a set of M open bounded subset of R 2 randomly generated. For simplicity, we decided to confine all sets into a reference square Q = [−2, 2] 2 . In order to generate a domain Ω we selected a random number r (between 3 and 20) and a random set of r points into Q. Starting from such a set of points, Ω was constructed by means of interpolation using polyshape routine in MATLAB and, in some randomly selected cases, the spline routine (to smooth the boundary). Therefore the boundary of Ω was either a closed polygonal path that passes through (a subset of) the random points, or a closed curve interpolating (a subset of) the random points with a spline. Thereafter we considered problem (2.2) on each of the previous set and we looked for a numerical approximate value of the Torsion. In a fairly standard way, the domain Ω was approximated by a computational domain Ω h . On such a domain, a weak formulation of the original PDE was considered. By the Galerkin method [15] we found an approximate solution u h to the original problem (2.2) written as linear combination of basis functions φ i : Here V h is the space of piece-wise linear functions, leading to the so-called P1 Finite Elements (FE). We repeat the computations on M domains Ω j , j = 1, . . . , M and denote the approximate value of the Torsion byT (Ω j ). All the computations were made using Matlab, in particular the PDEs toolbox for the FE, the core Computational Geometry repository for the construction of the different istances of Ω j , and solvepde routine to solve numerically the PDE.
In Figure 3.1, we present some of the domains generated and the numerical value of the Torsion (RT Reference Torsion value) .

3.2.
Computation of Torsion via NN. The first step consisted in turning {Ω j , j = 1, 2, ..., M } into a reasonable binary input. A straightforward way is to use an image for each domain Ω j . Black and white images of size N × N pixels, basically a square matrix of zeros and ones. ByΩ j ∈ {0, 1} N 2 with j = 1, 2, ..., M we denote the binary images corresponding to the sets Ω j .
Then we set up the approximation problem as follows: The first question which arises is how to choose the space of approximating functions. The problem is a high dimensional approximation problem: in view of the classical Weierstrass Theorem one can think to use standard procedure to construct such approximation. Indeed, such problem cannot be solved pratically using classical approaches such as polynomials, piecewise polynomials, or truncated Fourier series because of the so called curse of dimensionality: the number N dof of parameters required to achieve certain accuracy depends exponentially on the dimension N 2 . On the other hand, the Universal Approximation Theorem states that under very mild conditions, any continuous function can be uniformly approximated on compact domains by neural network functions, see [4,6,8,9,10,19]. In the recent work [19] the course of dimensionality has been overcome in the case of deep CNN. These are the common networks used for the treatment of problems involving images [5,18] for instance in medical applications such as in automatic tumor markers [11,12]. For all these considerations, we decided to use a set of deep CNN (see next section for more details).
Our numerical problem then is to find a suitable CNN that depends on a finite set of (trainable) parameters θ ∈ R N dof . SinceT (·) is uniquely determined by the training set of parameters θ, when necessary, we explictly emphasize such a dependence by writingT θ (·). The optimization reads: The condition to be satisfied is that T * (Ω j ) is close toT (Ω j ) ∀j ∈ {1, ..., M } according to a certain cost function L (called also loss function). Namely, if we denote byŶ = {ŷ j =T (Ω j ) ∈ R + with j = 1, ..., M } the set of Torsion values obtained by the neural network, we want to minimize a suitable notion of distance between Y andŶ .
We generated 5 · 10 3 images of size 677 × 677 pixels and calculate reference Torsion values on each of these: the target values. To such a set we applied a simple procedure of data augmentation which consists in considering new copies obtained by rotating and translating the original images. We denote the resulting set, made of 2 · 10 4 images, by F. Then, we randomly splitted this set in three disjoint subsets: training set Tr, validation set Val and test set Te: Following a standard procedure, Tr, Val, Te are selected containing more or less 70%, 10% and 20% of the images, respectively. Common practice is indeed to tune the parameter of the Network to match the training set. Use the Validation set for instance to take under control, during the optimization process, overfitting issues. At the end of the process, the test set provides an unbaised evaluation of the final NN, and does not influence directly the process of learning. From now on we refer to Y andŶ to denote the training data and the corresponding values obtained by the neural network. Therefore M represents just the number of images in the training set. The optimal vaules θ * are determinated by an optimization procedure that minimizes the loss function: where {w j } j=1,...,v are the weights of the network: a subset of the parameters θ.
Here λ is some positive constant to be choosen in advance.
The first term on the righthand side of (3.3) is the Mean Squared Error (MSE) between target and predicted values. The second term consists of the penalty term: a fixed positive parameter λ multiplied by the squared 2 norm of {w j }. The MSE is an widely used loss function in Machine Learning problem; it exhibits robustness to outliers. The main drawback of this measure is that it loses accuracy on small data. On the other hand, the actual value of the Torsion is small each time the set has a very small area (remember that by omothety the Torsion rescales as the square of the area) and here is when the approximation by pixels becomes less and less accurate. Therefore there is no need to push the Network to look for accuracy in these cases. Finally, the penalty (or regularization) term is a standard practice in ML as well.
It allows us to control the amplitude of the network weights, and reduces the danger of an overfitting phenomena.
So, in summary, we want to determine (3.4) θ * = arg min θ L Y,Ŷ , θ and T * ≡ T θ * . The minimization is obtained through a training process performed on the network called backward propagation method. Similarly to a gradient descent, the training process generates a sequence of DL neural networks that has to be stopped at the k-iteration. The number of iterations (epoch) k has to be choosen accurately. Eventually, the parameters θ (k) defines the network.

Neural Network Architecture
In this section, we describe the architecture of the CNN model (see Figure 3). The Convolutional Neural Network model takes as input an imageΩ and gives as ouput T * (Ω) ≈ T (Ω). The model applies discrete convolutional operations between the matrix representing the imageΩ and another matrix called kernel K. The result of this operation is called feature map C What happens in a convolutional layer can be summarized in the following steps: random kernels are generated (with a fixed size), and convolutional operations are applied on all the inputsΩ with the same K. A parameter called stride manages the displacement of the filter along the image, i.e. how changes the index (i, j). It is also possible to change the kernel and repeat the procedure, obtaining a different feature map. The set of feature maps obtained changing the kernel elements is the real output of the convolutional layer. It is possible to concatenate the convolutional layer with other layers (also of different types), obtaining a multi-layer neural network called Deep Convolutional Neural Network (DCNN). In our case, we use a very well known DCNN called VGG16-Net (see Figure 3) [16]. More in detail, the computational blocks highlighted in yellow are Convolutional layers; the red ones are MaxPooling kernels, i.e. a downsampling layer that extracts the max value from a fixed window. Moreover, the purple layer is a Fully Connected layer, i.e. a layer whose inside neurons connect to every neuron in the preceding layer. The input of VGG16-Net is an image with dimension 224 × 224 pixel, so some steps of preprocessing consist of a procedure for image downscaling. The final output of the network is the predicted value of Torsion of the input image. Vgg16-Net is a Convolutional Neural Network composed of 13 convolutional layers and three fully connected layers with activation function ReLU [7]. A peculiarity of this NN is the small kernel size, which is important to capture the basic spatial information. Furthermore, the zero-padding is used to preserve the dimensions.

Experimental results on the trained network
After the training procedure, we tested the model in several ways.

5.1.
Test set: the network robustness. Following a stadard procedure, in the first step, we use the classical test set Te defined in (3.2), made of images generated with same method used for the training one. The test set contains more or less 4000 images. The results are presented in Table 1 together with those for the training and validation. The parameter used are: learning rate of 10 −4 , regularization of 10 −6 , dropout of 0.5 and batch size of 16.
The values of the loss function and MSE function for the test set are in perfect agreement with those of the validation set, more than satifactory in terms of accuracy. In Figure 4 we have a global picture of the computed and the predicted values. The Torsion is plotted aginst the square of the area. The solid line represents the theoretical line of the torsional rigidity of disks. From the Saint-Venant property (2.3) no point can lay above that line. The picture clearly shows that the predicted values meet such rule. Apart in few cases for very small values of the Torsion where, the choice of the loss function (mean square error) account for less accuracy.
As we already mention, in the loss function we use the standard MSE measure. We give more importance, on purpose, to those set having a larger value of torsion, and we pay the price to lose accuracy on smaller values. But small value of the reference set Y are intrinsecally less accurate, since they mostly correspond to small domains with a less accurate resolution of the boundary.
By construction, every random set is enclosed in the box Q, and no value of the Torsion happens to exceed 1. In order to provide a more precise estimate of the accuracy, we splitted each one of the Training, Validation and Test set, in three subgroups according to the value of the Torsion.
The results are in Table 2. The MAPE, as expected, increases on small values of Torsion. But the overall results show that the NN succesfully approximate the functional.

Polygonal domains.
We decided to perform an additional test, restricting the analysis on polygonal domains. Firstly we generated 1000 polygonal domains with number of vertices from 4 to 11. In Figure 5 we provide a picture of the  Thereafter we restricted to pentagons. Results are presented in Figure 6, as usual Torsion is plotted against squared area. According to Conjecture 1, all points in the picture should lay below the continuos line representing regular pentagons. The agreement is almost perfect. Please observe that Conjecture 1 is, to a certain extent, a refinement of the Saint-Venant property and therefore requires a greater accuracy. For the sake of completeness predicted values of the Torsion on regular pentagons are presented in Figure 7. In the first one (top row), the accuracy of the network increases as expected when the set (and the Torsion as well) gets bigger. In the second example (bottom row) there is a very good accuracy on a small scale, more or less preserved under dilation. One can take advantage of the scaling law to look for the estimate of the Torsion on the right scale. On a small scale (T < 0.01) one takes the risk of a slack prediction.

Untrained cases
By untrained cases we refer to classes of sets that the DNN has never seen before. We left this classes unexplored on purpose, to check the extrapolation skills of the DNN. Bear in mind that no matter how large is the training set, there will be always some blind spot in which the DNN has to extrapolate. We consider: (A) Disconnected sets. (B) Multiple connected sets.
6.1. (A) Disconnected sets. From Section 2 we know that on disconnected sets (A) the Torsion is an additive functional: the Torsion of the union is the sum of the torsions. In Figure 9 we present the results where analytical values and predicted values for unions of ellipses are compared. To the level of accuracy achieved by the DNN we can state that the network understands that the Torsion is additive under union.

(B) Multiple connected sets.
More delicate is the case of multiple connectd sets. The Torsion can be very sensitive to holes. Let us consider the explicit computation of the Torsion on the annular ring A r1 in (2.6) and compare with the    Torsion on the disk D 1 (2.4). Following the intuition, T (A r1 ) converges to T (D 1 ) as r goes to 0. However such a convergence is very slow (logarithmic w.r.t. r). If we consider for instance the Torsion of the disk of radius one T (D 1 ) = 0.39 and the Torsion of the annular ring T (A 0.02 1 ) = 0.29, we see that a tiny hole of radius 0.02 accounts for a decrease of 25%. Of course, expecting an accurate prediction with such a small hole is unreasonable, for several reasons, not the least the resolution of the images. It is quite surprising that the DNN catches the behavior (see Figure 10(a)). As the hole increases the absolute error decreases (see Figure 10(b)). Figure 10. Prediction vs. reference values of the Torsion for two annuli. On the left, despite the small size of the hole, the network "understands" that the Torsion is noticeably smaller than on the unit disk (where the value is 0.39). On the right, we show a larger hole, and the network shows greater accuracy.
We provide the general picture in Figure 11. The Network perfectly catches the behavior w.r.t. the internal radius, even if in general it underestimates the value of the Torsion. A more intriguing test was performed on eccentric annuli. It is well known that for given inner and outer radii, the more eccentric is the annulus the bigger is the torsional rigidity, the concentric annulus providing the smallest possible value. In Figure 12 we show some examples of the prediction vs. reference. In Figure 13 we provide the plot of the Torsion w.r.t to the distance between the centers (of inner circle and outer circle). With few exceptions the DNN captures the monotonicity. There is a general underestimation of the torsion, but again the network has never seen anything similar during the training.

Conclusions
We consider this paper as a tentative new approach to the branch of Calculus of Variation known as Shape Optimization. In this paper we have considered the training of a Deep Neural Network for the prediction of Torsional Rigidity. The use of the Torsion is purely accidental, in the sense that it is nothing but a nice example of Shape Functional. From torsional rigidity to thermal insulation, electrostatic capacity etc., the steps are small, which means that the same approach can be easily generalized in many other meaningful physical problems. As ususal in Machine Learning, we have trained a NN and checked it on training, validation, and test sets. We noticed a very good accuracy. However, our training data set did not include some classes of domains on purpose. Indeed, we checked that the NN properly extrapolate informations also on sets topologically different from those we fed the network during the training. Apart from that, a well trained NN has some undeniable advantage: • Short computational time (realtime answer).
• It works with images, even hand drawings, and does not require any analytical expression or approximation of the the boundary of the set. • It can be easily employed in an automated optimization procedure. For instance to minimize (maximize) the shape functional under some geometrical constraints. Our future perspectives include • Try out new functionals and check other networks architectures to find out the most competitive (in terms of accuracy). • Look for different loss functions which possibly allow to recover good approximation also at a "small" scale. • Train a NN on some Shape functional and then set up a shape optimization problem to be solved by means of NNs, perhaps in conjunction with genetic algorithms. Figure 13. The predicted values of the Torsion (blue dots) w.r.t the distance between centers for eccentric annular rings. The corresponding reference values (numerical computation) are plotted in red.