## 4 Results
### Bubble Detection  
The first step consists of training the GGRBM. The training inputs are slices of \(k=8\) lags of volatility, return and cumulative slopes, and returns of \(\delta=375\), \(\delta=500\), and \(\delta=1250\) days backward, giving a total of 22 features. The GGRBM was trained with a hidden layer with \(n=16\) units, 1200 epochs, batch size of 64, Persistent Contrastive Divergence (PCD) using 1 step of the Gibbs sampling, and learning rate between 0.005 and 0.008 with a decay rate of 0.1 to make the learning rate decrease smoothly as the number of iterations progresses. In the second step, we train the BRF with the values of the hidden units of the GGRBM. For this case, we need to construct the class variable that tells us when we are in the presence  
Figure 7: Time series of the S&P500 index (green color) on the y-axes left, and the probabilities of instability for each day (red color) in the y-axes right based on the BBRBM-ANN with \(k=16\) lags. The vertical stripes in yellow highlight the periods of instabilities between the maximum value of the index and its lowest value. The strip (a) represents the Black Monday of 1987, (b) the dot-com crisis of 2000, (c) the Subprime crisis of 2008, (d) the COVID-19 crisis, and (e) the stock market decline of 2022. Note: The index values and features have been scaled to values between 0 and 1 to improve the readability of the time series and their relationship to each other. The two plots below show the same in more detail for the 2008 Subprime crisis and the COVID-19 crisis through July 2024.  
of a bubble and when we are not. As indicated in Section 3.3, we use a practical approach. We recognize the critical point \(t_{c}\) corresponding to the highest index value reached just before the sudden drop in the index occurs. We leave samples that are \(r\) days behind \(t_{c}\) as bubble samples (\(y=1\)) and all others at \(y=0\). We test by training BRF with \(r=50\) and \(r=90\) days backward, which allows us to assess whether there is any difference in the estimated bubble probabilities. The BRF was trained using n_estimators = 500 (500 trees), max_features=sqrt, max_depth = 10, and of course, with 16 features, corresponding to the values of the hidden units of the GGRBM. To evaluate the model's ability to detect bubbles, we trained three sets of GGRBM-BRF with different training sets: the first one using only the 1987 Black Monday crisis, the second using the Black Monday crisis and the dot-com crisis of 2000, and the third using the two previous crises and the Subprime crisis of 2008. Figure 6 (right) shows the model's performance on different classical measures to evaluate classifiers. It is possible to note interesting results despite the complexity of our problem. As we indicated in the Introduction, similar financial regime change detection studies do not usually provide objective performance measures, with a few exceptions. We have examined studies that provide relevant benchmarks using supervised learning models. For instance, ref. [78] uses univariate predictors, logit models, and SVMs to forecast financial shocks in the Eurozone. Their best model achieved an accuracy of approximately 90%, comparable to our Balanced Random Forest results. However, their true positive rate (TPR) was only 19%, while our model achieved TPRs exceeding 60%, highlighting a potential advantage in identifying pre-crisis conditions. Similarly, [53] implemented various machine learning classifiers (RF, SVM, XGBoost, and others) to forecast market crises using financial indicators. Their best model yielded an AUC of around 80%, which is in the same range as our results. Figure 8 (Right) shows an idea of the performance achieved using the BRF-based bubble detector, using the 1987 (Black Monday), 2000 (dot-com), and 2008 (Subprime) crises. Overall, the results are promising. First, note that the overall performance decreases marginally as we train with more shocks. This happens because when we train the detector with only one crisis, it only receives samples from that one.