matlab-optic,optics的matlab实现

% -------------------------------------------------------------------------

% Function:

% [RD,CD,order]=optics(x,k)

% -------------------------------------------------------------------------

% Aim:

% Ordering objects of a data set to obtain the clustering structure

% -------------------------------------------------------------------------

% Input:

% x - data set (m,n); m-objects, n-variables

% k - number of objects in a neighborhood of the selected object

% (minimal number of objects considered as a cluster)

% -------------------------------------------------------------------------

% Output:

% RD - vector with reachability distances (m,1)

% CD - vector with core distances (m,1)

% order - vector specifying the order of objects (1,m)

% -------------------------------------------------------------------------

% Example of use:

% x=[randn(30,2)*.4;randn(40,2)*.5+ones(40,1)*[4 4]];

% [RD,CD,order]=optics(x,4)

% -------------------------------------------------------------------------

%

function [RD,CD,order]=optics(x,k)

[m,n]=size(x);

CD=zeros(1,m);

RD=ones(1,m)*10^10;

% Calculate Core Distances

% for i=1:m

% D=sort(dist(x(i,:),x));

% CD(i)=D(k+1);

% end

order=[];

seeds=[1:m];

ind=1;

i3 = 1;

while ~isempty(seeds)

i3 = i3 + 1

ob=seeds(ind);

seeds(ind)=[];

order=[order ob];

mm=max([ones(1,length(seeds))*CD(ob);dist(x(ob,:),x(seeds,:))]);

ii=(RD(seeds))>mm;

RD(seeds(ii))=mm(ii);

[i1 ind]=min(RD(seeds));

end

RD(1)=max(RD(2:m))+.1*max(RD(2:m));

function [D]=dist(i,x)

% function: [D]=dist(i,x)

%

% Aim:

% Calculates the Euclidean distances between the i-th object and all objects in x

% Input:

% i - an object (1,n)

% x - data matrix (m,n); m-objects, n-variables

%

% Output:

% D - Euclidean distance (m,1)

[m,n]=size(x);

D=(sum((((ones(m,1)*i)-x).^2)'));

if n==1

D=abs((ones(m,1)*i-x))';

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值