\chapter{Results and Discussion}

In this chapter, the results of the experiments conducted to generate smooth \gls{mp}s between musical scales, particularly in the context of Western and Persian music, are presented. This chapter provides an in-depth analysis of the \gls{som} model's performance, including the various metrics used to assess the quality of \gls{mp}s. Specifically, we focus on the evaluation of the map's ability to represent musical scales, the smoothness of transitions between them, and the efficiency with which these transitions preserve musical relationships and coherence. We also compare the results with known modulation practices from music theory to evaluate the effectiveness and potential applications of the \gls{som}-based approach.

The chapter is divided into several sections, starting with the introduction of evaluation criteria and experimental setup, followed by the detailed analysis of the performance of the \gls{som} model across different parameter configurations. We also provide insights into the trade-offs between different evaluation metrics and the impact of various parameters on the final results. Finally, we examine the results of the smooth modulation generation and provide both objective and subjective evaluations of the model’s performance. This chapter also discusses the practical applications of the \gls{som} model in both Western and Persian music theory, highlighting its potential to offer new insights into musical transitions and scale relationships. Additionally, we explore the implications of the findings for future research in computational music theory and its possible influence on music composition and analysis. The analysis also touches on how the \gls{som} approach could be used to bridge the gap between different musical systems, providing a platform for cross-cultural music exploration. By presenting both qualitative and quantitative assessments of the generated \gls{mp}s, the chapter provides a comprehensive overview of the \gls{som}-based model's potential to generate musically coherent and emotionally effective transitions.

\section{Evaluation Criteria}

In order to assess the performance of the \gls{som} for musical modulation, we defined and employed a set of comprehensive evaluation criteria. These criteria are designed to quantify how well the \gls{som} captures the underlying structure of musical data and its effectiveness in preserving the relationships between musical notes and scales during modulation. The three key evaluation criteria we focus on are \gls{qe}, \gls{te}, and \gls{rp}, each of which serves as an indicator of a different aspect of the model's performance.

\subsection{Quantization Error}

\gls{qe} is one of the most fundamental measures used to assess the performance of the \gls{som}. It quantifies the average distance between the input data points and their corresponding \gls{bmu} on the map. This error acts as a direct indicator of how well the map represents the input data space. In essence, the \gls{qe} provides insight into how accurately the \gls{som} maps high-dimensional data into a lower-dimensional grid. A lower \gls{qe} suggests that the map’s neurons are closely matching the input data, while a higher error indicates that the map is poorly representing the input space and might require improvements \cite{83}. To evaluate the performance of the \gls{som} in clustering musical scales, the \gls{qe} is calculated after training the map, and it helps in determining how effectively the scales are organized on the map. By minimizing the \gls{qe}, the \gls{som} is better able to represent the tonal relationships between musical scales, which is crucial for generating smooth modulation paths \cite{84}.

\textbf{Definition:} \gls{qe} is mathematically defined as the sum of the distances between each input vector and its closest neuron, the \gls{bmu}. This distance is typically computed using Euclidean distance, which measures the straight-line distance between the input vector and the \gls{bmu} on the map. In this case, the Euclidean distance function captures how far apart the input data and the \gls{bmu} are in the multi-dimensional space, and the error is averaged over all input vectors. Formally, \gls{qe} is expressed as:

\begin{equation}
    QE = \frac{1}{N} \sum_{i=1}^{N} || \mathbf{x}_i - \text{BMU}(\mathbf{x}_i) ||
\end{equation}
    

where \(N\) represents the total number of data points, \(\mathbf{x}_i\) is the \(i\)-th input vector, and \(\text{BMU}(\mathbf{x}_i)\) refers to the weight vector of the neuron that is closest to \(\mathbf{x}_i\). The distance function \(|| \cdot ||\) represents the Euclidean distance between the input vector and its best-matching unit.

\textbf{Interpretation:} 
A low \gls{qe} signifies that the \gls{som} has accurately mapped the input data, implying that the neurons in the map represent the data points in a well-organized manner. This is a key characteristic of a successful \gls{som}, as it shows that the map is a good abstraction of the original data. In musical terms, a low \gls{qe} indicates that the \gls{som} has successfully clustered similar musical scales together, thereby preserving the relationships between them.  
A high \gls{qe}, on the other hand, suggests that the map has failed to represent the input space effectively. This can occur when the map is poorly trained, or when the network fails to adequately capture the complex structure of the input data. In such cases, the \gls{som} may place dissimilar data points too close together, resulting in a poor representation of the underlying relationships in the data. This can lead to a failure in the smooth modulation of musical scales, as the transition between scales may appear jarring or incoherent.

In practice, achieving a balance between low \gls{qe} and effective training is crucial. While a very low \gls{qe} might suggest that the map is overfitting to the data or losing generalizability, a high \gls{qe} is a sign that the map has failed to adequately capture the structure of the input data. Therefore, the goal is to minimize the \gls{qe} while ensuring that the map retains enough flexibility to generalize well to new, unseen data.

Figure \ref{fig:figure18} illustrates a method of evaluation using \gls{qe}, which measures the difference between the input data and the closest matching nodes. The map shown demonstrates how data points are assigned to their \glspl{bmu}, and the corresponding error is computed based on the distance between the input vectors and the \glspl{bmu}.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (27).png}
    \caption{Averaging the \gls{qe} over four \glspl{bmu} for input evaluation.}
    \label{fig:figure18}
\end{figure}

\subsection{Topographic Error}

\gls{te} is another critical evaluation metric used to assess how well the \gls{som} preserves the topology of the input space. In other words, it measures how well the map maintains the relative positions of input data points during the training process. This metric is crucial because, for modulation paths between musical scales to be smooth, the map must reflect the natural closeness of musical notes and their relationships to each other. If the topology is well-preserved, similar musical scales or notes should be mapped close to each other on the grid, reflecting their inherent similarity in terms of intervals or tonality \cite{85}. A high \gls{te} suggests that the map has not adequately preserved the relative distances between input points, potentially leading to inaccurate clustering and poor modulation path generation \cite{86}. As such, minimizing the \gls{te} is a vital step in training a \gls{som} that is effective for mapping musical scales and understanding their interrelationships.

\textbf{Definition:} The \gls{te} counts the proportion of input data points for which the two closest neurons, the \glspl{bmu}, are not adjacent to each other on the map. The \gls{bmu} is the neuron that most closely matches a given input vector. For an ideal map that preserves topology perfectly, the two closest neurons should always be adjacent to each other. When this does not happen, the map has failed to preserve the topological relationships of the input data. The \gls{te} \(TE\) is computed as:

\[
T(\mathbf{x}_i) = \begin{cases}
1 & \text{if the two closest neurons are not adjacent on the map} \\
0 & \text{if the two closest neurons are adjacent}
\end{cases}
\]

\begin{equation}
    TE = \frac{1}{N} \sum_{i=1}^{N} T(\mathbf{x}_i)
\end{equation}
    

where \(T(\mathbf{x}_i)\) represents the \gls{te} for the \(i\)-th input vector, and \(N\) is the total number of data points in the dataset. Essentially, the function \(T(\mathbf{x}_i)\) returns a value of 1 if the two closest neurons are not adjacent on the map and 0 if they are adjacent. The overall \gls{te} \(TE\) is then computed by averaging these values over all input vectors in the dataset.

\textbf{Interpretation:}
A low \gls{te} (close to 0) indicates that the \gls{som} has done an excellent job of preserving the topology of the input data. In this case, similar data points are mapped to nearby neurons, which is essential for generating smooth modulation paths between musical scales. This low error signifies that the map has captured the inherent relationships between the input data, ensuring that musical scales with similar characteristics are placed in close proximity on the map. For instance, scales with similar intervals or tonal structures will be grouped together, facilitating smooth transitions during modulation.
A high \gls{te} suggests that the \gls{som} has failed to preserve the topology effectively. This results in a less accurate representation of the relationships between the data points. In the context of musical scales, a high \gls{te} means that similar scales may be placed far apart on the map, which could lead to abrupt transitions between them during modulation. This is undesirable because it could result in a less natural flow between the scales, potentially creating discordant or jarring musical modulations.

In practice, minimizing \gls{te} is important for ensuring that the map can be used to generate smooth and musically coherent transitions between scales. However, it is also essential to find a balance, as a very low \gls{te} might sometimes imply overfitting to the specific data, making the map less generalizable to new data. Therefore, achieving an optimal balance between \gls{te} and the overall representation of the data is a key factor in the successful use of the \gls{som} for musical modulation.

Figure \ref{fig:figure19} illustrates a method of evaluation using \gls{te}, which measures the preservation of neighborhood relationships by assessing how often the Best Matching Unit and its second-best match are adjacent. The figure demonstrates the concept of \gls{te}, where the relative position of the closest neurons is evaluated to determine how well the \gls{som} preserves the topological relationships of the input data.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (28).png}
    \caption{Evaluating \gls{te} by checking \gls{bmu} adjacency.}
    \label{fig:figure19}
\end{figure}

\subsection{Reconstruction Percentage}

\gls{rp} is a metric used to measure how well the \gls{som} preserves the original input data after it has been mapped onto the grid. Essentially, this metric evaluates how accurately the map represents the positions of the input data points in the output space, after the training process has been completed. In the context of musical scales, this is particularly important because the \gls{som} must retain the key structural features of the input data (such as interval patterns and tonal relationships) to ensure that the modulation paths generated are musically meaningful and coherent \cite{87}. The higher the \gls{rp}, the more faithfully the map has preserved the input data, which is essential for generating transitions between scales that are both musically accurate and smooth \cite{88}.

\textbf{Definition:} The \gls{rp} is calculated by comparing the positions of the original input data points with the positions of the neurons in the trained \gls{som} after the mapping process. It is expressed as the ratio of accurately reconstructed points to the total number of data points, multiplied by 100 to provide a percentage. Formally, the \gls{rp} can be expressed as:

\begin{equation}
    \text{Reconstruction Percentage} = \frac{\text{Number of accurately reconstructed points}}{\text{Total number of points}} \times 100
\end{equation} 

\begin{itemize}
    \item \textit{Number of accurately reconstructed points}: Refers to the data points for which the output map provides a sufficiently close match to the original input data in terms of position or structure.
    \item \textit{Total number of points}: Refers to the total number of data points in the dataset being evaluated.
\end{itemize}

This formula provides a straightforward way of quantifying how well the map has preserved the structure of the input data after training.

\textbf{Interpretation:}
A higher \gls{rp} indicates that the map has done an excellent job of retaining the original data’s structural integrity. In the context of musical scales, this suggests that the relationships between notes and intervals within the scales have been effectively preserved, ensuring that the musical features that define the scales, such as tonal structures and modal relationships, remain intact. This, in turn, makes the generated modulation paths more reliable and coherent, leading to smooth transitions between scales that accurately reflect their inherent musical qualities. A high \gls{rp} also implies that the trained \gls{som} is capable of accurately representing the underlying patterns in the input data, which is essential for ensuring that modulation transitions between scales are musically valid. Essentially, a higher \gls{rp} means that the map has not only clustered the scales based on their similarities but has also done so in a way that preserves their fundamental musical relationships, making the \gls{som} more effective in creating meaningful modulations.

A lower \gls{rp} indicates that the \gls{som} has failed to preserve some of the original data’s structure. This could mean that certain critical features, such as intervals, tonal relationships, or modal qualities, were lost or distorted during the mapping process. As a result, the modulation paths generated using such a map may not accurately reflect the relationships between the scales, leading to less accurate or musically inconsistent transitions. This can be particularly problematic in the context of complex musical structures, where even small changes in interval patterns or tonal relationships can have a significant impact on the emotional and tonal qualities of the music, potentially resulting in modulations that feel abrupt or unnatural. A lower \gls{rp} might indicate that the model has failed to capture the full richness of the input data, which could undermine the validity of the modulation paths.

To ensure the \gls{som} is effective for generating smooth modulation paths, a high \gls{rp} is desirable. This ensures that the map captures the essential characteristics of the input data, such as intervallic relationships and tonal structures, and that the modulation paths derived from it preserve these musical relationships. A well-trained \gls{som} with a high \gls{rp} ensures that modulation transitions will be musically valid, smooth, and coherent, allowing for a natural progression from one scale to another. On the other hand, a low \gls{rp} suggests that the model may need further tuning, such as adjusting the training parameters (\gls{lr}, neighborhood radius) or increasing the complexity of the map (e.g., adding more nodes or increasing map resolution), to better capture the nuances of the input data and to improve the accuracy and musical validity of the generated modulations.

In Figure \ref{fig:figure20}, a method of evaluation using \gls{rp} is presented. This metric measures how accurately the input data can be recreated based on the learned representations of the trained model. The figure illustrates the process of comparing original data points with the positions of neurons in the trained \gls{som} to evaluate how well the map has preserved the original structure.  

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (32).png}
    \caption{Assessing reconstruction accuracy by comparing input data with \gls{som} neurons.}
    \label{fig:figure20}
\end{figure}

\section{Experimental Setup}

For the experiments, we systematically varied the parameters of the \gls{som} model, including map dimensions, \acrfull{sv}, \gls{lr}, and \acrfull{ni}. These parameters significantly impact the \gls{som}'s ability to generate accurate modulation paths. By adjusting them, we aimed to identify the optimal configuration that maximizes performance across the key evaluation metrics: \gls{qe}, \gls{te}, and \gls{rp}.

The first set of experiments focused on varying the dimensions of the map. We kept the \gls{sv}, \gls{lr}, and \gls{ni} constant during this phase. This allowed us to isolate the effect of the map's dimensions on the \gls{som}'s performance. The chosen constant values for these parameters were carefully selected based on preliminary trials to ensure a stable and efficient training process. The specific constant values were:

\begin{itemize}
    \item \gls{sv}: 0.5
    \item \gls{lr}: 0.1
    \item \gls{ni}: 1000
\end{itemize}

To evaluate dimension's impact on the \gls{som}'s ability to represent musical scales effectively ww should adjust it. Larger maps, containing more neurons, captured finer details and provided a more precise representation, particularly beneficial for complex musical structures like microtonal scales. However, this increased resolution came at the cost of longer training times, higher computational demands, and the need for careful parameter tuning, such as adjusting the \gls{lr} and neighborhood radius.

In contrast, smaller maps trained faster, required fewer computational resources, and simplified parameter adjustments. However, they lacked the granularity needed to preserve subtle relationships between scales, potentially resulting in less accurate modulation paths. Therefore, selecting the appropriate map size required balancing precision with efficiency based on the specific application needs.

In Figure \ref{fig:figure21}, a table presents the evaluation of \gls{som} performance across different \gls{lr} and iteration values, while keeping other parameters constant. This experiment allowed us to observe the effect of \gls{lr} and the \gls{ni} on the \gls{som}'s accuracy and performance. By varying these parameters, we assessed how quickly the \gls{som} converged and how well it captured the underlying structure of the input data. The results of this evaluation are summarized in the table shown.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (34).png}
    \caption{Evaluation of \gls{som} performance across different \gls{lr} and \gls{ni}.}
    \label{fig:figure21}
\end{figure}

In Figure \ref{fig:figure22}, the evaluation of \gls{som} performance across different map dimensions and \glspl{sv} is presented, while keeping other parameters constant. This set of experiments focuses on analyzing the relationship between map size, \gls{sv}, and the quality of the \gls{som} representation. The results allowed us to assess how these parameters interacted with each other and their effect on the map's ability to represent the input data and generate smooth modulation paths.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (35).png}
    \caption{Evaluation of \gls{som} performance across different map dimensions and \glspl{sv}.}
    \label{fig:figure22}
\end{figure}

Thus, by experimenting with different map dimensions, we sought to determine the optimal balance between detail and computational efficiency. The results of these experiments were crucial in understanding how the map's size affects the performance of the \gls{som}, particularly in its ability to generate modulation paths that accurately reflect the musical relationships between the scales. Additionally, we observed how changes in the map dimensions influenced the other evaluation metrics, providing us with insights into the overall effectiveness of the \gls{som} and its ability to preserve the structural integrity of the musical data.

In the second set of experiments, we focused on varying the \glspl{sv} while keeping the map dimensions constant at 60 × 60. This approach enabled us to examine the specific effect of the \gls{sv} on the overall performance of the \gls{som} model. The \gls{sv} controls the width of the neighborhood function during training, and adjusting it can influence how the weights of neighboring neurons are updated during each iteration. A higher \gls{sv} results in a wider neighborhood and more significant weight adjustments, which may lead to faster convergence. In contrast, a lower \gls{sv} limits the neighborhood's influence and allows for more fine-grained adjustments to individual neurons, potentially leading to a more precise map representation.

Through these experiments, we sought to identify the optimal \gls{sv} that balanced the model's ability to capture the underlying musical data structure while maintaining the smoothness and coherence of the generated modulation paths.

\section{Impact of Map Dimensions on Criteria}

The results of the experiments revealed that the dimensions of the \gls{som} have a significant impact on the model's overall performance, particularly in terms of the three key evaluation criteria: \gls{te}, \gls{qe}, and \gls{rp}. During the experimentation process, it became evident that increasing the number of neurons in the map (i.e., expanding the map dimensions) had both positive and negative effects on these performance metrics. Specifically, we observed that as the map's dimensions increased, there was a noticeable reduction in the \gls{te}, which indicated a better preservation of the input data's topology. This was expected, as a larger map allows for more neurons to be available for mapping the data, leading to a finer representation of the data relationships and smoother modulation paths.

However, this improvement in \gls{te} was accompanied by some trade-offs. As the number of neurons increased, the \gls{qe} also increased, indicating that the map's neurons were not as accurately representing the input data as they did in smaller maps. This could be due to the map's larger size, which, although offering more neurons, also means that some neurons are farther from the actual input data points, leading to larger distances between the data and their \glspl{bmu}. Consequently, a higher \gls{qe} was observed.

Additionally, the \gls{rp} decreased as the map dimensions increased. This suggests that although the map was able to preserve the topological structure of the data better, it was not as effective at maintaining the original data's precise structure in terms of reconstruction. The increased map size led to a loss of some of the finer details of the input data, which affected the \gls{rp} negatively.

Given these observations, it became clear that optimizing the map dimensions was crucial for achieving the best possible performance across all evaluation metrics. The trade-offs between \gls{te}, \gls{qe}, and \gls{rp} had to be carefully considered. Based on the experimental results and the analysis of these trade-offs, the optimal map dimension was determined to be 240 × 240. This configuration yielded the best balance between the three key criteria, ensuring that the model could preserve the input data's topology while also maintaining a reasonable level of \gls{qe} and reconstruction accuracy.

Through the various experiments conducted with different map dimensions, it was clear that the optimal choice of map size directly influenced the model's ability to generate smooth and accurate modulation paths. The 240 × 240 map dimension not only improved the preservation of the data structure but also helped in creating more coherent modulation transitions, which is essential for the smoothness and musical integrity of the generated paths.

In \ref{fig:figure23}, the chart presents an in-depth analysis of the impact of map dimensions on the performance of the \gls{som}, focusing on the trade-offs between \gls{te}, \gls{qe}, and \gls{rp}. The horizontal axis represents the map dimension, denoted as \(N \times N\), where \(N\) refers to the number of neurons in each direction of the two-dimensional map grid. This dimension is varied to observe how different map sizes affect the \gls{som} performance.

The vertical axis displays the \textbf{Normalized Metric Value}, which is a measure used to evaluate the different error metrics and \gls{rp} on a normalized scale for comparison. The chart compares the behavior of three key performance metrics as the map size increases:
\begin{itemize}
    \item \textbf{\gls{te}}: As the map size increases, we observe improvements in \gls{te}, indicating that larger maps preserve the spatial relationships between nodes better.
    \item \textbf{\gls{qe}}: Conversely, the \gls{qe} tends to rise as the map size increases. This shows that larger maps may fit the input data less precisely, as the resolution of the map grows, leading to more generalization of the data.
    \item \textbf{\gls{rp}}: There is also a noticeable decline in \gls{rp} as the map size increases. This suggests that although the map may represent the data's topography more accurately, the ability to perfectly reconstruct the input data from the map decreases, indicating a trade-off between capturing topographic relationships and maintaining data fidelity.
\end{itemize}

Figure \ref{fig:figure23} demonstrates the inherent trade-offs that need to be carefully balanced during \gls{som} training and map optimization. The chart emphasizes the need to fine-tune parameters for achieving the best performance in terms of both accuracy and computational efficiency.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (36).png}
    \caption{Impact of map dimensions on \gls{som} performance, showing the trade-off between \gls{te}, \gls{qe}, and \gls{rp}. As map size increases, \gls{te} improves, while \gls{qe} rises and \gls{rp} decreases.}
    \label{fig:figure23}
\end{figure}

Calculation of the optimal 240 × 240 map dimension, achieving the best balance across all evaluation criteria. This configuration represented the sweet spot where the \gls{som} could effectively preserve the input data's topology, reduce \gls{qe}, and maintain an adequate \gls{rp}. The chart in Figure \ref{fig:figure24} shows the results, plotting \textbf{SOM Dimension (N×N)} on the horizontal axis and \textbf{Normalized Metric Value} on the vertical axis. The formula used for determining the best configuration is in the Figure \ref{fig:figure24}.

\textbf{Note}: Lower values indicate better performance for \gls{qe}, higher for \gls{te}, and higher for \gls{rp}.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (37).png}
    \caption{Optimal 240 × 240 map dimension, balancing evaluation criteria for effective topology preservation, minimized \gls{qe}, and maintained \gls{rp}.}
    \label{fig:figure24}
\end{figure}

\section{Trade-off Between Criteria}

An interesting observation that emerged from the experimental analysis was the trade-off between the three key evaluation criteria: \gls{te}, \gls{qe}, and \gls{rp}. As the map dimensions and \glspl{sv} increased, we noticed a significant improvement in the \gls{te}, suggesting that the map was better preserving the topology of the input data. This improvement in \gls{te} meant that the map was more accurately representing the relationships and spatial arrangement of the input data, which is crucial for ensuring that related data points were positioned closer to each other in the map’s structure. However, this improvement in \gls{te} came at the expense of the other two metrics, as both the \gls{qe} and \gls{rp} worsened. This trade-off indicates that optimizing for one evaluation criterion such as \gls{te} can lead to the degradation of another, like \gls{qe} or \gls{rp}. The challenge in training the \gls{som} lies in balancing these competing factors, where improving one criterion might inadvertently worsen others.

In practical terms, this means that finding the optimal configuration for the \gls{som} involves carefully navigating this delicate balance between the different evaluation criteria. A configuration that minimizes \gls{te} may not necessarily lead to the best representation of the input data in terms of quantization or reconstruction accuracy. The relationship between the criteria was complex and required thoughtful consideration of how different parameters influenced the model's behavior. For example, a larger map or a higher \gls{sv} could lead to a more accurate representation of the data’s topological structure by providing more neurons and allowing for a more detailed organization of the data. However, these adjustments might also increase the distance between data points and their corresponding \glspl{bmu}, thus raising the \gls{qe}. This happens because as the map becomes more detailed, the neurons can drift further apart, leading to a less precise match between the input data and the closest node in the grid. Similarly, larger map dimensions and higher \glspl{sv} could cause the map to lose some of the finer details of the data’s structure, negatively impacting the \gls{rp}. These losses in reconstruction fidelity can have significant implications when it comes to the model’s ability to accurately represent the original input data, which is a critical aspect of ensuring the \gls{som}'s ability to generate smooth and meaningful modulation paths between scales.

This delicate balance between the three criteria is one of the central challenges in \gls{som}-based music modulation path generation. The trade-offs and interactions between \gls{te}, \gls{qe}, and \gls{rp} highlight the complexity of training the \gls{som} to effectively capture the nuances of musical scales. Addressing this challenge requires careful tuning of the model's parameters and a comprehensive understanding of how adjustments to the map dimensions, \gls{sv}, and \gls{lr} affect the model's ability to generate both accurate and meaningful results.

To tackle this challenge, we normalized the values of all three evaluation criteria to ensure that they could be compared on a similar scale. Normalization allowed us to account for the differences in magnitude between the metrics, making it easier to compare them directly and identify which configuration resulted in the most balanced performance. This step also facilitated a more objective comparison between different parameter configurations, as it ensured that no single criterion dominated the evaluation process due to differences in scale. The inverse of the \gls{rp} was used for normalization purposes, as lower \gls{rp}s represent poorer performance, and we wanted a lower value to indicate better performance, consistent with the other metrics. By normalizing the data in this way, we ensured that all evaluation criteria were treated equally, and the final assessment of the \gls{som}'s performance was more reflective of its overall ability to generate smooth, musically valid modulation paths.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (39).png}
    \caption{A 3D visualization of the trade-off among all three evaluation criteria, illustrating the complex relationship between \gls{te}, \gls{qe}, and \gls{rp}. This visualization helps in understanding the interplay between the metrics and the need for careful parameter selection.}
    \label{fig:figure25}
\end{figure}

Once the values of the three criteria \gls{qe}, \gls{te}, and \gls{rp} were normalized, we computed the sum of the normalized values, giving equal weighting to each criterion. This approach allowed us to quantify the overall performance of the \gls{som} and, by doing so, systematically assess how well the \gls{som} was performing across all aspects. The normalization process was crucial because it ensured that each criterion contributed equally to the final evaluation, removing any biases that might arise due to differing scales or units of measurement across the three criteria. By treating each criterion with equal importance, we were able to assess the \gls{som}'s performance in a more holistic manner, considering both the precision of the map's clustering ability and its overall structural integrity.

After the normalization, we proceeded to compute the sum of the normalized values for each experiment. This sum, which represented the cumulative performance of the \gls{som} across all criteria, enabled us to pinpoint the configuration that provided the best balance between the different aspects of the map’s behavior. The goal was to identify a configuration that minimized the sum of the normalized values, as this would indicate the optimal balance across all three criteria, ensuring that no one aspect of the map’s performance was disproportionately prioritized over the others. Through this process of summing the normalized values and minimizing them, we were able to systematically refine the \gls{som}'s configuration until we identified the optimal configuration that achieved the best overall performance.

Through an extensive and iterative process of evaluating and refining the Self-Organizing Map (\gls{som}), we were able to determine the optimal configuration that best met the needs of the model. The final configuration consisted of a map dimension of 242 × 242, a \gls{sv} of 6, a \gls{lr} of 0.9, and 100,000 iterations. This setup provided the ideal balance across the three main evaluation criteria: quantization error (\gls{qe}), topographic error (\gls{te}), and reconstruction percentage (\gls{rp}). By carefully adjusting these parameters, we achieved the most accurate clustering results, minimized the \gls{te}, and maximized the \gls{rp} values.

The choice of a map dimension of 242 × 242 was essential, as it ensured that there were enough neurons to adequately capture the subtle relationships and variations present between the different musical scales, all while keeping computational demands at a manageable level. The \gls{sv} of 6, in conjunction with the \gls{lr} of 0.9, allowed for a more efficient training process, ensuring that the \gls{som} model could converge at an optimal rate while preserving accuracy. Additionally, the 100,000 iterations provided ample time for the model to learn and stabilize, ensuring that it was capable of delivering the best possible performance across all evaluation metrics.

In Figure \ref{fig:figure26}, we present the grid search results for optimizing the \gls{som} configuration. The figure includes heatmaps for the three evaluation metrics \gls{qe}, \gls{te}, and \gls{rp} from left to right. The optimal configuration was determined by minimizing the sum of all three normalized values, which underscores the importance of a multi-criteria optimization approach in obtaining the most effective configuration for the \gls{som} model. This thorough evaluation of parameters ensures that the model can effectively balance all key metrics, contributing to more accurate and reliable results.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (54).png}
    \caption{Grid search results for \gls{som} optimization, displaying heatmaps of \gls{qe}, \gls{te}, and \gls{rp}, with the optimal setup found by minimizing their summed normalized values.}
    \label{fig:figure26}
\end{figure}

With the optimal configuration determined, the following results in figure \ref{fig:figure27} were obtained, showcasing the best balance between the evaluation metrics. These results are crucial for ensuring that the \gls{som} model generates smooth and musically coherent modulation paths between scales.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (40).png}
    \caption{Optimal \gls{som} results, showing the best balance of \gls{qe}, \gls{te}, and \gls{rp} for generating smooth musical transitions.
    }
    \label{fig:figure27}
\end{figure}

To optimize the \gls{som} configuration, we conducted a grid search, varying the \gls{lr} and \gls{ni}, while adjusting map dimensions and \glspl{sv}. This helped identify the best combination of parameters for improved model performance and smoother modulation paths, enhancing the \gls{som}’s effectiveness in musical scale analysis.

Figure \ref{fig:figure28} shows three plots from the grid search for optimizing \gls{som} configuration by varying learning rate, iterations, map dimensions, and sigma values to balance quantization error, topographic error, and reconstruction percentage. The grid search approach enabled a thorough evaluation of the parameter space and identification of the optimal parameter set.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (41).png}
    \caption{Grid search optimizing \gls{som} configuration by varying \gls{lr}, iterations, map dimensions, and \glspl{sv} to balance \gls{qe}, \gls{te}, and \gls{rp}, identifying the best parameter set.}
    \label{fig:figure28}
\end{figure}

Finally, these values, which represent the optimal configuration, led to the best possible balance between the three evaluation metrics. The \gls{som} model was thus optimized to generate smooth modulation paths between musical scales, with minimized trade-offs between the evaluation criteria. This process of careful optimization ensures that the generated paths preserve musical relationships while achieving the desired smoothness in transitions.
Figure \ref{fig:figure29} illustrates the optimal values, showing the best balance between the three evaluation metrics, resulting in the most effective configuration of the SOM model. This optimized setup ensures smooth modulation paths between scales, highlighting the model's utility in both music theory and computational music applications.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (42).png}
    \caption{Optimal values balancing evaluation metrics for \gls{som} optimization in generating smooth modulation paths.}
    \label{fig:figure29}
\end{figure}

\section{Qualitative Evaluation of the Model}
The quality of the generated modulations was assessed through both objective and subjective evaluation methods. The objective analysis involved calculating the differences between adjacent steps in the modulation path to quantify the smoothness of the transition between scales. Specifically, we calculated the difference between each pair of corresponding items in the two adjacent step lists. The result of the average difference was computed for 50 random but conventional scales in music. The results were then averaged to provide an overall measure of the modulation system's performance.

\textbf{Analyzing the Step Differences:} The step differences were calculated as the absolute difference between the corresponding items in two adjacent lists. These differences reflect the transitions between the musical scales and provide insight into the smoothness of the modulation process.

In Figure \ref{fig:figure33}, this is illustrated by comparing two consecutive steps in the proposed modulation path. The quarter-tone differences between each adjacent step within an 8-tone musical framework are analyzed, allowing the quantification and averaging of the differences between the two steps.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (48).png}
    \caption{A proposed path between two scales, where quarter-tone differences between adjacent steps are analyzed and averaged within an 8-tone framework.}
    \label{fig:figure33}
\end{figure}

\textbf{Result of Average Difference:} We calculated the average difference across 50 randomly selected scales, and the results were stored in a list. The average of these values was calculated to give an overall measure of the quality of the modulation system. The following list of average differences was obtained for the 50 scales:

In Figure \ref{fig:figure34}, the table shows the average difference values calculated across 50 randomly selected scales, which helps to illustrate the smooth transitions generated by the modulation system. These values represent the consistency and quality of the modulation process as it moves between different scales. The final average of 0.23 falls well within the acceptable range, which indicates that the system is effectively generating smooth and accurate modulation paths between scales. This confirms that the system is performing as expected and ensuring seamless transitions in the musical composition.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (49).png}
    \caption{Average difference values across 50 scales, with a final average of 0.06, confirming smooth transitions.}
    \label{fig:figure34}
\end{figure}

The average of these 50 experiences was found to be approximately 0.06, which falls well within the acceptable range of 0.06 < 0.23 < 0.50. This result confirms that the modulation system generates smooth transitions between scales.

\textbf{Survey on Modulations Between Scales:} After the modulation steps are generated by the system, we use a melody generator to create an auditory piece by following this path with a random melody. The frequencies of the notes are chosen randomly, but the likelihood of selecting the note-based step is higher than the others. The status of all notes follows the scale's pattern, with each note's duration set to one quarter note. The significance of this melody lies in its adherence to the modulation path rather than the aesthetic quality of the melody. We expect that the listener may not notice the changes in scales and modes, but there will be a transition from the source scale to the destination scale in terms of note statuses and sounds.
This melody generator is written in Python and uses the "MIDO" library \cite{mido2025}, which creates \acrfull{midi} files. The only limitation of this library is its inability to generate microtones, so we have had to generate melodies using scales that include half-step intervals.
To further validate the effectiveness of the modulation generation system, a web-based survey was conducted where users were asked to listen to 28 generated melodies and rate them based on the smoothness of the modulation.
In Figure \ref{fig:figure35}, using the \gls{midi} audio file generated by the melody generator, we capture the tablature image of the melody in Mixcraft software \cite{mixcraft2025}. This image includes a timeline diagram of when each note is played. From this diagram, it is clear that the frequency of note-based steps is higher than that of other notes in each step.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (47).png}
    \caption{Tablature image generated by Mixcraft, displaying the melody's note-based structure in \gls{midi} format.}
    \label{fig:figure35}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (50).png}
    \caption{The image displays a custom-designed online survey that enables users to provide ratings after listening to the melodies. The ratings scale ranges from 1 to 5.}
    \label{fig:figure36}
\end{figure}

The questionnaire in figure \ref{fig:figure36} was designed to gather feedback on the perception of subtle modulations within musical melodies. The objective was to evaluate how smoothly the key or mode changes occurred within a piece, and whether these transitions were noticeable to the listener. The melodies presented in this questionnaire contained several modulations, where the changes in tonality or mode were gradual and intended to be as seamless as possible. 

Participants were provided with a series of audio files, each containing a melody that underwent multiple modulations throughout its course. The changes in key or mode were purposefully subtle, with the goal of ensuring that the transitions between keys or modes occurred smoothly, without causing an abrupt or jarring shift in the melody. 

As the participant listened to each melody, they were asked to pay close attention to any moments where the tonality or mode of the melody shifted. The modulations were intended to be perceived as a natural evolution of the melody, ideally happening without drawing much attention. This exercise was meant to test the effectiveness of these subtle modulations in achieving a seamless transition between musical scales.

After listening to each of the provided files, the participant was asked to rate their perception of the modulations on a scale from 1 to 5. The scale was defined as follows:

\begin{itemize}
    \item \textbf{1:} The participant clearly noticed the changes in key or mode, and the transition was not smooth. The modulation was easily perceptible and disrupted the flow of the melody.
    \item \textbf{2:} The participant noticed the changes, but the transition was somewhat smooth. However, the key or mode change still felt somewhat abrupt or noticeable in places.
    \item \textbf{3:} The participant noticed the changes to some extent, but the modulation felt relatively smooth and blended into the melody. There were minor disruptions in the flow, but they did not significantly affect the listening experience.
    \item \textbf{4:} The participant could hardly notice the changes, and the modulation felt quite seamless. The transition was subtle but detectable if paying close attention.
    \item \textbf{5:} The participant did not notice any changes in the key or mode at all, and the modulation was as subtle as intended. The transitions were so smooth that they went unnoticed throughout the melody.
\end{itemize}

It is important to note that each of the melodies contained between 5 and 20 modulations. These changes were spread throughout the melody, and the participant's task was to evaluate how seamlessly these modulations occurred. The rating should reflect their perception of the fluidity and naturalness of the key or mode changes. Each file was rated individually, based on the participant's experience of listening to the modulation transitions.

\textbf{Participant Information:}
To begin the survey, the participant was asked to enter their name. This information helped to organize and analyze the results of the questionnaire.

The participant's feedback was crucial in improving the understanding of subtle modulation techniques in music.
To analyze the survey results, we first collected all the votes and calculated the mean scores for each melody. Missing values were not considered in the calculation of the averages for each melody. The results of these averages are presented in the table in Figure \ref{fig:figure37}.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (51).png}
    \caption{The survey results reflect the average ratings assigned to each melody.}
    \label{fig:figure37}
\end{figure}

\textbf{Analyzing the Step Differences:} In addition to the previous evaluation, another qualitative assessment was conducted, where several melodies featuring modulations were carefully selected. The modulation steps in these melodies were documented by paying close attention to key changes and shifts in the axis notes during the transitions. These changes were recorded and analyzed in detail. The next step involved comparing the modulation paths generated by the system with the expected paths based on the starting and destination keys of each song.

To perform this analysis, we compiled a collection of songs featuring modulations, taking note of the specific key changes and any shifts in the axis notes. The modulation paths were then organized into a list. For each modulation, the system was provided with the starting key and the target modulation key, and the system proposed its own modulation path. We compared the proposed path with the actual modulation steps in the melody and documented which steps were present or absent in the system's suggestion.

The following steps summarize the approach:

\begin{itemize}
    \item The starting and ending points of the modulation were given to the system.
    \item The system generated a proposed modulation path based on the provided keys.
    \item The steps in the system's proposed path were compared to the steps that occurred in the expected modulation.
    \item We calculated the \acrfull{tpr} by dividing the number of expected steps that the system proposed correctly by the total number of expected steps.
    \item Similarly, the Miss Rate or \acrfull{fnr} was calculated by dividing the number of expected steps that the system failed to propose by the total number of expected steps.
\end{itemize}

As an example, consider Adele's song \textit{All I Ask}, which modulates from E Major to F Major. The following steps are observed in the modulation:

\begin{itemize}
    \item E Major, Axis note: B
    \item E Major, Axis note: A
    \item E Major, Axis note: E
    \item E Major, Axis note: F\#
    \item F Major, Axis note: A
    \item F Major, Axis note: B\# 
\end{itemize}

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (52).png}
    \caption{An example showing the comparison of 'hit' and 'miss' between the actual modulations previously created by the composer and the proposed path between the source and destination scales by the application.}
    \label{fig:figure38}
\end{figure}

\textbf{Hit vs. Miss:} The "hit" refers to the modulation steps that the system correctly proposed, and the "miss" refers to the steps that the system did not propose but were expected.

This method was applied to 40 different pieces of music. Each song's modulation was analyzed, and the expected steps were compared to the system’s proposed modulation paths.

The hit rate (\gls{tpr}) and miss rate (\gls{fnr}) were calculated based on the number of steps that were correctly proposed and those that were missing, as follows:

\begin{equation}
    \text{Hit Rate (TPR)} = 100 \times \frac{\text{True Positives}}{\text{Total Expected Steps}}
\end{equation}
    
\begin{equation}
    \text{Miss Rate (FNR)} = 100 \times \frac{\text{False Negatives}}{\text{Total Expected Steps}}
\end{equation}
    

For this evaluation, the results are summarized as follows:

\begin{figure}[H]
    \centering
    \includegraphics[width=1.0\linewidth]{images/chapter5/Figure (53).png}
    \caption{The table presents the results based on the occurrence of 'hit' and 'miss' between the actual modulation path in the songs and the path suggested by the application, which were used to calculate \gls{tpr} and \gls{fnr}.}
    \label{fig:figure39}
\end{figure}

The TPR value was deemed acceptable, but the reason for the 17\% \gls{fnr} could be attributed to several factors:

\begin{itemize}
    \item Measurement errors during the analysis.
    \item Errors in the construction of the self-organizing map.
    \item Non-gradual changes intentionally introduced by composers in some of the melodies used in the study.
\end{itemize}

Since the self-organizing map was specifically designed to focus on gradual changes, the system tended to propose more modulation steps than were actually present in the expected paths. This led to a higher rate of steps being proposed by the system, contributing to the calculated \gls{fnr}. In many cases, composers deliberately included sudden or dramatic modulations, which did not align with the map's focus on gradual transitions. This discrepancy further explains the 17\% \gls{fnr} observed in this evaluation.

\section{Evaluation of Modulation Paths}

After the \gls{mp} are generated, they are evaluated using both objective and subjective methods. Automatically, after training, the map contains clusters of musical scales that have been formed based on updates through the \gls{bmu} and neighborhoods. These updates ensure that similar scales are grouped together, reflecting underlying patterns in the data.

\begin{itemize}
    \item \textbf{Step Differences:} The step difference between adjacent nodes in the modulation path is calculated. A smaller step difference indicates a smoother transition, while a larger step difference suggests a more abrupt modulation. The goal is to ensure that the step differences are minimal, resulting in a seamless flow from one scale to another. This measure is important because abrupt jumps between scales may break the tonal coherence of the music, leading to a less pleasant listening experience. By minimizing these differences, we can create modulation paths that feel natural and fluid.
    \item \textbf{True Positive Rate:} The \gls{tpr} is used to measure the accuracy of the generated modulation paths. The \gls{tpr} is computed by comparing the generated paths with known modulation examples from musical theory. A high \gls{tpr} indicates that the generated modulation paths align with the expected patterns of modulation. This metric serves as a key objective evaluation tool, allowing us to quantify how closely the generated paths match traditional musical knowledge and theory.
    \item \textbf{User Evaluation:} A user survey was conducted with participants from the Polytechnic University of Turin. Participants were asked to listen to sample melodies that followed the generated modulation paths and rate the perceived smoothness of the transitions. Feedback from the users was used to assess the emotional impact of the modulation and to refine the model further. This subjective evaluation helps capture the human experience of the music, which may not always be fully represented in objective measures. It provides valuable insights into the effectiveness of the modulation paths in evoking the intended emotional responses.
\end{itemize}