entropy.m
来自「数据降维工具箱」· M 代码 · 共 40 行
M
40 行
function e = entropy(x, y)%ENTROPY Computes entropy e for vector x or joint entropy for (x, y).%% e = entropy(x)% e = entropy(x, y)%% Computes entropy e for vector x or joint entropy for (x, y). This% function uses base number 1024 for the logarithm.%%% This file is part of the Matlab Toolbox for Dimensionality Reduction v0.3b.% The toolbox can be obtained from http://www.cs.unimaas.nl/l.vandermaaten% You are free to use, change, or redistribute this code in any way you% want for non-commercial purposes. However, it is appreciated if you % maintain the name of the original author.%% (C) Laurens van der Maaten% Maastricht University, 2007 warning off % Compute relative frequency of values x = x(1:end); if nargin == 1 p = freq(double(x)); else if numel(x) ~= numel(y) e = -1; warning('Sizes of vector do not match.'); return; end y = y(1:end); p = joint_freq(double(x), double(y)); end % Compute Shannon entropy xlogy(repmat(256, [length(p) 1]), p); e = -sum(p .* xlogy(repmat(256, [length(p) 1]), p));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?