matlab - 更好的(非线性)分箱

标签 matlab matrix

我问的最后一个问题涉及如何通过 x 坐标对数据进行装箱。解决方案简单而优雅,我很遗憾我没有看到它。这个问题可能更难(或者我可能只是盲目的)。

我从大约 140000 个数据点开始,将它们分成 70 个沿 x 轴等距分布的组,然后获取每组的平均位置 (x_avg, y_avg) 并绘制它们;一条漂亮的曲线出现了。不幸的是有两个问题。首先,边缘的人口比图中心少得多;其次,某些领域的变化比其他领域更大,因此需要更好的解决方案。

因此,我有两个具体问题和一般邀请提出建议:

Matlab 是否有内置方法将矩阵拆分为固定数量的较小矩阵或固定大小的较小矩阵?

是否有算法(或 matlab 函数,但我发现不太可能)来确定更精细地划分感兴趣区域所需的边界?

更一般地说,是否有更好的方法将数以万计的数据点浓缩成一个整齐的趋势?

最佳答案

听起来您想使用大小根据 x 值的密度而变化的箱。我认为您仍然可以使用 HISTC 函数,就像在上一篇文章的答案中一样,但您只需给它一组不同的边即可。

我不知道这是否正是您想要的,但这里有一个建议:不要将 x 轴拆分为 70 个等距的组,而是将排序后的 x 数据拆分为 70 个相等的组并确定边缘值。我认为这段代码应该有效:

% Start by assuming x and y are vectors of data:

nBins = 70;
nValues = length(x);
[xsort,index] = sort(x);  % Sort x in ascending order
ysort = y(index);         % Sort y the same way as x
binEdges = [xsort(1:ceil(nValues/nBins):nValues) xsort(nValues)+1];

% Bin the data and get the averages as in previous post (using ysort instead of y):

[h,whichBin] = histc(xsort,binEdges);

for i = 1:nBins
    flagBinMembers = (whichBin == i);
    binMembers = ysort(flagBinMembers);
    binMean(i) = mean(binMembers);
end

这应该为您提供大小随数据密度而变化的箱。


更新:另一个版本...

这是我在发表一些评论后提出的另一个想法。使用此代码,您可以为 x 中相邻数据点之间的差异设置阈值 (maxDelta)。任何与其较大邻居相差大于或等于 maxDelta 的 x 值都被迫位于自己的 bin 中(全部由其单独的)。您仍然为 nBins 选择一个值,但当分散点降级到它们自己的 bin 时,最终的 bin 数量将大于该值。

% Start by assuming x and y are vectors of data:

maxDelta = 10; % Or whatever suits your data set!
nBins = 70;
nValues = length(x);
[xsort,index] = sort(x);  % Sort x in ascending order
ysort = y(index);         % Sort y the same way as x

% Create bin edges:

edgeIndex = false(1,nValues);
edgeIndex(1:ceil(nValues/nBins):nValues) = true;
edgeIndex = edgeIndex | ([0 diff(xsort)] >= maxDelta);
nBins = sum(edgeIndex);
binEdges = [xsort(edgeIndex) xsort(nValues)+1];

% Bin the data and get the y averages:

[h,whichBin] = histc(xsort,binEdges);

for i = 1:nBins
    flagBinMembers = (whichBin == i);
    binMembers = ysort(flagBinMembers);
    binMean(i) = mean(binMembers);
end

我在几个小样本数据集上对此进行了测试,它似乎达到了预期的效果。希望它也适用于您的数据集,无论它包含什么! =)

关于matlab - 更好的(非线性)分箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/427221/

相关文章:

algorithm - 我知道如何检查 4-neighborhood,但如何在这里组合它?

c++ - Mat 类型的 OpenCV 最大可能值

python - 处理大矩阵的硬件要求 - python

c - 我只是想像二维数组一样打印一维数组。但是当我运行这个程序时它没有显示任何输出

matlab - 我可以使用神经网络在仅知道输入的情况下获得输出序列的估计吗?

matlab - 超几何函数

matlab - 为什么有时我使用 |有时|| MATLAB 中的 "or"?

c# - 如何在 asp.net mvc3 中显示矩阵表?

C++ qt基础问题

opengl - 3D 图形矩阵 4x4 中最后一行的 magic 4 的用途是什么?