## 2 Materials and Methods
### Problem Formulation  
The insertion of the electrode array is configured such that it is presented as \((x,y,\theta)\) in the plane where \((x,y)\) points are considered as the location of array tip, and \(\theta\) angle represents heading of the array with respect to centre line of the ST model towards either of the modular/lateral walls (as depicted in Figure 7A). Let \(\vec{d}\) be the centre line trajectory of the electrode array and \(\vec{v}\) be defined as direction of array insertion away from the centre line direction. The goal of the insertion is to keep the electrode array in the centre of the straight path of the ST model until it touches the curved path, where it slides along the curved path. The motivation of keeping the electrode array on the centre line trajectory is twofold: (1) it would not damage the delicate structure of the ST walls; (2) the centre line insertion imposes less overall force when the array touches the curved path and slides along it.  
For this problem, we are considering the ST model as two paths; one is the straight path and the other is the curved path, as shown in Figure 7B. One of the classification models would predict whether the position of the electrode array is located in the straight path or the curved path at a certain time. In this work, we will be generating the control signals for only the straight path, as we were unable to find any mechanism to control array in the curved path.  
For real-time prediction, we have used two classifiers: (1) classifier A for trajectory prediction, and (2) classifier B for path/position prediction. Both classifiers would be trained on 4 mm subsequence data of the most apical electrode pairs because this is where most of the information about insertion is.  
Although a reasonable accuracy has been achieved by our individual model, the ensemble approach has been used to increase the classification accuracy for both our classifiers. According to [42], ensemble learning is the method in which multiple classifiers are combined to take their weighted vote to make predictions on new data. Each classifier makes its prediction and then votes for the final prediction, as shown in Figure 5. This figure explains one of the ensemble learning processes that is called majority voting ensemble. In this kind of scheme, the final predictor would be the predictor that receives the majority vote from the multiple classifiers. In our setup, we have three classifiers (RF, SNN, and KNN) that achieved the maximum accuracy. Although it is possible to give uneven weights to the individual classifier vote, equal weight is given to each classifier in our system.  
All the offline classification is carried out using Python 3.6, but in order to keep a homogeneous system along with actuation and sensing, a machine learning system is developed again in MATLAB. All the hyperparameters of learning models remain the same, and individual models are trained and tested again to make sure performance is kept the same as Python models. The ensemble majority voting algorithm is also developed in MATLAB.  
Figure 7: (**A**) Electrode array insertion configuration. (**B**) Division of insertion path into straight and curved sections.  
Once we have ensemble-based trained models for both classifier A and B, we set up the system for real-time prediction and correction. Figure 8 shows the control flow graph for real-time prediction and correction of the insertion trajectory. As mentioned above, this control strategy is for the straight path only to keep the electrode array at the centre line of the ST model. For this, there is a need to first predict whether the electrode array is in the straight path or the curved path.