muspy.metrics
Objective metrics.
This module provides common objective metrics in music generation. These objective metrics could be used to evaluate a music generation system by comparing the statistical difference between the training data and the generated samples.
Functions
drum_in_pattern_rate
drum_pattern_consistency
empty_beat_rate
empty_measure_rate
groove_consistency
n_pitch_classes_used
n_pitches_used
pitch_class_entropy
pitch_entropy
pitch_in_scale_rate
pitch_range
polyphony
polyphony_rate
scale_consistency
- muspy.metrics.drum_in_pattern_rate(music, meter)[source]
Return the ratio of drum notes in a certain drum pattern.
The drum-in-pattern rate is defined as the ratio of the number of notes in a certain scale to the total number of notes. Only drum tracks are considered. Return NaN if no drum note is found. This metric is used in [1].
\[drum\_in\_pattern\_rate = \frac{ \#(drum\_notes\_in\_pattern)}{\#(drum\_notes)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.meter (str, {'duple', 'triple'}) – Meter of the drum pattern.
- Returns
Drum-in-pattern rate.
- Return type
See also
muspy.drum_pattern_consistency()
Compute the largest drum-in-pattern rate.
References
Hao-Wen Dong, Wen-Yi Hsiao, Li-Chia Yang, and Yi-Hsuan Yang, “MuseGAN: Multi-track sequential generative adversarial networks for symbolic music generation and accompaniment,” in Proceedings of the 32nd AAAI Conference on Artificial Intelligence (AAAI), 2018.
- muspy.metrics.drum_pattern_consistency(music)[source]
Return the largest drum-in-pattern rate.
The drum pattern consistency is defined as the largest drum-in-pattern rate over duple and triple meters. Only drum tracks are considered. Return NaN if no drum note is found.
\[drum\_pattern\_consistency = \max_{meter}{ drum\_in\_pattern\_rate(meter)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Drum pattern consistency.
- Return type
See also
muspy.drum_in_pattern_rate()
Compute the ratio of drum notes in a certain drum pattern.
- muspy.metrics.empty_beat_rate(music)[source]
Return the ratio of empty beats.
The empty-beat rate is defined as the ratio of the number of empty beats (where no note is played) to the total number of beats. Return NaN if song length is zero. This metric is also implemented in Pypianoroll [1].
\[empty\_beat\_rate = \frac{\#(empty\_beats)}{\#(beats)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Empty-beat rate.
- Return type
See also
muspy.empty_measure_rate()
Compute the ratio of empty measures.
References
Hao-Wen Dong, Wen-Yi Hsiao, and Yi-Hsuan Yang, “Pypianoroll: Open Source Python Package for Handling Multitrack Pianorolls,” in Late-Breaking Demos of the 18th International Society for Music Information Retrieval Conference (ISMIR), 2018.
- muspy.metrics.empty_measure_rate(music, measure_resolution)[source]
Return the ratio of empty measures.
The empty-measure rate is defined as the ratio of the number of empty measures (where no note is played) to the total number of measures. Note that this metric only works for songs with a constant time signature. Return NaN if song length is zero. This metric is used in [1].
\[empty\_measure\_rate = \frac{\#(empty\_measures)}{\#(measures)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.measure_resolution (int) – Time steps per measure.
- Returns
Empty-measure rate.
- Return type
See also
muspy.empty_beat_rate()
Compute the ratio of empty beats.
References
Hao-Wen Dong, Wen-Yi Hsiao, Li-Chia Yang, and Yi-Hsuan Yang, “MuseGAN: Multi-track sequential generative adversarial networks for symbolic music generation and accompaniment,” in Proceedings of the 32nd AAAI Conference on Artificial Intelligence (AAAI), 2018.
- muspy.metrics.groove_consistency(music, measure_resolution)[source]
Return the groove consistency.
The groove consistency is defined as the mean hamming distance of the neighboring measures.
\[groove\_consistency = 1 - \frac{1}{T - 1} \sum_{i = 1}^{T - 1}{ d(G_i, G_{i + 1})}\]Here, \(T\) is the number of measures, \(G_i\) is the binary onset vector of the \(i\)-th measure (a one at position that has an onset, otherwise a zero), and \(d(G, G')\) is the hamming distance between two vectors \(G\) and \(G'\). Note that this metric only works for songs with a constant time signature. Return NaN if the number of measures is less than two. This metric is used in [1].
- Parameters
music (
muspy.Music
) – Music object to evaluate.measure_resolution (int) – Time steps per measure.
- Returns
Groove consistency.
- Return type
References
Shih-Lun Wu and Yi-Hsuan Yang, “The Jazz Transformer on the Front Line: Exploring the Shortcomings of AI-composed Music through Quantitative Measures”, in Proceedings of the 21st International Society for Music Information Retrieval Conference, 2020.
- muspy.metrics.n_pitch_classes_used(music)[source]
Return the number of unique pitch classes used.
Drum tracks are ignored.
- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Number of unique pitch classes used.
- Return type
See also
muspy.n_pitches_used()
Compute the number of unique pitches used.
- muspy.metrics.n_pitches_used(music)[source]
Return the number of unique pitches used.
Drum tracks are ignored.
- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Number of unique pitch used.
- Return type
See also
muspy.n_pitch_class_used()
Compute the number of unique pitch classes used.
- muspy.metrics.pitch_class_entropy(music)[source]
Return the entropy of the normalized note pitch class histogram.
The pitch class entropy is defined as the Shannon entropy of the normalized note pitch class histogram. Drum tracks are ignored. Return NaN if no note is found. This metric is used in [1].
\[pitch\_class\_entropy = -\sum_{i = 0}^{11}{ P(pitch\_class=i) \times \log_2 P(pitch\_class=i)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Pitch class entropy.
- Return type
See also
muspy.pitch_entropy()
Compute the entropy of the normalized pitch histogram.
References
Shih-Lun Wu and Yi-Hsuan Yang, “The Jazz Transformer on the Front Line: Exploring the Shortcomings of AI-composed Music through Quantitative Measures”, in Proceedings of the 21st International Society for Music Information Retrieval Conference, 2020.
- muspy.metrics.pitch_entropy(music)[source]
Return the entropy of the normalized note pitch histogram.
The pitch entropy is defined as the Shannon entropy of the normalized note pitch histogram. Drum tracks are ignored. Return NaN if no note is found.
\[pitch\_entropy = -\sum_{i = 0}^{127}{ P(pitch=i) \log_2 P(pitch=i)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Pitch entropy.
- Return type
See also
muspy.pitch_class_entropy()
Compute the entropy of the normalized pitch class histogram.
- muspy.metrics.pitch_in_scale_rate(music, root, mode)[source]
Return the ratio of pitches in a certain musical scale.
The pitch-in-scale rate is defined as the ratio of the number of notes in a certain scale to the total number of notes. Drum tracks are ignored. Return NaN if no note is found. This metric is used in [1].
\[pitch\_in\_scale\_rate = \frac{\#(notes\_in\_scale)}{\#(notes)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.root (int) – Root of the scale.
mode (str, {'major', 'minor'}) – Mode of the scale.
- Returns
Pitch-in-scale rate.
- Return type
See also
muspy.scale_consistency()
Compute the largest pitch-in-class rate.
References
Hao-Wen Dong, Wen-Yi Hsiao, Li-Chia Yang, and Yi-Hsuan Yang, “MuseGAN: Multi-track sequential generative adversarial networks for symbolic music generation and accompaniment,” in Proceedings of the 32nd AAAI Conference on Artificial Intelligence (AAAI), 2018.
- muspy.metrics.pitch_range(music)[source]
Return the pitch range.
Drum tracks are ignored. Return zero if no note is found.
- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Pitch range.
- Return type
- muspy.metrics.polyphony(music)[source]
Return the average number of pitches being played concurrently.
The polyphony is defined as the average number of pitches being played at the same time, evaluated only at time steps where at least one pitch is on. Drum tracks are ignored. Return NaN if no note is found.
\[polyphony = \frac{ \#(pitches\_when\_at\_least\_one\_pitch\_is\_on) }{ \#(time\_steps\_where\_at\_least\_one\_pitch\_is\_on) }\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Polyphony.
- Return type
See also
muspy.polyphony_rate()
Compute the ratio of time steps where multiple pitches are on.
- muspy.metrics.polyphony_rate(music, threshold=2)[source]
Return the ratio of time steps where multiple pitches are on.
The polyphony rate is defined as the ratio of the number of time steps where multiple pitches are on to the total number of time steps. Drum tracks are ignored. Return NaN if song length is zero. This metric is used in [1], where it is called polyphonicity.
\[polyphony\_rate = \frac{ \#(time\_steps\_where\_multiple\_pitches\_are\_on) }{ \#(time\_steps) }\]- Parameters
music (
muspy.Music
) – Music object to evaluate.threshold (int, default: 2) – Threshold of number of pitches to count into the numerator.
- Returns
Polyphony rate.
- Return type
See also
muspy.polyphony()
Compute the average number of pitches being played at the same time.
References
Hao-Wen Dong, Wen-Yi Hsiao, Li-Chia Yang, and Yi-Hsuan Yang, “MuseGAN: Multi-track sequential generative adversarial networks for symbolic music generation and accompaniment,” in Proceedings of the 32nd AAAI Conference on Artificial Intelligence (AAAI), 2018.
- muspy.metrics.scale_consistency(music)[source]
Return the largest pitch-in-scale rate.
The scale consistency is defined as the largest pitch-in-scale rate over all major and minor scales. Drum tracks are ignored. Return NaN if no note is found. This metric is used in [1].
\[scale\_consistency = \max_{root, mode}{ pitch\_in\_scale\_rate(root, mode)}\]- Parameters
music (
muspy.Music
) – Music object to evaluate.- Returns
Scale consistency.
- Return type
See also
muspy.pitch_in_scale_rate()
Compute the ratio of pitches in a certain musical scale.
References
Olof Mogren, “C-RNN-GAN: Continuous recurrent neural networks with adversarial training,” in NeuIPS Workshop on Constructive Machine Learning, 2016.