# Creative Chord Sequence Generation for Electronic Dance Music
## 2 Methods
### Diatonicity  
The statistical model described above is based on root and triad quality movements and captures local statistics but does not enforce global key consistency. In some settings, it may be desirable to restrict chords to a particular key, generate more adventurous sequences that do not follow a key, or in general something in between.  
Consider the set of chords \(\mathcal{K}\) compatible with a specified key, e.g. for A major (ionian mode):  
\[\mathcal{K}=\{\mathsf{AM},\mathsf{Bm},\mathsf{C\sharp m},\mathsf{DM},\mathsf{ EM},\mathsf{F\sharp m},\mathsf{C\sharp dim}\}.\]  
Different sets \(\mathcal{K}\) are defined for all seven modes formed above all diatonic roots (Equation (1)). To control the overall diatonicity of a chord sequence in a given key, the sequence can be viewed as progressing jointly with a sequence \(\boldsymbol{d}=d_{1}\ldots d_{\ell}\) sampled from Bernoulli variables \(D_{1},\ldots,D_{\ell}\) indicating whether the respective chord \(c_{i}\) is diatonic in the given key, so \(d_{i}=1\) if \(c_{i}\) is in \(\mathcal{K}\). The joint probability can be factored as:  
\[\mathbb{P}(\boldsymbol{d},\boldsymbol{c}) =\mathbb{P}(d_{1}\ldots d_{\ell})\times\mathbb{P}(c_{1}\ldots c_{ \ell}\mid d_{1}\ldots d_{\ell})\] \[\approx\prod_{i=1}^{\ell}\mathbb{P}(d_{i})\times\mathbb{P}(c_{i }\mid d_{i},h_{i}) \tag{4}\]  
with Figure 3 depicting this as a graphical model.  
For the plug-in we assume the \(D_{i}\) are i.i.d., i.e. that they have the same probability distribution. This allows the diatonicity of a chord sequence to be expressed simply by one global parameter \(\delta=\mathbb{P}(D_{i}\!=\!1)\). Therefore, \(\delta=1\) will give a fully diatonic sequence, \(\delta=0\) implies \(\mathbb{P}(D_{i}\!=\!0)=1\) and a fully non-diatonic sequence will be generated.  
Figure 3: The basic cyclic model extended with diatonicity variables.  
Figure 2: For the pattern \(X\{8\}+\), the probability density of information content estimated from 100,000 samples (curved), and the information content of the 150 corpus sequences (histogram).  
The right-hand term of Equation (4) can be expressed in terms of the basic model in Equation (2) according to the following derivation  
\[\mathbb{P}(c_{i}\mid d_{i},h_{i}) =\mathbb{P}(c_{i},d_{i},h_{i})\big{/}\mathbb{P}(d_{i},h_{i})\] \[=\mathbb{P}(c_{i},d_{i}\mid h_{i})\mathbb{P}(h_{i})\Big{/}\sum_{c} \mathbb{P}(c,d_{i},h_{i})\] \[=\mathbb{P}(c_{i},d_{i}\mid h_{i})\Big{/}\sum_{c}\mathbb{P}(c,d_{i }\mid h_{i}) \tag{5}\] \[\mathbb{P}(c_{i},d_{i}\mid h_{i}) =\left\{\begin{array}{ll}\mathbb{P}(c_{i}\mid h_{i})&\mathbf{1} _{\mathcal{K}}(c_{i})=d_{i}\\ 0&\text{otherwise}\end{array}\right.\]  
Given that the \(D_{i}\) are i.i.d., this derivation implies conveniently that, once \(\mathcal{K}\) and \(\delta\) have been specified, they can be efficiently \"compiled\" into the basic transition matrix (Equation (3)) by substituting Equation (5) into Equation (4) and precomputing \(\mathbb{P}(d)\times\mathbb{P}(c,d\mid h)\) for both \(d\!=\!1\) and \(d\!=\!0\) and for all possible chord bigrams \((h,c)\in\mathcal{T}\times\mathcal{T}\).