<jupyter_start><jupyter_text>Distribution of segments' sizes in MIREX10 The study of the MIREX10 annotations in [1] shows that segments in this dataset are regular, and mostly centered around the size of 16 onbeats.We replicated these results by studying the size in number of bars, more adapted to our context.<jupyter_code>hide.repartition_bar_lengths_RWCPop()<jupyter_output>Number of segments: 1619<jupyter_text>We see in this histogram that most of the segment (more than a half) last 8 bars, and that numerous other segments last 4 bars. The other values are less represented. Hence, it should be interesting to enforce these sizes in our algorithm. Thus, we modified our algorithm to include a regularization function, which favoures certain sizes of segments.This regularization function only depends on the size of the segment, and is subtracted to the convolution cost. Hence, it's a penalty added to the raw convolution cost. Denoting $c_{b_1, b_2}$ the convolution cost as defined previously (see Notebook 1 or the Appendix which details our algorithm), the "regularized" cost is defined as $c'_{b_1,b_2} = c_{b_1,b_2} - \lambda p(b_2 - b_1 + 1) c_{k8}^{max}$, with: - $p(b_2 - b_1 + 1)$ the regularization function, which we will present in next part, - $\lambda$, a ponderation to handle the influence of this function, - $c_{k8}^{max}$, which represents the maximal convolution score on all intervals of size 8 of the current song, and its associated autosimilarity matrix. The idea of this score is to adapt the penalty to the specific shape of this autosimilarity. It can analogously be seen as a normalization of the raw convolution score: $\frac{c_{b_1,b_2}}{ c_{k8}^{max}} - \lambda p(b_2 - b_1 + 1)$In this notebook, we will try to define the function $p$ and to study the influence of the parameter $\lambda$.  Definition of the regularization functions We developped two types of regularization functions: - **Symmetric functions centered on 8, as in [1]**: the idea of this method is to favoure segments lasting 8 bars, as the majority of segments have this size, and to penalize all the other segments as the difference between their size and 8, raised to a certain power. Concretely, this results in:     $p(n) = |n - 8| ^{\alpha}$         with $n$ the size of the segment. Here, $\alpha$ is a parameter, and we will try     - $\alpha = \frac{1}{2}$     - $\alpha = 1$     - $\alpha = 2$      - **"Modulo functions"**: the idea of this method is to enforce specific sizes of segments, based on prior knowledge. They may be more empirical, but are also more adaptable to the need. Our main idea when developping this function was to favoure 8 wihout penalizing too much 4 or 16, that we know are current sizes (especially 4 in RWC Pop, as shown above). In addition, we considered that segments of even sizes should appear more often than segments of odd sizes in western pop music, which is less obvious in the distribution from above.      We will try 3 different types of function:     - "Favouring modulo 4": in this case:         - if $n \equiv 0 \pmod 4, p(n) = 0$,         - else, if $n \equiv 0 \pmod 2, p(n) = \frac{1}{2}$,         - else, $p(n) = 1$.     - "Favouring 8, then modulo 4": in this case:         - if $n = 8, p(n) = 0$,         - else, if $n \equiv 0 \pmod 4, p(n) = \frac{1}{4}$,         - else, if $n \equiv 0 \pmod 2, p(n) = \frac{1}{2}$,         - else, $p(n) = 1$.     - "Favouring little segments of 8, then 4": in this case:         - if $n > 12, p(n) = 100$ (we forbid the algorithm to select segments lasting more than 12 bars),         - else, if $n = 8, p(n) = 0$,         - else, if $n \equiv 0 \pmod 4, p(n) = \frac{1}{4}$,         - else, if $n \equiv 0 \pmod 2, p(n) = \frac{1}{2}$,         - else, $p(n) = 1$. We will now test all these functions on the entire RWC Pop database. - First, we will fix the ranks to $T' = 32$ (rank for factor $H$) and $B' = 32$ (rank for factor $Q$), and search for the best $\lambda$ in this condition. **In this condition, scores will only be plotted for the tolerance window of 0.5 seconds**. - Secondly, we will keep the best parameter $\lambda$ for the ranks 32,32, and we will try several values of ranks with this $\lambda$ fixed. **In this condition, we will show scores with both tolerances 0.5 seconds and 3 seconds, in that order**.   As stated in the previous notebook, we now fix the subdivision to 96.<jupyter_code>subdivision = 96<jupyter_output><empty_output><jupyter_text>Estimating $\lambda$, with fixed ranks $T' = 32$ and $B' = 32$  Symmetric functions centered on 8  $\alpha = \frac{1}{2}$<jupyter_code>param_range = [i/100 for i in range(0,100,5)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "sargentdemi")<jupyter_output>c:\users\amarmore\desktop\projects\phd main projects\on git\code\tensor factorization\musicntd\autosimilarity_segmentation.py:43: RuntimeWarning: invalid value encountered in true_divide
  this_array = np.array([list(i/np.linalg.norm(i)) for i in this_array.T]).T<jupyter_text>For $\alpha = \frac{1}{2}$, the best $\lambda$ (in our range) seems to be **0.4**.  $\alpha = 1$<jupyter_code>param_range = [i/1000 for i in range(0,100, 5)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "sargentun")<jupyter_output><empty_output><jupyter_text>For $\alpha = 1$, the best $\lambda$ seems to be **0.09**.  $\alpha = 2$<jupyter_code>param_range = [i/1000 for i in range(0,20)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "sargentdeux")<jupyter_output><empty_output><jupyter_text>For $\alpha = 2$, the best $\lambda$ seems to be **0.004**.  Modulo functions  "Favouring modulo 4"<jupyter_code>param_range = [i/10 for i in range(0,20)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "modulo4")<jupyter_output><empty_output><jupyter_text>In this function, the best $\lambda$ seems to be **0.9**.  "Favouring 8, then modulo 4"<jupyter_code>param_range = [i/10 for i in range(0,20)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "modulo8")<jupyter_output><empty_output><jupyter_text>In this function, the best $\lambda$ seems to be **1**.  "Favouring little segments of 8, then 4"<jupyter_code>param_range = [i/10 for i in range(0,20)]
hide.convolution_parameter_on_all_rwc(param_range, subdivision = subdivision, penalty_func = "moduloSmall8and4")<jupyter_output><empty_output><jupyter_text>In this function, the best $\lambda$ seems to be **1**.  Results with different ranks, $\lambda$ fixed Now, we will fix $\lambda$ to the previous optimal value, and try different ranks for the decomposition.For both $H$ and $Q$, we will try ranks in the range [12,16,20,24,28,32,36].<jupyter_code>ranks_rhythm = [12,16,20,24,28,32,36]
ranks_pattern = [12,16,20,24,28,32,36]<jupyter_output><empty_output><jupyter_text>Note: I conceed that tables are a bit long, you can jump directly to the conclusion to see what we considered to be the best outputs, and check if it's coherent in the tables afterwards.  Symmetric functions centered on 8  $\alpha = 1/2$<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern,subdivision=subdivision, 
                                                  penalty_weight = 0.4, penalty_func = "sargentdemi")<jupyter_output><empty_output><jupyter_text>$\alpha = 1$<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern,subdivision=subdivision, 
                                                  penalty_weight = 0.09, penalty_func = "sargentun")<jupyter_output><empty_output><jupyter_text>$\alpha = 2$<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern,subdivision=subdivision, 
                                                  penalty_weight = 0.004, penalty_func = "sargentdeux")<jupyter_output><empty_output><jupyter_text>Modulo functions  "Favouring modulo 4"<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern, subdivision=subdivision,
                                                  penalty_weight = 0.9, penalty_func = "modulo4")<jupyter_output><empty_output><jupyter_text>"Favouring 8, then modulo 4"<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern, subdivision=subdivision,
                                                  penalty_weight = 1, penalty_func = "modulo8")<jupyter_output><empty_output><jupyter_text>"Favouring little segments of 8, then 4"<jupyter_code>zero_five_chr, three_chr = hide.compute_ranks_RWC(ranks_rhythm,ranks_pattern, subdivision=subdivision,
                                                  penalty_weight = 1, penalty_func = "moduloSmall8and4")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10372370345370682, 'fraction_numerical': 0.02857464281696479, 'mean_word_length': 4.153623188405797, 'pattern_counts': {'":': 3, '<': 59, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '351954', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2718, 'n_words': 992, 'path': 'Notebooks/Notebooks ISMIR 2020/4 - Penalty regularity function.ipynb', 'repo_name': 'ax-le/MusicNTD', 'size': '8889'}