# Robust Algorithm for Calculating the Alignment of Guide Rolls in Slab Continuous Casting Machines
## 3 Angle Conversion Algorithms
### Optimization-Based Approach  
The geometric approaches calculate the positions of one roll at a time in a chain-like computation. As will be shown in Section 4, this works well as long as the measured angles are completely accurate. However, the geometric approaches can be sensitive to errors in the angle measurements. Since measurement errors are not avoidable in practice, this poses a significant challenge.  
Figure 6: Geometry of one step of the full geometric algorithm (case 2). The roll position errors in this figure are greatly exaggerated. The line \(a_{1}=\overline{AK}\) is not shown for clarity.  
This leads to the idea to develop an algorithm that takes a different approach than the purely geometric ones. Rather than calculating the roll positions one-by-one, it should simultaneously consider all \(n-1\) measured angles and compute all roll positions at once. With this in mind, an algorithm was developed that is based on the idea of optimization using backpropagation and gradient descent. It leverages the fact that the conversion of roll positions into tangential angles--the reverse of what the algorithm is supposed to calculate--is an easy and unambiguous trigonometric calculation that can be computed for all rolls at once. Rather than trying to directly convert the angles into the positions (as the geometric approaches do) the optimization-based algorithm systematically searches for a set of roll positions that would result in measured angles that are as close as possible to the actually measured angles. Optimization using gradient descent allows this to be performed without ever actually converting tangential angles into roll positions. The search is conducted in an iterative loop and each iteration of this loop consists of steps 3-7 of the following procedure (see Figure 7):  
1. The zero-mean compensation is applied to the set of measured angles.
2. A set of random roll positions is generated. Each roll receives a random position error with only a radial component.
3. Forward Function: Using this set of roll positions and some trigonometry, the angles that an SCM would measure are calculated.
4. Loss Function: The set of angles from the previous step are compared to the measured angles and the loss is calculated.
5. If the loss has not stopped decreasing, continue the loop. Otherwise, end the loop and return the best set of roll positions.
6. Backpropagation: Every mathematical operation that is applied to convert the roll positions into the loss is tracked and recorded. That allows to propagate the loss backwards through the computation graph, yielding gradients for each roll position with respect to the loss.
7. Gradient Descent: Using the gradients from the previous step, each roll position is shifted by a small amount, reducing the loss and therefore bringing the calculated positions closer to the actual ones. With this new set of roll positions, repeat from Step 3.  
Figure 7: Structure of the optimization-based algorithm.  
The algorithm is programmed in Python, version 3.11.4. Using tools from the popular data science library PyTorch, version 2.6.0, the tracking of gradients, backpropagation and optimization steps are implemented. The underlined steps are explained in further detail in the following paragraphs.