Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirentropy.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function varargout = mirentropy(x,varargin) | |
2 % h = mirentropy(a) calculates the relative entropy of a. | |
3 % (Cf. User's Manual.) | |
4 % mirentropy(..., ?Center?) centers the input data before | |
5 % transforming it into a probability distribution. | |
6 | |
7 center.key = 'Center'; | |
8 center.type = 'Boolean'; | |
9 center.default = 0; | |
10 option.center = center; | |
11 | |
12 specif.option = option; | |
13 | |
14 varargout = mirfunction(@mirentropy,x,varargin,nargout,specif,@init,@main); | |
15 | |
16 | |
17 function [x type] = init(x,option) | |
18 if isamir(x,'miraudio') | |
19 x = mirspectrum(x); | |
20 end | |
21 type = 'mirscalar'; | |
22 | |
23 | |
24 function h = main(x,option,postoption) | |
25 if iscell(x) | |
26 x = x{1}; | |
27 end | |
28 m = get(x,'Data'); | |
29 v = cell(1,length(m)); | |
30 for h = 1:length(m) | |
31 v{h} = cell(1,length(m{h})); | |
32 for k = 1:length(m{h}) | |
33 mk = m{h}{k}; | |
34 mn = mk; | |
35 if isa(x,'mirhisto') || isa(x,'mirscalar') | |
36 mn = mn'; | |
37 end | |
38 | |
39 if option.center | |
40 mn = center(mn); | |
41 end | |
42 | |
43 % Negative data is trimmed: | |
44 mn(mn<0) = 0; | |
45 | |
46 % Data is normalized such that the sum is equal to 1. | |
47 mn = mn./repmat(sum(mn)+repmat(1e-12,... | |
48 [1 size(mn,2) size(mn,3) size(mn,4)]),... | |
49 [size(mn,1) 1 1 1]); | |
50 | |
51 % Actual computation of entropy | |
52 v{h}{k} = -sum(mn.*log(mn + 1e-12))./log(size(mn,1)); | |
53 | |
54 if isa(x,'mirhisto') || isa(x,'mirscalar') | |
55 v{h}{k} = v{h}{k}'; | |
56 end | |
57 end | |
58 end | |
59 t = ['Entropy of ',get(x,'Title')]; | |
60 h = mirscalar(x,'Data',v,'Title',t); |