if (FALSE) {
# Download 260 sounds from the supplements in Anikin & Persson (2017)
# - see http://cogsci.se/publications.html
# Unzip them into a folder, say '~/Downloads/temp'
myfolder = '~/Downloads/temp260' # 260 .wav files live here
# Optimization of SEGMENTATION
# Import manual counts of syllables in 260 sounds from
# Anikin & Persson (2017) (our "key")
key = segmentManual # a vector of 260 integers
# Run optimization loop several times with random initial values
# to check convergence
# NB: with 260 sounds and default settings, this might take ~20 min per iteration!
res = optimizePars(myfolder = myfolder, myfun = 'segment', key = key,
pars = c('shortestSyl', 'shortestPause'),
fitnessPar = 'nBursts', otherPars = list(method = 'env'),
nIter = 3, control = list(maxit = 50, reltol = .01, trace = 0))
# Examine the results
print(res)
for (c in 2:ncol(res)) {
plot(res[, c], res[, 1], main = colnames(res)[c])
}
pars = as.list(res[1, 2:ncol(res)]) # top candidate (best pars)
s = do.call(segment, c(myfolder, pars)) # segment with best pars
cor(key, as.numeric(s[, fitnessPar]))
boxplot(as.numeric(s[, fitnessPar]) ~ as.integer(key), xlab='key')
abline(a=0, b=1, col='red')
# Try a grid with particular parameter values instead of formal optimization
res = optimizePars(myfolder = myfolder, myfun = 'segment', key = segmentManual,
pars = c('shortestSyl', 'shortestPause'),
fitnessPar = 'nBursts', otherPars = list(method = 'env'),
mygrid = expand.grid(shortestSyl = c(30, 40),
shortestPause = c(30, 40, 50)))
1 - res$fit # correlations with key
# Optimization of PITCH TRACKING (takes several hours!)
key = as.numeric(log(pitchManual))
res = optimizePars(
myfolder = myfolder,
myfun = 'analyze',
key = key, # log-scale better for pitch
pars = c('windowLength', 'silence'),
bounds = list(low = c(5, 0), high = c(200, .2)),
fitnessPar = 'pitch_median',
nIter = 2,
otherPars = list(plot = FALSE, loudness = NULL, novelty = NULL,
roughness = NULL, nFormants = 0),
fitnessFun = function(x) {
1 - cor(log(x), key, use = 'pairwise.complete.obs') *
(1 - mean(is.na(x) & is.finite(key))) # penalize failing to detect f0
})
}
Run the code above in your browser using DataLab