## 3 Onset Detection
```
1:\(t\gets 0\);
2: Set current individual \(I_{0}\) as the best of \(\lambda\) individuals created randomly;
3:while a stop condition is not fulfilled, do
4:for i = 1 to \(\lambda\)do
5: Create a copy \(x_{i}\) of current individual \(I_{t}\);
6: Mutate each gene of \(x_{i}\) with probability \(p\);
7:endfor
8: Set new current individual \(I_{t+1}\) as the best of \(I_{t}\cup\{x_{1},\ldots,x_{\lambda}\}\);
9:\(t\gets t+1\);
10:endwhile
```

**Algorithm 2** Algorithm \(((1+\lambda)EA)\). This means that, in this special case, the population size is always \(1+\lambda\). First, we select the best from \(\lambda\) randomly created individuals. Then, at each iteration (generation), \(\lambda\) new individuals are generated by applying mutations on the individual previously selected as the best among the population. Then, the best among the current individuals (\(1+\lambda\)) becomes the current individual for the next iteration (generation). An offspring can become the current individual in the next iteration when it has the same fitness as the current individual and there is no other individual with a better fitness. According to [PERSON] [59], an empirical value for \(\lambda\) is 4, which was the value we used. ### Binarization

Our CGP system architecture evolves one classifier for each piano note. The final output of each classifier should be a binary output: when the corresponding note is detected, the output is 1; otherwise, it is 0. In order to evolve each classifier, there is a training stage (see Section 5.1). During this stage, each generated individual for each classifier is evaluated using a fitness function. To compute the fitness value, we use F-measure, which is a measure of a test's accuracy for binary classification. Therefore, for each audio frame used as input, we need to generate a binary output for each classifier. However, our CGP system is comprised of mathematical functions in which the arguments are vectors and that also return vectors. Thus, at the end of each CGP graph (output node), we have a vector of float values. A binarization process was added at the end of each classifier to transform its output vector into a binary output. This was done by applying a spectral mask with harmonic information: each classifier uses its own mask built by the system. The fundamental frequency of the corresponding note detected by the classifier (\(F_{0}\)) is computed and 2 or more triangles are placed centered in \(n\times F_{0}\) (see Figure 10b); in this case, we use a harmonic mask parameter \(n=2\). This means that we use 2 triangles (\(n=1\) and \(n=2\)). The amplitude and width of each triangle are also configurable parameters as well as the number of harmonics. To calculate \(F_{0}\) for a piano note (key), we use the following equation that gives the fundamental frequency \(F_{0}(n)\) of the \(n^{th}\) key:

Figure 4:0

In order to accomplish a binary output, we use a comparison process between the CGP output vector normalized in amplitude \(O_{cgp}[n]\) and the spectral harmonic mask with the frequency corresponding to the pitch of the estimator, \(M_{F0}[n]\). The first step is normalization of the output vector in amplitude. This way, all the elements of the vector fall in the interval [0; 1]. Then, we generate the following scalar computing the inner product between the 2 vectors:

Figure 4:1

where \(x\) measures the discrete intersection between two discrete signals. If we approximate these signals to a continuous domain, we could see \(x\) as the intersected area between the two signals. Finally, we use a threshold function to accomplish the binary result:

\[T(x)= \begin{cases}1,&\text{if }x>\theta\\ 0,&\text{if }x<=\theta\end{cases}  \tag{14}\]

where \(\theta\) is the threshold value. Since both signals are normalized, the max value for \(x\) is as follows:

\[x_{\text{max}}=\sum_{n=0}^{N}M_{F0}[n]. \tag{15}\]

Figure 10: (**a**) CGP output signal, (**b**) harmonic mask, and (**c**) computing intersection. This threshold value also evolves (mutates) during the training stage.