-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCost.m
34 lines (26 loc) · 893 Bytes
/
Cost.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
function [z,Output]=Cost(x,xtrain,ytrain,xtest,ytest)
global NFE;
if isempty(NFE)
NFE=0;
end
NFE=NFE+1;
X1 = CreateRegressorsMatrix(xtrain,x);
X1=Check(X1);
temp=X1*X1'+eye(size(X1*X1'));
temp=Check(temp);
c = ytrain*(pinv(temp)*X1)';
Y1hat = c*(X1);
Y1hat = min(max(Y1hat,0),1);
X2 = CreateRegressorsMatrix(xtest,x);
Y2hat = c*(X2);
% [test.Accuracy,test.Precision,test.Se,test.FSCORE,test.Sp]=multiclassparam(round(ytest'),round(ytest'),round(Y2hat)',round(Y2hat)');
Y1hat=real(Y1hat);
Y2hat=real(Y2hat);
[~,test]=calculate_info_theory(round(ytrain'),round(ytest'),round(Y1hat)',round(Y2hat)');% 0 and 1s
test.MCC=Check(test.MCC);
test.Sp=Check(test.Sp);
test.Se=Check(test.Se);
z=(1-(test.MCC*test.Se+test.Sp*test.Precision)/2);
Output.test=test;
Output.c=c;
end