amads.melody.contour.interpolation_contour#
Calculates the Interpolation Contour of a melody, along with related features, as implemented in the FANTASTIC toolbox of Müllensiefen (2009) [1] (features 23–27). Includes a modified version of the FANTASTIC method that is better suited to short melodies than the original implementation. This ‘AMADS’ method defines turning points using reversals, and is the default method. All features are returned for either method.
- class amads.melody.contour.interpolation_contour.InterpolationContour(pitches, times, method='amads')[source]#
Class for calculating and analyzing the interpolated contours of melodies, according to Müllensiefen (2009) [1]. This representation was first formalised by Steinbeck (1982) [2], and informed a varient of the present implementation in Müllensiefen & Frieler (2004) [3]. An interpolation contour is produced by first identifying turning points in the melody, and then interpolating a linear gradient between each turning point. The resulting list of values represents the gradient of the melody at evenly spaced points in time.
- Parameters:
pitches (
list
[int
])times (
list
[float
])method (
str
)
- static calculate_interpolation_contour(pitches, times, method='amads') list[float] [source]#
Calculate the interpolation contour representation of a melody [1].
- Returns:
Array containing the interpolation contour representation
- Return type:
list[float]
- Parameters:
pitches (
list
[int
])times (
list
[float
])method (
str
)
- property class_label: str#
Classify an interpolation contour into gradient categories. Can be invoked for either FANTASTIC or AMADS method.
The contour is sampled at 4 equally spaced points and each gradient is normalized to units of pitch change per second (expressed in units of semitones per 0.25 seconds.) The result is then classified into one of 5 categories:
‘a’: Strong downward (-2) - normalized gradient <= -1.45
‘b’: Downward (-1) - normalized gradient between -1.45 and -0.45
‘c’: Flat (0) - normalized gradient between -0.45 and 0.45
‘d’: Upward (1) - normalized gradient between 0.45 and 1.45
‘e’: Strong upward (2) - normalized gradient >= 1.45
- Returns:
String of length 4 containing letters a-e representing the gradient categories at 4 equally spaced points in the contour
- Return type:
str
Examples
Upwards, then downwards contour >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4]) >>> ic.class_label ‘ddbb’
FANTASTIC method returns ‘cccc’ for this example, as though the contour is flat >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4], method=”fantastic”) >>> ic.class_label ‘cccc’
- property direction_changes: float#
Calculate the proportion of interpolated gradient values that consistute a change in direction. For instance, a gradient value of -0.5 to 0.25 is a change in direction. Can be invoked for either FANTASTIC or AMADS method.
- Returns:
Ratio of the number of changes in contour direction relative to the number of different interpolated gradient values
- Return type:
float
Examples
>>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4]) >>> ic.direction_changes 1.0
FANTASTIC method returns 0.0 for this example >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4], method=”fantastic”) >>> ic.direction_changes 0.0
- property global_direction: int#
Calculate the global direction of the interpolation contour by taking the sign of the sum of all contour values. Can be invoked for either FANTASTIC or AMADS method.
- Returns:
1 if sum is positive, 0 if sum is zero, -1 if sum is negative
- Return type:
int
Examples
Flat overall contour direction (returns the same using FANTASTIC method) >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4]) >>> ic.global_direction 0
Upwards contour direction (returns the same using FANTASTIC method) >>> ic = InterpolationContour([60, 62, 64, 65, 67], [0, 1, 2, 3, 4]) >>> ic.global_direction 1
Downwards contour direction (returns the same using FANTASTIC method) >>> ic = InterpolationContour([67, 65, 67, 62, 60], [0, 1, 2, 3, 4]) >>> ic.global_direction -1
- property gradient_std: float#
Calculate the standard deviation of the interpolation contour gradients. Can be invoked for either FANTASTIC or AMADS method.
- Returns:
Standard deviation of the gradient values (by default, using Bessel’s correction)
- Return type:
float
Examples
>>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4]) >>> ic.gradient_std 2.0254...
FANTASTIC method returns 0.0 for this example >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4], method=”fantastic”) >>> ic.gradient_std 0.0
- property mean_gradient: float#
Calculate the absolute mean gradient of the interpolation contour. Can be invoked for either FANTASTIC or AMADS method.
- Returns:
Mean of the absolute gradient values
- Return type:
float
Examples
Steps of 2 semitones per second >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4]) >>> ic.mean_gradient 2.0
FANTASTIC method returns 0.0 for this example >>> ic = InterpolationContour([60, 62, 64, 62, 60], [0, 1, 2, 3, 4], method=”fantastic”) >>> ic.mean_gradient 0.0