我尝试自定义DBSCAN算法,以便只有 x方向中两点之间的距离 才能启动新群集大于某个数字,或者仅在 y方向中的两个点之间的距离大于某个数字。但是,我在这方面遇到了一些麻烦。
到目前为止,这是我的代码:
public void ComputeClusterDbscan(DatasetItem[] allPoints, double epsilon, int minPts, double[] currentpt, double[] nextpt, out HashSet<DatasetItem[]> clusters)
{
var allPointsDbscan = allPoints.Select(x => new DbscanPoint(x)).ToArray();
int clusterId = 0;
for (int i = 0; i < allPointsDbscan.Length - 1 ; i++)
{
int j = i + 1;
DbscanPoint p = allPointsDbscan[i];
if (p.IsVisited)
continue;
p.IsVisited = true;
DbscanPoint[] neighborPts = null;
RegionQuery(allPointsDbscan, p.ClusterPoint, epsilon, out neighborPts);
//calculate distance between points in x and y directions
double xDirection = Math.Abs(allPointsDbscan[j].ClusterPoint.X - allPointsDbscan[i].ClusterPoint.X);
double yDirection = Math.Abs(allPointsDbscan[j].ClusterPoint.Y - allPointsDbscan[i].ClusterPoint.Y);
if (xDirection > 0.299 | yDirection > 0.199)
{
//begin new cluster
}
if (neighborPts.Length < minPts)
p.ClusterId = (int)ClusterIds.Noise;
else
{
clusterId++;
ExpandCluster(allPointsDbscan, p, neighborPts, clusterId, epsilon, minPts);
}
}
clusters = new HashSet<DatasetItem[]>(
allPointsDbscan
.Where(x => x.ClusterId > 0)
.GroupBy(x => x.ClusterId)
.Select(x => x.Select(y => y.ClusterPoint).ToArray())
);
}
答案 0 :(得分:0)
您不需要修改DBSCAN来执行此操作。
三种解决方案:
实际上,所有这些方法都会改变&#34; regionQuery&#34;结果