我有一个来自流式细胞术数据的 n x 2 数组,代表细胞的前向散射和侧向散射(有 n 个细胞)。这些值代表细胞的物理特征,我希望过滤细胞。 当绘制为散点图时,数据显示出强烈的椭圆云,然后有更多分散的细胞。我希望“门控”这些数据,以便保留主要的云并过滤掉所有其余的(在下图中,我想保留灰色椭圆边界内的点。
我想要的是得到一个二进制 n x 1 数组,其中如果该单元格位于云中,则索引 i 处的值为 1,否则为 0。
我其实不知道如何过滤掉椭圆外的数据。但我尝试使用 K-means 指定 4 个簇。然而,主要簇被检测为单个组(见下图)。 我需要能够以编程方式检测主导簇。如果有人可以提供帮助,我将不胜感激。 样本数据在这里 FS_SS.txt (hosted at AnonFiles.com)
最佳答案
如果您有 statistical toolbox ,尝试这样的事情:
a = dlmread('~\downloads\-data-anonfiles-1383150325725.txt'); % read data
p = mvnpdf(a,mean(a),cov(a)); % multivariate PDF of your data
p_sample = numel(p)*p/sum(p); % normalize pdf to number of samples
thresh = 0.5; % set an arbitrary threshold to filter
idx_thresh = p_sample > thresh; % logical indices of samples that meet the threshold
a_filtered = a(idx_thresh,:);
然后使用过滤后的数据再次重复此操作。
p = mvnpdf(a,mean(a_filtered),cov(a_filtered));
p_sample = numel(p)*p/sum(p); % normalize pdf to number of samples
thresh = 0.1; % set an arbitrary threshold to filter
idx_thresh = p_sample > thresh; % logical indices of samples that meet the threshold
a_filtered = a_filtered (idx_thresh,:);
我只需 2 次迭代就能得出大部分主导分布。但我认为你会想要重复直到平均值(a_filtered)和cov(a_filtered)达到稳定状态值。将它们绘制为迭代函数,当它们接近平坦线时,您就找到了正确的值。
这相当于使用旋转椭圆进行过滤,但在我看来,它更容易、更有用,因为现在您实际上拥有 5 mvnpdf重现分布所需的参数(mu_x、mu_y、sigma_xx、sigma_yy、sigma_xy)。如果将等值线 (p(x,y) = thresh) 建模为旋转椭圆,则必须操作短轴和长轴 (a,b)、平移坐标 (h,k) 和旋转 ( theta) 来获取 mvnpdf 参数。
提取第一个分布后,您可以重复该过程来查找辅助分布。
关于matlab - 消除椭圆外的所有二维数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688480/