# An Analysis of Rhythmic Patterns with Unsupervised Learning
## 2 The Compositional Hierarchical Model for Rhythm Modeling
### Model Description
#### 2.1.1 Rhythmic Compositions  
Each part on a successive layer \(\mathcal{L}_{n}\) is a composition of one or more (sub-)parts on the previous layer \(\mathcal{L}_{n-1}\). Formally, a composition \(P_{i}^{n}\) of \(K\) subparts \(\{P_{k_{0}}^{n-1}\dots P_{k_{K-1}}^{n-1}\}\) is defined as:  
\[P_{i}^{n}=\{P_{k_{0}}^{n-1},\{P_{k_{j}}^{n-1},(\mu_{1,j},\sigma_{1,j}),(\mu_{2,j},\sigma_{2,j})\}_{j=1}^{K-1}\} \tag{3}\]  
Relations between the subparts forming the composition are governed by two Gaussians, which control their _relative_ spacing and scaling, leading to a tempo invariant representation of a rhythmic pattern. All subparts relate to the first subpart of the composition.  
The first Gaussian with parameters \((\mu_{1,j},\sigma_{1,j})\) defines the size of the subpart relative to the size of the first subpart. Values of \(\mu_{1}\) larger than one indicate that the second subpart is longer than the first subpart; the values smaller than one indicate the inverse. When the model is trained on a corpus, the values of \(\mu_{1,j}\) usually converge to integer ratios commonly present in different time signatures, e.g., 1/5, 1/4, 1/3, 1/2, 1, 2, etc. Given activations subparts \(P_{k_{0}}^{n-1}\) and \(P_{k_{1}}^{n-1}\), the value of \(\mu_{1,1}\) is calculated as:  
\[\mu_{1,1}=\frac{A_{S}(P_{k_{1}}^{n-1})*(1+\mu_{1}(P_{k_{1}}^{n-1}))}{A_{S}(P_{k _{0}}^{n-1})*(1+\mu_{1}(P_{k_{0}}^{n-1}))}. \tag{4}\]  
The second Gaussian with parameters \((\mu_{2,j},\sigma_{2 means that the second subpart starts exactly at the end of the first subpart, while smaller values indicate overlap between both subparts. The parameter \(\mu_{2}\) is calculated from activations of two subparts as:  
\[\mu_{2,1}=\frac{A_{T}(P_{k_{1}}^{n-1})-A_{T}(P_{k_{0}}^{n-1})}{A_{S}(P_{k_{0}}^{ n-1})*(1+\mu_{1}(P_{k_{0}}^{n-1}))}. \tag{5}\]  
The parameter \(\sigma_{1,1}\) is estimated from the distribution of pairs of activations with values near \(\mu_{1,1}\), between 0.75-1.5 times the first subpart activation scale. Similarly, \(\sigma_{2,1}\) is estimated from the distributions of pairs of activations with values near \(\mu_{2,1}\), within 0.75-1.5 of the first subpart's length, therefore [0.75*\(\mu_{2,1}\), 1.5*\(\mu_{2,1}\)]. These limits are imposed to exclude the influence of combinations of parts which could represent a double or half beat granulation, and would significantly skew the Gaussian.  
In Figure 3, we show four simple first layer compositions with different values of \(\mu_{1,1}\) and \(\mu_{2,1}\). All parameters of a composition are learned during training and their values reflect the nature of the training data. For example, in studio-recorded music, tempo will be more even, so the variance of pattern lengths and their relative positions will be small, while the values will increase for live recordings.  
Figure 3: An example of four different RhythmCHM compositions. In the first example, the second subpart is the same length as the first subpart and is positioned exactly one \(P_{1}^{0}\) length after the first subpart’s position. In \(P_{2}^{1}\), the second subpart is the same length as the first subpart and occurs at twice its length. In \(P_{3}^{1}\), the second subpart is twice the length of the first subpart and starts at half its length. In \(P_{4}^{1}\), the second subpart is half the length of the first subpart and starts exactly at its end. The green arrow represents the length (1) of the first subpart, while the blue arrow represents the length of the second subpart. The offset of the second subpart is marked with a gray arrow.