-
Notifications
You must be signed in to change notification settings - Fork 3
/
cross_entropy.m
64 lines (52 loc) · 1.39 KB
/
cross_entropy.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
% Main paper:
% Segmentation of Brain MRI using an Altruistic Harris Hawks' Optimization algorithm
% Rajarshi Bandopadhyay, Rohit Kundu, Diego Oliva, Ram Sarkar
% _____________________________________________________
function [fit] = cross_entropy(x,h)
st = size(x,2);
for i = 1:st+1
if i == 1 % The 1st Part
ti = x(i);
ti_1 = 1;
nu(i) = mEin(ti_1,ti,h)*(log(mEin(ti_1,ti,h)/mZero(ti_1,ti,h))); %cross entropy
elseif i> st % Last Part
ti=256;
ti_1=x(i-1);
nu(i) = mEin(ti_1,ti,h)*(log(mEin(ti_1,ti,h)/mZero(ti_1,ti,h)));
else % Original
ti=x(i);
ti_1=x(i-1);
nu(i) =mEin(ti_1,ti,h)*(log( mEin(ti_1,ti,h)/mZero(ti_1,ti,h)));
end
end
sumNU=sum(nu);
if (isnan(sumNU)==1)
fit=-1*sumNU;
else
fit=-1*sumNU;
end
end
function [u] = mEin(aa,bb,ih)
bm_1=bb-1;
dif_bm_1=abs(aa-bb);
inten= linspace(aa,bm_1,dif_bm_1);
inten=inten';
H=ih(aa:bm_1);
% if size(inten,1)~=size(H,1)
% size(inten,1)
% size(H,1)
% size(inten,1)
% end
% if size(inten,2)~=size(H,2)
% size(inten,2)
% size(H,2)
% end
%
uu=inten.*H;
u=sum(uu);
end
function [u]=mZero(aa,bb,ih)
bm_1=bb-1;
h=ih(aa:bm_1);
u= sum(h);
end