|
@@ -290,57 +290,58 @@ void GMHIKernelRaw::updateTableT ( const NICE::Vector _x ) const
|
|
int indexElem = 0;
|
|
int indexElem = 0;
|
|
// element of the feature
|
|
// element of the feature
|
|
double elem = i->value;
|
|
double elem = i->value;
|
|
-
|
|
|
|
- for (uint idxProto = 0; idxProto < hmax; idxProto++) // previously j
|
|
|
|
|
|
+
|
|
|
|
+ idxProtoElem = this->q->quantize ( elem, dim );
|
|
|
|
+
|
|
|
|
+ uint idxProto;
|
|
|
|
+ double * itProtoVal = prototypes + dim*hmax;
|
|
|
|
+ double * itT = this->table_T + dim*hmax;
|
|
|
|
+
|
|
|
|
+ // special case 1:
|
|
|
|
+ // loop over all prototypes smaller then the smallest quantized example in this dimension
|
|
|
|
+ for ( idxProto = 0; idxProto < idxProtoElem; idxProto++, itProtoVal++, itT++) // idxProto previously j
|
|
{
|
|
{
|
|
- double fvalProto = prototypes[ dim*hmax + idxProto ];
|
|
|
|
- double t;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- idxProtoElem = this->q->quantize ( elem, dim );
|
|
|
|
|
|
+ // current prototype is smaller than all known examples
|
|
|
|
+ // -> resulting value = fval * sum_l=1^n alpha_l
|
|
|
|
+ (*itT) = (*itProtoVal) * ( this->table_B[ dim ][ nnz-1 ] );
|
|
|
|
+ }//for-loop over prototypes -- special case 1
|
|
|
|
|
|
-
|
|
|
|
- if ( (indexElem == 0) && (idxProto < idxProtoElem) )
|
|
|
|
- {
|
|
|
|
- // current prototype is smaller than everything else
|
|
|
|
- // resulting value = fval * sum_l=1^n alpha_l
|
|
|
|
- t = fvalProto*( this->table_B[ dim ][ nnz-1 ] );
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- //move to next example, which is smaller then the current prototype (if necessary)
|
|
|
|
|
|
+ // standard case: prototypes larger then the smallest element, but smaller then the largest one in the corrent dimension
|
|
|
|
+ for ( ; idxProto < hmax; idxProto++, itProtoVal++, itT++)
|
|
|
|
+ {
|
|
|
|
+ //move to next example, which is smaller then the current prototype after quantization
|
|
// pay attentation to not loop over the number of non-zero elements
|
|
// pay attentation to not loop over the number of non-zero elements
|
|
- while ( (idxProto >= idxProtoElem) && ( indexElem < ( nnz - 1 ) ) ) //(this->ui_n-1-nrZeroIndices)) )
|
|
|
|
- {
|
|
|
|
- indexElem++;
|
|
|
|
- iPredecessor = i;
|
|
|
|
- i++;
|
|
|
|
-
|
|
|
|
- if ( i->value != iPredecessor->value )
|
|
|
|
- {
|
|
|
|
- idxProtoElem = this->q->quantize ( i->value, dim );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // compute current element in the lookup table and keep in mind that
|
|
|
|
- // indexElem is the next element and not the previous one
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if ( (idxProto >= idxProtoElem) && ( indexElem==( nnz-1 ) ) )
|
|
|
|
- {
|
|
|
|
- // the current prototype is equal to or larger than the largest training example in this dimension
|
|
|
|
- // -> the term B[ dim ][ nnz-1 ] - B[ dim ][ indexElem ] is equal to zero and vanishes, which is logical, since all elements are smaller than j!
|
|
|
|
- t = table_A[ dim ][ indexElem ];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- // standard case
|
|
|
|
- t = table_A[ dim ][ indexElem-1 ] + fvalProto*( table_B[ dim ][ nnz-1 ] - table_B[ dim ][ indexElem-1 ] );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this->table_T[ dim*hmax + idxProto ] = t;
|
|
|
|
- }//for-loop over prototypes
|
|
|
|
|
|
+ while ( (idxProto >= idxProtoElem) && ( indexElem < ( nnz - 1 ) ) ) //(this->ui_n-1-nrZeroIndices)) )
|
|
|
|
+ {
|
|
|
|
+ indexElem++;
|
|
|
|
+ iPredecessor = i;
|
|
|
|
+ i++;
|
|
|
|
+
|
|
|
|
+ // only quantize if value changed
|
|
|
|
+ if ( i->value != iPredecessor->value )
|
|
|
|
+ {
|
|
|
|
+ idxProtoElem = this->q->quantize ( i->value, dim );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // did we looped over the largest element in this dimension?
|
|
|
|
+ if ( indexElem==( nnz-1 ) )
|
|
|
|
+ {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ (*itT) = table_A[ dim ][ indexElem-1 ] + (*itProtoVal)*( table_B[ dim ][ nnz-1 ] - table_B[ dim ][ indexElem-1 ] );
|
|
|
|
+ }//for-loop over prototypes -- standard case
|
|
|
|
+
|
|
|
|
+ // special case 2:
|
|
|
|
+ // the current prototype is equal to or larger than the largest training example in this dimension
|
|
|
|
+ // -> the term B[ dim ][ nnz-1 ] - B[ dim ][ indexElem ] is equal to zero and vanishes, which is logical, since all elements are smaller than the remaining prototypes!
|
|
|
|
+
|
|
|
|
+ for ( ; idxProto < hmax; idxProto++, itProtoVal++, itT++)
|
|
|
|
+ {
|
|
|
|
+ (*itT) = table_A[ dim ][ indexElem ];
|
|
|
|
+ }//for-loop over prototypes -- special case 2
|
|
|
|
+
|
|
}//for-loop over dimensions
|
|
}//for-loop over dimensions
|
|
|
|
|
|
|
|
|