function result = kl_divg(p, q)
epsilon = 1e-10;
p = max(p, epsilon);
q = max(q, epsilon);
result = sum(p .* log2(p ./ q));
end
E_plus = [0.89 0.03 0.08; 0.42 0.05 0.35; 0.73 0.02 0.06; 0.85 0.02 0.05];
E_minus = [0.23 0.21 0.08; 0.02 0.18 0.35; 0.08 0.84 0.06; 0.43 0.25 0.05];
E_i_set = {
[0.89 0.03 0.08; 0.42 0.18 0.35; 0.08 0.02 0.89; 0.80 0.05 0.11],
[0.23 0.11 0.64; 0.03 0.13 0.82; 0.73 0.08 0.15; 0.73 0.14 0.10],
[0.52 0.05 0.26; 0.04 0.10 0.85; 0.68 0.06 0.26; 0.43 0.25 0.13],
[0.74 0.10 0.16; 0.02 0.05 0.89; 0.08 0.84 0.06; 0.85 0.05 0.09],
[0.68 0.21 0.08; 0.05 0.06 0.87; 0.13 0.09 0.75; 0.65 0.02 0.05]
};
for i = 1:length(E_i_set)
E_i = E_i_set{i};
dgs_plus = zeros(size(E_i, 1), 1);
dgs_minus = zeros(size(E_i, 1), 1);
for j = 1:size(E_i, 1)
p = E_i(j, :) ./ sum(E_i(j, :));
q_plus = E_plus(j, :) ./ sum(E_plus(j, :));
q_minus = E_minus(j, :) ./ sum(E_minus(j, :));
m_plus = (p + q_plus) / 2;
dgs_plus(j) = 0.5 * (kl_divg(p, m_plus) + kl_divg(q_plus, m_plus));
m_minus = (p + q_minus) / 2;
dgs_minus(j) = 0.5 * (kl_divg(p, m_minus) + kl_divg(q_minus, m_minus));
end
closeness_coefficient = mean(dgs_minus) / (mean(dgs_plus) + mean(dgs_minus));
fprintf('E%d: DGS(Ei, E+) = %.4f, DGS(Ei, E-) = %.4f, Closeness Coefficient = %.4f\n', i
, mean
(dgs_plus
), mean
(dgs_minus
), closeness_coefficient
); end
ZnVuY3Rpb24gcmVzdWx0ID0ga2xfZGl2ZyhwLCBxKQogICAgZXBzaWxvbiA9IDFlLTEwOwogICAgcCA9IG1heChwLCBlcHNpbG9uKTsKICAgIHEgPSB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X3BsdXMoaiwgOikpOwogICAgICAgIHFfbWludXMgPSBFX21pbnVzKGosIDopIC4vIHN1bShFX21pbnVzKGosIDopKTsKICAgICAgICAKICAgICAgICBtX3BsdXMgPSAocCArIHFfcGx1cykgLyAyOwogICAgICAgIGRnc19wbHVzKGopID0gMC41ICogKGtsX2RpdmcocCwgbV9wbHVzKSArIGtsX2RpdmcocV9wbHVzLCBtX3BsdXMpKTsKICAgICAgICAKICAgICAgICBtX21pbnVzID0gKHAgKyBxX21pbnVzKSAvIDI7CiAgICAgICAgZGdzX21pbnVzKGopID0gMC41ICogKGtsX2RpdmcocCwgbV9taW51cykgKyBrbF9kaXZnKHFfbWludXMsIG1fbWludXMpKTsKICAgIGVuZAogICAgCiAgICBjbG9zZW5lc3NfY29lZmZpY2llbnQgPSBtZWFuKGRnc19taW51cykgLyAobWVhbihkZ3NfcGx1cykgKyBtZWFuKGRnc19taW51cykpOwogICAgZnByaW50ZignRSVkOiBER1MoRWksIEUrKSA9ICUuNGYsIERHUyhFaSwgRS0pID0gJS40ZiwgQ2xvc2VuZXNzIENvZWZmaWNpZW50ID0gJS40ZlxuJywgaSwgbWVhbihkZ3NfcGx1cyksIG1lYW4oZGdzX21pbnVzKSwgY2xvc2VuZXNzX2NvZWZmaWNpZW50KTsKZW5kCgo=
E1: DGS(Ei, E+) = 0.1575, DGS(Ei, E-) = 0.2947, Closeness Coefficient = 0.6517
E2: DGS(Ei, E+) = 0.1675, DGS(Ei, E-) = 0.1993, Closeness Coefficient = 0.5433
E3: DGS(Ei, E+) = 0.1312, DGS(Ei, E-) = 0.1868, Closeness Coefficient = 0.5875
E4: DGS(Ei, E+) = 0.2395, DGS(Ei, E-) = 0.0767, Closeness Coefficient = 0.2425
E5: DGS(Ei, E+) = 0.1929, DGS(Ei, E-) = 0.1989, Closeness Coefficient = 0.5077