-
Notifications
You must be signed in to change notification settings - Fork 5
/
FeatureSelectionCost.m
56 lines (42 loc) · 1.03 KB
/
FeatureSelectionCost.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
function [z, out]=FeatureSelectionCost(s,data)
% Read Data Elements
x=data.x;
t=data.t;
% Selected Features
S=find(s~=0);
% Number of Selected Features
nf=numel(S);
% Ratio of Selected Features
rf=nf/numel(s);
% Selecting Features
xs=x(S,:);
% Weights of Train and Test Errors
wTrain=0.8;
wTest=1-wTrain;
% Number of Runs
nRun=1;
EE=zeros(1,nRun);
for r=1:nRun
% Create and Train ANN
results=CreateAndTrainANN(xs,t);
% Calculate Overall Error
EE(r) = wTrain*results.TrainData.E + wTest*results.TestData.E;
end
E=mean(EE);
%if isinf(E)
% E=1e10;
%end
% Calculate Final Cost
beta=0.5;
z=E*(1+beta*rf);
% Set Outputs
out.S=S;
out.nf=nf;
out.rf=rf;
out.E=E;
out.z=z;
%out.net=results.net;
%out.Data=results.Data;
%out.TrainData=results.TrainData;
%out.TestData=results.TestData;
end