Example #1
0
//----------------------------------------------------------------------
void KCsplit::getNeighbors(		// get neighbors for internal node
    KMctrIdxArray	cands,			// candidate centers
    int			kCands)			// number of centers
{
    if (kCands == 1)  				// only one cand left?
    {
        // post points as neighbors
        postNeigh(this, sum, sumSq, n_data, cands[0]);
    }
    else
    {
        // get closest cand to box
        int cc = closestToBox(cands, kCands, bnd_box);
        KMctrIdx closeCand = cands[cc];		// closest candidate index
        // space for new candidates
        KMctrIdxArray newCands = new KMctrIdx[kCands];
        int newK = 0;				// number of new candidates
        for (int j = 0; j < kCands; j++)
        {
            if (j == cc || !pruneTest(		// is candidate close enough?
                        kcCenters[cands[j]],
                        kcCenters[closeCand],
                        bnd_box))
            {
                newCands[newK++] = cands[j];	// yes, keep it
            }
        }
        // apply to children
        child[KM_LO]->getNeighbors(newCands, newK);
        child[KM_HI]->getNeighbors(newCands, newK);
        delete [] newCands;			// delete new candidates
    }
}
Example #2
0
//----------------------------------------------------------------------
void KCsplit::getAssignments(		// get assignments for internal node
    KMctrIdxArray	cands,			// candidate centers
    int			kCands,			// number of centers
    KMctrIdxArray 	closeCtr,		// closest center per point
    double*	 	sqDist)			// sq'd distance to center
{
    if (kCands == 1) {				// only one cand left?
						// no more pruning needed
	child[KM_LO]->getAssignments(cands, kCands, closeCtr, sqDist);
	child[KM_HI]->getAssignments(cands, kCands, closeCtr, sqDist);
    }
    else {
    						// get closest cand to box
	int cc = closestToBox(cands, kCands, bnd_box);
	KMctrIdx closeCand = cands[cc];		// closest candidate index
						// space for new candidates
	KMctrIdxArray newCands = new KMctrIdx[kCands];
	int newK = 0;				// number of new candidates
	for (int j = 0; j < kCands; j++) {
	    if (j == cc || !pruneTest(		// is candidate close enough?
	    			kcCenters[cands[j]],
	    			kcCenters[closeCand],
				bnd_box)) {
	    	newCands[newK++] = cands[j];	// yes, keep it
	    }
	}
						// apply to children
	child[KM_LO]->getAssignments(newCands, newK, closeCtr, sqDist);
	child[KM_HI]->getAssignments(newCands, newK, closeCtr, sqDist);
	delete [] newCands;			// delete new candidates
    }
}