diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/MultiNcut/discretisation.m | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/MultiNcut/discretisation.m')
| -rwxr-xr-x | SD-VBS/common/toolbox/MultiNcut/discretisation.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/MultiNcut/discretisation.m b/SD-VBS/common/toolbox/MultiNcut/discretisation.m new file mode 100755 index 0000000..70b5650 --- /dev/null +++ b/SD-VBS/common/toolbox/MultiNcut/discretisation.m | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | function [SegLabel,EigenVectors]=discretisation(EigenVectors,nr,nc) | ||
| 2 | % | ||
| 3 | % EigenvectorsDiscrete=discretisation(EigenVectors) | ||
| 4 | % | ||
| 5 | % Input: EigenVectors = continuous Ncut vector, size = ndata x nbEigenvectors | ||
| 6 | % Output EigenvectorsDiscrete = discrete Ncut vector, size = ndata x nbEigenvectors | ||
| 7 | % | ||
| 8 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004 | ||
| 9 | |||
| 10 | [n,k]=size(EigenVectors); | ||
| 11 | |||
| 12 | vm = sqrt(sum(EigenVectors.*EigenVectors,2)); | ||
| 13 | EigenVectors = EigenVectors./repmat(vm,1,k); | ||
| 14 | |||
| 15 | R=zeros(k); | ||
| 16 | R(:,1)=EigenVectors(1+round(rand(1)*(n-1)),:)'; | ||
| 17 | c=zeros(n,1); | ||
| 18 | for j=2:k | ||
| 19 | c=c+abs(EigenVectors*R(:,j-1)); | ||
| 20 | [minimum,i]=min(c); | ||
| 21 | R(:,j)=EigenVectors(i,:)'; | ||
| 22 | end | ||
| 23 | |||
| 24 | lastObjectiveValue=0; | ||
| 25 | exitLoop=0; | ||
| 26 | nbIterationsDiscretisation = 0; | ||
| 27 | nbIterationsDiscretisationMax = 20;%voir | ||
| 28 | while exitLoop== 0 | ||
| 29 | nbIterationsDiscretisation = nbIterationsDiscretisation + 1 ; | ||
| 30 | EigenvectorsDiscrete = discretisationEigenVectorData(EigenVectors*R); | ||
| 31 | [U,S,V] = svd(EigenvectorsDiscrete'*EigenVectors,0); | ||
| 32 | NcutValue=2*(n-trace(S)); | ||
| 33 | |||
| 34 | if abs(NcutValue-lastObjectiveValue) < eps | nbIterationsDiscretisation > nbIterationsDiscretisationMax | ||
| 35 | exitLoop=1; | ||
| 36 | else | ||
| 37 | lastObjectiveValue = NcutValue; | ||
| 38 | R=V*U'; | ||
| 39 | end | ||
| 40 | end | ||
| 41 | |||
| 42 | %%%% | ||
| 43 | |||
| 44 | SegLabel = zeros(nr,nc); | ||
| 45 | for j=1:size(EigenvectorsDiscrete,2), | ||
| 46 | SegLabel = SegLabel + j*reshape(EigenvectorsDiscrete(:,j),nr,nc); | ||
| 47 | end | ||
| 48 | EigenVectors = reshape(EigenVectors,nr,nc,size(EigenVectors,2)); | ||
| 49 | |||
