Exemplo n.º 1
0
plComputableObjectList createClusterJointDist( const Variables& variables, const Cluster& cluster ) {
  plComputableObjectList cndProbTab;
  const Variable& var =  variables[*cluster.begin()];
  const DistValues probs = createNBUniVarProbTab( var.cardinality() ) ;
  const plProbTable probTab( var, probs, true );
  cndProbTab *= probTab;

  DistValueMat clusterProbTables = createClusterProbTables( variables, cluster );
  //./bVariables clustVars;
  // clustVars ^= var;
  
  Cluster::const_iterator curr, next;
  curr = cluster.begin(); next = curr + 1;

  DistValueMat::const_iterator ptIt = clusterProbTables.begin();
  while ( next != cluster.end() ) {
    plDistributionTable distTab_Xi_Z( variables[*next], variables[*curr] ); 
    for (size_t h = 0; h < variables[*curr].cardinality(); ++h) {
      distTab_Xi_Z.push( plProbTable( variables[*next], ptIt->at(h)), (int)h );
    }
    cndProbTab *= distTab_Xi_Z; 
    ++curr; ++next; ++ptIt;
  }

  return cndProbTab; //plJointDistribution( clustVars, cndProbTab );
}
Exemplo n.º 2
0
DistValueMat createClusterProbTables( const Variables& variables, const Cluster& cluster ) {
  DistValueMat distValueMat;
  Cluster::const_iterator curr, next;
  curr = cluster.begin(); next = curr + 1;
  while ( next != cluster.end() ) {
    DistValueVec X_Z;    
    for (size_t i = 0; i < variables[*curr].cardinality(); ++i) {      
      DistValues X_Z_i = createNBUniVarProbTab( variables[*next].cardinality() );
      X_Z_i[i] = 1.0 / (1.0 - RATE);
      normalizeDistValues(X_Z_i);
      X_Z.push_back(X_Z_i);      
    }    
    distValueMat.push_back(X_Z);
    ++curr; ++next;
  }
  return distValueMat;
}
Exemplo n.º 3
0
bool ClusterDbscan::ClusterNoise(pClusterPoint& p, Cluster& neighbors)
{
	if (m_result.size() > 1)
	{
		std::vector<unsigned int> cluster_count;
		cluster_count.resize(m_result.size(), 0);

		for (ClusterIter iter = neighbors.begin();
			iter != neighbors.end(); ++iter)
		{
			if ((*iter)->noise)
				continue;
			int index = m_result.find_(*iter);
			if (index == -1)
				continue;
			cluster_count[index]++;
		}

		//find max
		auto result = std::max_element(
			cluster_count.begin(), cluster_count.end());
		if (*result)
		{
			int index = std::distance(cluster_count.begin(), result);
			m_result[index].push_back(p);
			p->noise = false;
			return true;
		}
		else return false;
	}
	else
	{
		Cluster cluster;
		cluster.push_back(p);
		p->noise = false;
		m_result.push_back(cluster);
		return true;
	}
}
Exemplo n.º 4
0
void ClusterDbscan::ExpandCluster(pClusterPoint& p, Cluster& neighbors, Cluster& cluster)
{
	cluster.push_back(p);
	p->noise = false;
	for (ClusterIter iter = neighbors.begin();
		iter != neighbors.end(); ++iter)
	{
		pClusterPoint p2 = *iter;
		if (!p2->visited)
		{
			p2->visited = true;
			Cluster neighbors2 = GetNeighbors(p2, m_eps, m_intw);
			if (neighbors2.size() >= m_size)
				neighbors.join(neighbors2);
		}
		if (!m_result.find(p2))
		{
			cluster.push_back(p2);
			p2->noise = false;
		}
	}
}
Exemplo n.º 5
0
inline void MatchingDynamicClusterer::find_matches( const Cluster &step_cluster, vector<int> &matches )
{
	int size_step = (int)step_cluster.size();
	if( size_step < MIN_CLUSTER_SIZE )
	{
		return;
	}
	DynamicClustering::iterator dit;
	DynamicClustering::iterator dend = m_dynamic.end();
	int dyn_index = 0;
	for( dit = m_dynamic.begin() ; dit != dend; dit++, dyn_index++ )
	{
		// Dead?
		if( m_death_age > 0 && m_dynamic[dyn_index].is_dead( m_step, m_death_age ) )
		{
			continue;
		}
		Cluster& front = (*dit).front();
		int size_front = front.size();
		set<NODE> tmp;
     	set_intersection(step_cluster.begin(), step_cluster.end(), front.begin(), front.end(), insert_iterator< set < NODE > > (tmp,tmp.begin()) );
		int inter = tmp.size();
		if( inter == 0 )
		{
			continue;
		}
#ifdef SIM_OVERLAP
		double sim = (double)(inter)/min(size_step,size_front);
#else
		double sim = (double)(inter)/(size_step+size_front-inter);
#endif
		if( sim > m_threshold )
		{
			matches.push_back( dyn_index );
		}
	}
}