forked from jbhuang0604/SelfSimSR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindCoef3.m
70 lines (64 loc) · 3.13 KB
/
FindCoef3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% Copyright 2010 Chih-Yuan Yang, Jia-Bin Huang, and Ming-Hsuan Yang
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%Chih-Yuan Yang, EECS, UC Merced
%2013/2/22
function CoefMatrix = FindCoef3( Para , Iter)
TempFolder = Para.TempDataFolder;
SaveName = Para.SaveName;
% tStart = now;
addpath(fullfile('Lib','spgl1-1.7'));
codesize = Para.DictionarySize;
load(fullfile(TempFolder, [SaveName '_ClusterResultAllMatchArray_Avg' num2str(Para.AvgSignalNumPerCluster) '.mat']), 'AllMatchArray', 'ClusterNum');
LoadData = load(fullfile(TempFolder, [SaveName '_DlDh' num2str(Iter-1) '.mat']));
Dictionary = [LoadData.DlDh];
clear LoadData;
LoadData = load(fullfile(TempFolder, [SaveName '_XlXh.mat']));
XlXh = LoadData.XlXh;
SignalNum = size(XlXh,2);
clear LoadData;
CoefMatrix_Sum = zeros( codesize, SignalNum ); %out of memory here
CoefMatrix_ClusterCount = zeros(1,SignalNum);
BaseSigma = Para.BaseSigma;
opts = spgSetParms('verbosity',0,'iterations',Para.IterNumForGroupSparseCoding); %1000
OptimizationSum = 0;
for CluIdx = 1:ClusterNum
MatchArray = AllMatchArray(:,CluIdx);
InClusterNum = sum(MatchArray);%AllInClusterNum(CluIdx);
sigma = BaseSigma * sqrt(InClusterNum); %Feb 17, add sqrt, adding should be correct
InClusterGroupIdx = MatchArray';
Y = XlXh(:,InClusterGroupIdx);
if ~isempty(Y)
Coef = spg_mmv(Dictionary,Y,sigma,opts); %the form is min ||X||1,2 s.t. ||AX-B||2,2 <= sigma
CoefMatrix_Sum(1:codesize, InClusterGroupIdx) = CoefMatrix_Sum(1:codesize, InClusterGroupIdx) + Coef;
CoefMatrix_ClusterCount(InClusterGroupIdx) = CoefMatrix_ClusterCount(InClusterGroupIdx) + 1;
disp( ['Find Coef ...' num2str(CluIdx) ' / ' num2str(ClusterNum)]);
DiffMatrix = Y - Dictionary * Coef;
DiffSquare = DiffMatrix.*DiffMatrix;
GroupSignalDiff = sum(DiffSquare(:));
CoefSquare = Coef .* Coef;
CoefpqNorm = sum(sqrt(sum(CoefSquare,2)));
OptimizationSum = OptimizationSum + GroupSignalDiff + CoefpqNorm;
end
%Compute the optimization sum
%pause(0.1);
end
CoefMatrix = CoefMatrix_Sum ./ repmat(CoefMatrix_ClusterCount , codesize , 1);
% OptSum_Coef = OptimizationSum;
% WriteToInfoFile(OptSum_Coef, Para);
save(fullfile(TempFolder, [SaveName '_CoefMatrix_Iter' num2str(Iter) '.mat']) , 'CoefMatrix' );
% rmpath('lib\spgl1-1.7');
% tEnd = now;
% CoefFindTime = ['(Iter' num2str(Iter) ')' datestr(tEnd-tStart, 'dd:HH:MM:SS')];
% WriteToInfoFile( CoefFindTime , Para );
end