def make_lda_features_from_spks(SpkFileNames): "all files should have been generated by the same parameters" clu_means, clu_covs = [], [] pars0 = n_ch, sample_rate, s_before, s_after = get_pars_from_xml2( switch_ext(SpkFileNames[0], "xml")) print "parameters: %s" % str(pars0[1:]) for fname in SpkFileNames: pars = get_pars_from_xml2(switch_ext(fname, "xml")) if pars[1:] != pars0[1:]: print "%s has wrong parameters. skipping" % fname continue n_ch = pars[0] X_nsc = read_spk(fname, n_ch, s_after + s_before) Clu_n = read_clu(switch_ext(fname, "clu.1")) for i_ch in xrange(n_ch): Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n, X_nsc[:, :, i_ch]) for mean, cov, count in zip(Mean_ms, Cov_mss, Count_m): if count > 100: clu_means.append(mean) clu_covs.append(cov) Feat_ss = compute_feats_lda(clu_means, clu_covs) save_feature_info(Feat_ss, s_before, s_after, sample_rate)
def make_pca_features_from_spk(SpkFileName): """ Make pca features from a .spk file and save them to features.txt """ SpkDir = os.path.dirname(SpkFileName) n_ch,sample_rate,s_before,s_after = get_pars_from_xml2(find_file_with_ext(SpkDir,"xml",True)) X_ns = np.fromfile(SpkFileName,dtype=np.int16).reshape(-1,s_before+s_after,n_ch)[:,:,0] Feats_ss = compute_pcs(X_ns) save_feature_info(Feats_ss,s_before,s_after,sample_rate)
def make_pca_features_from_spk(SpkFileName): """ Make pca features from a .spk file and save them to features.txt """ SpkDir = os.path.dirname(SpkFileName) n_ch, sample_rate, s_before, s_after = get_pars_from_xml2( find_file_with_ext(SpkDir, "xml", True)) X_ns = np.fromfile(SpkFileName, dtype=np.int16).reshape(-1, s_before + s_after, n_ch)[:, :, 0] Feats_ss = compute_pcs(X_ns) save_feature_info(Feats_ss, s_before, s_after, sample_rate)
def make_lda_features_from_spks(SpkFileNames): "all files should have been generated by the same parameters" clu_means, clu_covs = [],[] pars0 = n_ch,sample_rate,s_before,s_after = get_pars_from_xml2(switch_ext(SpkFileNames[0],"xml")) print "parameters: %s"%str(pars0[1:]) for fname in SpkFileNames: pars = get_pars_from_xml2(switch_ext(fname,"xml")) if pars[1:] != pars0[1:]: print "%s has wrong parameters. skipping"%fname continue n_ch = pars[0] X_nsc = read_spk(fname,n_ch,s_after+s_before) Clu_n = read_clu(switch_ext(fname,"clu.1")) for i_ch in xrange(n_ch): Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n,X_nsc[:,:,i_ch]) for mean,cov,count in zip(Mean_ms, Cov_mss, Count_m): if count > 100: clu_means.append(mean) clu_covs.append(cov) Feat_ss = compute_feats_lda(clu_means,clu_covs) save_feature_info(Feat_ss,s_before,s_after,sample_rate)