def test(self): expected = array([1,13,21,25]) print(self.mfcc.shape) segStart = to_segments(self.mfcc.T) print(segStart) print(expected) self.assertEqual(segStart,expected)
def analyze_config(self,config): cache = {} num_bands=config.num_bands.get_value() freq_lims = (config.min_freq.get_value(),config.max_freq.get_value()) window_length = config.window_length.get_value() time_step = config.time_step.get_value() use_praat = config.use_praat.get_value() num_coeffs = config.num_coeffs.get_value() num_bands = config.num_bands.get_value() use_window = config.use_window.get_value() use_power = config.use_power.get_value() use_segments = config.use_segments.get_value() if config.representation == 'envelopes': if use_window: to_rep = partial(to_envelopes, num_bands=num_bands, freq_lims=freq_lims, window_length=window_length, time_step=time_step) else: to_rep = partial(to_envelopes,num_bands=num_bands,freq_lims=freq_lims) elif config.representation == 'mfcc': if use_praat: to_rep = partial(to_mfcc_praat, freq_lims=freq_lims, num_coeffs=num_coeffs, win_len=window_length, time_step=time_step) else: to_rep = partial(to_mfcc,freq_lims=freq_lims, num_coeffs=num_coeffs, num_filters = num_bands, win_len=window_length, time_step=time_step, use_power = use_power) elif config.representation == 'mhec': to_rep = partial(to_mhec, freq_lims=freq_lims, num_coeffs=num_coeffs, num_filters = num_bands, window_length=window_length, time_step=time_step, use_power = use_power) elif config.representation == 'gammatone': if use_window: to_rep = partial(to_gammatone_envelopes,num_bands = num_bands, freq_lims=freq_lims, window_length=window_length, time_step=time_step) else: to_rep = partial(to_gammatone_envelopes,num_bands = num_bands, freq_lims=freq_lims) elif config.representation == 'melbank': to_rep = partial(to_melbank,freq_lims=freq_lims, win_len=window_length, time_step=time_step, num_filters = num_bands) elif config.representation == 'prosody': to_rep = partial(to_prosody,time_step=time_step) if config.match_algorithm == 'xcorr': dist_func = xcorr_distance elif config.match_algorithm == 'dtw': dist_func = dtw_distance elif config.match_algorithm == 'dct': dist_func = dct_distance x = [] y = [] for pm in self.mapping: listenertup = tuple(map(lambda x: os.path.split(x)[1],pm)) if listenertup not in self.listenerResp: continue if pm[0] not in cache: cache[pm[0]] = to_rep(pm[0]) if use_segments and cache[pm[0]] is not None: cache[pm[0]] = to_segments(cache[pm[0]]) if pm[1] not in cache: cache[pm[1]] = to_rep(pm[1]) if use_segments and cache[pm[1]] is not None: cache[pm[1]] = to_segments(cache[pm[1]]) if pm[2] not in cache: cache[pm[2]] = to_rep(pm[2]) if use_segments and cache[pm[2]] is not None: cache[pm[2]] = to_segments(cache[pm[2]]) base = cache[pm[0]] model = cache[pm[1]] shadow = cache[pm[2]] if base is None: continue if model is None: continue if shadow is None: continue dist1 = dist_func(base,model) if dist1 == 0 or isnan(dist1): print(base) print(model) print(dist1) print(dist2) raise(ValueError) dist2 = dist_func(shadow,model) if isnan(dist2): print(base) print(model) print(dist1) print(dist2) raise(ValueError) if config.use_similarity: dist1 = 1/dist1 dist2 = 1/dist2 ratio = dist2 / dist1 x.append(self.listenerResp[listenertup]) y.append(ratio) correlation = pearsonr(x,y) return correlation[0]