# NOT RUN {
# 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/temp' # 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 = 'segmentFolder', key = key,
pars = c('shortestSyl', 'shortestPause', 'sylThres'),
fitnessPar = 'nBursts',
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(segmentFolder, 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 = 'segmentFolder', key = segment_manual,
pars = c('shortestSyl', 'shortestPause'),
fitnessPar = 'nBursts',
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!)
res = optimizePars(
myfolder = myfolder,
myfun = 'analyzeFolder',
key = log(pitchManual), # log-scale better for pitch
pars = c('windowLength', 'silence'),
bounds = list(low = c(5, 0), high = c(500, 1)),
fitnessPar = 'pitch_median',
nIter = 2,
otherPars = list(plot = FALSE, verbose = FALSE, step = 50),
fitnessFun = function(x) {
1 - cor(log(x), key, use = 'pairwise.complete.obs') *
(1 - mean(is.na(x) & !is.na(key))) # penalize failing to detect f0
})
# }
Run the code above in your browser using DataLab