forked from ZhuoSun1987/GroupLassoSVM_SAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyperParaTuning_CV_SVM.m
101 lines (89 loc) · 2.85 KB
/
HyperParaTuning_CV_SVM.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function [ ReportStruct ] = HyperParaTuning_CV_SVM( X,Y,Dividing,SAAOption0,SparseOpt0,FolderRoot,LambdaArray,StepType)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
%
% this funciton is used to compute the result using different parameter
% and make a report
% Lambda(1) the weight of max margin, Lambda(2) the weight of SAR,
% lambda(3) the weight of sparsity
%
% LambdaArray is a cell array, and each cell is a parameter combination
PD=length(LambdaArray{1});
N =length(LambdaArray);
AccList=zeros(N,1);
AUCList=zeros(N,1);
SenList=zeros(N,1);
SpeList=zeros(N,1);
recallList=zeros(N,1);
gmeanList=zeros(N,1);
fList=zeros(N,1);
FolderList=cell(N,1);
precisionList=zeros(N,1);
if ~exist(FolderRoot,'dir')
mkdir(FolderRoot);
end
if nargin<7 | isempty(StepType)
StepType='Fix';
end
ReportPath=fullfile(FolderRoot,'ReportStruct.mat');
t1=clock;
% compute the result from different parameters
if ~exist(ReportPath,'file')
parfor i=1:N
LambdaList=LambdaArray{i};
% generate folder name
FolderName=[];
for j=1:PD
FolderName=fullfile(FolderName,['L',num2str(j),'_',num2str(LambdaList(j))]);
end
FolderList{i}=FolderName;
% update the options for the current lambdalist
SparseOpt=SparseOpt0;
SparseOpt.Lambda4=LambdaList(3);
SparseOpt.C_Or_R=2;
SAAOption=SAAOption0;
Lambda=0;
if LambdaList(1)>0
Lambda=LambdaList(1);
if LambdaList(2)>0
SAAOption.Ratio=LambdaList(2)/LambdaList(1);
else
% only the max margin
SAAOption.Ratio=0;
end
else
Lambda=LambdaList(2);
if LambdaList(2)>0
SAAOption.OnlySAA=1;
else
Lambda=0;
SAAOption.Ratio=0;
end
end
% computing
[ Result ] = nFold_ZhuoSVM_TrainingSet( X,Y,Dividing,Lambda,SAAOption,SparseOpt,FolderRoot,FolderName,StepType);
%
AccList(i)=Result.accuracy;
AUCList(i)=Result.AUC;
SenList(i)=Result.sensitivity;
SpeList(i)=Result.specificity;
recallList(i)=Result.recall;
gmeanList(i)=Result.gmean;
precisionList(i)=Result.precision;
fList(i)=Result.f_measure;
end
ReportStruct=[];
ReportStruct.AccList=AccList;
ReportStruct.AUCList=AUCList;
ReportStruct.SenList=SenList;
ReportStruct.SpeList=SpeList;
ReportStruct.precisionList=precisionList;
ReportStruct.recallList=recallList;
ReportStruct.gmeanList=gmeanList;
ReportStruct.fList=fList;
ReportStruct.FolderList=FolderList;
ReportStruct.LambdaArray=LambdaArray;
end
t2=clock;
disp(['Start from ',datestr(t1),' to ',datestr(t2),' time cost ',num2str(etime(t2,t1)),' seconds'])
end