## 2 Materials and Methods
### Parallel Algorithms
#### 2.4.2 optimize_params Algorithm (Parameter Optimization)  
The optimize_params algorithm (Algorithm 10) is designed to automatically optimize the parameters (size and bias) of an error classification model using the Optuna library. It uses the objective function objective_function (Algorithm 9) to estimate the quality of the parameters and iteratively searches for a set of parameters minimizing the MSE between the input signal and its approximation.  
```
1:Input:\(y\)--one-dimensional array of signal points with error,
2:\(error\)--string, the name of the error type,
3:\(iters\)--number of optimization iterations.
4:Output: Best MSE value
5:\(study\leftarrow\) create_study(direction='minimize', sampler = TPESampler()) \(\triangleright\) Create a minimization problem based on the TPESampler algorithm.
6:\(objective\_lambda(trial)=\) objective_function(\(trial,y,error\)) \(\triangleright\) Wrapper for objective_function
7:\(study.optimize(objective\_lambda,n\_trials=iters)\)\(\triangleright\) Start Optimization return study.best_value\(\triangleright\) Return the best value found
```  
**Algorithm 10** optimize_params (parameter optimization)  
Main Steps of the Algorithm  
Input data: The algorithm takes as input a one-dimensional array y of signal points with an error, a string error indicating the type of error, and an integer iters specifying the number of optimization iterations that Optuna should perform.  
Creating an optimization problem: A study object is created using the create_study function. The direction='minimize' parameter indicates that the optimization objective is to minimize the target function (MSE). The parameter sampler=TPESampler() specifies the parameter sampling algorithm; in this case, the tree-structured Parzen estimator (TPE) is used, which is an efficient algorithm for Bayesian optimization.  
Define lambda function for Objective Function: A lambda function objective_lambda is created that \"closes\" the target function objective_function with specific inputs y and error. This is necessary so that Optuna can call the target function with the argument trial without passing y and error each time. In fact, objective_lambda(trial) is equivalent to objective_function(trial, y, error).  
Start optimization: The optimization process is started using the study.optimize method. The lambda function objective_lambda is passed as the first argument, and the parameter n_trials=iters specifies the number of optimization iterations (the number of times the target function is called to examine different sets of parameters). The optimizeriteratively calls objective_lambda, offering different parameter values (size and shift) and trying to find those that minimize the return value (MSE).  
Obtaining the best value: After completing a given number of optimization iterations, the algorithm retrieves the best found value of the target function (minimum MSE) achieved during the optimization using the study.best_value attribute.  
Output: The algorithm returns the best MSE value found during the optimization process. This value represents the minimum MSE achieved for a given error type error and input signal y, with optimized size and shift parameters.  
Remarks  
The optimize_params algorithm automates the process of finding optimal parameters for modeling an error of a given type. Using the TPE method, we can efficiently explore the parameter space and find the values that provide the best fit between the error model and the input signal according to the MSE criterion. The number of iters iterations affects the quality of optimization and the execution time; a larger number of iterations tends to increase the probability of finding the global minimum, but also increases the computational cost.