# MLGen: Generative Design Framework Based on Machine Learning and Topology Optimization
## 4 The MLGen Framework Description
### Design and Training of the LSTM Network  
In this part of the work, a detailed description of the network architecture, the training procedure and the database creation is presented. As previously stated, in the literature, LSTM networks are used successfully in several time-series classification problems. In this study, the scope for using the LSTM networks is to derive the density class of every element of the FE discretization. This class is defined according to the final one that the SIMP approach would have calculated, after multiple iterations, at convergence. It is worth mentioning that the prediction does not use information regarding the support conditions, the location of the element in the mesh of the design domain, the loading conditions or the desired volume fraction. The only information used is the density value of each element in the first 20 iterations of the SIMP approach in the original problem. This strategy is chosen in order to assure that the same trained network can offer high quality results without needing to be retrained regardless of the problem definition. LSTMs present the ability to handle inputs that, apart from a single value per time-step, also include additional values (features) per time step. Assuming that SIMP is applied on a test example with a population of finite elements equal to \(nx\times ny=m\) finite elements and a number of \(k\) iterations are performed until convergence is achieved, then a matrix \(D\) containing all densities \(d_{i,j}\) per FE is formulated as follows [19]:  
\[D=\left[ \begin{array}{ccccc}d_{1,1}&d_{1,2}&.&.&d_{1,k}\\ d_{2,1}&d_{2,2}&.&.&d_{2,k}\\.&.&.&.&.\\ d_{m,1}&d_{m,2}&.&.&d_{m,k}\end{array} \right] \tag{5}\]  
It is noted that in the remaining part of this work, the density of an FE is defined as \(d\) rather than \(x\), which is used in Section 2. In an attempt to improve the performance of the network, a decision is made to increase the features of the input instead of just using the density of one FE. The additional features that are used as inputs are the density values of neighboring finite elements of the element to be classified. In detail, apart from the density of the FE whose final density is to be classified, the densities of extra 24 FEs that are the closest to it in terms of center weights coordinates are also used as features of the networks' inputs. For example, in case of an element \(e(i,j)\), the density recording input at the \(t\)th iteration is presented in Equation (6). \[D_{i,j}^{t}=\left[ \begin{array}{c}d_{i-2,j-2}\\ d_{i-2,j-1}\\.\\.\\ d_{i,j}\\.\\.\\ d_{i+2,j+1}\\ d_{i+2,j+2}\end{array} \right] \tag{6}\]The formulation of the database for \(m\) finite elements containing their density values over the optimization process until convergence, where the first \(t\) iterations of the SIMP approach out of the \(T\) are needed for convergence, is presented in Equation (7). \[\left[ \begin{array}{cccc|c}D_{1}^{1}&D_{1}^{2}&\dots&D_{1}^{t}\\ D_{2}^{1}&D_{2}^{2}&\dots&D_{2}^{t}\\ \vdots&\vdots&\ddots&\vdots&\vdots&\ddots&\vdots\\ D_{m-1}^{1}&D_{m-1}^{2}&\dots&D_{m-1}^{t}\\ D_{m}^{1}&D_{m}^{2}&\dots&D_{m}^{t}\\ \end{array} \right] \begin{array}{cccc|c}D_{1}^{t+1}&\dots&D_{1}^{t-1}\\ D_{2}^{t+1}&\dots&D_{2}^{t-1}\\ \vdots&\vdots&\ddots&\vdots\\ D_{m-1}^{t+1}&\dots&D_{m-1}^{t-1}\\ D_{m}^{t+1}&\dots&D_{m}^{t-1}\\ \end{array} \right] \tag{7}\]  
\(m\)InputVectors\(Output\)  
A schematic representation of the features used can also be seen in Figure 3. It is worth pointing out that in the case of finite elements located close to the boundaries of the design domain in which there are no neighboring elements in one or more directions, padding of the necessary rows and/or columns is performed. The volume fractions of the generated FEs are set equal to the volume of their existing neighboring element. As previously stated, the LSTM network is used for classifying the time series of the volume fluctuation of each finite element in the design domain.