Example #1
0
//----------------------------------------------------------------------
//  swapOneCenter
//	Swaps one center point with a sample point.  Optionally we make
//	sure that the new point is not a duplicate of any of the centers
//	(including the point being replaced).
//----------------------------------------------------------------------
void KMfilterCenters::swapOneCenter(		// swap one center
    bool allowDuplicate)			// allow duplicate centers
{
    int rj = kmRanInt(kCtrs);			// index of center to replace
    int dim = getDim();
    KMpoint p = kmAllocPt(dim);			// alloc replacement point
    pts->sampleCtr(p);				// sample a replacement
    if (!allowDuplicate) {			// duplicates not allowed?
        bool dupFound;				// was a duplicate found?
        do {					// repeat until successful
	    dupFound = false;
	    for (int j = 0; j < kCtrs; j++) { 	// search for duplicates
		if (kmEqualPts(dim, p, ctrs[j])) {
		    dupFound = true;
		    pts->sampleCtr(p);		// try again
		    break;
		}
	    }
	} while (dupFound);
    }
    kmCopyPt(dim, p, ctrs[rj]);			// copy sampled point
    if (kmStatLev >= STEP) {			// output swap info
        *kmOut << "\tswapping: ";
        kmPrintPt(p, getDim(), true);
        *kmOut << "<-->Center[" << rj << "]\n";
    }
    kmDeallocPt(p);				// deallocate point storage
    invalidate();				// distortions now invalid
}
Example #2
0
void KMfilterCenters::print(bool fancy)		// print centers and distortion
{
    for (int j = 0; j < kCtrs; j++) 
	{
		*kmOut << "    " << setw(4) << j << "\t";
		kmPrintPt(ctrs[j], getDim(), true);
		*kmOut << " dist = " << setw(8) << dists[j] << endl;
    }
}
Example #3
0
void kmPrintPts(                  // print points
  std::string            title,                  // name of point set
  KMpointArray      pa,                  // the point array
  int                  n,                  // number of points
  int                  dim,                  // the dimension
  bool            fancy)                    // print plain or fancy?
{
  *kmOut << "  (" << title << ":\n";
  for(int i = 0; i < n; i++) {
    *kmOut << "    " << i << "\t";
    kmPrintPt(pa[i], dim, fancy);
    *kmOut << "\n";
  }
  *kmOut << "  )" << std::endl;
}
Example #4
0
//----------------------------------------------------------------------
void KCtree::print(			// print entire tree
    bool	with_pts)			// print points as well?
{
    if (with_pts) {			// print point coordinates
	*kmOut << "    Points:\n";
	for (int i = 0; i < n_pts; i++) {
	    *kmOut << "\t" << i << ": ";
	    kmPrintPt(pts[i], kcDim, true);
            *kmOut << "\n";
	}
    }
    if (root == NULL)			// empty tree?
	*kmOut << "    Null tree.\n";
    else {
    	root->print(0);			// invoke printing at root
    }
}
Example #5
0
//----------------------------------------------------------------------
void KCleaf::print(			// print leaf node
    int		level)			// depth of node in tree
{
    *kmOut << "    ";
    for (int i = 0; i < level; i++)	// print indentation
	*kmOut << ".";

    // *kmOut << "Leaf <" << (void*) this << ">";
    *kmOut << "Leaf";			// print without address
    *kmOut << " n=" << n_data << " <";
    for (int j = 0; j < n_data; j++) {
	*kmOut << bkt[j];
	if (j < n_data-1) *kmOut << ",";
    }
    *kmOut << ">"
       	<< " sm=";  kmPrintPt(sum, kcDim, true);
    *kmOut << " ss=" << sumSq << "\n";
}
Example #6
0
void KCsplit::print(		// print splitting node
    int		level)			// depth of node in tree
{
    					// print high child
    child[KM_HI]->print(level+1);

    *kmOut << "    ";			// print indentation
    for (int i = 0; i < level; i++)
	*kmOut << ".";

    kmOut->precision(4);
    *kmOut << "Split"			// print without address
        << " cd=" << cut_dim << " cv=" << setw(6) << cut_val
       	<< " nd=" << n_data
       	<< " sm=";  kmPrintPt(sum, kcDim, true);
    *kmOut << " ss=" << sumSq << "\n";
    					// print low child
    child[KM_LO]->print(level+1);
}