Optics算法.docx
- 文档编号:10675650
- 上传时间:2023-02-22
- 格式:DOCX
- 页数:13
- 大小:65.94KB
Optics算法.docx
《Optics算法.docx》由会员分享,可在线阅读,更多相关《Optics算法.docx(13页珍藏版)》请在冰豆网上搜索。
Optics算法
1 什么是OPTICS算法
在前面介绍的DBSCAN算法中,有两个初始参数E(邻域半径)和minPts(E邻域最小点数)需要用户手动设置输入,并且聚类的类簇结果对这两个参数的取值非常敏感,不同的取值将产生不同的聚类结果,其实这也是大多数其他需要初始化参数聚类算法的弊端。
为了克服DBSCAN算法这一缺点,提出了OPTICS算法(OrderingPointstoidentifytheclusteringstructure)。
OPTICS并不显示的产生结果类簇,而是为聚类分析生成一个增广的簇排序(比如,以可达距离为纵轴,样本点输出次序为横轴的坐标图),这个排序代表了各样本点基于密度的聚类结构。
它包含的信息等价于从一个广泛的参数设置所获得的基于密度的聚类,换句话说,从这个排序中可以得到基于任何参数E和minPts的DBSCAN算法的聚类结果。
2 OPTICS两个概念
核心距离:
对象p的核心距离是指是p成为核心对象的最小E’。
如果p不是核心对象,那么p的核心距离没有任何意义。
可达距离:
对象q到对象p的可达距离是指p的核心距离和p与q之间欧几里得距离之间的较大值。
如果p不是核心对象,p和q之间的可达距离没有意义。
例如:
假设邻域半径E=2,minPts=3,存在点A(2,3),B(2,4),C(1,4),D(1,3),E(2,2),F(3,2)
点A为核心对象,在A的E领域中有点{A,B,C,D,E,F},其中A的核心距离为E’=1,因为在点A的E’邻域中有点{A,B,D,E}>3;
点F到核心对象点A的可达距离为,因为A到F的欧几里得距离,大于点A的核心距离1.
3 算法描述
OPTICS算法额外存储了每个对象的核心距离和可达距离。
基于OPTICS产生的排序信息来提取类簇。
算法描述如下:
算法:
OPTICS
输入:
样本集D, 邻域半径E, 给定点在E领域内成为核心对象的最小领域点数MinPts
输出:
具有可达距离信息的样本点输出排序
方法:
1 创建两个队列,有序队列和结果队列。
(有序队列用来存储核心对象及其该核心对象的直接可达对象,并按可达距离升序排列;结果队列用来存储样本点的输出次 序);
2 如果所有样本集D中所有点都处理完毕,则算法结束。
否则,选择一个未处理(即不在结果队列中)且为核心对象的样本点,找到其所有直接密度可达样本点,如过该样本点不存在于结果队列中,则将其放入有序队列中,并按可达距离排序;
3 如果有序队列为空,则跳至步骤2,否则,从有序队列中取出第一个样本点(即可达距离最小的样本点)进行拓展,并将取出的样本点保存至结果队列中,如果它不存在结果队列当中的话。
3.1 判断该拓展点是否是核心对象,如果不是,回到步骤3,否则找到该拓展点所有的直接密度可达点;
3.2 判断该直接密度可达样本点是否已经存在结果队列,是则不处理,否则下一步;
3.2 如果有序队列中已经存在该直接密度可达点,如果此时新的可达距离小于旧的可达距离,则用新可达距离取代旧可达距离,有序队列重新排序;
3.3 如果有序队列中不存在该直接密度可达样本点,则插入该点,并对有序队列重新排序;
4 算法结束,输出结果队列中的有序样本点。
大家或许会很疑惑,这里不也有输入参数E和MinPts吗?
其实这里的E和MinPts只是起到算法辅助作用,也就是说E和MinPts的细微变化并不会影响到样本点的相对输出顺序,这对我们分析聚类结果是没有任何影响。
我们采用与先前DBSCAN相同的样本点集合,
对于样本点
a={2,3};b={2,4};c={1,4};d={1,3};e={2,2};f={3,2};
g={8,7};h={8,6};i={7,7};j={7,6};k={8,5};
l={100,2};//孤立点
m={8,20};n={8,19};o={7,18};p={7,17};q={8,21};
并且使用相同的E=2 MinPts=4时,输出序列为
1->a:
1.0
2->e:
1.0
3->b:
1.0
4->d:
1.0
5->c:
1.4142135623730951
6->f:
1.4142135623730951
------
7->g:
1.4142135623730951
8->j:
1.4142135623730951
9->k:
1.4142135623730951
10->i:
1.4142135623730951
11->h:
1.4142135623730951
------
12->n:
2.0
13->q:
2.0
14->o:
2.0
15->m:
2.0
如图,按照算法,分三个阶段输出了三波值
{a,e,b,d,c,f},{g,j,k,I,h},{n,q,o,m}
这和DBSCAN的类簇结果是一样的。
不仅如此,我们通过分析有序图还能直接得到当参数E=1.5,minPts=4时DBSCAN的类簇结果,只要在坐标图中找到Y值小于1.5的样本点即可,只有两类{a,e,b,d,c,f},{g,j,k,I,h},其他点被认为是孤立点,和DBSCAN聚类算法取E=1.5,minPts=4时的结果一致。
所以说,这个OPTICS聚类算法所得的簇排序信息等价于一个广泛的参数设置所获得的基于密度的聚类结果。
具体实现算法如下:
packagecom.optics;
publicclassDataPoint{
privateStringname;//样本点名
privatedoubledimensioin[];//样本点的维度
privatedoublecoreDistance;//核心距离,如果该点不是核心对象,则距离为-1
privatedoublereachableDistance;//可达距离
publicDataPoint(){
}
publicDataPoint(DataPointe){
this.name=e.name;
this.dimensioin=e.dimensioin;
this.coreDistance=e.coreDistance;
this.reachableDistance=e.reachableDistance;
}
publicDataPoint(doubledimensioin[],Stringname){
this.name=name;
this.dimensioin=dimensioin;
this.coreDistance=-1;
this.reachableDistance=-1;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicdouble[]getDimensioin(){
returndimensioin;
}
publicvoidsetDimensioin(double[]dimensioin){
this.dimensioin=dimensioin;
}
publicdoublegetCoreDistance(){
returncoreDistance;
}
publicvoidsetCoreDistance(doublecoreDistance){
this.coreDistance=coreDistance;
}
publicdoublegetReachableDistance(){
returnreachableDistance;
}
publicvoidsetReachableDistance(doublereachableDistance){
this.reachableDistance=reachableDistance;
}
}
packagecom.optics;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.Comparator;
importjava.util.List;
publicclassClusterAnalysis{
classComparatorDpimplementsComparator
publicintcompare(DataPointarg0,DataPointarg1){
doubletemp=arg0.getReachableDistance()-arg1.getReachableDistance();
inta=0;
if(temp<0){
a=-1;
}else{
a=1;
}
returna;
}
}
publicList
doubleradius,intObjectNum){
List
List
inttotal=0;
while(total if(isContainedInList(dataPoints.get(total),dpList)==-1){ List dataPoints,radius,ObjectNum); if(tmpDpList! =null&&tmpDpList.size()>0){ DataPointnewDataPoint=newDataPoint(dataPoints.get(total)); dpQue.add(newDataPoint); } } while(! dpQue.isEmpty()){ DataPointtempDpfromQ=dpQue.remove(0); DataPointnewDataPoint=newDataPoint(tempDpfromQ); dpList.add(newDataPoint); List dataPoints,radius,ObjectNum); System.out.println(newDataPoint.getName()+": "+newDataPoint.getReachableDistance()); if(tempDpList! =null&&tempDpList.size()>0){ for(inti=0;i DataPointtempDpfromList=tempDpList.get(i); intindexInList=isContainedInList(tempDpfromList, dpList); intindexInQ=isContainedInList(tempDpfromList,dpQue); if(indexInList==-1){ if(indexInQ>-1){ intindex=-1; for(DataPointdataPoint: dpQue){ index++; if(index==indexInQ){ if(dataPoint.getReachableDistance()>tempDpfromList .getReachableDistance()){ dataPoint .setReachableDistance(tempDpfromList .getReachableDistance()); } } } }else{ dpQue.add(newDataPoint(tempDpfromList)); } } } //TODO: 对Q进行重新排序 Collections.sort(dpQue,newComparatorDp()); } } System.out.println("------"); total++; } returndpList; } publicvoiddisplayDataPoints(List for(DataPointdp: dps){ System.out.println(dp.getName()+": "+dp.getReachableDistance()); } } privateintisContainedInList(DataPointdp,List intindex=-1; for(DataPointdataPoint: dpList){ index++; if(dataPoint.getName().equals(dp.getName())){ returnindex; } } return-1; } privateList List List doublecoreDistance;//核心距离 for(inti=0;i DataPointdp=dataPoints.get(i); doubledistance=getDistance(dataPoint,dp); if(distance<=radius){ distances.add(distance); arrivableObjects.add(dp); } } if(arrivableObjects.size()>=ObjectNum){ List Collections.sort(distances); coreDistance=distances.get(ObjectNum-1); for(intj=0;j if(coreDistance>newDistances.get(j)){ if(newDistances.get(j)==0){ dataPoint.setReachableDistance(coreDistance); } arrivableObjects.get(j).setReachableDistance(coreDistance); }else{ arrivableObjects.get(j).setReachableDistance(newDistances.get(j)); } } returnarrivableObjects; } returnnull; } privatedoublegetDistance(DataPointdp1,DataPointdp2){ doubledistance=0.0; double[]dim1=dp1.getDimensioin(); double[]dim2=dp2.getDimensioin(); if(dim1.length==dim2.length){ for(inti=0;i doubletemp=Math.pow((dim1[i]-dim2[i]),2); distance=distance+temp; } distance=Math.pow(distance,0.5); returndistance; } returndistance; } publicstaticvoidmain(String[]args){ ArrayList double[]a={2,3}; double[]b={2,4}; double[]c={1,4}; double[]d={1,3}; double[]e={2,2}; double[]f={3,2}; double[]g={8,7}; double[]h={8,6}; double[]i={7,7}; double[]j={7,6}; double[]k={8,5}; double[]l={100,2};//孤立点 d
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Optics 算法