Expectation

Full module path: melody_features.feature_definitions.expectation.

Also importable via import melody_features as mf (for example mf.pitch_range).

Expectation feature definitions.

narmour_registral_direction(pitches)[source]

Narmour registral-direction score for the final three notes.

The last three pitches define an implicative interval followed by a realized interval. This feature returns 1 when a large implicative interval (greater than a tritone) is followed by a change of direction, or when a small implicative interval (smaller than a tritone) continues in the same direction. It returns 0 otherwise.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • int – Narmour registral direction score (0 or 1)

  • Citation

  • ——–

  • Narmour (1990)

Return type:

int

narmour_proximity(pitches)[source]

Narmour proximity score for the final melodic interval.

Proximity rewards small realized intervals. It is calculated as 6 - d, where d is the absolute semitone distance between the final two notes, and is clipped at 0 for intervals of a tritone or larger. Unisons therefore receive 6, whole tones receive 4, perfect fourths receive 1, and perfect fifths receive 0.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • int – Narmour proximity score (0 to 6)

  • Citation

  • ——–

  • Narmour (1990)

Return type:

int

narmour_closure(pitches)[source]

Narmour closure score for the final three-note pattern.

The last three pitches define two successive intervals. One point is awarded when the second interval changes direction relative to the first. A second point is awarded when the second interval is at least two semitones smaller than the first in absolute size. The resulting score ranges from 0 to 2.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • int – Narmour closure score (0 to 2)

  • Citation

  • ——–

  • Narmour (1990)

Return type:

int

narmour_registral_return(pitches)[source]

Narmour registral-return score for the final three-note pattern.

Registral return measures whether the last three notes move away from a pitch and then return toward it. The contour must change direction and neither interval may be a repeated note. An exact return to the first pitch scores 3; returning within one semitone scores 2; returning within two semitones scores 1; all other patterns score 0.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • int – Narmour registral return score (0 to 3)

  • Citation

  • ——–

  • Narmour (1990)

Return type:

int

narmour_intervallic_difference(pitches)[source]

Narmour intervallic-difference score for the final three notes.

The last three pitches define an implicative interval followed by a realized interval. If the implicative interval is large (greater than a tritone), this feature returns 1 when the realized interval is sufficiently smaller: at least three semitones smaller in the same direction, or at least two semitones smaller after a direction change. If the implicative interval is small (smaller than a tritone), it returns 1 when the realized interval is similar in size, within the same margins. Otherwise it returns 0.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • int – Narmour intervallic difference score (0 or 1)

  • Citation

  • ——–

  • Narmour (1990)

Return type:

int

melodic_embellishment(pitches, starts, ends)[source]

The proportion of melodic embellishments in the melody. Melodic embellishments are identified by notes that are surrounded on both sides by notes with durations at least 3 times longer than the central note.

Parameters:
  • pitches (list[int]) – List of MIDI pitch values

  • starts (list[float]) – List of note start times

  • ends (list[float]) – List of note end times

Returns:

Proportion of notes that are embellishments (0.0-1.0). Returns -1.0 if input is None, 0.0 if input is empty.

Return type:

float

mobility(pitches)[source]

The melodic mobility for each note based on von Hippel (2000). Mobility describes why melodies change direction after large skips by observing that they would otherwise run out of the comfortable melodic range. It uses lag-one autocorrelation between successive pitch heights.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • list[float] – One mobility value per input pitch (length matches pitches).

  • Citation

  • ——–

  • von Hippel (2000)

Return type:

list[float]

mean_mobility(pitches)[source]

The arithmetic mean of the mobility values across all notes.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Mean mobility value

Return type:

float

mobility_std(pitches)[source]

The standard deviation of the mobility values across all notes.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

Standard deviation of mobility values

Return type:

float

melodic_attraction(pitches, starts, ends)[source]

Melodic attraction values following Lerdahl’s tonal-attraction model.

Parameters:
Return type:

list[float]

mean_melodic_attraction(pitches, starts, ends)[source]

The arithmetic mean of Lerdahl melodic-attraction values.

Parameters:
Return type:

float

melodic_attraction_std(pitches, starts, ends)[source]

The population standard deviation of Lerdahl melodic-attraction values.

Parameters:
Return type:

float

melodic_accent(pitches)[source]

Melodic accent salience for each note using Thomassen’s contour model.

Thomassen’s model assigns accent strength from the melodic contour formed by three-note pitch windows. Notes at locally salient contour positions receive higher values. The implementation follows the MIDI Toolbox melaccent.m convention and returns values from 0 (no salience) to 1 (maximum salience).

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • list[float] – List of melodic accent values for each note

  • Citation

  • ——–

  • Thomassen (1982)

Return type:

list[float]

mean_melodic_accent(pitches)[source]

The arithmetic mean of Thomassen melodic-accent values.

Melodic accent values estimate local contour salience from three-note pitch windows. This feature averages those note-level salience values across the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • float – Mean melodic accent value

  • Citation

  • ——–

  • Thomassen (1982)

Return type:

float

melodic_accent_std(pitches)[source]

The sample standard deviation of Thomassen melodic-accent values.

Melodic accent values estimate local contour salience from three-note pitch windows. This feature summarizes how unevenly that salience is distributed across the melody.

Parameters:

pitches (list[int]) – List of MIDI pitch values

Returns:

  • float – Standard deviation of melodic accent values

  • Citation

  • ——–

  • Thomassen (1982)

Return type:

float

compltrans(melody)[source]

The melodic originality measure, according to Simonton (1984). Calculated based on 2nd order pitch-class distribution derived from 15,618 classical music themes. Higher values indicate higher melodic originality (less predictable transitions).

Parameters:

melody (Melody) – The melody to analyze

Returns:

  • float – Originality score scaled 0-10 (higher = more original/unexpected)

  • Citation

  • ——–

  • Simonton (1984)

Return type:

float

pitch_stm_mean_information_content(melody)[source]

The average information content across all notes in a melody, calculated using IDyOM’s prediction-by-partial-matching (PPM) algorithm. Information content is perceptually related to surprise, and can be calculated for pitches or rhythms.

Citation

Pearce, M. (2005)

Parameters:

melody (Melody)

Return type:

float

pitch_ltm_mean_information_content(melody)[source]

The average information content across all notes in a melody, calculated using IDyOM’s long-term model (LTM). Information content is perceptually related to surprise, and can be calculated for pitches or rhythms.

Citation

Pearce, M. (2005)

Parameters:

melody (Melody)

Return type:

float

rhythm_stm_mean_information_content(melody)[source]

The average rhythmic information content across all notes in a melody, calculated using IDyOM’s short-term model (STM). Information content is perceptually related to surprise, and can be calculated for pitches or rhythms.

Citation

Pearce, M. (2005)

Parameters:

melody (Melody)

Return type:

float

rhythm_ltm_mean_information_content(melody)[source]

The average rhythmic information content across all notes in a melody, calculated using IDyOM’s long-term model (LTM). Information content is perceptually related to surprise, and can be calculated for pitches or rhythms.

Citation

Pearce, M. (2005)

Parameters:

melody (Melody)

Return type:

float

get_narmour_features(melody)[source]

Calculate Narmour’s implication-realization features.

Parameters:

melody (Melody) – The melody to analyze as a Melody object

Returns:

Dictionary containing scores for: - Registral direction (0 or 1) - Proximity (0-6) - Closure (0-2) - Registral return (0-3) - Intervallic difference (0 or 1)

Return type:

Dict

Notes

Features represent: - Registral direction: Large intervals followed by direction change - Proximity: Closeness of consecutive pitches - Closure: Direction changes and interval size changes - Registral return: Return to previous pitch level - Intervallic difference: Relationship between consecutive intervals