comparison src/matlab/prune_corpus.m @ 0:c52bc3e8d3ad tip

user: boblsturm branch 'default' added README.md added assets/.DS_Store added assets/playButton.jpg added assets/stopButton.png added assets/swapButton.jpg added data/.DS_Store added data/fiveoctaves.mp3 added data/glock2.wav added data/sinScale.mp3 added data/speech_female.mp3 added data/sweep.wav added nimfks.m.lnk added src/.DS_Store added src/matlab/.DS_Store added src/matlab/AnalysisCache.m added src/matlab/CSS.m added src/matlab/DataHash.m added src/matlab/ExistsInCache.m added src/matlab/KLDivCost.m added src/matlab/LoadFromCache.m added src/matlab/SA_B_NMF.m added src/matlab/SaveInCache.m added src/matlab/Sound.m added src/matlab/SynthesisCache.m added src/matlab/chromagram_E.m added src/matlab/chromagram_IF.m added src/matlab/chromagram_P.m added src/matlab/chromsynth.m added src/matlab/computeSTFTFeat.m added src/matlab/controller.m added src/matlab/decibelSliderReleaseCallback.m added src/matlab/drawClickCallBack.m added src/matlab/fft2chromamx.m added src/matlab/hz2octs.m added src/matlab/ifgram.m added src/matlab/ifptrack.m added src/matlab/istft.m added src/matlab/nimfks.fig added src/matlab/nimfks.m added src/matlab/nmfFn.m added src/matlab/nmf_beta.m added src/matlab/nmf_divergence.m added src/matlab/nmf_euclidean.m added src/matlab/prune_corpus.m added src/matlab/rot_kernel.m added src/matlab/templateAdditionResynth.m added src/matlab/templateDelCb.m added src/matlab/templateScrollCb.m
author boblsturm
date Sun, 18 Jun 2017 06:26:13 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c52bc3e8d3ad
1 function [ Y, PrunedFrames, KeepCorpusFrames ] = prune_corpus( target, corpus, reduction_coef )
2
3 if reduction_coef == 1
4 Y = corpus;
5 PrunedFrames = [];
6 KeepCorpusFrames = [];
7 return;
8 end
9 [targetRows, targetCols]= size( target );
10 [corpusRows, corpusCols]= size( corpus );
11
12 % Matrix: distances of every target frame to every other target frame
13 % i.e. Self-similarity matrix
14 TargetSelfSimMat = zeros(targetCols);
15
16 % Matrix: distances of every target frame to every corpus frame
17 % Matrix( i, j ) = Similarity of corpus frame i to target frame j
18 % TargetToCorpSimMat = -1*ones(WCols, targetCols);
19
20 % Calculate self-similarity of target (euclidean dist)
21 X2 = sum(target.^2,1);
22 TargetSelfSimMat = bsxfun(@plus,X2,X2')-2*(target'*target);
23 % TargetSelfSimMat = exp(-(1/10) * DistanceMat);
24
25 % Calculate the distance between each corpus frame to first target
26 % frame
27 KeepCorpusFrames = [];
28 RemainingTargetFrames = 1:targetCols;
29 RemainingCorpusFrames = 1:corpusCols;
30
31 while ~isempty(RemainingTargetFrames)
32 Dist = repmat(target(:,RemainingTargetFrames(1)),1, ...
33 length(RemainingCorpusFrames)) - corpus(:,RemainingCorpusFrames);
34 Distances = sum(Dist.^2,1);
35 % compute mean distances
36 meanDistance = mean(Distances);
37
38 % find those corpus frames closer than reduction_coef of mean
39 idxcorpuskeep = Distances < reduction_coef*meanDistance;
40 KeepCorpusFrames = [KeepCorpusFrames RemainingCorpusFrames(idxcorpuskeep)];
41
42 % find those target frames within twice that to next frame
43 distancetonext = TargetSelfSimMat(RemainingTargetFrames(1)+1,RemainingTargetFrames(1));
44 idxtarget = TargetSelfSimMat(RemainingTargetFrames,RemainingTargetFrames(1)) ...
45 < 2*distancetonext;
46
47 if ~any( idxtarget ) && distancetonext == 0
48 idxtarget = RemainingTargetFrames(2);
49 end
50
51 % shrink corpus
52 RemainingCorpusFrames = RemainingCorpusFrames(~idxcorpuskeep);
53
54 % shrink target frames index
55 RemainingTargetFrames = RemainingTargetFrames(~idxtarget);
56
57 fprintf( '%d remaining frames...\n', size( RemainingTargetFrames ) );
58 end
59
60 KeepCorpusFrames = sort( KeepCorpusFrames );
61 Y = corpus( :, KeepCorpusFrames );
62 PrunedFrames = setdiff( 1:corpusCols, KeepCorpusFrames );
63
64 fprintf( 'Pruned %d frames...\n', size( PrunedFrames ) );
65
66 end