Skip to content

Commit

Permalink
improve entropy
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Oct 22, 2017
1 parent 159d5cd commit c4df199
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions chapter01/entropy.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
% z: entropy z=H(x)
% Written by Mo Chen ([email protected]).
n = numel(x);
[u,~,x] = unique(x);

This comment has been minimized.

Copy link
@MTobe

MTobe Jan 2, 2019

[u,~,x] = unique(x);

k = numel(u);
idx = 1:n;
Mx = sparse(idx,x,1,n,k,n);
Px = nonzeros(mean(Mx,1));
[~,~,x] = unique(x);
Px = accumarray(x, 1)/n;
Hx = -dot(Px,log2(Px));
z = max(0,Hx);

0 comments on commit c4df199

Please sign in to comment.