Why is Matlab relativeEntropy Function inconsistent with Manual Method?
Mostrar comentarios más antiguos
Dear Matlab Experts,
When I use relativeEntropy function (R2020a) it appears inconsistent when I check it with a manual method.
Four questions:
1) Can I use real numbers with this Function,
2) Can I use different sample sizes (p vs q sample sizes)
3) Any idea why function vs manual method does not provide the same top-10 features with highest entropies?
4) Why does function vs manual has different orders of magnitude for all calculations?
Thank you for any insights.
Best Regards,
--Allen
% RELATIVE ENTROPY
% dataForRelEnt, 10 x 75 table
% dataForRelEnt values: 0.000 to 1.000
% 1:6 rows are controlled samples
% 7:10 rows are random samples
% 1:75 cols are features
% Sample Labels: Controlled=1, Random=0
%
% GOAL: Compute Relative Entropy for each feature (cols 1:75) to evaluate separation
% of controlled samples (rows 1:6) from random samples (rows 7:10)
% MATLAB FUNCTION
% https://www.mathworks.com/help/predmaint/ref/relativeentropy.html
relEntMatlab = relativeEntropy(dataForRelEnt{1:10,:},logical([1,1,1,1,1,1,0,0,0,0]));
[~, idxMaxMat] = maxk(~isinf(relEntMatlab),10); % 10 highest Entropies, Function
% MANUAL METHOD = sum(p(x)*ln(p(x)/q(x))
% p(x) true event prob; q(x) random or estimated event prob
% Since X values range from 0.000 to 1.000,
% let p(x for i-th feature)=mean(rows 1:6) for i-th col
% q(x for i-th feature)=mean(rows 7:10) for i-th col
% --> one controlled and random sample for each feature
for i=1:75
p_event = mean(dataForRelEnt{1:6,i}); % p(x)
q_event = mean(dataForRelEnt{7:10,i}); % q(x)
relEntManual(i)= p_event*log(p_event/q_event);
end
[~, idxMaxMan] = maxk(relEntManual,10); % 10 highest Entropies, Manual
% COMPARE FUNCTION vs MANUAL METHOD
compareTopFeatures=[idxMaxMat;idxMaxMan]';
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Resampling Techniques en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!