Beispiel #1
0
static std::vector<double> computeKMeans(
	KMdata & datapoints,
	uint64_t const k,
	uint64_t const runs,
	bool const debug
	)
{
	KMterm const term(runs, 0, 0, 0, 0.10, 0.10, 3, 0.50, 10, 0.95);
	datapoints.buildKcTree();
	KMfilterCenters ctrs(k, datapoints);
	KMlocalHybrid kmAlg(ctrs, term);
	ctrs = kmAlg.execute();

	std::vector<double> centrevector;
	for ( uint64_t i = 0; i < k; ++i )
	{
		centrevector.push_back(ctrs[i][0]);
		if ( debug )
			std::cerr << "centre[" << i << "]=" << ctrs[i][0] << std::endl;
	}

	std::sort(centrevector.begin(),centrevector.end());
	
	return centrevector;
}
Beispiel #2
0
					// standard constructor
KMfilterCenters::KMfilterCenters(int k, KMdata& p, double df)
    : KMcenters(k, p) {
    if (p.getKcTree() == NULL) {	// kc-tree not yet built?
      kmError("Building kc-tree", KMwarn);
      p.buildKcTree();			// build it now
    }
    sums	= kmAllocPts(kCtrs, getDim());
    sumSqs	= new double[kCtrs];
    weights	= new int[kCtrs];
    dists	= new double[kCtrs];
    currDist	= KM_HUGE;
    dampFactor	= df;
	currDBIndex = KM_HUGE;
	currXBIndex = KM_HUGE;
    invalidate();			// distortions are initially invalid
}