## 2 Materials and Methods
### Parallel Algorithms
#### 2.4.1 objective_function Algorithm (Loss Function)  
The objective_function algorithm (Algorithm 9) is a target function used in the parameter optimization process using the Optuna library (with TPESampler). This function is designed to evaluate the quality of the approximation of the input signal y using a model based on a given \"error\" type error. The quality of the approximation is evaluated using the mean square error (MSE). The function is used in the context of searching for optimal parameters (size and shift) to model a certain type of error in the signal. Main Steps of the Algorithm  
Input data: The algorithm takes as input a one-dimensional array y representing the signal points with an error, and a string error indicating the type of error to be modeled. Selecting parameters to optimize: The function uses the trial object to suggest parameter values to be optimized:  
* Error size (size): An integer value of size in the range from length(y) \(-\) 10 to length(y) + 10. This parameter specifies the length of the error signal to be generated and then reduced to the length of the y signal. * Error Shift (shift): An integer value of shift in the range of \(-\)length(y) to length(y). This parameter defines the shift in the error signal relative to the y signal. Time axis generation: An array x is created, representing evenly spaced values from 0 to 1, with a length equal to the length of the signal y. This array is used as an argument to the function Error_signal, which generates an error signal. ```
1:Input:\(y\)--one-dimensional array of signal points with error,
2:error--string, name of the error type
3:Output: MSE (Mean Square Error) for the given parameters
4:size \(\leftarrow\) (length\((y)-10\),length\((y)+10\)) \(\triangleright\) Integer size frames
5:\(shift\leftarrow(-\)length\((y),\)length\((y))\) \(\triangleright\) Integer Shift Frames
6:\(x\leftarrow\) array of uniform values from 0 to 1 of size length\((y)\)
7:\(ampl\gets 1\)
8:if\(shift\geq 0\)then
9:\(Error\leftarrow\) resize_vector\((\)Error_signal\((error,x,ampl,1),size)\)\(\triangleright\) Resize the error signal (See Algorithm 7). 10:\(Error\leftarrow\) resize\((Error,(1,\)length\((y)))\)\(\triangleright\) Change the dimension of the Error array to (1, length(y))
11:\(Error\gets Error[0]\)\(\triangleright\) Get the first line of the Error array
12:\(arr\_error\leftarrow\) concatenate\(([0,\ldots,0,Error])[:\) length\((x))\)\(\triangleright\) Complete with zeros and trim
13:else
14:\(Error\leftarrow\) resize_vector\((\)Error_signal\((error,x,ampl,1),size)\)\(\triangleright\) Resize the error signal (See Algorithm 7). 15:\(Error\leftarrow\) resize\((Error,(1,\)length\((y)))\)\(\triangleright\) Change the dimension of the Error array to (1, length(y))
16:\(Error\gets Error[0]\)\(\triangleright\) Get the first line of the Error array
17:\(arr\_error\leftarrow\) concatenate\(([Error,0,\ldots,0])[-\)length\((x):]\)\(\triangleright\) Complete with zeros and trim
18:endif
19:features_matrix \(\leftarrow\) vstack\(([1,\ldots,1],arr\_error).T\)\(\triangleright\) Create feature matrix
20:\(coefficients\leftarrow\) lstsq(features_matrix,\(y\))\(\triangleright\) Least Squares Method
21:\(approximated\_signal\leftarrow\) dot\((\)features_matrix,coefficients\()\)\(\triangleright\) Calculate approximated signal
22:\(mse\leftarrow\) MSE\((y,approximated\_signal)\)return\(mse\)
```  
**Algorithm 9** objective_function (loss function)  
Generation and resizing of the error signal: A \"base\" error signal is generated using the Error_signal(error, x, ampl, 1) function for the specified error type error, \"time axis\" x, amplitude ampl (fixed at 1), and scale 1. Then, using the function resize_vector (Algorithm 7), the size of the generated error signal is resized to the proposed value size. After resizing, the array Error is converted to dimension \((1,\)length\((y))\), and then the first row is extracted to obtain a one-dimensional array.