【问题标题】:How to Find the Medoid of a Set in MATLAB如何在 MATLAB 中找到集合的中心点
【发布时间】:2012-03-12 18:40:02
【问题描述】:

我正在尝试在 matlab 中计算 medoid。但是,我不知道该怎么做。我的数据集由多个三维数据点组成(因此在具有三个轴的系统中是一团点)。中心点是“与集群中所有其他对象的平均差异最小的点”(维基百科)。

有谁知道如何在matlab中计算medoid?


顺便说一句:据我所知,k-medoid algorithm 不能(有效地)用于计算中心点,这就是为什么我正在寻找另一种方法。

【问题讨论】:

    标签: matlab machine-learning graph average


    【解决方案1】:

    一旦您提供了指标,应该不难做到这一点。这是标量的实现:

         function m = medoid(set,metric)
              [X,Y] = meshgrid(set,set); %Create all possible pairs
              dist = metric(X,Y);  %Run metric
    
              %Each distance is calculated twice, that doesn't matter. 
              %Also addition of zeros doesn't matter because we are looking for minimum.
              totalDist = mean(dist,1); 
    
              [~,i] = min(totalDist);
              m = set(i);
         end
    

    以及用例:

    metric = @(x,y) ( abs(x-y));
    m = medoid([1 2 3 3 3 3 3], metric)
    

    您可以将它扩展到向量,我将把它作为练习留给读者。 (或者想要添加改进答案的人)。

    【讨论】:

    • 在您的示例中,您使用的是一维数据,对吗?这对 3d 数据(具有 x、y、z 值)如何工作?
    • @SamuelKiely,它不起作用。我写它是为了给出一个大致的方向。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多