|
@@ -45,7 +45,8 @@ FastMinKernel::FastMinKernel( const std::vector<std::vector<double> > & _X,
|
|
)
|
|
)
|
|
{
|
|
{
|
|
this->setDebug(_debug);
|
|
this->setDebug(_debug);
|
|
- this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dim);
|
|
|
|
|
|
+// this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dim);
|
|
|
|
+ this->X_sorted.set_features( _X, _dim);
|
|
this->ui_d = this->X_sorted.get_d();
|
|
this->ui_d = this->X_sorted.get_d();
|
|
this->ui_n = this->X_sorted.get_n();
|
|
this->ui_n = this->X_sorted.get_n();
|
|
this->d_noise = _noise;
|
|
this->d_noise = _noise;
|
|
@@ -77,7 +78,8 @@ FastMinKernel::FastMinKernel ( const std::vector< const NICE::SparseVector * > &
|
|
const uint & _dim)
|
|
const uint & _dim)
|
|
{
|
|
{
|
|
this->setDebug(_debug);
|
|
this->setDebug(_debug);
|
|
- this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dimensionsOverExamples, _dim);
|
|
|
|
|
|
+ this->X_sorted.set_features( _X, _dimensionsOverExamples, _dim);
|
|
|
|
+// this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dimensionsOverExamples, _dim);
|
|
this->ui_d = this->X_sorted.get_d();
|
|
this->ui_d = this->X_sorted.get_d();
|
|
this->ui_n = this->X_sorted.get_n();
|
|
this->ui_n = this->X_sorted.get_n();
|
|
this->d_noise = _noise;
|
|
this->d_noise = _noise;
|
|
@@ -159,7 +161,6 @@ void FastMinKernel::hik_prepare_kernel_multiplications(const std::vector< const
|
|
)
|
|
)
|
|
{
|
|
{
|
|
//FIXME why do we hand over the feature matrix here?
|
|
//FIXME why do we hand over the feature matrix here?
|
|
- std::cerr << "FastMinKernel::hik_prepare_kernel_multiplications -- size of _X : " << _X.size() << std::endl;
|
|
|
|
_X_sorted.set_features( _X, _dimensionsOverExamples, _dim );
|
|
_X_sorted.set_features( _X, _dimensionsOverExamples, _dim );
|
|
}
|
|
}
|
|
|
|
|
|
@@ -618,12 +619,8 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
|
|
|
|
uint dim = i->first;
|
|
uint dim = i->first;
|
|
double fval = i->second;
|
|
double fval = i->second;
|
|
-
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum (sparse)-- dim : " << dim << std::endl;
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum (sparse)-- fval : " << fval << std::endl;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- nrZeroIndices : " << nrZeroIndices << std::endl;
|
|
|
|
|
|
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
// all features are zero and let us ignore it completely
|
|
// all features are zero and let us ignore it completely
|
|
@@ -644,10 +641,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
position--;
|
|
position--;
|
|
}
|
|
}
|
|
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- position : " << position << std::endl;
|
|
|
|
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- this->ui_n : " << this->ui_n << std::endl;
|
|
|
|
-
|
|
|
|
//NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
|
|
//NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
|
|
//sum_{l \in L_k} \alpha_l x^l_k
|
|
//sum_{l \in L_k} \alpha_l x^l_k
|
|
double firstPart(0.0);
|
|
double firstPart(0.0);
|
|
@@ -655,9 +649,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
// Invalid read of size 8
|
|
// Invalid read of size 8
|
|
if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n) )
|
|
if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n) )
|
|
{
|
|
{
|
|
- std::cerr << " attempt to access A in " << position-nrZeroIndices;
|
|
|
|
firstPart = (_A[dim][position-nrZeroIndices]);
|
|
firstPart = (_A[dim][position-nrZeroIndices]);
|
|
- std::cerr << " with : " << firstPart << std::endl;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// sum_{u \in U_k} alpha_u
|
|
// sum_{u \in U_k} alpha_u
|
|
@@ -665,25 +657,20 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
// sum_{u \in U_k} alpha_u
|
|
// sum_{u \in U_k} alpha_u
|
|
// => double secondPart( B(dim, n-1) - B(dim, position));
|
|
// => double secondPart( B(dim, n-1) - B(dim, position));
|
|
//TODO in the next line there occurs the following error
|
|
//TODO in the next line there occurs the following error
|
|
- // Invalid read of size 8
|
|
|
|
- std::cerr << " attempt to access B in " << this->ui_n-1-nrZeroIndices;
|
|
|
|
|
|
+ // Invalid read of size 8
|
|
double secondPart( _B[dim][this->ui_n-1-nrZeroIndices]);
|
|
double secondPart( _B[dim][this->ui_n-1-nrZeroIndices]);
|
|
- std::cerr << " with : " << secondPart << std::endl;
|
|
|
|
//TODO in the "overnext" line there occurs the following error
|
|
//TODO in the "overnext" line there occurs the following error
|
|
// Invalid read of size 8
|
|
// Invalid read of size 8
|
|
if ( !posIsZero && (position >= nrZeroIndices) )
|
|
if ( !posIsZero && (position >= nrZeroIndices) )
|
|
{
|
|
{
|
|
- std::cerr << " attempt to access B in " << position-nrZeroIndices;
|
|
|
|
secondPart-= _B[dim][position-nrZeroIndices];
|
|
secondPart-= _B[dim][position-nrZeroIndices];
|
|
- std::cerr << " with : " << _B[dim][position-nrZeroIndices] << std::endl;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if ( _pf != NULL )
|
|
if ( _pf != NULL )
|
|
{
|
|
{
|
|
fval = _pf->f ( dim, fval );
|
|
fval = _pf->f ( dim, fval );
|
|
}
|
|
}
|
|
-
|
|
|
|
- std::cerr << " result dim " << dim << " impact " << firstPart + secondPart* fval << " firstPart " << firstPart << " secondPart " << secondPart << " fval " << fval << std::endl;
|
|
|
|
|
|
+
|
|
// but apply using the transformed one
|
|
// but apply using the transformed one
|
|
_beta += firstPart + secondPart* fval;
|
|
_beta += firstPart + secondPart* fval;
|
|
}
|
|
}
|
|
@@ -700,13 +687,10 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
uint dim ( 0 );
|
|
uint dim ( 0 );
|
|
for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
|
|
for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
|
|
{
|
|
{
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- dim : " << dim << std::endl;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
double fval = *i;
|
|
double fval = *i;
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- fval : " << fval << std::endl;
|
|
|
|
|
|
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- nrZeroIndices : " << nrZeroIndices << std::endl;
|
|
|
|
|
|
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
// all features are zero and let us ignore it completely
|
|
// all features are zero and let us ignore it completely
|
|
@@ -725,12 +709,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
if ( !posIsZero )
|
|
if ( !posIsZero )
|
|
{
|
|
{
|
|
position--;
|
|
position--;
|
|
- }
|
|
|
|
-
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- position : " << position << std::endl;
|
|
|
|
-
|
|
|
|
- std::cerr << " FastMinKernel::hik_kernel_sum -- this->ui_n : " << this->ui_n << std::endl;
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
//NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
|
|
//NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
|
|
@@ -742,9 +721,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
|
|
|
|
if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n) )
|
|
if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n) )
|
|
{
|
|
{
|
|
- std::cerr << " attempt to access A in " << position-nrZeroIndices;
|
|
|
|
firstPart = (_A[dim][position-nrZeroIndices]);
|
|
firstPart = (_A[dim][position-nrZeroIndices]);
|
|
- std::cerr << " with : " << firstPart << std::endl;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// sum_{u \in U_k} alpha_u
|
|
// sum_{u \in U_k} alpha_u
|
|
@@ -753,17 +730,13 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
// => double secondPart( B(dim, n-1) - B(dim, position));
|
|
// => double secondPart( B(dim, n-1) - B(dim, position));
|
|
//TODO in the next line there occurs the following error
|
|
//TODO in the next line there occurs the following error
|
|
// Invalid read of size 8
|
|
// Invalid read of size 8
|
|
- std::cerr << " attempt to access B in " << this->ui_n-1-nrZeroIndices;
|
|
|
|
double secondPart( _B[dim][this->ui_n-1-nrZeroIndices] );
|
|
double secondPart( _B[dim][this->ui_n-1-nrZeroIndices] );
|
|
- std::cerr << " with : " << secondPart << std::endl;
|
|
|
|
//TODO in the "overnext" line there occurs the following error
|
|
//TODO in the "overnext" line there occurs the following error
|
|
// Invalid read of size 8
|
|
// Invalid read of size 8
|
|
|
|
|
|
if ( !posIsZero && (position >= nrZeroIndices) )
|
|
if ( !posIsZero && (position >= nrZeroIndices) )
|
|
{
|
|
{
|
|
- std::cerr << " attempt to access B in " << position-nrZeroIndices;
|
|
|
|
secondPart-= _B[dim][position-nrZeroIndices];
|
|
secondPart-= _B[dim][position-nrZeroIndices];
|
|
- std::cerr << " with : " << _B[dim][position-nrZeroIndices] << std::endl;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -773,7 +746,6 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
fval = _pf->f ( dim, fval );
|
|
fval = _pf->f ( dim, fval );
|
|
}
|
|
}
|
|
|
|
|
|
- std::cerr << " result dim " << dim << " impact " << firstPart + secondPart* fval << " firstPart " << firstPart << " secondPart " << secondPart << " fval " << fval << std::endl;
|
|
|
|
// but apply using the transformed one
|
|
// but apply using the transformed one
|
|
_beta += firstPart + secondPart* fval;
|
|
_beta += firstPart + secondPart* fval;
|
|
}
|
|
}
|
|
@@ -881,7 +853,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
for ( iter = 1; iter <= _maxIterations; iter++ )
|
|
for ( iter = 1; iter <= _maxIterations; iter++ )
|
|
{
|
|
{
|
|
NICE::Vector perm;
|
|
NICE::Vector perm;
|
|
- randomPermutation( perm, indices, _sizeOfRandomSubset );
|
|
|
|
|
|
+ this->randomPermutation( perm, indices, _sizeOfRandomSubset );
|
|
|
|
|
|
if ( _timeAnalysis )
|
|
if ( _timeAnalysis )
|
|
{
|
|
{
|
|
@@ -893,7 +865,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
double res = r.normL2();
|
|
double res = r.normL2();
|
|
double resMax = r.normInf();
|
|
double resMax = r.normInf();
|
|
|
|
|
|
- cerr << "SimpleGradientDescent: TIME " << t.getSum() << " " << res << " " << resMax << endl;
|
|
|
|
|
|
+ std::cerr << "SimpleGradientDescent: TIME " << t.getSum() << " " << res << " " << resMax << std::endl;
|
|
|
|
|
|
t.start();
|
|
t.start();
|
|
}
|
|
}
|
|
@@ -978,15 +950,15 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
|
|
|
|
double delta = delta_alpha.normL2();
|
|
double delta = delta_alpha.normL2();
|
|
if ( this->b_verbose ) {
|
|
if ( this->b_verbose ) {
|
|
- cerr << "FastMinKernel::solveLin: iteration " << iter << " / " << _maxIterations << endl;
|
|
|
|
- cerr << "FastMinKernel::solveLin: delta = " << delta << endl;
|
|
|
|
- cerr << "FastMinKernel::solveLin: pseudo residual = " << pseudoResidual.scalarProduct(pseudoResidual) << endl;
|
|
|
|
|
|
+ std::cerr << "FastMinKernel::solveLin: iteration " << iter << " / " << _maxIterations << std::endl;
|
|
|
|
+ std::cerr << "FastMinKernel::solveLin: delta = " << delta << std::endl;
|
|
|
|
+ std::cerr << "FastMinKernel::solveLin: pseudo residual = " << pseudoResidual.scalarProduct(pseudoResidual) << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
if ( delta < _minDelta )
|
|
if ( delta < _minDelta )
|
|
{
|
|
{
|
|
if ( this->b_verbose )
|
|
if ( this->b_verbose )
|
|
- cerr << "FastMinKernel::solveLin: small delta" << endl;
|
|
|
|
|
|
+ std::cerr << "FastMinKernel::solveLin: small delta" << std::endl;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1429,6 +1401,12 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
|
|
_kstar.resize( this->ui_n );
|
|
_kstar.resize( this->ui_n );
|
|
_kstar.set(0.0);
|
|
_kstar.set(0.0);
|
|
|
|
|
|
|
|
+ if ( this->b_debug )
|
|
|
|
+ {
|
|
|
|
+ std::cerr << " FastMinKernel::hikComputeKernelVector -- input: " << std::endl;
|
|
|
|
+ _xstar.store( std::cerr);
|
|
|
|
+ }
|
|
|
|
+
|
|
//let's start :)
|
|
//let's start :)
|
|
for (SparseVector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++)
|
|
for (SparseVector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++)
|
|
{
|
|
{
|
|
@@ -1436,6 +1414,9 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
|
|
uint dim = i->first;
|
|
uint dim = i->first;
|
|
double fval = i->second;
|
|
double fval = i->second;
|
|
|
|
|
|
|
|
+ if ( this->b_debug )
|
|
|
|
+ std::cerr << "dim: " << dim << " fval: " << fval << std::endl;
|
|
|
|
+
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
// all features are zero so let us ignore them completely
|
|
// all features are zero so let us ignore them completely
|
|
@@ -1451,6 +1432,9 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
|
|
this->X_sorted.findFirstLargerInDimension(dim, fval, position);
|
|
this->X_sorted.findFirstLargerInDimension(dim, fval, position);
|
|
//position--;
|
|
//position--;
|
|
|
|
|
|
|
|
+ if ( this->b_debug )
|
|
|
|
+ std::cerr << " position: " << position << std::endl;
|
|
|
|
+
|
|
//get the non-zero elements for this dimension
|
|
//get the non-zero elements for this dimension
|
|
const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
|
|
const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
|
|
|
|
|
|
@@ -1460,11 +1444,15 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
|
|
for ( SortedVectorSparse<double>::const_elementpointer i = nonzeroElements.begin(); i != nonzeroElements.end(); i++, count++ )
|
|
for ( SortedVectorSparse<double>::const_elementpointer i = nonzeroElements.begin(); i != nonzeroElements.end(); i++, count++ )
|
|
{
|
|
{
|
|
uint origIndex(i->second.first); //orig index (i->second.second would be the transformed feature value)
|
|
uint origIndex(i->second.first); //orig index (i->second.second would be the transformed feature value)
|
|
|
|
+
|
|
|
|
+ if ( this->b_debug )
|
|
|
|
+ std::cerr << "i->1.2: " << i->second.first << " origIndex: " << origIndex << " count: " << count << " position: " << position << std::endl;
|
|
if (count < position)
|
|
if (count < position)
|
|
_kstar[origIndex] += i->first; //orig feature value
|
|
_kstar[origIndex] += i->first; //orig feature value
|
|
else
|
|
else
|
|
_kstar[origIndex] += fval;
|
|
_kstar[origIndex] += fval;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1556,16 +1544,13 @@ void FastMinKernel::hikComputeKernelVector( const NICE::Vector & _xstar,
|
|
_kstar.resize(this->ui_n);
|
|
_kstar.resize(this->ui_n);
|
|
_kstar.set(0.0);
|
|
_kstar.set(0.0);
|
|
|
|
|
|
- std::cerr << "test example: " << _xstar << std::endl;
|
|
|
|
- std::cerr << " init _kstar: " << _kstar << std::endl;
|
|
|
|
-
|
|
|
|
|
|
+
|
|
//let's start :)
|
|
//let's start :)
|
|
uint dim ( 0 );
|
|
uint dim ( 0 );
|
|
for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
|
|
for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
|
|
{
|
|
{
|
|
|
|
|
|
double fval = *i;
|
|
double fval = *i;
|
|
- std::cerr << " dim: " << dim << " fval: " << fval << std::endl;
|
|
|
|
|
|
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
if ( nrZeroIndices == this->ui_n ) {
|
|
@@ -1582,7 +1567,6 @@ void FastMinKernel::hikComputeKernelVector( const NICE::Vector & _xstar,
|
|
this->X_sorted.findFirstLargerInDimension(dim, fval, position);
|
|
this->X_sorted.findFirstLargerInDimension(dim, fval, position);
|
|
//position--;
|
|
//position--;
|
|
|
|
|
|
- std::cerr << " dim: " << dim << " fval: " << fval << std::endl;
|
|
|
|
|
|
|
|
//get the non-zero elements for this dimension
|
|
//get the non-zero elements for this dimension
|
|
const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
|
|
const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
|
|
@@ -1620,7 +1604,7 @@ void FastMinKernel::restore ( std::istream & _is,
|
|
if ( ! this->isStartTag( tmp, "FastMinKernel" ) )
|
|
if ( ! this->isStartTag( tmp, "FastMinKernel" ) )
|
|
{
|
|
{
|
|
std::cerr << " WARNING - attempt to restore FastMinKernel, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
std::cerr << " WARNING - attempt to restore FastMinKernel, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
- throw;
|
|
|
|
|
|
+ throw;
|
|
}
|
|
}
|
|
|
|
|
|
_is.precision (numeric_limits<double>::digits10 + 1);
|
|
_is.precision (numeric_limits<double>::digits10 + 1);
|