亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? huffman.m

?? Generates a static minimum-variance Huffman code tree.
?? M
字號:
function C = huffman(D,W,varargin)
% HUFFMAN   Huffman encoder.
%    C = HUFFMAN(D,W) generates a static minimum-variance Huffman tree and
%    corresponding codebook C for the source symbols with nonnegative
%    weights given by vector W, using a D-ary output code alphabet,
%    e.g. D = 2 for a binary output code alphabet.
%    W is an N-vector of nonnegative source symbol weights, where N is the
%    number of source symbols.
%    The generated Huffman code C minimizes the weighted codeword length,
%    e.g. if the weight is the probability of the source symbol, then C
%    minimizes the expected codeword length.
%    C is an N-vector of strings (i.e. cell array) giving the
%    codewords for each of the N source symbols in W.
%
%    C = HUFFMAN(D,W,L,'screen') additionally displays a simple text
%    rendition of the resulting Huffman code tree, with the source symbol
%    labels given by L. L is an N-vector of strings (i.e. cell array)
%    containing the labels for each of the N source symbols.
%
%    C = HUFFMAN(D,W,L,'dot') additionally creates a DOT file describing the
%    resulting Huffman code tree, and runs Graphviz DOT to create the
%    corresponding PNG image. The output files are automatically
%    time-stamped. The source symbol labels are given by L, which is an
%    N-vector of strings (i.e. cell array) containing the labels for each
%    of the N source symbols. Please ensure that Graphviz DOT is accessible
%    from the current directory (e.g. by adding it to the path).
%
%    Multiple output can be requested using a single command, e.g.
%    C = HUFFMAN(D,W,L,'dot','screen')


% VALIDATE INPUT ARGUMENTS

% check vector W describing the nonnegative source symbol weights
if ~isvector(W)
	error('Input argument W must be a vector.');
end

if min(W) < 0
	error('Input argument W must contain nonnegative entries.');
end

% number of source symbols
N = length(W);

% check code alphabet size D
if ~isscalar(D)
	error('Input argument D must be a scalar.');
end

codeAlphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if D > length(codeAlphabet)
	error(['Not enough literal characters to accommodate requested code alphabet; '...
		'please modify the source code manually to add more characters.']);
end

% source symbol labels
if ~isempty(varargin)
	L = varargin{1};

	if ~isvector(L)
		error('Input argument L must be a vector.');
	end

	if  length(L) ~= N
		error('Input arguments W and L must be vectors of the same length.');
	end
end

% output types
outputScreen = false;
outputDot = false;

for i = 2:length(varargin)
	output = varargin{i};

	if strcmp(output,'screen')
		outputScreen = true;
	elseif strcmp(output,'dot')
		outputDot = true;
	else
		error(['Input argument ''' output ''' is not a recognized output type.']);
	end
end


% BUILD HUFFMAN CODE TREE

% create a tree node for each of the N source symbols
for i = 1:N
	H(i).weight = W(i);  % weight
	H(i).children = [];  % this node has no children
	H(i).height = 0;     % this subtree has height 0
	H(i).exposed = true; % this node is exposed
	H(i).dummy = false;  % this node is not a dummy
end

% check if dummy nodes are needed
k = floor((N-1) / (D-1));
nDummyNodes = 0;
if (N-1) - k*(D-1) ~= 0
	nDummyNodes = (k+1) * (D-1) - (N-1);

	for i = 1:nDummyNodes
		H(N+i).weight = 0;     % weight
		H(N+i).children = [];  % this node has no children
		H(N+i).height = 0;     % this subtree has height 0
		H(N+i).exposed = true; % this node is exposed
		H(N+i).dummy = true;   % this node is a dummy
	end
end

% iteratively merge D subtrees at a time, until only 1 subtree is left
while sum([H.exposed] == true) > 1

	% sort exposed nodes in ascending order of weight
	exposedIndices = find([H.exposed] == true);
	allWeights = [H.weight];
	allHeights = [H.height];
	[Y,I] = sortrows([allWeights(exposedIndices)' allHeights(exposedIndices)'], [1 2]);
	sortedIndices = exposedIndices(I);

	% combine first D nodes into a new node
	combinedIndices = sortedIndices(1:D);
	for i = 1:D
		H(combinedIndices(i)).exposed = false;
	end

	ii = length(H) + 1;
	H(ii).weight = sum(allWeights(combinedIndices));  % sum of weights
	H(ii).children = sortedIndices(1:D);  % this node has D children
	H(ii).height = max(allHeights(combinedIndices)) + 1; % height of new subtree
	H(ii).exposed = true; % this node is exposed
	H(ii).dummy = false;  % this node is not a dummy
end

% PARSE CODE TREE TO GENERATE CODEWORDS

rootIndex = find([H.exposed] == true);
if isscalar(rootIndex) == false
	error('Internal error building Huffman tree.');
end

% initialize return value, i.e. codewords
for i = 1:N
	C{i} = '';
end

if outputDot
	% open DOT output file for writing
	filename = ['dot.' datestr(now,'yyyymmdd.HHMMSS')];
	fid = fopen([filename '.txt'],'w');

	fprintf(fid,'digraph Huffman {\nrankdir=TB');
end

% parse the code tree, beginning from the root
parseCodeTree(rootIndex,'');

if outputScreen
	% display statistics
	fprintf('\n\nSTATISTICS:');
	fprintf('\n   Number of source symbols N = %d', N);

	if nDummyNodes > 0
		fprintf('\n   Number of dummy nodes added = %d', nDummyNodes);
	end

	tw = 0;
	for i = 1:N
		tw = tw + W(i);
	end
	fprintf('\n   Total weight = sum{i=1:N} W_i = %g', tw);

	wcl = 0;
	for i = 1:N
		wcl = wcl + length(C{i}) * W(i);
	end
	fprintf('\n   (A) Weighted codeword length = sum{i=1:N} length(C_i) * W_i = %g', wcl);

	wll = 0;
	for i = 1:N
		wll = wll + length(L{i}) * W(i);
	end
	fprintf('\n   (B) Weighted label length    = sum{i=1:N} length(L_i) * W_i = %g', wll);

	fprintf('\n   Ratio (A) / (B) = %g', wcl / wll);

	fprintf('\n\n');
end

% call Graphviz dot if requested
if outputDot
	fprintf(fid,'\n}\n');
	fclose(fid);
	eval(['!dot -Tpng ' filename '.txt -o ' filename '.png']);

	% display image using default external program
	eval(['!' filename '.png']);

	% display image in MATLAB
	%[X, map] = imread([filename '.png']);
	%figure(1);
	%image(X);
	%colormap(map);
	%axis off;
	%axis image;
end


% NESTED FUNCTIONS

	function parseCodeTree(nodeIndex,nodeCodeword)
		% Parse nodes in the code tree recursively.

		node = H(nodeIndex);

		if outputScreen
			% create padding string
			padding = [''];
			for l = 1:length(nodeCodeword);
				padding = [padding '   '];
			end
		end

		if outputScreen
			if nodeIndex == rootIndex
				rootIndicator = ' (ROOT)';
			else
				rootIndicator = '';
			end
		end

		if isempty(node.children)
			if node.dummy == true
				% this is a dummy leaf node
				if outputScreen
					fprintf('\n%s[''%s'',%g]%s (DUMMY)',...
						padding, nodeCodeword, node.weight,rootIndicator);
				end

				if outputDot
					fprintf(fid,'\nNODEID%s [shape=record, label="''%s''\\n[%g]\\n(DUMMY)%s", style=filled, fillcolor=lightgrey]',...
						nodeCodeword, nodeCodeword, node.weight, rootIndicator);
				end
			else
				% this is a source symbol (non-dummy leaf node)
				C{nodeIndex} = nodeCodeword;

				if outputScreen
					fprintf('\n%s[''%s'',%g] ''%s''%s (SOURCE)',...
						padding, nodeCodeword, node.weight, L{nodeIndex}, rootIndicator);
				end

				if outputDot
					fprintf(fid,'\nNODEID%s [shape=record, label="''%s''\\n[%g]\\n''%s''\\n(SOURCE)%s", style=filled, fillcolor=salmon]',...
						nodeCodeword, nodeCodeword, node.weight, L{nodeIndex}, rootIndicator );
				end
			end
		else
			% this node is not a leaf
			if outputScreen
				fprintf('\n%s[''%s'',%g]%s',...
					padding, nodeCodeword, node.weight, rootIndicator);
			end

			if outputDot
				fprintf(fid,'\nNODEID%s [shape=record, label="''%s''\\n[%g]\\n%s", style=filled, fillcolor=white]',...
					nodeCodeword, nodeCodeword, node.weight, rootIndicator);
			end

			% recurse into child nodes
			for l = 1:length(node.children)
				childCodeword = [nodeCodeword, codeAlphabet(l)];

				if outputDot
					if H(node.children(l)).dummy == true
						% child is a dummy node
						fprintf(fid,'\nNODEID%s -> NODEID%s [sametail, label="%s", style=dotted]',...
							nodeCodeword, childCodeword, codeAlphabet(l));
					else
						% child is not a dummy node
						fprintf(fid,'\nNODEID%s -> NODEID%s [sametail, label="%s"]',...
							nodeCodeword, childCodeword, codeAlphabet(l));
					end
				end

				parseCodeTree(node.children(l), childCodeword);
			end
		end
	end

end

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
琪琪久久久久日韩精品| 欧美日韩国产综合一区二区| 欧美亚洲一区二区三区四区| 欧美电影免费观看完整版| 亚洲欧洲日韩综合一区二区| 狠狠网亚洲精品| 欧美日韩一区二区在线观看| 亚洲欧洲三级电影| 高潮精品一区videoshd| 欧美日韩卡一卡二| 一区在线中文字幕| 国产99精品视频| 精品免费视频.| 热久久一区二区| 欧美日本在线视频| 亚洲成人tv网| 欧美三级电影在线看| 亚洲人成网站影音先锋播放| 成人av片在线观看| 久久精品视频在线看| 韩国视频一区二区| 日韩精品最新网址| 免费在线看成人av| 欧美一区二区三区电影| 日韩—二三区免费观看av| 欧美色图在线观看| 亚洲第一成人在线| 欧美精品日韩一区| 免费人成精品欧美精品| 日韩欧美国产综合| 经典三级视频一区| 久久久天堂av| 成人天堂资源www在线| 中文幕一区二区三区久久蜜桃| 国产精品自拍毛片| 国产精品久久久久aaaa樱花 | 欧美大片国产精品| 国内久久婷婷综合| 久久精品日韩一区二区三区| 国产69精品久久久久777| 日本一区二区免费在线| www.色精品| 亚洲小说欧美激情另类| 69久久99精品久久久久婷婷| 美国十次了思思久久精品导航| 日韩一二三四区| 国产精品中文字幕欧美| 中文一区一区三区高中清不卡| 成人av资源站| 亚洲电影一区二区| 精品国产成人在线影院 | jizzjizzjizz欧美| 中文字幕人成不卡一区| 欧美日韩国产综合一区二区 | 亚洲国产cao| 日韩区在线观看| 国产91对白在线观看九色| 成人免费在线视频| 4438成人网| 大胆欧美人体老妇| 亚洲最大色网站| 日韩久久免费av| 色综合久久久久综合体桃花网| 天堂精品中文字幕在线| 久久一留热品黄| 欧美亚洲另类激情小说| 久草热8精品视频在线观看| 国产精品久久久久久久午夜片| 欧美在线播放高清精品| 国内久久精品视频| 一区二区三区国产精品| 精品国产91亚洲一区二区三区婷婷| 99国产欧美久久久精品| 免费成人深夜小野草| 亚洲视频每日更新| 精品国产成人在线影院 | 久久综合色天天久久综合图片| 成人国产视频在线观看| 男女激情视频一区| 一区二区三区日韩精品视频| 精品电影一区二区| 欧美日韩精品专区| 91亚洲男人天堂| 国产精品77777竹菊影视小说| 丝袜a∨在线一区二区三区不卡| 国产女人水真多18毛片18精品视频| 884aa四虎影成人精品一区| 91麻豆免费观看| 国产成人午夜电影网| 久久精品国产亚洲aⅴ| 亚洲一区在线看| 最新久久zyz资源站| 国产午夜三级一区二区三| 91精品黄色片免费大全| 色综合久久久久网| 不卡一区二区中文字幕| 国产高清不卡一区| 精品一区二区三区日韩| 天天射综合影视| 亚洲精品成人悠悠色影视| 国产精品国产三级国产aⅴ入口 | 欧美日本精品一区二区三区| 91首页免费视频| 国产suv精品一区二区883| 国产在线播放一区三区四| 六月丁香综合在线视频| 爽爽淫人综合网网站| 午夜a成v人精品| 五月开心婷婷久久| 天天综合日日夜夜精品| 日本一道高清亚洲日美韩| 午夜伊人狠狠久久| 日韩精彩视频在线观看| 日韩极品在线观看| 蜜桃av一区二区三区| 九色综合狠狠综合久久| 精品系列免费在线观看| 国产一区二区女| 成人午夜免费av| 色偷偷久久一区二区三区| 欧洲精品在线观看| 欧美精选一区二区| 日韩一区二区免费电影| wwwwxxxxx欧美| 国产精品久久夜| 亚洲精品国产高清久久伦理二区| 一区二区三区在线视频观看 | 亚洲丝袜另类动漫二区| 亚洲精品成人精品456| 午夜在线成人av| 狠狠色综合日日| www.视频一区| 欧美精品亚洲一区二区在线播放| 欧美一级高清大全免费观看| 26uuu国产在线精品一区二区| 国产午夜精品福利| 亚洲女同一区二区| 日日夜夜免费精品视频| 国产麻豆视频精品| 欧美在线观看你懂的| 精品99一区二区| 国产精品久久久久久久久图文区| 亚洲一区免费观看| 精品一区二区三区久久久| 国产91高潮流白浆在线麻豆| 在线观看免费成人| 久久久久久久综合日本| 中文字幕一区av| 人禽交欧美网站| 99国产精品久久久久久久久久久| 7777精品伊人久久久大香线蕉的 | 欧美精品 国产精品| 26uuu久久综合| 一区二区三区国产精品| 久久se这里有精品| 日本久久一区二区三区| 精品免费视频.| 亚洲va在线va天堂| 波多野结衣在线aⅴ中文字幕不卡| 欧美日韩精品一区二区| 国产欧美va欧美不卡在线| 午夜不卡av在线| 色综合中文字幕| 久久久精品国产免费观看同学| 亚洲午夜激情网站| 本田岬高潮一区二区三区| 日韩欧美一区二区久久婷婷| 亚洲另类一区二区| 国产成人午夜片在线观看高清观看| 欧美精品自拍偷拍| 一区二区三区中文字幕在线观看| 国产一区二区网址| 欧美一级高清大全免费观看| 一二三四区精品视频| 国产**成人网毛片九色| 精品99999| 卡一卡二国产精品| 欧美二区三区的天堂| 亚洲男人的天堂一区二区| 大胆亚洲人体视频| 国产亚洲婷婷免费| 国产精品一二三四| 欧美精品一区在线观看| 久久国产精品色婷婷| 制服丝袜在线91| 亚洲成人av资源| 欧美优质美女网站| 亚洲理论在线观看| 色激情天天射综合网| 亚洲欧美一区二区三区极速播放| 国产福利精品导航| 国产欧美日本一区视频| 国产成人精品免费在线| 国产日韩欧美一区二区三区乱码 | 欧美国产97人人爽人人喊| 国产精品12区| 久久免费美女视频| 国产高清在线精品| 亚洲国产精品成人综合色在线婷婷 | 欧美精品免费视频|