Mercurial > forge
changeset 2638:d2a6ba4f9e96 octave-forge
huffmandict updated to perform as wanted in the mailing list: with code-words for zero probability symbols, eventhough I wouldnt do it myself, and moreover its 'canonical huffman' which I think warrants this
author | gnumuthu |
---|---|
date | Mon, 09 Oct 2006 16:15:35 +0000 |
parents | 0e554b247bbd |
children | 29221eb66fd1 |
files | main/comm/inst/huffmandict.m |
diffstat | 1 files changed, 6 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/main/comm/inst/huffmandict.m Mon Oct 09 16:06:33 2006 +0000 +++ b/main/comm/inst/huffmandict.m Mon Oct 09 16:15:35 2006 +0000 @@ -88,8 +88,11 @@ % %need to find & eliminate the zero-probability code words. %in practice we donot need to assign anything to them. Reasoning - %being that if it doesnt occur why bother saving its vale anyway? - % + %being that if_ it doesnt occur why bother saving its value anyway? + %--(Oct 9) Actually some experts in the area dont agree to this, + %and being a generic implementation we should stick to generating + %CW's for_ zero symbols. Why impose a bad implementation? --Muthu + % origsource_prob=source_prob; @@ -112,15 +115,6 @@ end end - %index - %source_prob - - idx=find(source_prob==0); - if(not(isempty(idx))) - source_prob=source_prob(1:idx(1)-1); - end - clear idx; - stage_list={}; cw_list{1:L}=[]; @@ -234,4 +228,5 @@ %! %!assert(huffmandict(1:4,[0.5 0.25 0.15 0.1],1), {[0],[1 0],[1 1 1],[1 1 0]},0) %!assert(huffmandict(1:4,0.25*ones(1,4),1),{[1 1],[1 0],[0 1],[0 0]},0) +%!assert(huffmandict(1:4,[1 0 0 0 ]),{[1],[0 1],[0 0 0],[0 0 1]},0) %!