Transform encoder model generation method for terahertz metamaterial sensor and sensor
By generating data samples through electromagnetic simulation, constructing a Transformer encoder model, and optimizing parameters, the problem of cumbersome and time-consuming traditional design methods is solved, enabling efficient design and accurate prediction of terahertz metamaterial sensors and improving detection performance.
Patent Information
- Application Number
- CN202511643928.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-11
- Publication Date
- 2026-05-01
AI Technical Summary
Traditional terahertz metamaterial sensor design methods require extensive experience and involve a cumbersome and time-consuming design process. Transformer-based metamaterial sensor design methods suffer from unsatisfactory prediction results when dealing with the mapping relationship between structural parameters and absorption spectra.
Multiple sets of data samples were generated using electromagnetic simulation software. Outliers were removed and the data was standardized. A Transformer encoder model was constructed, and the model parameters were optimized to improve prediction accuracy. A deep network structure combining multi-head self-attention mechanism and residual connection layer was adopted. The backpropagation algorithm was used to determine key hyperparameters, and forward and reverse design optimizations were performed.
This improves the design efficiency and performance of terahertz metamaterial sensors, enhances the model's ability to characterize the relationship between structural parameters and absorption rate, and ensures the sensor's detection sensitivity and measurement accuracy.
Smart Images

Figure CN121960593A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of model generation, and in particular relates to a method for generating a Transformer encoder model for a terahertz metamaterial sensor and the sensor itself. Background Technology
[0002] Terahertz metamaterial sensors have broad application prospects in fields such as biological detection due to their unique electromagnetic properties and high sensitivity. However, traditional metamaterial sensor design methods require designers to have extensive experience and involve repeated parameter scanning and electromagnetic simulation calculations, making the design process cumbersome and time-consuming, which restricts the research and development efficiency of terahertz metamaterial sensors.
[0003] In related technologies, intelligent design methods based on deep learning are commonly employed. Among them, the Transformer model, through its self-attention mechanism, can effectively capture the dependencies between features in the input data. Compared with traditional RNN and LSTM models, it can better handle long-range interactive sequence data and exhibits good performance in the design of metamaterial sensors.
[0004] However, the aforementioned Transformer-based metamaterial sensor design method suffers from problems such as large differences in feature dimensions and uneven data distribution when dealing with the mapping relationship between structural parameters and absorption spectra, which reduces the accuracy of model prediction results and leads to less than ideal sensor performance. Summary of the Invention
[0005] This application provides a method for generating Transformer encoder models for terahertz metamaterial sensors and a sensor in general, which improves the accuracy of model prediction results and thus enhances sensor performance.
[0006] Firstly, this application provides a method for generating a Transformer encoder model for terahertz metamaterial sensors. The method involves generating multiple sets of data samples from the acquired training data using electromagnetic simulation software. Each set of data samples includes structural parameters and absorption rate values. Outlier removal and standardization are performed on the multiple sets of data samples to obtain a training dataset. A Transformer encoder model is then constructed. The training dataset is divided into a training set and a test set according to a preset ratio. Based on the training set, the Transformer encoder model is optimized using a backpropagation algorithm with mean squared error as the loss function. Based on the mean squared error on the test set, the optimal values for the dimension of the feature vector output from the input embedding layer, the number of subspaces in the multi-head self-attention layer, the learning rate, and the batch size are determined to obtain an optimized Transformer encoder model for terahertz metamaterial sensor design.
[0007] By employing the aforementioned technical solution, multiple sets of data samples containing structural parameters and absorptivity values were generated using electromagnetic simulation software. After outlier removal and standardization, a high-quality training dataset was obtained. The Transformer encoder model built upon this dataset comprises a deep structure including an input embedding layer, multiple cascaded encoder units, and an output layer, enabling it to fully learn the complex nonlinear mapping relationship between structural parameters and absorptivity. The multi-head self-attention mechanism in the model captures the interactions between different structural parameters and their combined impact on absorptivity. The combination of residual connections and layer normalization ensures both the training stability of the deep network and maintains the model's expressive power. The model parameters are optimized using the backpropagation algorithm, and the optimal values of key hyperparameters are determined based on the mean squared error on the test set. This results in good generalization performance, improved accuracy of model predictions, and ultimately, enhanced sensor performance.
[0008] In conjunction with some embodiments of the first aspect, in some embodiments, constructing a Transformer encoder model specifically includes: constructing an input embedding layer to convert structural parameters or absorptivity values into feature vectors through a linear transformation; constructing a multi-head self-attention layer to map the feature vectors to multiple subspaces and output a first feature vector; constructing a first residual connection layer to add the feature vector and the first feature vector to obtain a second feature vector; constructing a first normalization layer to normalize the second feature vector to obtain a normalized second feature vector; constructing a two-layer feedforward neural network to obtain a third feature vector from the normalized second feature vector through a first linear transformation, a ReLU activation function, and a second linear transformation; and constructing a second... A residual connection layer is constructed to add the feature vector to the third feature vector to obtain the fourth feature vector. A second normalization layer is constructed to normalize the fourth feature vector to obtain a normalized fourth feature vector. The multi-head self-attention layer, the first residual connection layer, the first normalization layer, two feedforward neural networks, the second residual connection layer, and the second normalization layer are sequentially connected to obtain an encoder unit. Four encoder units are cascaded to obtain an encoder layer, and the output of the fourth encoder unit is used as the final output feature of the encoder layer. An output layer is constructed to transform the final output feature vector through a linear transformation to obtain the model output. The input embedding layer, encoder layer, and output layer are constructed to form a Transformer encoder model.
[0009] By employing the above technical solutions, the input embedding layer transforms the original parameters into high-dimensional feature vectors, facilitating subsequent processing. The multi-head self-attention layer maps the feature vectors to multiple subspaces for parallel processing, improving the model's ability to perceive features at different scales. The combined use of two residual connections and layer normalization preserves the original information while improving the stability of the feature distribution. Two layers of feedforward neural networks enhance the model's feature extraction capability through nonlinear transformations. The cascaded arrangement of four encoder units forms a progressive feature extraction process, enabling the model to progressively deepen its understanding of the relationship between structural parameters and absorptivity. Finally, the output layer converts the extracted high-level features into target predicted values, achieving a more accurate mapping from structural parameters to absorptivity.
[0010] In conjunction with some embodiments of the first aspect, in some embodiments, after obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: constructing multiple sets of Transformer encoder models with different encoder layers and feature vector dimensions, each set of Transformer encoder models being trained using a training set to obtain a corresponding training model; inputting a test set into each set of training models for forward prediction, determining the optimal encoder layers and feature vector dimensions based on a preset mean square error evaluation index to obtain a forward prediction optimization model; inputting structural parameters into the forward prediction optimization model to obtain predicted absorption rate values; converting the predicted absorption rate values into absorption rate curves; and determining that the forward prediction optimization model meets preset prediction accuracy requirements when the mean square error between the absorption rate curve and the absorption rate curve calculated by electromagnetic simulation software is less than a preset threshold.
[0011] By employing the above technical solution, positive prediction experiments were conducted on the test set. The optimal network configuration was selected based on the mean square error evaluation index, thus improving the model's prediction accuracy. The predicted absorbance values were converted into absorbance curves and quantitatively compared with electrochemical simulation results. The model's prediction accuracy was strictly controlled by setting a reasonable error threshold. This optimization strategy based on multiple validation allows the model to improve prediction accuracy while maintaining low computational overhead, enabling a faster and more reliable evaluation of the absorption characteristics corresponding to different combinations of structural parameters.
[0012] In conjunction with some embodiments of the first aspect, in some embodiments, after obtaining the optimized Transformer encoder model for the design of terahertz metamaterial sensors, the method further includes: inputting a test set into each training model for reverse design; determining the optimal number of encoder layers and feature vector dimensions based on a preset mean square error evaluation index to obtain a reverse design optimization model; inputting the absorption rate value into the reverse design optimization model to obtain predicted structural parameters; inputting the predicted structural parameters into electromagnetic simulation software to calculate the absorption rate curve; and determining that the reverse design optimization model meets the preset design accuracy requirements when the mean square error between the absorption rate curve and the preset original absorption rate is less than a preset threshold.
[0013] By adopting the above technical solution, reverse design optimization is further carried out on the basis of forward prediction. The reverse design performance of different model configurations is evaluated on a test set to select the optimal number of encoder layers and feature vector dimensions. The target absorption rate is input into the optimized model to predict the corresponding structural parameters, and the accuracy of the design results is verified using electromagnetic simulation software. By comparing the mean square error between the simulated absorption rate curve and the preset target, and setting a reasonable error threshold, the reliability of the reverse design results is improved. This bidirectional optimization strategy combining forward prediction and reverse design enables the model to simultaneously meet the needs of structural analysis and parameter design, improving the design efficiency of terahertz metamaterial sensors.
[0014] In conjunction with some embodiments of the first aspect, in some embodiments, after obtaining the optimized Transformer encoder model for the design of a terahertz metamaterial sensor, the method further includes: constructing a three-dimensional model of the sensor from the structural parameters output by the optimized Transformer encoder model; setting boundary conditions for electromagnetic simulation on the three-dimensional model, wherein periodic boundary conditions are set in the x and y directions, and open boundary conditions are set in the z direction; performing electromagnetic field simulation based on the three-dimensional model and boundary conditions to obtain the reflection coefficient of the sensor, and determining the square of the reflection coefficient as the reflectivity; calculating the absorptivity of the sensor based on the reflectivity, and plotting the absorption characteristic curve of the absorptivity changing with frequency; based on the absorption characteristic curve, if the absolute value of the difference between the real part of the sensor's equivalent impedance at the resonant frequency and a preset value is less than a preset difference threshold and the difference between the imaginary part and zero is within a preset interval, determining that the optimized Transformer encoder model meets the preset design requirements.
[0015] By employing the above technical solution, the structural parameters output by the optimized Transformer encoder model are used to construct a three-dimensional model of the sensor. Electromagnetic simulation boundary conditions are then set to perform electromagnetic field simulation, obtaining the sensor's reflection coefficient and absorptivity, and generating an absorption characteristic curve. Based on this curve, the equivalent impedance characteristics of the sensor at the resonant frequency are verified, ensuring that the model-designed sensor possesses ideal impedance matching characteristics. When the difference between the real part of the equivalent impedance and the preset value is less than a threshold and the imaginary part is close to zero, it indicates that the sensor has achieved impedance matching with free space at the resonant frequency, reducing electromagnetic wave reflection on the sensor surface and improving the absorption efficiency of electromagnetic waves in the sensor. This verification method evaluates the design performance of the model through rigorous impedance matching criteria, ensuring that the model-designed sensor has good operating characteristics and improving the sensor's detection sensitivity and measurement accuracy.
[0016] In conjunction with some embodiments of the first aspect, in some embodiments, after obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: simultaneously changing the values of at least two structural parameters to generate multiple sets of perturbation parameters, each set of perturbation parameters including the original value and the changed value of the structural parameters; inputting the multiple sets of perturbation parameters into electromagnetic simulation software to obtain the absorptivity value corresponding to each set of perturbation parameters; calculating the absorptivity change of each set of perturbation parameters based on the absorptivity value; constructing a sensitivity matrix from the multiple sets of perturbation parameters and the corresponding absorptivity changes, where each element in the sensitivity matrix represents the absorptivity change corresponding to the structural parameter combination; inputting the sensitivity matrix into the optimized Transformer encoder model for prediction to obtain a prediction sensitivity matrix; when determining a preset element difference threshold for the difference between adjacent elements in the prediction sensitivity matrix, marking the corresponding structural parameter combination as a co-sensitive parameter group; adjusting the input layer structure of the optimized Transformer encoder model based on the co-sensitive parameter group, so that the structural parameters in the co-sensitive parameter group are used as combined inputs.
[0017] By employing the aforementioned technical solution, a set of perturbation parameters is generated by simultaneously changing multiple structural parameters. Electromagnetic simulation is then used to calculate the corresponding changes in absorbance and construct a sensitivity matrix. This allows for the evaluation of the impact of different combinations of structural parameters on sensor performance. The sensitivity matrix is then input into an optimized Transformer encoder model for prediction. By analyzing the differences between adjacent elements in the predicted sensitivity matrix, combinations of structural parameters exhibiting cooperative sensitivity characteristics can be identified. This method can demonstrate the influence of the coupling relationship between structural parameters on sensor performance and uncover the interaction mechanism between parameters. By labeling the cooperative sensitivity parameter sets and adjusting the model's input layer structure accordingly, the model can more accurately capture the mutual influence between structural parameters, improving its ability to characterize the relationship between sensor structure and performance and enhancing its guiding role in sensor design optimization.
[0018] In conjunction with some embodiments of the first aspect, in some embodiments, adjusting the input layer structure of the optimized Transformer encoder model based on the co-sensitive parameter set specifically includes: obtaining a combined feature vector by linearly transforming the structural parameters in the co-sensitive parameter set; constructing a combined input layer to map the combined feature vector and the feature vectors of the remaining structural parameters to different subspaces; concatenating the output of the combined input layer with the output of the input embedding layer of the optimized Transformer encoder model to obtain the adjusted feature vector; and inputting the adjusted feature vector into the first encoder unit of the optimized Transformer encoder model, so that the structural parameters in the co-sensitive parameter set are used as the combined input.
[0019] By employing the aforementioned technical solution, the structural parameters in the co-sensitive parameter group are linearly transformed to obtain a combined feature vector. A dedicated combined input layer is then constructed to map the feature vectors of this vector to different subspaces, achieving differentiated processing of the co-sensitive parameters. The output of the combined input layer is concatenated with the output of the original input embedding layer, ensuring that the adjusted feature vector retains both the independent feature information of each parameter and the coupling feature information between the co-sensitive parameters. This improved input layer structure enhances the model's ability to learn the combined features of the co-sensitive parameters and improves the model's accuracy in representing the interactions between structural parameters. By using structural parameters with coupling effects as combined inputs, the model can more accurately predict the comprehensive impact of parameter changes on sensor performance, improving the model's application effect in sensor design optimization.
[0020] In a second aspect, embodiments of this application provide a sensor comprising: one or more processors and a memory; the memory is coupled to one or more processors and is used to store computer program code, the computer program code including computer instructions, wherein one or more processors invoke the computer instructions to cause the sensor to perform the method described in the first aspect and any possible implementation thereof.
[0021] Thirdly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on a sensor, cause the sensor to perform the method described in the first aspect and any possible implementation thereof.
[0022] Fourthly, embodiments of this application provide a computer program product that, when run on a sensor, causes the sensor to perform the method described in any possible implementation of the first aspect.
[0023] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. This application provides a method for generating a Transformer encoder model for a terahertz metamaterial sensor. Multiple sets of data samples containing structural parameters and absorptivity values are generated using electromagnetic simulation software. After outlier removal and standardization, a high-quality training dataset is obtained. The Transformer encoder model built based on this dataset contains a deep structure including an input embedding layer, multiple cascaded encoder units, and an output layer, enabling it to fully learn the complex nonlinear mapping relationship between structural parameters and absorptivity. The multi-head self-attention mechanism in the model captures the interactions between different structural parameters and their combined impact on absorptivity. The combination of residual connections and layer normalization ensures both the training stability of the deep network and maintains the model's expressive power. The model parameters are optimized using the backpropagation algorithm, and the optimal values of key hyperparameters are determined based on the mean squared error on the test set, resulting in good generalization performance and improved accuracy of the model's predictions, thereby enhancing the sensor's performance.
[0024] 2. This application provides a method for generating Transformer encoder models for terahertz metamaterial sensors. By simultaneously changing multiple structural parameters to generate a set of perturbation parameters, and using electromagnetic simulation to calculate the corresponding changes in absorbance to construct a sensitivity matrix, the impact of different combinations of structural parameters on sensor performance can be evaluated. The sensitivity matrix is input into the optimized Transformer encoder model for prediction. By analyzing the differences between adjacent elements in the predicted sensitivity matrix, combinations of structural parameters with cooperative sensitivity characteristics can be identified. This method can reflect the influence of the coupling relationship between structural parameters on sensor performance and discover the interaction mechanism between parameters. By labeling the cooperative sensitivity parameter sets and adjusting the model input layer structure accordingly, the model can more accurately capture the mutual influence between structural parameters, improving the model's ability to represent the relationship between sensor structure and performance, and enhancing the model's guiding role in sensor design optimization. Attached Figure Description
[0025] Figure 1 This is a flowchart illustrating a method for generating a Transformer encoder model for a terahertz metamaterial sensor, as described in this application.
[0026] Figure 2 This is another flowchart illustrating a method for generating a Transformer encoder model for a terahertz metamaterial sensor, as described in this application.
[0027] Figure 3 This is a schematic diagram of the physical device structure for generating a terahertz metamaterial sensor using a Transformer encoder model, as provided in an embodiment of this application. Detailed Implementation
[0028] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0029] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0030] This application provides a Transformer encoder model generation method for terahertz metamaterial sensors. The sensor is a terahertz metamaterial sensor, and its unit structure integrates microfluidic channels. The terahertz metamaterial sensor is composed of a polyimide cover layer, a metallic aluminum resonant layer, a microfluidic channel layer, a metallic aluminum reflective layer, and a lower high-resistivity silicon substrate layer.
[0031] Terahertz (THz) waves are electromagnetic waves with frequencies ranging from 0.1 to 10 THz, located between the infrared and microwave ranges. Metamaterials are artificial materials composed of subwavelength structures. By adjusting the geometry of periodic units, they can respond to electromagnetic waves, thus achieving unique electromagnetic properties not found in natural materials. Microfluidics is a science and technology that precisely manipulates and processes fluids at the microscale. It enables high-resolution, high-sensitivity detection of trace reagents and samples, possessing advantages such as miniaturization, integration, high throughput, and low consumption.
[0032] The terahertz metamaterial sensor disclosed in this application comprises, from top to bottom, a cover layer, a resonant structure layer, a microfluidic channel layer, a metal reflective layer, and a high-resistivity silicon substrate layer. The metal microstructure layer is composed of square, circular, and rhombic metal rings. The cover layer is made of polyimide with a dielectric constant of 3.5. Both the metal microstructure layer and the metal reflective layer are made of aluminum with a conductivity of 4.56 × 10⁷ S / m. The substrate is silicon, which does not affect the sensor's performance and has a dielectric constant of 11.9. The period of the unit structure is p, the side length of the square metal ring is L1, the radius of the circular metal ring is r, the side length of the rhombic metal ring is L2, and the linewidth of the metal resonant structure is w.
[0033] The following example is used in conjunction with Figure 1 The present application describes a method for generating a Transformer encoder model for a terahertz metamaterial sensor. Please refer to the following: Figure 1 This is a flowchart illustrating a method for generating a Transformer encoder model for a terahertz metamaterial sensor according to an embodiment of this application.
[0034] S101. The acquired training data is used to generate multiple sets of data samples using electromagnetic simulation software; The acquired training data is used to generate multiple sets of data samples using electromagnetic simulation software. Each set of data samples includes structural parameters and absorption rate values. The structural parameters include the side length of the square metal ring, the side length of the rhombic metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. This step mainly uses electromagnetic simulation software to simulate and calculate the structural parameters of the terahertz metamaterial sensor, generating multiple sets of data samples. Each set of data samples includes two parts: structural parameters and absorption rate values. The structural parameters include five dimensions: the side length of the square metal ring, the side length of the rhombic metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. The side length of the square metal ring refers to the outer side length of the square metal resonant ring in the terahertz metamaterial sensor; the side length of the rhombic metal ring refers to the diagonal length of the rhombic metal resonant ring; the radius of the circular metal ring refers to the radius of the circular metal resonant ring; the linewidth of the metal resonant structure refers to the width of the metal lines constituting the various metal resonant rings; and the height of the microfluidic channel layer refers to the thickness of the microfluidic channel used to support the sample under test. The absorptivity value refers to the proportion of terahertz waves absorbed after irradiation by the metamaterial sensor, typically between 0 and 1. The choice of electromagnetic simulation software can be determined based on actual needs and is not limited here. The number of generated data samples can be determined based on model training requirements, typically requiring several thousand to tens of thousands of data sets, and is not limited here. CSTMicrowaveStudio software can be used for electromagnetic simulation. First, a 3D model of the terahertz metamaterial sensor is established in the software, setting the side length of the square metal ring to 50-200 micrometers, the side length of the rhombic metal ring to 40-180 micrometers, the radius of the circular metal ring to 20-100 micrometers, the linewidth of the metal resonant structure to 5-20 micrometers, and the height of the microfluidic channel layer to 10-50 micrometers. Then, the frequency range of the terahertz waves is set to 0.1-10 THz, and a frequency domain solver is used for calculation. Through the parameter scanning function, the various structural parameters are combined and scanned. Each simulation calculation yields the corresponding absorptivity spectrum curve, from which the absorptivity value at a specific frequency point is extracted. Another approach is to use COMSOL Multiphysics software to create a two-dimensional or three-dimensional metamaterial sensor model and perform electromagnetic field simulation using the radio frequency module. The boundary conditions are set to periodic conditions, and the excitation source is a plane wave. The structural parameters are automatically changed using the parametric scanning function, and the absorptivity under different parameter combinations is calculated in batches. For each set of structural parameters, Maxwell's equations are solved to obtain the electromagnetic field distribution, and then the absorptivity value is calculated.
[0035] S102. Perform outlier removal and standardization on multiple sets of data samples to obtain the training dataset; The process includes two main steps: outlier removal and standardization. Outlier removal identifies and removes data points that significantly deviate from the normal range in the dataset. These outliers may be caused by numerical errors in the simulation software, incorrect parameter settings, or other reasons. Standardization transforms data with different dimensions and numerical ranges to a uniform scale, ensuring that each feature has equal importance in model training. Statistical outlier detection methods can be used. First, the mean and standard deviation of each feature are calculated, and data points exceeding the mean plus or minus three times the standard deviation are marked as outliers and removed. For structural parameters, values outside the physically reasonable range are checked, such as negative side lengths or radii. For absorptivity values, data points less than 0 or greater than 1 are removed. Standardization uses the Z-score standardization method, calculating the mean μ and standard deviation σ for each feature, and then converting the original data x to (x-μ) / σ. Another approach is to use an outlier detection method based on quartiles. Calculate the first quartile Q1 and the third quartile Q3 for each feature. The interquartile range (IQR) is calculated as IQR = Q3 - Q1. Data points less than Q1 - 1.5 × IQR or greater than Q3 + 1.5 × IQR are considered outliers. Standardization can be performed using the Min-Max standardization method, which linearly maps the data to the interval [0, 1]. The transformation formula is (x - min) / (max - min), where min and max are the minimum and maximum values of the feature, respectively.
[0036] S103. Construct the Transformer encoder model; The Transformer encoder model comprises an input embedding layer, four cascaded encoder units, and an output layer. Each encoder unit sequentially includes a multi-head self-attention layer, a first residual connection layer, a first normalization layer, two feedforward neural networks, a second residual connection layer, and a second normalization layer. Specifically, constructing the Transformer encoder model includes: constructing an input embedding layer to convert structural parameters or absorptivity values into feature vectors through a linear transformation; constructing a multi-head self-attention layer to map the feature vectors to multiple subspaces and output a first feature vector; constructing a first residual connection layer to add the feature vector and the first feature vector to obtain a second feature vector; constructing a first normalization layer to normalize the second feature vector to obtain a normalized second feature vector; constructing a two-layer feedforward neural network to obtain a third feature vector from the normalized second feature vector through a first linear transformation, a ReLU activation function, and a second linear transformation; and constructing a second residual connection layer to... The eigenvector is added to the third eigenvector to obtain the fourth eigenvector. A second normalization layer is constructed to normalize the fourth eigenvector, resulting in a normalized fourth eigenvector. The multi-head self-attention layer, the first residual connection layer, the first normalization layer, two feedforward neural networks, the second residual connection layer, and the second normalization layer are sequentially connected to form an encoder unit. Four encoder units are cascaded to form the encoder layer, and the output of the fourth encoder unit is used as the final output feature of the encoder layer. An output layer is constructed to transform the final output feature vector through a linear transformation to obtain the model output. The input embedding layer, encoder layer, and output layer are combined to form a Transformer encoder model. The input embedding layer maps the original input data to a high-dimensional feature space through a fully connected layer; its core is a linear transformation matrix. For a 5-dimensional structural parameter input, a weight matrix W of dimension 5×d_model and a bias vector b of dimension d_model are used. The input is transformed into a d_model-dimensional feature vector through matrix multiplication H=XW+b, where d_model is typically set to 128 or 256. To ensure training stability, the output needs to be multiplied by a scaling factor √d_model, making the variance of the embedding vector independent of the model dimension. The weight matrix is initialized uniformly using Xavier, i.e., uniformly sampled from the interval [-√(6 / (fan_in+fan_out)), √(6 / (fan_in+fan_out))], ensuring that the signal variance remains stable during forward propagation. In the PyTorch implementation, a linear layer is constructed using nn.Linear(input_dim, d_model), and a scaling operation, embedded=embedded*math.sqrt(self.d_model), is added to the forward function. This design ensures both the preservation of information from low to high dimensions and provides sufficient expressive space for subsequent self-attention calculations.
[0037] The multi-head self-attention layer first transforms the input features into Query, Key, and Value matrices through three independent linear transformations, each with a dimension of d_model × d_model. These matrices are then uniformly partitioned into h heads (typically h = 8 or 16) along the feature dimension, with each head having a dimension of d_k = d_model / h. For each head, a scaled dot-product attention is calculated independently: Attention(Q_i, Ki, V_i) = softmax(Q_iK_i^T / √d_k)V_i, where the scaling factor 1 / √d_k prevents the dot-product value from becoming too large, causing the softmax gradient to vanish. After calculation, the outputs of all heads are concatenated along the feature dimension, and then a linear transformation is performed through a d_model × d_model output projection matrix W_O. In the implementation, view and transpose operations are used for efficient multi-head partitioning and merging, avoiding explicit loop calculations. The attention weight matrix is calculated using torch.matmul for batch matrix multiplication, and the softmax operation normalizes the last dimension. This parallelized multi-head design enables the model to simultaneously focus on different aspects of the input, significantly improving feature learning capabilities.
[0038] Residual connections directly pass the input to the output via an identity mapping, adding it to the output of the sublayer to form a structure: Output = Input + Sublayer(Input). The first residual connection layer adds the original feature vector to the output of the multi-head self-attention layer, and the second residual connection layer adds the normalized feature vector to the output of the feedforward network. The core of this design is to provide a gradient propagation path without any nonlinear transformations, allowing gradients to be directly passed from deep layers to shallow layers, effectively alleviating the gradient vanishing problem in deep networks. In implementation, it is necessary to ensure that the dimensions of the two tensors being added are perfectly matched; typically, the sublayer design guarantees that the input and output dimensions are the same. Another important function of residual connections is that they make it easier for the network to learn the identity mapping. When certain transformations are not needed, the network can learn the weights of the sublayer to be close to zero, thus skipping that layer. Numerically, direct tensor addition is computationally efficient, does not introduce additional parameters, and is one of the simplest and most effective techniques in deep learning.
[0039] Layer normalization independently calculates the mean μ and standard deviation σ on the feature dimension of each sample, using the formula LayerNorm(x) = γ*(x-μ) / σ+β, where γ and β are learnable scaling and offset parameters, both with dimension d_model. The mean is calculated as μ = (1 / d_model)*Σx_i, and the standard deviation is calculated as σ = sqrt((1 / d_model)*Σ(x_i-μ)²+ε), where ε (usually 1e-6) is a small constant added for numerical stability. Unlike batch normalization, layer normalization does not depend on batch statistics, thus exhibiting consistent behavior during training and inference, making it particularly suitable for handling variable-length sequences and mini-batch data. The learnable parameters γ and β are initialized to 1 and 0, respectively, making the network approach an identity transformation in the early stages of training. In the PyTorch implementation, γ and β are registered as model parameters using nn.Parameter. The forward function uses tensor.mean(dim=-1, keepdim=True) and tensor.std(dim=-1, keepdim=True) to calculate statistics, with keepdim=True ensuring the broadcast mechanism works correctly. Layer normalization accelerates network convergence and improves training stability by controlling the distribution of activation values.
[0040] The two-layer feedforward neural network employs an expansion-then-compression structure. The first layer maps the d_model dimension input to the d_ff dimension (typically d_ff = 4d_model), and the second layer maps it back to the d_model dimension, introducing non-linearity using the ReLU activation function in between. The specific calculation is FFN(x) = W_2ReLU(W_1*x + b_1) + b_2, where W_1 is d_model × d_ff and W_2 is d_ff × d_model. This expansion of dimensions allows the network to perform non-linear transformations in higher-dimensional spaces, enhancing the model's expressive power. The ReLU activation function is widely used due to its computational simplicity and good gradient propagation; its form is ReLU(x) = max(0, x). In the implementation, the two linear layers are constructed using nn.Linear, and the activation function is nn.ReLU(). To prevent overfitting, a dropout layer is typically added after ReLU, with a dropout rate set to 0.1. Weight initialization uses the He initialization method, which is particularly suitable for the ReLU activation function; the initialization formula is W~N(0, 2 / fan_in). This structure design, which first expands and then compresses, allows the features at each location to undergo complex nonlinear transformations independently.
[0041] The encoder unit assembles its sub-components in a specific order: input → multi-head self-attention layer → Dropout → first residual connection → first normalization layer → feedforward neural network → Dropout → second residual connection → second normalization layer → output. This structure follows the Post-LN design pattern of residual connection first, normalization last, and has better performance than Pre-LN (normalization first). The Dropout layer is added after the output of the self-attention and feedforward networks to prevent overfitting by randomly setting some activation values to zero; the dropout rate is usually set to 0.1. The flow of data in the encoder unit follows a strict computational graph: x_attn=MultiHeadAttention(x), x_res1=x+Dropout(x_attn), x_norm1=LayerNorm(x_res1), x_ff=FFN(x_norm1), x_res2=x_norm1+Dropout(x_ff), output=LayerNorm(x_res2). Each sub-component maintains a consistent input and output dimension (both d_model), ensuring the feasibility of residual connections. This standardized encoder unit design allows for easy stacking of multiple layers to form deep network structures.
[0042] The encoder layer is constructed by concatenating four structurally identical but parameter-independent encoder units, forming a feature extraction network of depth 4. Each encoder unit receives the output of the previous unit as input and extracts higher-level feature representations layer by layer: output_1 = EncoderUnit_1(input), output_2 = EncoderUnit_2(output_1), output_3 = EncoderUnit_3(output_2), output_4 = EncoderUnit_4(output_3). In the PyTorch implementation, nn.ModuleList is used to store each encoder unit, ensuring that the parameters of each unit are correctly registered and updated. The four-layer design is an experimentally validated and reasonable depth. The first layer mainly learns local feature relationships, the second and third layers gradually expand the receptive field to learn global dependencies, and the fourth layer integrates all information to generate the final representation. The stacked depth allows the model to learn multi-level abstract representations, but excessively deep networks may lead to optimization difficulties and overfitting. Therefore, four layers represent a good balance between model capacity and training difficulty. The number of parameters in each layer is approximately 4d_model² + 2d_model * d_ff, and the total number of parameters increases linearly with the number of layers, requiring reasonable setting based on the dataset size.
[0043] The output layer maps the encoder's d_model-dimensional feature vector to the required output dimension for the task through a linear transformation. For the task predicting assimilation, the output dimension is 1; for the task predicting structural parameters, the output dimension is 5. The output layer is implemented using a single fully connected layer: output = W_out * x + b_out, where W_out has the dimension of d_model × output_dim, and b_out has the dimension of output_dim. Since this is a regression task, the output layer does not use an activation function, maintaining a linear output to cover the continuous value range. If the encoder output is in sequence form (features at multiple positions), aggregation is required first. Common methods include taking the output of the last position, global average pooling, or global max pooling. Weight initialization uses Xavier initialization, and bias initialization is set to zero to ensure the initial output is within a reasonable range. During training, the gradient of the output layer comes directly from the loss function and is the starting point of the entire backpropagation; therefore, its parameter updates are usually quite drastic, potentially requiring a smaller learning rate or a separate optimizer setting. The design of the output layer is simple yet crucial, directly affecting the numerical range and accuracy of the model's predictions.
[0044] A complete Transformer encoder model is assembled in the order of input embedding layer → encoder layer → output layer, forming an end-to-end prediction network. In PyTorch, the nn.Module base class is inherited, and each component is instantiated in the __init__ method, while the data flow is defined in the forward method. The key hyperparameters of the model include input dimension input_dim (5 or 1), model dimension d_model (128 or 256), number of attention heads n_heads (8 or 16), feedforward network dimension d_ff (512 or 1024), output dimension output_dim (1 or 5), number of encoder layers n_units (4), and dropout rate (0.1). For a typical configuration (d_model=256, n_heads=8, d_ff=1024, n_units=4), there are approximately 3-4 million parameters. When initializing the model, it is necessary to correctly set the parameters of each layer, especially to ensure dimension matching and a reasonable initial value distribution. The initialization strategy can be uniformly applied through model.apply(initialize_weights).
[0045] Model parameter initialization employs strategies tailored to different layer types: linear layers use Xavier uniform initialization (also known as Glorot initialization), sampling from a uniform distribution; the scaling parameter γ for layer normalization is initialized to 1, and the offset parameter β is initialized to 0; embedding layers can be initialized using a normal distribution. The optimizer is typically Adam, whose adaptive learning rate mechanism is suitable for handling sparse gradients and non-stationary objectives. Key parameters are set to lr=0.001, betas=(0.9, 0.999), and eps=1e-8. A warmup strategy is used for learning rate scheduling: the learning rate is linearly increased from 0 to the initial value in the first warmup_steps (e.g., 1000 steps), then kept constant or gradually decreased using cosine annealing. Gradient clipping is set to a maximum norm of 1.0, implemented using `torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)`, to prevent gradient explosion. In addition to dropout within the model, regularization can also include L2 weight decay, set in the optimizer to `weight_decay=1e-4`. This complete initialization and optimization strategy ensures that the model can be trained stably and efficiently, achieving optimal performance.
[0046] S104. Divide the training dataset into a training set and a test set according to a preset ratio; The preset ratio refers to the ratio of training set to test set data volume. Common ratios include 8:2, 7:3, or 9:1, etc. The specific ratio can be determined based on the dataset size and model complexity, and is not limited here. The training set is used for learning and optimizing model parameters, and the test set is used to evaluate the model's generalization performance. Both should maintain a consistent data distribution. A random partitioning method can be used. The `train_test_split` function from Python's `sklearn` library can be used, setting the `test_size` parameter to 0.2 (corresponding to an 8:2 partition) and the `random_state` parameter to a fixed value to ensure repeatable results. Another implementation method is to use a hierarchical partitioning method, which is particularly suitable for unevenly distributed data. First, the data is divided into several intervals based on the absorptivity value. Then, within each interval, the data is partitioned in the same proportion to ensure that the training set and test set are distributed consistently across all absorptivity intervals.
[0047] S105. Based on the training set, the Transformer encoder model is optimized using the backpropagation algorithm with mean squared error as the loss function. The mean squared error (MSE), used as a loss function, calculates the average of the squared differences between the predicted and true values, and is suitable for regression tasks. Backpropagation is a standard optimization method in deep learning. It updates the parameters by calculating the gradient of the loss function with respect to the parameters of each layer, following the direction of gradient descent. During training, hyperparameters such as learning rate, batch size, and number of training epochs need to be set. The specific values of these parameters can be determined experimentally and are not limited here. The Adam optimizer can be used for training. An initial learning rate of 0.001, a batch size of 32, and 200 training epochs are set. In each training epoch, the training set is randomly shuffled and divided into multiple batches. For each batch, forward propagation is performed to calculate the predicted value and the MSE loss. Then, backpropagation is performed to calculate the gradient, and the Adam algorithm is used to update the model parameters. The Adam optimizer combines the advantages of momentum and adaptive learning rate, accelerating convergence and improving training stability. Another implementation is to use the SGD optimizer with a learning rate decay strategy. An initial learning rate of 0.01 and a momentum parameter of 0.9 are set, and the learning rate is multiplied by 0.5 every 50 epochs. This method uses a large learning rate to rapidly decrease the learning rate in the early stages of training, and then uses a smaller learning rate for fine-tuning in the later stages, which helps to find a better local optimum.
[0048] S106. Based on the mean square error on the test set, determine the optimal values of the dimension of the feature vector output by the input embedding layer, the number of subspaces of the multi-head self-attention layer, the learning rate, and the batch size to obtain the optimized Transformer encoder model for the design of terahertz metamaterial sensors. The feature vector dimension determines the model's expressive power; higher dimensions result in stronger expressive power but also higher computational complexity. The number of subspaces in the multi-head self-attention layer (i.e., the number of attention heads) affects the model's ability to capture different types of feature relationships. The learning rate controls the step size of parameter updates, while the batch size affects the accuracy of gradient estimation and training efficiency. The optimal configuration is selected by evaluating the mean squared error (MSE) of different hyperparameter combinations on the test set. A grid search method can be used. Candidate values for feature vector dimension are set to [64, 128, 256, 512], candidate values for the number of attention heads are [4, 8, 16], candidate values for learning rate are [0.0001, 0.001, 0.01], and candidate values for batch size are [16, 32, 64]. Training and evaluation are performed on all possible combinations, recording the MSE of each combination on the test set, and selecting the combination with the smallest MSE as the optimal hyperparameter. Another implementation method is to use Bayesian optimization. A Gaussian process is used to model the relationship between hyperparameters and performance, and the next most promising hyperparameter combination is selected for evaluation by obtaining a function. This method is more efficient than grid search and can find near-optimal hyperparameter configurations with fewer evaluations.
[0049] S107. Construct multiple Transformer encoder models with different encoder layers and feature vector dimensions; Multiple Transformer encoder models with different numbers of encoder layers and feature vector dimensions are constructed. Each set of Transformer encoder models is trained using a training set to obtain the corresponding trained model. This step explores the impact of model architecture depth and width on performance. The number of encoder layers determines the model depth; more layers can learn more complex feature representations, but also increase training difficulty. The feature vector dimension determines the model width, affecting the expressive power of each layer. By constructing and training models with different configurations, the optimal balance between performance and complexity can be found. Models with 2, 4, 6, and 8 encoder layers and feature vector dimensions of 64, 128, 256, and 512 can be constructed, forming 16 different model configurations. Each configuration is trained using the same training set, keeping other hyperparameters (such as learning rate and batch size) consistent. During training, the training loss curve and validation loss curve of each model are recorded to analyze model convergence and overfitting. Another implementation approach is to use progressive architecture search. First, train a basic 2-layer, 128-dimensional model. Then, gradually increase the number of layers or dimensions, changing only one dimension at a time, and observe the performance changes. Stop the search when the performance improvement is no longer significant or overfitting occurs. This method can find a suitable model configuration more quickly.
[0050] S108. Input the test set into each training model for positive prediction. Determine the optimal number of encoder layers and feature vector dimension based on the preset mean square error evaluation index to obtain the positive prediction optimization model. This step evaluates the forward prediction performance of different model architectures. Forward prediction refers to predicting the uptake rate value based on the input structural parameters. The preset mean squared error (MSE) evaluation metric can be the absolute MSE value or the relative error percentage; the specific threshold is determined according to application requirements and is not limited here. By comparing the prediction errors of each model on the test set, the model architecture with the best performance is selected as the forward prediction optimization model. For each trained model, the structural parameters from the test set can be input into the model to obtain the predicted uptake rate value, and the MSE of the predicted uptake rate can be calculated. Other evaluation metrics such as mean absolute error (MAE) and coefficient of determination (R²) are also calculated to comprehensively evaluate model performance. The model configuration with the smallest MSE and the closest R² to 1 is selected. Another implementation method is to use cross-validation for evaluation. The original dataset is divided into 5 folds, and 4 folds are used for training and 1 fold for testing each time, repeated 5 times to obtain 5 MSE values. The mean and standard deviation are calculated. The model configuration with the smallest mean MSE and the smallest standard deviation is selected to ensure the stability of model performance.
[0051] S109. Input the structural parameters into the forward prediction optimization model to obtain the predicted absorption rate value; The input structural parameters include five dimensions: the side length of the square metal ring, the side length of the rhombic metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. The model outputs the corresponding absorption rate value, which can be the absorption rate at a single frequency point or an absorption rate vector at multiple frequency points. The five structural parameters are combined into an input vector, subjected to the same standardization process as during training, and then input into the model for forward propagation calculation to obtain the predicted absorption rate value. If it is necessary to predict multiple frequency points, the model output layer can be designed as a multi-output form to predict the absorption rate at multiple frequency points simultaneously. Another approach is to use an ensemble prediction method, training multiple models with different initialization parameters, and averaging the prediction results of multiple models for the same input, which can improve the stability and accuracy of the prediction.
[0052] S110. Convert the predicted absorption rate values into an absorption rate curve; If the model predicts the absorbance at multiple frequency points, these points can be directly connected to form a curve. If the model predicts the absorbance at a single or a few key frequency points, a complete absorbance curve needs to be constructed using interpolation or fitting methods. The absorbance curve reflects the sensor's absorption characteristics at different frequencies and is an important indicator for evaluating sensor performance. Spline interpolation can be used. For the predicted discrete frequency points and their corresponding absorbance values, cubic spline interpolation is used to generate a smooth curve. The frequency range and resolution of the interpolation are set, such as one point every 0.01 THz within the range of 0.1-10 THz. Another approach is to use Lorentz function fitting. Assuming the absorption peak conforms to a Lorentz shape, nonlinear least squares is used to fit the peak position, peak width, and peak height parameters to generate a theoretical absorption curve. This method is particularly suitable for cases with obvious resonance peaks.
[0053] S111. When the mean square error between the absorption rate curve and the absorption rate curve calculated by the electromagnetic simulation software is less than a preset threshold, the positive prediction optimization model is determined to meet the preset prediction accuracy requirements. This step verifies the model's prediction accuracy by comparing it with electromagnetic simulation results. The absorption rate curve calculated by the electromagnetic simulation software is used as a reference for the true value. The preset threshold is determined according to the actual application requirements, such as MSE less than 0.01 or relative error less than 5%, which is not limited here. Only when the error between the predicted curve and the simulated curve meets the requirements is the model considered to have sufficient prediction accuracy. A set of structural parameters not used in training can be selected, and absorption rate curves can be obtained using both model prediction and electromagnetic simulation software calculations. The MSE of the two curves is calculated at the same frequency point; if it is less than the preset threshold, the verification is passed. Another approach is to calculate the similarity index of the curves, such as using the Dynamic Time Warping (DTW) algorithm to calculate the distance between the two curves, or calculating the correlation coefficient of the curves, to comprehensively evaluate the prediction accuracy.
[0054] S112. Input the test set into each training model for positive prediction. Determine the optimal number of encoder layers and feature vector dimension based on the preset mean square error evaluation index to obtain the positive prediction optimization model. This step is similar to S108, but it evaluates the reverse engineering performance. Reverse engineering refers to inputting a target absorbance value and predicting the structural parameters that can achieve that absorbance. This is a more challenging task because multiple sets of structural parameters may produce similar absorbances. By evaluating the reverse engineering accuracy of different model architectures, the most suitable model configuration is selected. Absorbance values from the test set can be input into various models to predict the corresponding structural parameters. Then, the predicted structural parameters are input into electromagnetic simulation software to calculate the actual absorbance, and the difference between the actual and target absorbances is compared. The model architecture that minimizes the error in reconstructing the absorbance is selected. Another approach is to directly compare the errors between the predicted and actual structural parameters, calculate the relative errors across all parameter dimensions, and select the model with the smallest average relative error.
[0055] S113. Input the absorption rate value into the reverse design optimization model to obtain the predicted structural parameters; This step uses an optimized inverse design model for actual inverse prediction. The input can be the target absorbance at a single frequency point, an absorbance vector across multiple frequencies, or a complete absorbance curve feature. The model outputs five corresponding structural parameters, including the side length of the square metal ring, the side length of the rhomboid metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. If the input is a complete absorbance curve, key features such as absorption peak position, peak value, and full width at half maximum (FWHM) can be extracted and used as model input. If discrete absorbance values are directly input, it must be ensured that they correspond to the frequency points used during training. The output structural parameters need to be denormalized to convert them back to actual physical dimensions. Another implementation method is to use a conditional generative model, adding a decoder structure to the Transformer encoder, using the absorbance features as conditional input to generate the corresponding structural parameters.
[0056] S114. Input the predicted structural parameters into the electromagnetic simulation software to calculate the absorption rate curve. This step verifies the reverse design results through electromagnetic simulation. The structural parameters predicted by the model are input into the electromagnetic simulation software to establish a corresponding terahertz metamaterial sensor model. The actual absorptivity curve is obtained through numerical calculation. This step is crucial for verifying the effectiveness of the reverse design. The same electromagnetic simulation software and settings used to generate the training data can be used. A 3D model is built in CST or COMSOL based on the predicted structural parameters, with the same material properties, boundary conditions, and excitation source set, and frequency domain scanning calculations are performed. The calculated S-parameters are recorded, and the absorptivity A = 1 - |S11|² is calculated using the S11 parameter. Another approach is to use a parametric model template. A parametric sensor model is pre-built in the simulation software, and the structural parameters are automatically updated and the simulation is run via a script interface, improving verification efficiency.
[0057] S115. When the mean square error between the absorption rate curve and the preset original absorption rate is less than the preset threshold, the reverse design optimization model is determined to meet the preset design accuracy requirements.
[0058] This step is the final stage of reverse engineering verification. The preset raw absorbance is the input target for reverse engineering. By comparing the difference between the absorbance curve obtained from simulation and the target absorbance, the success of the reverse engineering is evaluated. The setting of the preset threshold needs to consider the tolerance requirements of practical applications, such as MSE less than 0.02 or absorbance deviation at key frequency points less than 10%, but this is not limited here. The MSE of the target absorbance and the simulated absorbance can be calculated at the same frequency sampling points. If the target is a specific absorption peak, peak position shift, peak error, and peak width variation can be the focus of evaluation. Multiple evaluation indicators can be set, such as peak position shift less than 0.1 THz, peak error less than 5%, and peak width variation less than 20%. A successful design is considered to be achieved when all these criteria are met. Another approach is to use a weighted evaluation method, assigning different weights to different performance indicators and calculating a comprehensive score. The requirement is considered met when the score exceeds a set threshold.
[0059] In the above embodiments, multiple sets of data samples containing structural parameters and absorptivity values are generated using electromagnetic simulation software. After outlier removal and standardization, a high-quality training dataset is obtained. The Transformer encoder model built based on this dataset contains a deep structure including an input embedding layer, multiple cascaded encoder units, and an output layer, enabling it to fully learn the complex nonlinear mapping relationship between structural parameters and absorptivity. The multi-head self-attention mechanism in the model captures the interactions between different structural parameters and their combined impact on absorptivity. The combination of residual connections and layer normalization ensures both the training stability of the deep network and maintains the model's expressive power. The model parameters are optimized using the backpropagation algorithm, and the optimal values of key hyperparameters are determined based on the mean squared error on the test set. This results in good generalization performance, improved accuracy of model predictions, and ultimately, enhanced sensor performance.
[0060] Furthermore, the structural parameters output by the optimized Transformer encoder model are used to construct a 3D model of the sensor. The optimized Transformer encoder model outputs five structural parameters: the side length of the square metal ring, the side length of the rhombus metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. The 3D model construction process first establishes a parameterized geometric model in electromagnetic simulation software (such as CSTMicrowaveStudio or COMSOLMultiphysics). In specific implementation, a metal resonant structure layer is constructed on the xy plane, including a nested structure of square rings, rhombus rings, and circular rings, with each ring arranged concentrically. The square rings are formed by connecting four straight line segments of equal length, the rhombus rings are formed by rotating four straight line segments of equal length at 45 degrees, and the circular rings are generated using parameterized circular arcs. The linewidth of all metal structures is uniformly set to the linewidth parameters of the metal resonant structure output by the model. In the z-direction, the bottom layer is a metal ground plane (typically 200 nm thick), the middle layer is a dielectric substrate layer (such as polyimide, approximately 25 μm thick), the top layer is a metal resonant structure layer (approximately 200 nm thick), and the topmost layer is a microfluidic channel layer, the height of which is determined by parameters output from the model. In the material property settings, the conductivity of the metal portion (typically gold or copper) is set to 4.5 × 10^7 S / m, the relative permittivity of the dielectric substrate is set to 3.5, the loss tangent is set to 0.02, and the dielectric parameters of the microfluidic channel layer are set according to the characteristics of the sample under test.
[0061] Boundary conditions for electromagnetic simulation are set for the 3D model, with periodic boundary conditions in the x and y directions and open boundary conditions in the z direction. The boundary conditions directly affect the accuracy and computational efficiency of the simulation results. Periodic boundary conditions (PBCs) are set in the x and y directions to simulate an infinitely large periodic array structure, because actual terahertz metamaterial sensors are typically composed of a large number of identical periodic cells. The periodic boundary conditions are implemented through Floquet ports to ensure that the electromagnetic field satisfies the periodicity conditions at the cell boundaries: E(x+a, y) = E(x, y)exp(jkx·a) and E(x, y+b) = E(x, y)exp(jky·b), where a and b are the periods in the x and y directions, respectively, and kx and ky are the wave vector components in the corresponding directions. Open boundary conditions (OpenBoundaryConditions) are set in the z direction, using a perfectly matched layer (PML) to absorb outwardly propagating electromagnetic waves and avoid interference from boundary reflections on the simulation results. The PML layer thickness is typically set to 1 / 4 of the maximum wavelength, approximately 75-100 μm in the terahertz band. The excitation source is a vertically incident plane wave, and the electric field polarization direction can be set to the x or y direction as needed. The incident power is normalized to 1 W. Adaptive meshing technology is used for mesh generation, with the mesh being fined at metal edges and material interfaces to ensure the capture of rapid changes in the electromagnetic field. The typical minimum mesh size is 1 / 10 of the metal linewidth.
[0062] Electromagnetic field simulations were performed based on a 3D model and boundary conditions to obtain the sensor's reflection coefficient, and the square of the reflection coefficient was determined as the reflectivity. The electromagnetic field simulation obtained the sensor's electromagnetic response characteristics by solving Maxwell's equations. In the frequency domain simulation, the Helmholtz equation was solved at each frequency point: ∇×(μr^(-1)∇×E)-k0^2(εr-jσ / ωε0)E=0, where E is the electric field strength, μr is the relative permeability, εr is the relative permittivity, σ is the conductivity, and k0 is the free space wavenumber. Numerical solutions were performed using the finite element method (FEM) or finite integral technique (FIT). The computational domain was discretized into tetrahedral or hexahedral mesh elements, and the electromagnetic field was expanded using basis functions within each element, transforming the partial differential equations into a system of linear equations for solution. The simulation frequency range was set to 0.1-10 THz with a frequency step size of 0.01 THz to ensure accurate capture of resonance characteristics. The S-parameters are calculated using port boundary conditions, with a focus on the reflection coefficient S11, defined as the ratio of the complex amplitude of the reflected wave to that of the incident wave. The reflection coefficient includes amplitude and phase information: S11 = |S11|exp(jφ), where |S11| represents the amplitude of the reflected wave and φ represents the phase. To ensure simulation convergence, an energy convergence criterion of -40dB is set, meaning that steady state is considered achieved when the system energy decays to 0.01% of its initial value. After simulation, the S11 parameters at each frequency point are extracted to form the frequency response curve of the reflection coefficient. The reflectivity R is defined as the ratio of reflected power to incident power, calculated from the square of the modulus of the reflection coefficient: R = |S11|^2. Since the model uses a metal floor design, the transmittance T = 0. According to the law of conservation of energy, the absorptivity A can be directly calculated from the reflectivity: A = 1 - RT = 1 - |S11|^2. This calculation method is based on the physical characteristics of the sensor: the incident terahertz wave is either reflected or absorbed (converted into heat or other forms of energy), and the metal floor prevents transmission. In practical calculations, attention must be paid to the normalization of S-parameters, ensuring that power-normalized S-parameters are used. For each frequency point fi, the corresponding absorptivity A(fi) = 1 - |S11(fi)|^2 is calculated, yielding discrete absorptivity data points. To improve data quality, the original S-parameters can be smoothed to remove numerical noise, but care must be taken not to over-smooth, which could distort the resonant characteristics. The physical meaning of absorptivity is the sensor's ability to absorb electromagnetic energy. At the resonant frequency, due to the strong localization and enhancement effect of the electromagnetic field, the absorptivity reaches its peak, which is the basis for the sensor to achieve high-sensitivity detection.
[0063] The absorptivity of the sensor is calculated based on reflectivity, and an absorption characteristic curve is plotted showing the absorptivity as a function of frequency. Plotting the absorption characteristic curve requires connecting discrete absorptivity data points into a continuous curve, with the horizontal axis representing frequency (unit: THz) and the vertical axis representing absorptivity (dimensionless, range 0-1). Visualization is performed using professional plotting software (such as Origin, MATLAB, or Python's matplotlib library). Spline interpolation or cubic Hermitian interpolation methods are used to smooth the transitions between data points, with the interpolation density set to 1 / 10 of the original data point interval to ensure curve smoothness. Key features should be highlighted when plotting the curve: the location of the resonance peak (the frequency corresponding to the maximum absorptivity), peak absorptivity, and full width at half maximum (FWHM, characterizing the sharpness of the resonance peak). Appropriate ranges and scales are used for the coordinate axes; the frequency axis is typically 0.1-10 THz, and the absorptivity axis is 0-1, with major scale intervals set to 1 THz and 0.2, respectively. Adding grid lines improves readability, and using different line styles or colors distinguishes multiple curves (e.g., results under different structural parameters or sample conditions). The legend should include key structural parameter information, and the title should clearly state that this is an absorption characteristic curve of a terahertz metamaterial sensor. For ease of quantitative analysis, the specific values of the resonant frequency fr and the maximum absorptivity Amax can be directly labeled on the graph.
[0064] Based on the absorption characteristic curve, when the absolute value of the difference between the real part of the equivalent impedance of the sensor at the resonant frequency and the preset value is less than the preset difference threshold and the difference between the imaginary part and zero is within the preset interval, it is determined that the optimized Transformer encoder model meets the preset design requirements. Equivalent impedance analysis is a key step in evaluating the impedance matching characteristics of the sensor. At the resonant frequency, the sensor can be equivalent to an RLC resonant circuit, and the equivalent impedance Z = R + jX, where R is the real part (resistance) and X is the imaginary part (reactance). The equivalent impedance can be calculated by the reflection coefficient: Z = Z0×(1 + S11) / (1 - S11), where Z0 is the characteristic impedance of free space (about 377Ω). The ideal impedance matching condition is Z = Z0, that is, the normalized impedance z = Z / Zo = 1 + j0. At this time, the reflection coefficient S11 = 0 and the absorption rate reaches 100%. Due to material loss and structural limitations of the actual sensor, it is difficult to achieve perfect matching. Therefore, it is set that the absolute value of the difference between the real part and the preset value (usually 1) is less than the preset difference threshold (such as 0.1), that is, |Re(z) - 1| < 0.1; the difference between the imaginary part and zero is within the preset interval (such as [-0.05, 0.05]), that is, -0.05 < Im(z) < 0.05. These conditions ensure that the sensor has good impedance matching characteristics at the resonant frequency, thus achieving a high absorption rate. The calculation of the equivalent impedance requires the use of the complex S11 value at the resonant frequency, which contains amplitude and phase information, and the real and imaginary parts of the impedance are obtained through complex operations. The physical meaning of impedance matching is to maximize the energy coupling efficiency between the incident wave and the sensor, reduce the reflection loss, and improve the sensitivity of the sensor. The complete process of model verification includes: first, extracting the resonant frequency fr of the absorption characteristic curve (the frequency corresponding to the maximum absorption rate), then obtaining the complex reflection coefficient S11(fr) = |S11|exp(jφ) at this frequency, and calculating the normalized equivalent impedance z = (1 + S11) / (1 - S11) = zr + jzi. The determination conditions include two aspects: the impedance real part condition |zr - 1| < δr (δr is the preset difference threshold, such as 0.1), and the impedance imaginary part condition zi ∈ [zi_min, zi_max] (such as [-0.05, 0.05]). Only when both conditions are met, it is considered that the structural parameters output by the model can achieve the expected sensor performance. If the requirements are not met, the deviation situation needs to be recorded, and it may be necessary to adjust the training strategy of the model or increase the training data. In addition, auxiliary determination indicators can be added, such as the maximum absorption rate Amax > 0.9 (to ensure high absorption), the quality factor Q = fr / FWHM > 10 (to ensure that the resonant peak is sharp enough), and the resonant frequency stability |fr - fr_target| / fr_target < 5% (to ensure frequency accuracy), etc. The entire verification process needs to be automated, connecting the model output, simulation software, and data analysis through scripts to form a closed-loop verification system, improving the design efficiency and reliability.
[0065] In the above embodiments, the structural parameters output by the optimized Transformer encoder model are used to construct a three-dimensional model of the sensor. Electromagnetic simulation boundary conditions are set to perform electromagnetic field simulation, which yields the sensor's reflection coefficient and absorptivity, generating an absorption characteristic curve. Based on this curve, the equivalent impedance characteristics of the sensor at the resonant frequency are verified, ensuring that the model-designed sensor has ideal impedance matching characteristics. When the difference between the real part of the equivalent impedance and a preset value is less than a threshold and the imaginary part is close to zero, it indicates that the sensor has achieved impedance matching with free space at the resonant frequency, reducing electromagnetic wave reflection on the sensor surface and improving the absorption efficiency of electromagnetic waves in the sensor. This verification method evaluates the design performance of the model through rigorous impedance matching criteria, ensuring that the model-designed sensor has good operating characteristics and improving the sensor's detection sensitivity and measurement accuracy.
[0066] The first embodiment described above achieves precise design of a terahertz metamaterial sensor by constructing and optimizing a Transformer encoder model, combined with 3D model simulation and impedance matching verification. However, in practical applications, complex coupling relationships often exist between the structural parameters of the sensor, and the coordinated changes of these parameters can significantly affect the sensor's performance. To better understand and utilize this parameter coupling effect and improve the design accuracy of the model, the following section combines... Figure 2 Another method for generating a Transformer encoder model for a terahertz metamaterial sensor, as described in the embodiments of this application, is as follows: Please refer to... Figure 2 This is another flowchart illustrating a method for generating a Transformer encoder model for a terahertz metamaterial sensor, as described in this application.
[0067] S201. Simultaneously change the values of at least two structural parameters to generate multiple sets of disturbance parameters; Simultaneously changing the values of at least two structural parameters generates multiple sets of perturbation parameters, each set including the original and changed values of the structural parameters. This step explores the coupling effects between parameters by simultaneously changing multiple structural parameters. A perturbation parameter refers to the amount of change applied to the original structural parameters; each set contains both the original and changed values. The original value is the parameter value before the perturbation is applied, and the changed value is the parameter value after the perturbation is applied. Simultaneously changing at least two structural parameters means that in the same set of perturbations, at least two parameters (such as the side length of a square metal ring and the side length of a rhombus metal ring) change simultaneously. The magnitude of the perturbation can be a fixed value or a percentage of the original value, typically set to ±5%, ±10%, or ±20% of the original value; the specific value is determined based on the sensitivity of the parameter and is not limited here. The number of perturbation parameter sets generated depends on the number of parameter combinations and perturbation levels to be explored, and can range from tens to thousands, and is not limited here. The perturbation parameters can be generated through systematic grid scanning or random sampling, and is not limited here.
[0068] In terms of specific implementation, orthogonal experimental design can be used to generate perturbation parameters. First, determine the structural parameters that need to be changed simultaneously, such as selecting the side length L1 of a square metal ring and the side length L2 of a rhombus metal ring as perturbation objects. Set the perturbation level for each parameter. For example, the original value of L1 is 100 μm, and three levels are set: 90 μm (-10%), 100 μm (0%), and 110 μm (+10%); the original value of L2 is 80 μm, and three levels are set: 72 μm (-10%), 80 μm (0%), and 88 μm (+10%). Nine sets of perturbation parameter combinations are generated through the orthogonal array L9(3²), ensuring that each level of each parameter is combined with each level of other parameters. Another implementation method is to use the Latin Hypercube Sampling method. Divide the range of variation of each parameter evenly into N intervals, and then randomly select a value in each interval to ensure that each interval of each parameter is sampled once. For example, when three parameters are perturbed simultaneously, an N×3 sampling matrix is generated, with each row representing a set of perturbed parameters. This method can achieve more uniform coverage in the parameter space.
[0069] When generating a large number of perturbed parameter sets, technical problems may be encountered where certain parameter combinations result in physically unfeasible structures. To solve this problem, a constraint condition checking mechanism can be added during the perturbed parameter generation process. Specifically, when implementing, define the constraint relationships between the structural parameters. For example, the side length of the square metal ring must be greater than the side length of the rhombus metal ring plus twice the line width (L1 > L2 + 2w), and the radius of the circular metal ring must be less than the radius of the inscribed circle of the rhombus metal ring (r < L2 / (2√2) - w). After generating each set of perturbed parameters, immediately check whether all the constraint conditions are met. For parameter combinations that do not meet the requirements, ensure physical feasibility by adjusting the parameter values that violate the constraints or regenerating the set of parameters. This constraint checking mechanism can avoid ineffective work in subsequent simulation calculations and improve the overall efficiency.
[0070] S202. Input multiple sets of perturbed parameters into an electromagnetic simulation software to obtain the absorption rate values corresponding to each set of perturbed parameters. This step inputs the generated perturbed parameter sets into the electromagnetic simulation software for batch simulation calculations. Each set of perturbed parameters corresponds to a specific sensor structure configuration. Through electromagnetic simulation, the absorption rate spectrum under this configuration can be obtained, and the absorption rate values at specific frequency points or frequency bands can be extracted from it. The absorption rate values can be the peak absorption rate at a single resonant frequency, the absorption rate vector at multiple frequency points, or the average absorption rate within a specific frequency band. The specific selection depends on the application requirements of the sensor and is not limited here.
[0071] In terms of specific implementation methods, the parameter sweep function of CSTMicrowaveStudio can be used for batch simulation. First, establish a parameterized sensor model in the software and set the structural parameters to be perturbed as variables. Then create a parameter sweep task, import the perturbed parameter table, and each row corresponds to a set of parameter values. Set the simulation frequency range (such as 0.5 - 5 THz) and the solver type (such as the frequency domain solver), and start the batch simulation. For each set of parameters, the software automatically updates the model geometry, runs the electromagnetic simulation, calculates the S parameters, and derives the absorption rate A = 1 - |S11|² from the S11 parameter. After the simulation is completed, extract the absorption rate values of each set of parameters at the target frequency (such as 2.5 THz) to form a parameter - absorption rate correspondence table. Another implementation method is to use the parameterized sweep function of COMSOL Multiphysics. Establish a finite element model of the sensor in COMSOL and use parameters to define the structural dimensions. Create a parameterized sweep study, set the parameter value list, and each parameter combination corresponds to a calculation case. Use the frequency domain study of the radio frequency module to set the port boundary conditions and periodic boundary conditions. Run all cases in batch mode and automatically save the S parameter results of each case. Use the post - processing function to calculate the absorption rate in batch and export the data table.
[0072] Large-scale batch simulations may encounter technical problems such as excessive computation time leading to inefficiency. To address this issue, a multi-level simulation strategy combined with a machine learning surrogate model can be employed. First, a coarse mesh and lower precision settings are used to quickly simulate all perturbation parameter groups, obtaining preliminary estimates of the absorptivity. Then, a lightweight neural network model (such as a multilayer perceptron) is trained to learn the mapping relationship between perturbation parameters and the coarse simulation absorptivity. This surrogate model is then used to predict the absorptivity of all parameter groups, identifying key parameter combinations with significant absorptivity variations. Finally, high-precision simulations are performed only on these key combinations to obtain accurate absorptivity values. This multi-level strategy concentrates computational resources on critical parameter regions, significantly reducing overall simulation time.
[0073] S203. Construct a sensitivity matrix by combining multiple sets of perturbation parameters and the corresponding changes in absorptivity. A sensitivity matrix is constructed by combining multiple sets of perturbation parameters and their corresponding absorptivity changes. Each element in the sensitivity matrix represents the absorptivity change corresponding to a specific combination of structural parameters. This step integrates perturbation parameter information and absorptivity response into a sensitivity matrix. The absorptivity change refers to the difference between the absorptivity after perturbation and the absorptivity under the original parameters, reflecting the degree of impact of parameter changes on performance. The sensitivity matrix is a two-dimensional array, with rows corresponding to different parameter combinations and columns corresponding to different perturbation levels or combinations. Each element in the matrix represents the absorptivity change for a specific parameter combination under a specific perturbation. For example, if the side lengths of the square ring and the rhombus ring are perturbed simultaneously, an element of the matrix might represent the absorptivity change when both parameters are increased by 10%. The dimension of the matrix depends on the number of parameter combinations and perturbation levels considered, and can range from tens to hundreds of times; no limit is imposed here.
[0074] In terms of specific implementation, the sensitivity matrix can be constructed using the central difference method. For the combination of two parameters p1 and p2, let the original values be (p1_0, p2_0) and the absorption rate be A_0. Calculate the absorption rates at the four perturbation points: A_++ represents the absorption rate of (p1_0+Δp1, p2_0+Δp2), A_+- represents the absorption rate of (p1_0+Δp1, p2_0-Δp2), A_-+ represents the absorption rate of (p1_0-Δp1, p2_0+Δp2), and A_-- represents the absorption rate of (p1_0-Δp1, p2_0-Δp2). Then, the cross-sensitivity S_12 = (A_++-A_+--A_-++A_--) / (4Δp1Δp2), representing the coupling effect when the two parameters change simultaneously. The sensitivity values for all parameter combinations are organized into a matrix, with row indices representing parameter pairs (p_i, p_j) and column indices representing perturbation types. Another approach is to construct the sensitivity matrix using a full factorial experimental design. For each parameter, k levels are set (e.g., k=3: low, medium, high), and a full factorial experiment of k^n (where n is the number of parameters simultaneously perturbed) is conducted. The absorbance at each experimental point is calculated, and then the main effects and interaction effects are calculated using analysis of variance (ANOVA). The main effects represent the impact of a single parameter change, while the interaction effects represent the synergistic effects of parameter combinations. These effect values are then organized into a sensitivity matrix according to parameter combinations and effect types.
[0075] When constructing a sensitivity matrix, a technical problem may arise where the large differences in the numerical range of matrix elements can hinder subsequent analysis. To address this issue, a normalized sensitivity matrix construction method can be employed. Specifically, the relative perturbation of each parameter, δp_i = Δp_i / p_i_0, is first calculated to ensure comparability of perturbations across different dimensions. Then, the relative absorbance change, δA = ΔA / A_0, is calculated to eliminate the influence of different operating point absorbance baseline values. The normalized sensitivity, S_norm = (δA / δp_i) or S_norm = (δA) / (δp_i × δp_j) (for parameter pairs), is defined so that the matrix elements represent the relative absorbance change caused by a unit change in the relative parameter. Finally, the entire matrix is standardized so that the mean of all elements is 0 and the standard deviation is 1. This normalization process ensures comparability of sensitivities for different parameter combinations, facilitating subsequent pattern recognition and analysis.
[0076] S204. Input the sensitivity matrix into the optimized Transformer encoder model for prediction to obtain the prediction sensitivity matrix; This step utilizes a pre-optimized Transformer encoder model to predict the sensitivity response to parameter perturbations. Using the sensitivity matrix as input, the model learns the mapping from perturbation parameters to changes in absorptivity. This requires the model to not only predict absolute absorptivity values but also accurately capture minute changes in absorptivity caused by parameter variations. The predicted sensitivity matrix has the same structure and dimensions as the input sensitivity matrix, with each element representing the predicted change in absorptivity for the corresponding parameter combination. The model's input can be a pair of perturbation parameters and their perturbation magnitudes, and the output is the predicted change in absorptivity; this is not limited here.
[0077] In terms of specific implementation, the sensitivity prediction task can be transformed into a regression problem. First, the sensitivity matrix is preprocessed, expanding each matrix element into a training sample. The input features for each sample include: a vector of original parameter values (e.g., 5-dimensional), indices of perturbed parameters (indicating which parameters are perturbed), and a perturbed vector (unperturbed parameters are set to 0). These features are concatenated into an expanded input vector, which may have 15-20 dimensions. Using an optimized Transformer encoder model, the input embedding layer may need to be adjusted to accommodate the new input dimensions. The model output is the predicted change in absorptivity (1-dimensional). After predicting all samples, the results are reorganized into a matrix form. Another implementation approach is to use matrix completion. The sensitivity matrix is treated as a partially observed matrix, where elements obtained through simulation calculations are known values, and the remaining elements are values to be predicted. The Transformer model is modified to handle matrix inputs, and features are extracted using 2D convolution or matrix factorization techniques in the input embedding layer. A self-attention mechanism is used to learn the relationships between elements at different positions in the matrix, especially the correlation between adjacent elements. During training, a masking mechanism is used to randomly obscure some known elements as prediction targets, thereby optimizing the mean square error between the predicted and true values.
[0078] S205. When determining the preset element difference threshold for the difference between adjacent elements in the prediction sensitivity matrix, the corresponding structural parameter combination is marked as a co-sensitivity parameter group. This step identifies synergistic effects between parameters by analyzing the relationships between elements in the predicted sensitivity matrix. Adjacent elements are those located close to each other in the sensitivity matrix; these can be adjacent elements in the same row or column, or elements describing similar parameter combinations. A preset element difference threshold is used to judge element similarity, typically set to 10% to 30% of the standard deviation of the sensitivity matrix elements; the specific value is determined based on application requirements and is not limited here. Synergistic sensitive parameter groups refer to parameter combinations that exhibit similar sensitivity patterns under perturbation, indicating a strong coupling relationship between these parameters, and their joint changes have a synergistic effect on sensor performance. The labeling process can be binary (yes or no) or continuous (synergy score), and is not limited here.
[0079] In terms of specific implementation, a sliding window method can be used to identify co-sensitive parameter groups. A 3×3 window is set and slid across the predicted sensitivity matrix. For each window position, the mean μ_w and standard deviation σ_w of all elements within the window are calculated. If σ_w < θ × σ_global (θ is a preset coefficient, such as 0.2; σ_global is the standard deviation of the entire matrix), the elements within the window are considered similar. The parameter combination corresponding to the center element of the window is extracted. If this combination satisfies the similarity condition at multiple window positions, it is marked as a co-sensitive parameter group. Another implementation method is to use cluster analysis. Each row of the sensitivity matrix (representing the sensitivity pattern of a parameter combination) is used as a feature vector. Hierarchical clustering algorithms (such as the Ward method) are used to cluster these feature vectors. The cluster tree is calculated, and a distance threshold (such as 30% of the maximum distance) is set to cut the cluster tree, resulting in several clusters. For each cluster, the average distance between elements within the cluster is calculated. If it is less than a preset threshold, all parameter combinations in that cluster are marked as a co-sensitive parameter group.
[0080] S206. Adjust and optimize the input layer structure of the Transformer encoder model based on the co-sensitive parameter set, so that the structural parameters in the co-sensitive parameter set are used as combined inputs.
[0081] The input layer structure of the optimized Transformer encoder model based on the co-sensitive parameter set is specifically as follows: The structural parameters in the co-sensitive parameter set are transformed linearly to obtain a combined feature vector; a combined input layer is constructed to map the combined feature vector and the feature vectors of the remaining structural parameters to different subspaces; the output of the combined input layer is concatenated with the output of the input embedding layer of the optimized Transformer encoder model to obtain the adjusted feature vector; the adjusted feature vector is input into the first encoder unit of the optimized Transformer encoder model, using the structural parameters in the co-sensitive parameter set as the combined input.
[0082] This step adjusts the model architecture based on the identified co-sensitive parameter sets, enabling the model to better capture the coupling relationships between parameters. The core of this adjustment is modifying the input layer structure, changing the originally independent input parameters to combined inputs. The combined feature vector is a high-dimensional representation obtained by jointly encoding the parameters in the co-sensitive parameter sets. The linear transformation can be a simple concatenation and projection, or a more complex feature interaction operation. The combined input layer is a newly added network layer specifically for handling feature extraction from parameter combinations. Mapping to different subspaces means that co-sensitive and independent parameters are processed through different transformation matrices to adapt to their different characteristics. Feature concatenation connects the combined and independent features along the feature dimension, forming a complete input representation.
[0083] The input layer can be adjusted using a grouped embedding method. Assume that parameters p1 and p2 are identified as a co-sensitive parameter group, and the original input is a 5-dimensional vector [p1, p2, p3, p4, p5]. First, a combined feature extraction layer is created: [p1, p2] is mapped to a d_group dimensional combined feature vector h_g = tanh(W_g × [p1, p2]^T + b_g) through a 2×d_group weight matrix W_g, where the tanh activation function enhances non-linear expressiveness. Then, an independent feature extraction layer is created: [p3, p4, p5] is mapped to a d_ind dimensional independent feature vector h_i = W_i × [p3, p4, p5]^T + b_i through a 3×d_ind weight matrix W_i. d_group = 2×d_model / 5 and d_ind = 3×d_model / 5, keeping the total dimension unchanged. Finally, h_g and h_i are concatenated to obtain a d_model dimensional feature vector, which is then input into the first encoder unit. Another implementation uses a combined input layer with an attention mechanism. For the co-sensitive parameter set [p1, p2], it is first embedded as d_model dimension vectors e1 and e2, respectively. Then, cross-attention is calculated: α = softmax(e1^TW_ae2), where W_a is a learnable attention weight matrix. Combined features h_g = α × e1 + (1-α) × e2 + MLP([e1; e2]), where MLP is a small multilayer perceptron used to capture non-linear interactions. The remaining parameters are then normally embedded to obtain e3, e4, and e5. All features are integrated using a self-attention mechanism: [h_g, e3, e4, e5] are passed through a multi-head self-attention layer to learn the relationship between combined features and independent features.
[0084] When adjusting the input layer structure of a model, the technical problem of overfitting due to the addition of new parameters may be encountered. To solve this problem, a strategy combining parameter sharing and regularization can be adopted. In specific implementation, for multiple co-sensitive parameter groups, if they contain parameters of the same type (such as all containing the metal ring side length parameter), then some embedding weights are shared. Define the shared embedding matrix W_shared and the specific embedding matrix W_specific. The calculation of the combined features becomes h_g=W_shared×[p_i, p_j]^T+W_specific_k×[p_i, p_j]^T, where k represents the k-th co-group. Add a regularization term to the loss function: L_total=L_task+λ_1×||W_specific||_F^2+λ_2×Σ||h_g^(i)-h_g^(j)||^2. The first term restricts the size of the specific weights, and the second term encourages similar co-groups to produce similar feature representations. In this way, the model can control the parameter scale while enhancing its expressive power and avoiding overfitting.
[0085] In the above embodiments, by simultaneously changing multiple structural parameters to generate a set of perturbation parameters, and using electromagnetic simulation to calculate the corresponding changes in absorptivity to construct a sensitivity matrix, the impact of different combinations of structural parameters on sensor performance can be evaluated. The sensitivity matrix is then input into the optimized Transformer encoder model for prediction. By analyzing the differences between adjacent elements in the predicted sensitivity matrix, combinations of structural parameters with cooperative sensitivity characteristics can be identified. This method can demonstrate the influence of the coupling relationship between structural parameters on sensor performance and discover the interaction mechanism between parameters. By labeling the cooperative sensitivity parameter sets and adjusting the model input layer structure accordingly, the model can more accurately capture the mutual influence between structural parameters, improving the model's ability to represent the relationship between sensor structure and performance, and enhancing the model's guiding role in sensor design optimization.
[0086] The sensors in the embodiments of this invention are described below from the perspective of hardware processing. Please refer to [link / reference needed]. Figure 3 This is a schematic diagram of the physical device structure for generating a terahertz metamaterial sensor Transformer encoder model, provided in an embodiment of this application.
[0087] It should be noted that, Figure 3 The structure of the sensor shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0088] like Figure 3As shown, the sensor includes a Central Processing Unit (CPU) 301, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on a program stored in Read-Only Memory (ROM) 302 or a program loaded from storage section 308 into Random Access Memory (RAM) 303. The RAM 303 also stores various programs and data required for sensor operation. The CPU 301, ROM 302, and RAM 303 are interconnected via a bus 304. An Input / Output (I / O) interface 305 is also connected to the bus 304.
[0089] The following components are connected to I / O interface 305: input section 306 including a camera, infrared sensor, etc.; output section 307 including a liquid crystal display (LCD) and speakers, etc.; storage section 308 including a hard disk, etc.; and communication section 309 including a network interface card such as a LAN (Local Area Network) card and a modem, etc. Communication section 309 performs communication processing via a network such as the Internet. Drive 310 is also connected to I / O interface 305 as needed. Removable media 311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 310 as needed so that computer programs read from them can be installed into storage section 308 as needed.
[0090] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 309, and / or installed from removable medium 311. When the computer program is executed by central processing unit (CPU) 301, it performs the various functions defined in the present invention.
[0091] It should be noted that the computer-readable medium shown in the embodiments of the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor sensor, device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with a sensor, device, or apparatus by instructions. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. The transmitted data signal can take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof.
[0092] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of sensors, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based sensor that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0093] In another aspect, the present invention also provides a computer-readable storage medium, which may be included in the sensor described in the above embodiments; or it may exist independently and not assembled into the sensor. The storage medium carries one or more computer programs that, when executed by a processor of a sensor, cause the sensor to implement the methods provided in the above embodiments.
[0094] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0095] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".
[0096] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0097] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for generating a Transformer encoder model for a terahertz metamaterial sensor, characterized in that, include: The acquired training data is used to generate multiple sets of data samples using electromagnetic simulation software. Each set of data samples includes structural parameters and absorption rate values. The structural parameters include the side length of the square metal ring, the side length of the rhomboid metal ring, the radius of the circular metal ring, the linewidth of the metal resonant structure, and the height of the microfluidic channel layer. The multiple sets of data samples are subjected to outlier removal and standardization to obtain the training dataset; A Transformer encoder model is constructed, which includes an input embedding layer, four cascaded encoder units, and an output layer. Each encoder unit includes, in sequence, a multi-head self-attention layer, a first residual connection layer, a first normalization layer, two feedforward neural networks, a second residual connection layer, and a second normalization layer. The training dataset is divided into a training set and a test set according to a preset ratio; Based on the training set, the Transformer encoder model is optimized using the backpropagation algorithm with mean squared error as the loss function. Based on the mean square error on the test set, the optimal values of the dimension of the feature vector output by the input embedding layer, the number of subspaces of the multi-head self-attention layer, the learning rate, and the batch size are determined, resulting in an optimized Transformer encoder model for the design of terahertz metamaterial sensors.
2. The method according to claim 1, characterized in that, The construction of the Transformer encoder model specifically includes: The input embedding layer is constructed to convert the structural parameters or the absorption rate values into the feature vector through a linear transformation; Construct the multi-head self-attention layer to map the feature vector to multiple subspaces and output the first feature vector; Construct the first residual connection layer to add the feature vector and the first feature vector to obtain the second feature vector; Construct the first normalization layer to normalize the second feature vector, and obtain the normalized second feature vector; The two-layer feedforward neural network is constructed to obtain the third feature vector from the normalized second feature vector through a first linear transformation, a ReLU activation function, and a second linear transformation; A second residual connection layer is constructed to add the feature vector to the third feature vector to obtain a fourth feature vector; Construct a second normalization layer to normalize the fourth feature vector, thereby obtaining a normalized fourth feature vector; The multi-head self-attention layer, the first residual connection layer, the first normalization layer, the two-layer feedforward neural network, the second residual connection layer, and the second normalization layer are connected sequentially to obtain the encoder unit; Four encoder units are connected in series to obtain an encoder layer, and the output of the fourth encoder unit is used as the final output feature of the encoder layer. The output layer is constructed to transform the final output feature vector through a linear transformation to obtain the model output; The input embedding layer, the encoder layer, and the output layer are constructed into the Transformer encoder model.
3. The method according to claim 1, characterized in that, After obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: Construct multiple sets of Transformer encoder models with different numbers of encoder layers and feature vector dimensions. Each set of Transformer encoder models is trained using the training set to obtain the corresponding training model. The test set is input into each training model for positive prediction. The optimal number of encoder layers and feature vector dimension are determined based on the preset mean square error evaluation index to obtain the positive prediction optimization model. The structural parameters are input into the positive prediction optimization model to obtain the predicted absorption rate value; Convert the predicted absorption rate values into an absorption rate curve; When the mean square error between the absorption rate curve and the absorption rate curve calculated by the electromagnetic simulation software is less than a preset threshold, the positive prediction optimization model is determined to meet the preset prediction accuracy requirement.
4. The method according to claim 1 or 3, characterized in that, After obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: The test set is input into each group of training models for reverse design. Based on the preset mean square error evaluation index, the optimal number of encoder layers and feature vector dimension are determined to obtain the reverse design optimization model. The absorption rate value is input into the reverse design optimization model to obtain the predicted structural parameters; The predicted structural parameters are input into the electromagnetic simulation software to calculate the absorption rate curve; When the mean square error between the absorption rate curve and the preset original absorption rate is less than the preset threshold, the reverse design optimization model is determined to meet the preset design accuracy requirements.
5. The method according to claim 1, characterized in that, After obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: The structural parameters output by the optimized Transformer encoder model are used to construct a three-dimensional model of the sensor. Boundary conditions for electromagnetic simulation are set for the three-dimensional model, wherein periodic boundary conditions are set in the x and y directions, and open boundary conditions are set in the z direction; Electromagnetic field simulation is performed based on the three-dimensional model and the boundary conditions to obtain the reflection coefficient of the sensor, and the square of the reflection coefficient is determined as the reflectivity. The absorptivity of the sensor is calculated based on the reflectivity, and an absorption characteristic curve of the absorptivity as a function of frequency is plotted. Based on the absorption characteristic curve, if the absolute value of the difference between the real part of the sensor's equivalent impedance at the resonant frequency and the preset value is less than the preset difference threshold and the difference between the imaginary part and zero is within the preset range, then the optimized Transformer encoder model is determined to meet the preset design requirements.
6. The method according to claim 1, characterized in that, After obtaining the optimized Transformer encoder model for terahertz metamaterial sensor design, the method further includes: Simultaneously change the values of at least two of the structural parameters to generate multiple sets of perturbation parameters, each set of perturbation parameters including the original value and the changed value of the structural parameter; The multiple sets of disturbance parameters are input into the electromagnetic simulation software to obtain the absorption rate value corresponding to each set of disturbance parameters; The change in absorptivity for each set of disturbance parameters is calculated based on the absorptivity value. The multiple sets of perturbation parameters and the corresponding changes in absorptivity are used to construct a sensitivity matrix, where each element in the sensitivity matrix represents the change in absorptivity corresponding to the combination of structural parameters. The sensitivity matrix is input into the optimized Transformer encoder model for prediction to obtain the prediction sensitivity matrix; When determining the preset element difference threshold for the difference between adjacent elements in the prediction sensitivity matrix, the corresponding structural parameter combination is marked as a cooperative sensitivity parameter group; The input layer structure of the optimized Transformer encoder model is adjusted based on the co-sensitive parameter set, so that the structural parameters in the co-sensitive parameter set are used as combined inputs.
7. The method according to claim 6, characterized in that, The adjustment of the input layer structure of the optimized Transformer encoder model based on the collaborative sensitivity parameter set specifically includes: The structural parameters in the collaborative sensitive parameter group are transformed linearly to obtain a combined feature vector; Construct a combined input layer to map the combined feature vector and the feature vectors of the remaining structural parameters to different subspaces; The output of the combined input layer is concatenated with the output of the input embedding layer of the optimized Transformer encoder model to obtain the adjusted feature vector. The adjusted feature vector is input into the first encoder unit of the optimized Transformer encoder model, so that the structural parameters in the co-sensitive parameter group are used as combined inputs.
8. A sensor, characterized in that, The sensor includes: One or more processors and a memory; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the sensor to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium comprising instructions, characterized in that, When the instruction is executed on the sensor, the sensor causes the sensor to perform the method as described in any one of claims 1-7.
10. A computer program product, characterized in that, When the computer program product is run on the sensor, the sensor causes the sensor to perform the method as described in any one of claims 1-7.