本文整理汇总了C#中Cluster.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Cluster.Add方法的具体用法?C# Cluster.Add怎么用?C# Cluster.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cluster
的用法示例。
在下文中一共展示了Cluster.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpandCluster
private void ExpandCluster(Point p, Cluster c, List<Point> neighbors)
{
c.Add(p);
p.inCluster = true;
// foreach (Point neighbor in neighbors)
for (int i=0; i<neighbors.Count; ++i)
{
Point neighbor = neighbors[i];
if (neighbor.Processed == false)
{
neighbor.Processed = true;
var newNeighbors = db.Neighbors(neighbor, Epsilon);
if (newNeighbors.Count >= MinPts)
{
neighbors = neighbors.Union(newNeighbors).ToList();
}
}
if (neighbor.inCluster == false)
{
c.Add(neighbor);
neighbor.inCluster = true;
}
}
}
示例2: Clustering
public void Clustering(string inputFile, int clusterNum)
{
int clusterIndex = 0;
var clusterOf = new int[db.Count()]; // cluster indexes of points
int curCluster = db.Count();
foreach (var pair in db.DistanceSortedList())
{
int p1 = pair.Key.id1;
int p2 = pair.Key.id2;
if (curCluster == clusterNum + 2)
break;
// If clusterOf[p1] == 0, p1 is not included into any cluster.
if (clusterOf[p1] == 0 && clusterOf[p2] == 0)
{
++ clusterIndex;
clusterOf[p1] = clusterIndex;
clusterOf[p2] = clusterIndex;
}
else if (clusterOf[p1] != 0 && clusterOf[p2] == 0)
{
clusterOf[p2] = clusterOf[p1];
}
else if (clusterOf[p1] == 0 && clusterOf[p2] != 0)
{
clusterOf[p1] = clusterOf[p2];
}
else if (clusterOf[p1] != 0 && clusterOf[p2] != 0)
{
int clusterIndex1 = clusterOf[p1];
int clusterIndex2 = clusterOf[p2];
if (clusterIndex1 == clusterIndex2) {
// no change
continue;
}
int minIndex = (clusterIndex1 < clusterIndex2) ? clusterIndex1 : clusterIndex2;
int maxIndex = (clusterIndex1 > clusterIndex2) ? clusterIndex1 : clusterIndex2;
for (int i=0; i<clusterOf.Length; ++i)
{
if (clusterOf[i] == maxIndex)
{
clusterOf[i] = minIndex;
}
}
}
-- curCluster;
}
HashSet<int> hSet = new HashSet<int>();
foreach (int idx in clusterOf)
{
hSet.Add(idx);
}
clusterList = new List<Cluster>();
foreach (int clustIdx in hSet)
{
Cluster cluster = new Cluster();
for (int i=0; i<clusterOf.Length; ++i)
{
if (clusterOf[i] == clustIdx)
{
cluster.Add(db[i]);
}
}
clusterList.Add(cluster);
}
WriteOutput(inputFile);
}
示例3: AssignRandomSeeds
private List<Point> AssignRandomSeeds(int clusterNum)
{
clusterList = new List<Cluster>();
var randomSeeds = RandomPoints(clusterNum);
for(int i=0; i<clusterNum; ++i)
{
Point seed = randomSeeds[i];
seed.inCluster = true;
seed.isSeed = true;
seed.clusterIdx = i;
Cluster cluster = new Cluster();
cluster.Add(seed);
clusterList.Add(cluster);
}
return randomSeeds;
}