Mercurial > hg > nimfks
comparison src/matlab/nmf_euclidean.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, cost] = nmf_euclidean(V, W, varargin) | |
2 | |
3 if nargin > 2 | |
4 nmf_params = varargin{1}; | |
5 L = nmf_params.Iterations; | |
6 convergence = nmf_params.Convergence_criteria; | |
7 r = nmf_params.Repition_restriction; | |
8 p = nmf_params.Polyphony_restriction; | |
9 c = nmf_params.Continuity_enhancement; | |
10 rot = nmf_params.Continuity_enhancement_rot; | |
11 pattern = nmf_params.Diagonal_pattern; | |
12 endtime = nmf_params.Modification_application; | |
13 | |
14 if nmf_params.Random_seed <= 0 | |
15 rng('shuffle'); | |
16 else | |
17 rng(nmf_params.Random_seed); | |
18 end | |
19 elseif nargin == 2 | |
20 L = 10; | |
21 convergence = 0; | |
22 r = 3; | |
23 p = 10; | |
24 c = 3; | |
25 pattern = 'Diagonal'; | |
26 endtime = false; | |
27 rng('shuffle'); | |
28 end | |
29 | |
30 waitbarHandle = waitbar(0, 'Starting NMF synthesis...'); | |
31 | |
32 cost=0; | |
33 targetDim=size(V); | |
34 sourceDim=size(W); | |
35 K=sourceDim(2); | |
36 M=targetDim(2); | |
37 | |
38 H=random('unif',0, 1, K, M); | |
39 | |
40 num=W'*V; | |
41 WTW = W'*W; | |
42 | |
43 for l=1:L-1 | |
44 waitbar(l/(L-1), waitbarHandle, ['Computing approximation...Iteration: ', num2str(l), '/', num2str(L-1)]) | |
45 | |
46 den=WTW*H; | |
47 H=H.*(num./den); | |
48 H(isnan(H))=0; | |
49 | |
50 if((r > 0 && ~endtime) || (r > 0 && endtime && l==L-1)) | |
51 waitbar(l/(L-1), waitbarHandle, ['Repition Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) | |
52 for k=1:K | |
53 %Updating H | |
54 for m=1:M | |
55 if(m>r && (m+r)<=M && H(k,m)==max(H(k,m-r:m+r))) | |
56 R(k,m)=H(k,m); | |
57 else | |
58 R(k,m)=H(k,m)*(1-(l+1)/L); | |
59 end | |
60 end | |
61 end | |
62 | |
63 H = R; | |
64 end | |
65 | |
66 if((p > 0 && ~endtime) || (p > 0 && endtime && l==L-1)) | |
67 waitbar(l/(L-1), waitbarHandle, ['Polyphony Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) | |
68 P = zeros(size(H)); | |
69 mask = zeros(size(H,1),1); | |
70 for m = 1:size(H, 2) | |
71 [~, sortedIndices] = sort(H(:, m),'descend'); | |
72 mask(sortedIndices(1:p)) = 1; | |
73 mask(sortedIndices(p+1:end)) = (1-(l+1)/L); | |
74 P(:,m)=H(:,m).*mask; | |
75 end | |
76 H = P; | |
77 end | |
78 | |
79 if((c > 0 && ~endtime) || (c > 0 && endtime && l==L-1)) | |
80 waitbar(l/(L-1), waitbarHandle, ['Continuity Enhancement...Iteration: ', num2str(l), '/', num2str(L-1)]) | |
81 switch pattern | |
82 case 'Diagonal' | |
83 C = conv2(H, rot_kernel( eye(c), rot ), 'same'); %Default | |
84 case 'Reverse' | |
85 C = conv2(H, flip(eye(c)), 'same'); %Reverse | |
86 case 'Blur' | |
87 C = conv2(H, flip(ones(c)), 'same'); %Blurring | |
88 case 'Vertical' | |
89 M = zeros(c, c); %Vertical | |
90 M(:, floor(c/2)) = 1; | |
91 C = conv2(P, M, 'same'); | |
92 end | |
93 H = C; | |
94 end | |
95 | |
96 if ~endtime | |
97 den=WTW*H; | |
98 H=H.*(num./den); | |
99 H(isnan(H))=0; | |
100 end | |
101 | |
102 cost(l)=norm(V-W*H, 'fro'); %Frobenius norm of a matrix | |
103 if(l > 5 && (cost(l) > cost(l-1) || abs(((cost(l)-cost(l-1)))/max(cost))<convergence)) | |
104 break; | |
105 end | |
106 end | |
107 | |
108 fprintf('Iterations: %i/%i\n', l, L); | |
109 fprintf('Convergence Criteria: %i\n', convergence*100); | |
110 fprintf('Repitition: %i\n', r); | |
111 fprintf('Polyphony: %i\n', p); | |
112 fprintf('Continuity: %i\n', c); | |
113 | |
114 Y=H; | |
115 Y = Y./max(max(Y)); | |
116 | |
117 close(waitbarHandle); | |
118 end |