# Melodic Similarity and Applications Using Biologically-Inspired Techniques
## 6 Data-Driven Modelling of Global Similarity
### Computing the Alignments for Melodic and Intra-Song Motivic Similarity  
For the modelling of melodic similarity, the results from Section 4 have indicated that, although Mafft is the best alignment strategy, the differences between various configurations are rather insignificant. Therefore, instead of generating a substitution matrix from clique alignments of one configuration only, we decided to use the following: Mafft-globalpair with \((-4,-2)\) gap penalties, Mafft-globalpair-allowshift with \((-4,-2)\) gap penalties and Mafft-localpair-allowshift with \((-2,-1)\) gap penalties. The melodic similarity matrices generated for the TuneFam-26 and Csv-60 datasets are denoted TFam-matrix and Csv-matrix respectively. For the modelling of intra-song motivic similarity, the idea is to align each sequence with artificial versions of itself, such that all possible instances of intra-song motifs are aligned. In such a context, a useful and informative version of a sequence is one that when aligned to the original, maximizes the overlap between different instances of perceived-as-similar motifs. This informativeness criterion partially agrees with [PERSON]'s and [PERSON]'s definition of interesting alignments: those whose symbol frequencies most differ from the a priori probabilities of the symbols [91]. However, since informativeness can be erroneously biased, we are interested in alignments that at the same time minimize the overlap between perceptually different motifs. Let us consider an example sequence \(S_{o}\) with two known motif instances \"ABF\" (cyan), \"AGG\" (green) of label \(L_{1}\) and one motif instance \"KLM\" (red) of label \(L_{2}\): XXABFXXXXAGGXXXXKLM. Furthermore, consider three versions of the \(S_{o}\) sequence based on arbitrary splitting in segments and further duplication or shuffling: KLXXXXABFXXXXAGXF, XAGGXXABFXAGGX and AGGXXKLMXXXABFXXX. Three possible pairwise alignments of the versions with the original are:  
---XXABFXXXXAGGXXXXKLMXXABFXXAGGXXKLMXXXABFXXXX-.....AGGXXKLLMXXXXABFXXXAGG--XK--X-AGGX-ABFX--AGGXXXKLMXXABFXX-- The first example contains alignment of same-label motif instances with themselves (e.g., ABF to ABF), which provide no new information regarding their variation and therefore is of no value. The second alignment matches different instances of same-label motifs (e.g., ABF to AGG) but incorrectly aligns different-label motifs (e.g., AGG to KLM). It is only the third case that satisfies our criteria of a useful version of a sequence. In order to identify the method that can be better used in practice to align any intra-song motifs (where the actual motifs are unknown), we design a simple experiment: we select all single sequences from the TuneFam-26 dataset that contain annotated motifs with two instances and devise three version-creation methods based on intuition. We then pairwise-align each original sequence to its different versions using different configurations of motif-agnostic alignment algorithms. In our experiment, the usefulness criteria are formulated as such: we are given the set \(L\) of all motif labels in a sequence \(S\) and \(M_{k}=\{m_{1}^{k},m_{2}^{k},...,m_{j}^{k}\}\), the set of all instances of intra-song motifs of label \(k\in L\).