Esempio n. 1
0
struct QuantizedValue *FindMatch(uint8 const *sample, int ndims,
								 uint8 *weights, struct QuantizedValue *q)
{
	InitHeap(&TheQueue);
	struct QuantizedValue *bestmatch=0;
	double besterror=1.0e63;
	PUSHNODE(q);
	for(;;)
	{
		struct QuantizedValue *test=(struct QuantizedValue *)
			RemoveHeapItem(&TheQueue);
		if (! test) break;		// heap empty
//    printf("got pop node =%p minerror=%f\n",test,test->MinError);
    
		if (test->MinError>besterror) break;
		if (test->Children[0])
		{
			// it's a parent node. put the children on the queue
			struct QuantizedValue *c1=test->Children[0];
			struct QuantizedValue *c2=test->Children[1];
			c1->MinError=MinimumError(c1,sample,ndims,weights);
			if (c1->MinError < besterror)
				HeapInsert(&TheQueue,&(c1->MinError));
			c2->MinError=MinimumError(c2,sample,ndims,weights);
			if (c2->MinError < besterror)
				HeapInsert(&TheQueue,&(c2->MinError));
		}
		else
		{
			// it's a leaf node. This must be a new minimum or the MinError
			// test would have failed.
			if (test->MinError < besterror)
			{
				bestmatch=test;
				besterror=test->MinError;
			}
		}
	}
	if (bestmatch)
	{
		SquaredError+=besterror;
		bestmatch->NQuant++;
		for(int i=0;i<ndims;i++)
			bestmatch->Sums[i]+=sample[i];
	}
	return bestmatch;
}
Esempio n. 2
0
void FORMTREE(char Po[])
{
   int i,j,k;
   struct STACK *N;
   O=NULL;
   for(i=0;Po[i]!='\0';i++){
       N=(struct STACK *)malloc(sizeof(struct STACK));
       N->data=Po[i]; N->L=NULL; N->R=NULL; N->next=NULL;
       N->FP[0]=0; N->LP[0]=0;
       if(Po[i]=='.'||Po[i]=='+'){
	  N->R=POPNODE();
	  N->L=POPNODE();
       }
       else if(Po[i]=='*'){
	  N->L=POPNODE();
	  N->R=NULL;
       }
       PUSHNODE(N);
   }
}