## 3 Materials and Methods
### Unsupervised Models  
As we can see in Figure 2, we have unsupervised processes involving Restricted Boltzmann Machines (RBMs), supervised processes involving a neural network (ANN) to detect a sudden price drop accompanied by high volatility, and a Balanced Random Forest (BRF) that allows us to warn if we are in a bubble. The traditional RBM is the Bernoulli-Bernoulli RBM, or BBRBM [62; 63], in which the \(m\) visible units of the input layer are binary \(v=(v_{1},\ldots,v_{m})\). The visible units represent the features that account for the system's state. These units are connected to each of the \(n\) hidden units of the hidden layer \(h=(h_{1},\ldots,h_{n})\), which also take binary values. Thus, the machine is a bipartite network in which the visible units are fully connected to each of the hidden units, but with the restriction that there are no connections between units of the same layer. This restriction allows the hidden units to be conditionally independent of each other but conditional on the values of all other visible units and vice versa. For the BBRBM, \((v,h)\in\{0,1\}^{m+n}\), and the joint distribution of \((v,h)\) can be written as \(p(\mathbf{v},\mathbf{h})=\frac{e^{-E(v,h)}}{Z}\), where \(Z\) is the normalization constant or partition function, and the energy function \(E(v,h)\) is as follows:  
\[E(v,h)=-\sum_{ij}w_{ij}v_{i}h_{j}-\sum_{i}^{m}b_{i}v_{i}-\sum_{j}^{n}c_{j}h_{j} \tag{2}\]  
where \(i\in\{1,\ldots,n\}\), and \(j\in\{1,\ldots,m\}\) indicate the hidden and visible units connected by the weighted edges, represented in the matrix \(W\) matrix with dimension \(n\times m\). The values \(b_{j}\) and \(c_{i}\) represent the biases of the visible and hidden units, respectively. The conditional probabilities are estimated from the propagation through the neural network via the following equations:  
\[p(\mathbf{v}|\mathbf{h})=f\Big{(}\mathbf{b}+\sum_{j=1}h_{j}w_{ij}\Big{)}, \tag{3}\]  
\[p(\mathbf{h}|\mathbf{v})=f\Big{(}\mathbf{c}+\sum_{i=1}v_{i}w_{ij}\Big{)} \tag{4}\]  
where \(f(. )\) is the sigmoid activation function. The values of the BBRBM's hidden layer units will be the input for a classifier (ANN) to tell us if we are in the presence of instability. It is equivalent to having a thermometer that evaluates market conditions in real time. However, we need more complex features that consider real (non-discretized) market values to evaluate the cumulative process that can give evidence of inflated price conditions or a financial bubble. For this case, we consider a  
Figure 2: A general warning model: The system identifies unstable and bubble samples independently. It employs a Bernoulli–Bernoulli Restricted Boltzmann Machine (BBRBM) and an Artificial Neural Network (ANN) to detect instability. To identify financial bubbles, a Gaussian–Gaussian RBM (GGRBM) and a Balanced Random Forest (BRF) are utilized. The models use the \(k\) lags of the financial index states (e.g., the S&P500) of volatility and variance of returns (daily price changes). Gaussian-Gaussian RBM (GGRBM) in which both the visible and hidden units support continuous value data. For this case, the energy function is given by  
\[E(v,h)=-\sum_{i,j}w_{ij}\frac{h_{j}}{s_{j}}\frac{v_{i}}{\sigma_{i}}-\sum_{i}^{m} \frac{(v_{i}-b_{i})^{2}}{2\sigma_{i}}-\sum_{j}^{n}\frac{(h_{j}-c_{j})^{2}}{2s_{ j}} \tag{5}\]  
where \(v_{i}\) and \(h_{j}\) are real values for the visible and hidden units, respectively. As before, \(b_{i}\) and \(c_{j}\) are biases to the visible and hidden units, respectively, connected through the weights \(w_{ij}\). The parameters \(\sigma_{i}\) and \(s_{j}\) are the standard deviations of the visible and hidden units, respectively.