问题描述
我正在尝试在Matlab中计算 medoid .但是,我不知道该怎么做.我的数据集由三维数据的多个点组成(因此,在具有三个轴的系统中点云). medoid是与簇中所有其他对象的平均相似度最小的 "(维基百科).
I am trying to calculate the medoid in matlab. However, i don't know how to do this. My dataset consists of multiple points of three-dimensional data (so a cloud of points in a system with three axes). The medoid is the point "whose average dissimilarity to all the other objects in the cluster is minimal" (wikipedia).
有人知道如何在matlab中计算类固醇吗?
Does anyone know how to calculate the medoid in matlab?
顺便说一句:据我所知 k-medoid算法无法用于(有效地)计算medoid,这就是为什么我正在寻找另一种方法.
Btw.: as far as i know the k-medoid algorithm cannot be used to calculate the medoid (efficiently), which is why i am looking for another way.
推荐答案
一旦提供了指标,就不难做到这一点.这是标量的实现:
Should not be difficult to do that once you provide the metric. Here is an implementation for scalars:
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)
您可以将其扩展为矢量,我将其作为练习留给读者. (或者想要添加改进答案的人.)
You can extend it to vectors, I will leave it as exercise for the reader. (Or someone who wants to add an improved answer).
这篇关于如何在MATLAB中查找集合的Medoid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!