Ejemplo n.º 1
0
VL_EXPORT
void
vl_hikm_push (VlHIKMTree *f, vl_uint *asgn, vl_uint8 const *data, int N)
{
  int i, d,
    M = vl_hikm_get_ndims (f),
    depth = vl_hikm_get_depth (f) ;
  
  /* for each datum */
  for(i = 0 ; i < N ; i++) {
    VlHIKMNode *node = f->root ;
    d = 0 ;      
    while (node) {
      /*
      vl_uint best = 
        vl_ikm_push_one (vl_ikm_get_centers (node->filter),  
                         data + i * M,
                         M,
                         vl_ikm_get_K (node->filter)) ;
      */
      
      vl_uint best ;
      vl_ikm_push (node->filter, &best, data + i * M, 1) ;
      
      asgn [i*depth + d] = best ;
      ++ d ;
      
      if (!node->children) break ;
      node = node->children [best] ;
    }
  }
}
Ejemplo n.º 2
0
void CHIKMTree::vl_hikm_push (vl_uint32 *asgn, vl_ikm_data const *data, int N)
{
  int i, d,
    M		= vl_hikm_get_ndims (),
    depth	= vl_hikm_get_depth ();
  
  /* for each datum */
  for(i = 0 ; i < N ; i++) {
    VlHIKMNode *node = m_VlHIKMTree->root ;
    d = 0 ;      
    while (node) {
      /*
      vl_uint best = 
        vl_ikm_push_one (vl_ikm_get_centers (node->filter),  
                         data + i * M,
                         M,
                         vl_ikm_get_K (node->filter)) ;
      */
      
      vl_uint32 best ;
      node->filter->vl_ikm_push (&best, data + i * M, 1) ;
      
      asgn [i*depth + d] = best ;
	  //cout<<"d = "<<d<<endl;
      ++ d ;
      
      if (!node->children) break ;
      node = node->children [best] ;
    }
  }
}
Ejemplo n.º 3
0
/** @brief MEX driver entry point 
 **/
void mexFunction (int nout, mxArray * out[], int nin, const mxArray * in[])
{
  enum {IN_TREE = 0, IN_DATA, IN_END} ;
  enum {OUT_ASGN = 0} ;
  vl_uint8 const *data; 

  int             opt ;
  int             next = IN_END ;
  mxArray const  *optarg ;
  
  int N = 0 ;
  int method_type = VL_IKM_LLOYD ;
  int verb = 0 ;
  
  /* -----------------------------------------------------------------
   *                                               Check the arguments
   * -------------------------------------------------------------- */
  if (nin < 2)
    mexErrMsgTxt ("At least two arguments required.");
  else if (nout > 1)
    mexErrMsgTxt ("Too many output arguments.");
  
  if (mxGetClassID (in[IN_DATA]) != mxUINT8_CLASS) {
    mexErrMsgTxt ("DATA must be of class UINT8");
  }
  
  N = mxGetN (in[IN_DATA]);   /* n of elements */
  data = (vl_uint8 *) mxGetPr (in[IN_DATA]);
  
  while ((opt = uNextOption(in, nin, options, &next, &optarg)) >= 0) {
    char buf [1024] ;
    
    switch (opt) {
      
    case opt_verbose :
      ++ verb ;
      break ;
      
    case opt_method :
      if (!uIsString (optarg, -1)) {
        mexErrMsgTxt("'Method' must be a string.") ;        
      }
      if (mxGetString (optarg, buf, sizeof(buf))) {
        mexErrMsgTxt("Option argument too long.") ;
      }
      if (strcmp("lloyd", buf) == 0) {
        method_type = VL_IKM_LLOYD ;
      } else if (strcmp("elkan", buf) == 0) {
        method_type = VL_IKM_ELKAN ;
      } else {
        mexErrMsgTxt("Unknown cost type.") ;
      }
      
      break ;
      
    default :
      assert(0) ;
      break ;
    }
  }

  /* -----------------------------------------------------------------
   *                                                        Do the job
   * -------------------------------------------------------------- */

  {
    VlHIKMTree *tree ;
    vl_uint  *ids  ;
    int j;
    int depth ;

    tree  = matlab_to_hikm (in[IN_TREE], method_type) ;
    depth = vl_hikm_get_depth (tree) ;

    if (verb) {
      mexPrintf("hikmeanspush: ndims: %d K: %d depth: %d\n",
                vl_hikm_get_ndims (tree), 
                vl_hikm_get_K (tree),
                depth) ;
    }
    
    out[OUT_ASGN] = mxCreateNumericMatrix (depth, N, mxUINT32_CLASS, mxREAL) ;
    ids = mxGetData (out[OUT_ASGN]) ;

    vl_hikm_push   (tree, ids, data, N) ;    
    vl_hikm_delete (tree) ;
    
    for (j = 0 ; j < N*depth ; j++) ids [j] ++ ;
  }
}
Ejemplo n.º 4
0
/** ----------------------------------------------------------------
 **
 **/
PyObject * vl_hikmeanspush_python(
		VlHIKMTree_python & inTree,
		PyArrayObject & inData,
		int verb,
		char * method)
{
	vl_uint8 const *data;

	int N = 0;
	int method_type = VL_IKM_LLOYD;

	N = inData.dimensions[1]; /* n of elements */

#ifdef DEBUG
	printf("n of elements: %d\n", N);
	printf("n of split: %d\n", inTree.K);
	printf("depth: %d\n", inTree.depth);
	printf("n of children: %d\n", inTree.sub.size());
#endif

	data = (vl_uint8 *) inData.data;

	if (strcmp("lloyd", method) == 0) {
		method_type = VL_IKM_LLOYD;
	} else if (strcmp("elkan", method) == 0) {
		method_type = VL_IKM_ELKAN;
	} else {
		printf("Unknown cost type.\n");
	}

	/* -----------------------------------------------------------------
	 *                                                        Do the job
	 * -------------------------------------------------------------- */

	VlHIKMTree * tree;
	vl_uint *ids;
	int j;
	int depth;

	tree = python_to_hikm(inTree, method_type);
	depth = vl_hikm_get_depth(tree);

	if (verb) {
		printf("hikmeanspush: ndims: %d K: %d depth: %d\n", vl_hikm_get_ndims(
			tree), vl_hikm_get_K(tree), depth);
	}

	npy_intp dims[2] = { depth, N };
	PyArrayObject * out_asgn = (PyArrayObject*) PyArray_NewFromDescr(
		&PyArray_Type, PyArray_DescrFromType(PyArray_INT32), 2, dims, NULL,
		NULL, NPY_F_CONTIGUOUS, NULL);

	ids = (vl_uint *) out_asgn->data;

	vl_hikm_push(tree, ids, data, N);
	vl_hikm_delete(tree);

	for (j = 0; j < N * depth; j++)
		ids[j]++;

	return PyArray_Return(out_asgn);

}