1

我有以下给我的代码,但我完全不确定这里的逻辑是什么。我相信这个想法是这将对我的数据进行直方图/量化。这是代码:

输入:

x = 180.*rand(1,1000); %1000 points from 0 to 180 degrees.
binWidth = 20;         %I want the binWidth to be 20 degrees.

主要功能:

% -------------------------------------------------------------------------
% Compute the closest bin center x1 that is less than or equal to x
% -------------------------------------------------------------------------

function [x1, b1] = computeLowerHistBin(x, binWidth)

% Bin index
bin = floor(x./binWidth - 0.5);

% Bin center x1
x1 = binWidth * (bin + 0.5);

% add 2 to get to 1-based indexing
b1 = bin + 2;
end

最后,最终的“量化”数据:

w = 1 - (x - x1)./binWidth

这是我不明白的:我不明白 - 根本 - 究竟为什么要按x1原样计算,以及为什么/如何w按原样计算。事实上,在所有事情中,w最让我困惑的是。我真的无法理解这里的逻辑,或者真正的意图。希望能详细说明这个逻辑。谢谢。

4

1 回答 1

1

他正在lb <= x < up对区间[0,180]进行分箱和拆分[-10,10), [10, 30), [30,40) ..., [150,170), [170,190)

假设x = 180,则:

bin = floor(180/20-0.5) = floor(9-0.5) = floor(8.5) = 8; 

而如果x = 0

bin = floor(`0/20-0.5) = floor(-0.5) = floor(-1) = -1; 

分别翻译成x1 = 20 * (8+0.5) = 170并且x1 = -10看起来像函数所暗示的那样lowerHistBin()

最后,w只需测量该点x与相应的较低 bin 的距离x1。请注意,w它在 (0,1] 中,w当 1 时为 1,当 时x = x1接近 0。x -> x1+binWidth因此,如果 x 说接近 170,w则将接近1 - (170-150)/20 = 0

于 2014-10-14T02:00:42.527 回答