Team:Peking/Fitness function

Scoring Algorithm

In order to simulate the mutation and evolution of music in the computer, we need to design a scoring function to judge the melody of the music.

We score the music from three dimensions: within a bar, between bars, and the entire phrase, using a way of combining music theory with actual music patterns. Because music theory often only stipulates the general framework of the music, we score the two dimensions of the inter-measure and the whole phrase based on the music theory. For the scoring within the bar, we used the method of comparing it with some known pleasing musical patterns and calculating the distance.

The main basis for scoring between the bars is the fourth-degree tendency of the chord progression. While the judgment of the fourth-degree tendency first needs to determine the chord of the bars.

The most commonly used chords for a composition in C major are C, F, and G, which forms the chord progression by interconversion. C chord (including C, E, and G) is called the tonic chord, G (including G, B, D) chord is called the dominant chord, F (including F, A, C) chord is called the sub dominant chord.

We use three chords C, G and F to denote the chord of each bar, and regard the note at the downbeat of each bar as the chord note. (neglect the rest or the extended tone)

We can establish a one-to-one correspondence between the chord tones and the chords: C→C chord; D→G chord; E→C chord →F chord; G →G chord; A →F chord; B →G chord. Thus, we have determined the chord of each bar, and therefore determined the pattern of chord progression of the whole composition.

The fourth-degree tendency is a rule of conversion between the chords. For instance, if the chord of a bar is tonic chord, it will make the melody more pleasant if the chord of next bar is sub dominant chord. On the contrary, it will make the melody lack vitality if the chord of next bar is tonic or dominant chord. By analogy, we give the following chord progression scoring rules: starting from the first chord, fix one chord at a time to see the relationship between it and the next chord; and then we can give out a scoring table according to the tendency between the chords (fourth-degree tendency):

Note: The first column in the table represents the target chord, the first row represents the next chord)

C G F
C -1 1 2
G 2 -1 1
F 1 2 -1

Finally, take an average of the scores obtained as the final score of this dimension.

Phrase scoring is based on the cadence of the phrase. In order to determine the cadence, we first need to determine the demarcation point of the phrase, that is, where the melody progresses are counted as the end of the previous phrase and the beginning of the next phrase.

The composition of a phrase has a cause (initial note), passing (passing note) and result (sustained note). Generally speaking, a phrase ends with a rest or a sustained note that is longer than 1 beat. So, we can simply use this situation to divide the phrase: Judge the appearance of sustained note and rest of the whole composition, if this happens at the end of a bar (i.e. there are no other notes after the sustained note or the rest), then define it as a termination of the phrase. The condition that upbeat to start the phrase is also illustrated in the figure below

Now we have divided a piece of music into phrases. It should be noted that there is no need to consider the scoring rules of chord progression and melody progression between the end of the phrase and the beginning of the next phrase. Now we will introduce the scoring method for the cadence of the phrase.

For the end of a phrase, we generally classify the cadence into several categories, including perfect cadence (full stop), imperfect cadence (comma), and half cadence (semicolon), which reflects the stability of the music. If the phrase does not end at a specific cadence, it will give us a feeling that the tension has not been released. Therefore, for the rule-abiding sustained note or the note before the qualified rest, we apply the following scoring method:

Note Score
C (perfect cadence) 1
E (imperfect cadence) 1
D, G, or B (half cadence) 1
others -1

After that, we take the average of all scores for the cadence as the final score.

So, whether the aforementioned method effectively judge the soundness of a melody? We carried out a test. We chose two sets of melodies, one of which is popular song melodies created by celebrated composer, and the other is random melodies generated by the computer, which are irregular noises for us. And then we scored the two sets of melodies respectively. The figure below shows the scoring results. It can be seen that our scoring function can effectively judge the melody of the musical composition.