We use a number of distance measures in Computational Musicology. compmus_long_distance brings them together into one place, along with common alternative names. In order to support plotting, the distances are returned in long format rather than matrix format. It is designed for convenience, not speed.

compmus_long_distance(xdat, ydat, feature, method = "euclidean")

compmus_self_similarity(dat, feature, method = "euclidean")

Arguments

xdat, ydat, dat

Data frames with start and duration columns.

feature

An (unquoted) column name over which to compute distances.

method

A character string indicating which distance metric to use (see Details). Default is Euclidean distance.

Value

A tibble with columns xstart, xduration, ystart,

yduration, and d.

Details

The following methods are supported.

manhattan,citybolock,taxicab,L1,totvar

Manhattan distance.

euclidean,L2

Euclidean distance.

chebyshev,maximum

Chebyshev distance.

pearson,correlation

Pearson's pseudo-distance.

cosine

Cosine pseudo-distance.

angular

Angular distance.

aitchison

Aitchison distance.

Functions

  • compmus_self_similarity: Self-similarity matrices in long format

Examples

library(tidyverse)
tallis <-
  get_tidy_audio_analysis("2J3Mmybwue0jyQ0UVMYurH") %>%
  select(segments) %>%
  unnest(segments) %>%
  mutate(pitches = map(pitches, compmus_normalise, "manhattan"))
chapelle <-
  get_tidy_audio_analysis("4ccw2IcnFt1Jv9LqQCOYDi") %>%
  select(segments) %>%
  unnest(segments) %>%
  mutate(pitches = map(pitches, compmus_normalise, "manhattan"))

compmus_long_distance(tallis, chapelle, pitches, method = "euclidean")
#> # A tibble: 1,166,165 × 5
#>    xstart xduration ystart yduration      d
#>     <dbl>     <dbl>  <dbl>     <dbl>  <dbl>
#>  1      0      2.09   0       2.84   0.0734
#>  2      0      2.09   2.84    0.220  0.380 
#>  3      0      2.09   3.06    0.157  0.519 
#>  4      0      2.09   3.22    0.157  0.558 
#>  5      0      2.09   3.37    0.319  0.479 
#>  6      0      2.09   3.69    0.262  0.368 
#>  7      0      2.09   3.95    0.186  0.542 
#>  8      0      2.09   4.14    0.267  0.679 
#>  9      0      2.09   4.41    0.0995 0.614 
#> 10      0      2.09   4.51    0.209  0.620 
#> # … with 1,166,155 more rows

compmus_self_similarity(tallis, pitches, method = "aitchison")
#> # A tibble: 1,357,225 × 5
#>    xstart xduration ystart yduration     d
#>     <dbl>     <dbl>  <dbl>     <dbl> <dbl>
#>  1      0      2.09   0       2.09    0   
#>  2      0      2.09   2.09    0.144   5.34
#>  3      0      2.09   2.24    0.0868  4.74
#>  4      0      2.09   2.32    0.129   5.84
#>  5      0      2.09   2.45    0.202   7.16
#>  6      0      2.09   2.65    0.0875  7.44
#>  7      0      2.09   2.74    0.592   5.04
#>  8      0      2.09   3.33    0.110   6.40
#>  9      0      2.09   3.44    0.290   5.51
#> 10      0      2.09   3.73    0.255   5.96
#> # … with 1,357,215 more rows