Exemplo n.º 1
0
void grouping(std::vector<tLineSegment<point>> &L, double eps, size_t minLines,
				distance_functor &_d, progress_visitor &pvis)
{
	size_t clusterID=0;
	std::queue<size_t> Q;
	pvis.init(L.size());
	for (size_t i=0; i < L.size(); i++)
	{
		if (i%100==0)
		pvis(i,L.size(),"Phase 2: Clustering Segments");
		if (L[i].cluster == UNCLASSIFIED)
		{
			std::vector<size_t> Ne = compute_NeIndizes<point>(L,i,eps,_d);
			//cout << "Ne[" << i << "]="<< Ne.size() << endl;
			
			if (Ne.size()+1 >= minLines)
			{
				L[i].cluster = clusterID;
				for (auto it = Ne.begin(); it != Ne.end(); it++)
				{
					L[*it].cluster = clusterID;
					Q.push(*it);
				}
				expandCluster(L,Q, eps,minLines,clusterID,_d);
				clusterID++;
			}else  // not minLines
			{
				L[i].cluster = NOISE; 
			}
		}		
		
	}
	/*Step 3: check that clusters come from more than minLines 
	 * 		  different trajectories*/
	for (int i=0; i < (int)clusterID; i++)
	{
		std::set<size_t> sources;
		for (size_t j = 0; j < L.size(); j++)
		  if (L[j].cluster == i)
		    sources.insert (L[j].trajectory_index);
		    
		if (sources.size() < minLines)
		{
		   for (size_t j = 0; j < L.size(); j++)
		      if (L[j].cluster == i)
			     L[j].cluster = REMOVED;
		}
	}
	/*Step 3a: ClusterID compression into a range*/
	
	
	
    /* Step 4: Representation*/	
    // left out, will do that later. This step creates a representative
    // trajectory for a cluster.
    	
};
Exemplo n.º 2
0
void DbScan::scan()
{
	unsigned clusterId = 1;
	std::vector<Point>::iterator p = points_.begin();
	while(p != points_.end())
	{
		// Point is thus far unclassified
		if(p->label == -1)
			expandCluster(p, clusterId);
		++p;
	}	
}
vector<vector<int>> cluster(vector<Segment> &D, double epsilon, int minlns){
	Segment L;
	vector<int> clus(D.size());
	fill(clus.begin(), clus.end(),-1);
	vector<int> temp_neigh;
	progress::begin();
	int clusterId = 0;
	for (int i = 0; i<D.size(); i++){
		progress::step("clustering: ", i, 1, D.size());
		if (clus[i]==-1){
			temp_neigh = neighborhood(D, i, epsilon);
			if(temp_neigh.size()>= minlns){
				clus[i]=clusterId;
				queue<int> Q;
				for(auto j : temp_neigh){
					clus[j]= clusterId;
					Q.push(j);
				}
				expandCluster(D, clus, Q, clusterId, epsilon, minlns);
				clusterId++;
			}
			else{
				clus[i]=-2;
			}
		}
	}
	progress::done();
	//collect and clean the clusters
	vector<vector<int>> ret(clusterId);
	vector<unordered_set<int>> participating(clusterId);
	for(int i = 0; i<clus.size(); i++){
		if (clus[i]>=0){
			ret[clus[i]].push_back(i);
			D[i].myclus = clus[i];
			participating[clus[i]].insert(D[i].mytraj);
		}
	}
	for(int i = 0; i<participating.size(); i++){
		if (participating[i].size()<=minlns){
			participating.erase(participating.begin() + i);
			ret.erase(ret.begin() + i);
			i--;
		}
	}
	sort(ret.begin(), ret.end(), cs);
	return ret;
}