Forráskód Böngészése

Persisent in new layout for main classes of gp-hik-core implemented

Alexander Freytag 11 éve
szülő
commit
b7eb0a2202

+ 119 - 227
FMKGPHyperparameterOptimization.cpp

@@ -79,9 +79,6 @@ FMKGPHyperparameterOptimization::FMKGPHyperparameterOptimization ( const Config
   //TODO 
   if ( _fmk == NULL )
     this->initialize ( _conf, _pf ); //then the confSection is also the default value
-  //TODO not needed anymore, only for backword compatibility
-//   else if ( _confSection.compare ( "HIKGP" ) == 0 )
-//     this->initialize ( _conf, _pf, _fmk );
   else
     this->initialize ( _conf, _pf, _fmk, _confSection );
 }
@@ -110,24 +107,29 @@ FMKGPHyperparameterOptimization::~FMKGPHyperparameterOptimization()
 
 void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, ParameterizedFunction *_pf, FastMinKernel *_fmk, const std::string & _confSection )
 {
-  if ( this->fmk != NULL )
-  {
-    std::cerr << "fmk deleted" << std::endl;
-    delete this->fmk;
-  }
+
   if ( _fmk != NULL )
   {
-    std::cerr << "fmk copied" << std::endl;    
+    if ( this->fmk != NULL )
+    {
+      delete this->fmk;
+      fmk = NULL;
+    }    
     this->fmk = _fmk;
   }
   
   this->pf = _pf;
-  std::cerr << "pf copied" << std::endl;
-  
   
-  std::cerr << "------------" << std::endl;
-  std::cerr << "|  set-up  |" << std::endl;
-  std::cerr << "------------" << std::endl;
+  this->verbose = _conf->gB ( _confSection, "verbose", false );
+  this->verboseTime = _conf->gB ( _confSection, "verboseTime", false );
+  this->debug = _conf->gB ( _confSection, "debug", false );
+
+  if ( verbose )
+  {  
+    std::cerr << "------------" << std::endl;
+    std::cerr << "|  set-up  |" << std::endl;
+    std::cerr << "------------" << std::endl;
+  }
 
 
   this->eig = new EVArnoldi ( _conf->gB ( _confSection, "eig_verbose", false ) /* verbose flag */, 10 );
@@ -144,17 +146,20 @@ void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, Paramete
   this->nrOfEigenvaluesToConsider = _conf->gI ( _confSection, "nrOfEigenvaluesToConsider", 1 );
   this->nrOfEigenvaluesToConsiderForVarApprox = _conf->gI ( _confSection, "nrOfEigenvaluesToConsiderForVarApprox", 2 );
 
-  this->verbose = _conf->gB ( _confSection, "verbose", false );
-  this->verboseTime = _conf->gB ( _confSection, "verboseTime", false );
-  this->debug = _conf->gB ( _confSection, "debug", false );
+
 
   bool useQuantization = _conf->gB ( _confSection, "use_quantization", false );
-  std::cerr << "_confSection: " << _confSection << std::endl;
-  std::cerr << "use_quantization: " << useQuantization << std::endl;
+  
+  if ( verbose ) 
+  {
+    std::cerr << "_confSection: " << _confSection << std::endl;
+    std::cerr << "use_quantization: " << useQuantization << std::endl;
+  }
+  
   if ( _conf->gB ( _confSection, "use_quantization", false ) ) {
     int numBins = _conf->gI ( _confSection, "num_bins", 100 );
     if ( verbose )
-      cerr << "FMKGPHyperparameterOptimization: quantization initialized with " << numBins << " bins." << endl;
+      std::cerr << "FMKGPHyperparameterOptimization: quantization initialized with " << numBins << " bins." << std::endl;
     this->q = new Quantization ( numBins );
   } else {
     this->q = NULL;
@@ -163,7 +168,7 @@ void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, Paramete
   bool ils_verbose = _conf->gB ( _confSection, "ils_verbose", false );
   ils_max_iterations = _conf->gI ( _confSection, "ils_max_iterations", 1000 );
   if ( verbose )
-    cerr << "FMKGPHyperparameterOptimization: maximum number of iterations is " << ils_max_iterations << endl;
+    std::cerr << "FMKGPHyperparameterOptimization: maximum number of iterations is " << ils_max_iterations << std::endl;
 
   double ils_min_delta = _conf->gD ( _confSection, "ils_min_delta", 1e-7 );
   double ils_min_residual = _conf->gD ( _confSection, "ils_min_residual", 1e-7/*1e-2 */ );
@@ -175,29 +180,29 @@ void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, Paramete
       std::cerr << "We use CG with " << ils_max_iterations << " iterations, " << ils_min_delta << " as min delta, and " << ils_min_residual << " as min res " << std::endl;
     this->linsolver = new ILSConjugateGradients ( ils_verbose , ils_max_iterations, ils_min_delta, ils_min_residual );
     if ( verbose )
-      cerr << "FMKGPHyperparameterOptimization: using ILS ConjugateGradients" << endl;
+      std::cerr << "FMKGPHyperparameterOptimization: using ILS ConjugateGradients" << std::endl;
   }
   else if ( ils_method.compare ( "CGL" ) == 0 )
   {
     this->linsolver = new ILSConjugateGradientsLanczos ( ils_verbose , ils_max_iterations );
     if ( verbose )
-      cerr << "FMKGPHyperparameterOptimization: using ILS ConjugateGradients (Lanczos)" << endl;
+      std::cerr << "FMKGPHyperparameterOptimization: using ILS ConjugateGradients (Lanczos)" << std::endl;
   }
   else if ( ils_method.compare ( "SYMMLQ" ) == 0 )
   {
     this->linsolver = new ILSSymmLqLanczos ( ils_verbose , ils_max_iterations );
     if ( verbose )
-      cerr << "FMKGPHyperparameterOptimization: using ILS SYMMLQ" << endl;
+      std::cerr << "FMKGPHyperparameterOptimization: using ILS SYMMLQ" << std::endl;
   }
   else if ( ils_method.compare ( "MINRES" ) == 0 )
   {
     this->linsolver = new ILSMinResLanczos ( ils_verbose , ils_max_iterations );
     if ( verbose )
-      cerr << "FMKGPHyperparameterOptimization: using ILS MINRES" << endl;
+      std::cerr << "FMKGPHyperparameterOptimization: using ILS MINRES" << std::endl;
   }
   else
   {
-    cerr << "FMKGPHyperparameterOptimization: " << _confSection << ":ils_method (" << ils_method << ") does not match any type (CG,CGL,SYMMLQ,MINRES), I will use CG" << endl;
+    std::cerr << "FMKGPHyperparameterOptimization: " << _confSection << ":ils_method (" << ils_method << ") does not match any type (CG,CGL,SYMMLQ,MINRES), I will use CG" << std::endl;
     this->linsolver = new ILSConjugateGradients ( ils_verbose , ils_max_iterations, ils_min_delta, ils_min_residual );
   }
   
@@ -212,7 +217,7 @@ void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, Paramete
     fthrow ( Exception, "Optimization method " << optimizationMethod_s << " is not known." );
 
   if ( verbose )
-    cerr << "Using optimization method: " << optimizationMethod_s << endl;
+    std::cerr << "Using optimization method: " << optimizationMethod_s << std::endl;
 
   downhillSimplexMaxIterations = _conf->gI ( _confSection, "downhillsimplex_max_iterations", 20 );
   // do not run longer than a day :)
@@ -221,11 +226,14 @@ void FMKGPHyperparameterOptimization::initialize ( const Config *_conf, Paramete
 
   optimizeNoise = _conf->gB ( _confSection, "optimize_noise", false );
   if ( verbose )
-    cerr << "Optimize noise: " << ( optimizeNoise ? "on" : "off" ) << endl;
+    std::cerr << "Optimize noise: " << ( optimizeNoise ? "on" : "off" ) << std::endl;
   
-  std::cerr << "------------" << std::endl;
-  std::cerr << "|   start   |" << std::endl;
-  std::cerr << "------------" << std::endl;  
+  if ( verbose )
+  {
+    std::cerr << "------------" << std::endl;
+    std::cerr << "|   start   |" << std::endl;
+    std::cerr << "------------" << std::endl;
+  }
 }
 
 // get and set methods
@@ -294,7 +302,7 @@ void FMKGPHyperparameterOptimization::performOptimization ( GPLikelihoodApprox &
     NICE::Vector uB = ikmsum->getParameterUpperBounds();
     
     if ( verbose )
-      cerr << "lower bound " << lB << " upper bound " << uB << " parameterStepSize: " << parameterStepSize << endl;
+      std::cerr << "lower bound " << lB << " upper bound " << uB << " parameterStepSize: " << parameterStepSize << std::endl;
 
     
     NICE::Vector tmp = gplike.getBestParameters(  );
@@ -331,7 +339,7 @@ void FMKGPHyperparameterOptimization::performOptimization ( GPLikelihoodApprox &
     
     OPTIMIZATION::SimpleOptProblem optProblem ( &gplike, initialParams, initialParams /* scales*/ );
 
-    //     cerr << "OPT: " << mypara << " " << nlikelihood << " " << logdet << " " << dataterm << endl;
+    //     std::cerr << "OPT: " << mypara << " " << nlikelihood << " " << logdet << " " << dataterm << std::endl;
     optimizer.setMaxNumIter ( true, downhillSimplexMaxIterations );
     optimizer.setTimeLimit ( true, downhillSimplexTimeLimit );
     optimizer.setParamTol ( true, downhillSimplexParamTol );
@@ -430,7 +438,7 @@ void FMKGPHyperparameterOptimization::optimizeBinary ( const sparse_t & data, co
     }
   }
   y.resize ( examples.size() );
-  cerr << "Examples: " << examples.size() << endl;
+  std::cerr << "Examples: " << examples.size() << std::endl;
 
   optimize ( data, y, examples, noise );
 }
@@ -440,7 +448,7 @@ void FMKGPHyperparameterOptimization::optimize ( const sparse_t & data, const NI
 {
   Timer t;
   t.start();
-  cerr << "Initializing data structure ..." << std::endl;
+  std::cerr << "Initializing data structure ..." << std::endl;
   if ( fmk != NULL ) delete fmk;
   fmk = new FastMinKernel ( data, noise, examples );
   t.stop();
@@ -560,7 +568,7 @@ void FMKGPHyperparameterOptimization::optimize ( std::map<int, NICE::Vector> & b
   
   if (verbose)
   {
-    std::cerr << "Initial noise level: " << fmk->getNoise() << endl;
+    std::cerr << "Initial noise level: " << fmk->getNoise() << std::endl;
 
     std::cerr << "Number of classes (=1 means we have a binary setting):" << nrOfClasses << std::endl;
     std::cerr << "Effective number of classes (neglecting classes without positive examples): " << knownClasses.size() << std::endl;
@@ -623,7 +631,7 @@ void FMKGPHyperparameterOptimization::optimize ( std::map<int, NICE::Vector> & b
     std::cerr << "Time used for performing the optimization: " << t1.getLast() << std::endl;
 
   if ( verbose )
-    cerr << "Preparing classification ..." << endl;
+    std::cerr << "Preparing classification ..." << std::endl;
 
   t1.start();
   this->transformFeaturesWithOptimalParameters ( *gplike, parameterVectorSize );
@@ -1169,185 +1177,33 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
   {
     if ( b_restoreVerbose ) 
       std::cerr << " in FMKGP restore" << std::endl;
-    //load the underlying data
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "FMKGPHyperparameterOptimization" ) )
+    {
+        std::cerr << " WARNING - attempt to restore FMKGPHyperparameterOptimization, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+	throw;
+    } 
+
     if (fmk != NULL)
+    {
       delete fmk;
+      fmk = NULL;
+    }
     
-    if ( ikmsum == NULL )
+    if ( ikmsum != NULL )
     {
-        ikmsum = new IKMLinearCombination (); 
-        if ( b_restoreVerbose ) 
-          std::cerr << "ikmsum object created" << std::endl;
+      delete ikmsum;
     }
-    else
-    {
-      if ( b_restoreVerbose ) 
-        std::cerr << "ikmsum object already existing" << std::endl;
-    }    
-    
-    std::string tmp;
-    is >> tmp; //class name    
-    
-    if ( b_restoreVerbose ) 
-      std::cerr << " create FMK" << std::endl;
-    fmk = new FastMinKernel;
-    if ( b_restoreVerbose ) 
-      std::cerr << " restore FMK" << std::endl;
-    fmk->restore(is,format); 
+    ikmsum = new IKMLinearCombination (); 
     if ( b_restoreVerbose ) 
-      std::cerr << "fmk->restore done " << std::endl;
-    
-    is.precision ( numeric_limits<double>::digits10 + 1 );
-    
-    
-
-
-    
-//     is >> tmp; //precomputedA:
-//     is >> tmp; //size:
-// 
-//     int preCompSize ( 0 );
-//     is >> preCompSize;
-//     precomputedA.clear();
-// 
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "restore precomputedA with size: " << preCompSize << std::endl;
-//     for ( int i = 0; i < preCompSize; i++ )
-//     {
-//       int nr;
-//       is >> nr;
-//       PrecomputedType pct;
-//       pct.setIoUntilEndOfFile ( false );
-//       pct.restore ( is, format );
-//       precomputedA.insert ( std::pair<int, PrecomputedType> ( nr, pct ) );
-//     }
-//     
-//     is >> tmp; //precomputedB:
-//     is >> tmp; //size:
-// 
-//     is >> preCompSize;
-//     precomputedB.clear();
-// 
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "restore precomputedB with size: " << preCompSize << std::endl;
-//     for ( int i = 0; i < preCompSize; i++ )
-//     {
-//       int nr;
-//       is >> nr;
-//       PrecomputedType pct;
-//       pct.setIoUntilEndOfFile ( false );
-//       pct.restore ( is, format );
-//       precomputedB.insert ( std::pair<int, PrecomputedType> ( nr, pct ) );
-//     }    
-//     
-//     is >> tmp; //precomputedT: std::cerr << " content of tmp: " << tmp << std::endl; 
-//     is >> tmp; //size: std::cerr << " content of tmp: " << tmp << std::endl;
-//     
-//     int precomputedTSize ( 0 );
-//     is >> precomputedTSize;
-// 
-//     precomputedT.clear();
-//     
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "restore precomputedT with size: " << precomputedTSize << std::endl;
-// 
-//     if ( precomputedTSize > 0 )
-//     {
-//       if ( b_restoreVerbose ) 
-//         std::cerr << " restore precomputedT" << std::endl;
-//       is >> tmp;
-//       int sizeOfLUT;
-//       is >> sizeOfLUT;    
-//       
-//       for (int i = 0; i < precomputedTSize; i++)
-//       {
-//         is >> tmp;
-//         int index;
-//         is >> index;        
-//         double * array = new double [ sizeOfLUT];
-//         for ( int i = 0; i < sizeOfLUT; i++ )
-//         {
-//           is >> array[i];
-//         }
-//         precomputedT.insert ( std::pair<int, double*> ( index, array ) );
-//       }
-//     } 
-//     else
-//     {
-//       if ( b_restoreVerbose ) 
-//         std::cerr << " skip restoring precomputedT" << std::endl;
-//     }
-// 
-//     //now restore the things we need for the variance computation
-//     is >> tmp;
-//     if ( b_restoreVerbose ) 
-//       std::cerr << " content of tmp: " << tmp << std::endl;
-//     int sizeOfAForVarEst;
-//     is >> sizeOfAForVarEst;
-//     
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "restore precomputedAForVarEst with size: " << sizeOfAForVarEst << std::endl;
-//     
-//     if (sizeOfAForVarEst > 0)
-//     {
-//       precomputedAForVarEst.clear();
-//       
-//       precomputedAForVarEst.setIoUntilEndOfFile ( false );
-//       std::cerr << "restore precomputedAForVarEst" << std::endl;
-//       precomputedAForVarEst.restore ( is, format );
-//     }    
-// 
-//     is >> tmp; //precomputedTForVarEst
-//       if ( b_restoreVerbose ) 
-//     std::cerr << "content of tmp: " << tmp << std::endl;
-//     is >> tmp; // NOTNULL or NULL
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "content of tmp: " << tmp << std::endl;    
-//     if (tmp.compare("NOTNULL") == 0)
-//     {
-//       if ( b_restoreVerbose ) 
-//         std::cerr << "restore precomputedTForVarEst" << std::endl;
-//       
-//       int sizeOfLUT;
-//       is >> sizeOfLUT;      
-//       precomputedTForVarEst = new double [ sizeOfLUT ];
-//       for ( int i = 0; i < sizeOfLUT; i++ )
-//       {
-//         is >> precomputedTForVarEst[i];
-//       }      
-//     }
-//     else
-//     {
-//       if ( b_restoreVerbose ) 
-//         std::cerr << "skip restoring of precomputedTForVarEst" << std::endl;
-//       if (precomputedTForVarEst != NULL)
-//         delete precomputedTForVarEst;
-//     }
-//     
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "restore eigenMax and eigenMaxVectors " << std::endl;
-//     
-//     
-//     if ( b_restoreVerbose ) 
-//       std::cerr << " create ikmsum object" << std::endl;
-//     
-// 
-//       
-// 
-//     is >> tmp; //"numberOfModels:"
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "content of tmp: " << tmp << std::endl;
-//     int nrOfModels ( 0 );
-//     is >> nrOfModels;
-//     if ( b_restoreVerbose ) 
-//       std::cerr << "number of models to add in total: " << nrOfModels << std::endl;
-//     
-//     if ( b_restoreVerbose ) 
-//       std::cerr << " restore IKMNoise " << std::endl;
-//     
+      std::cerr << "ikmsum object created" << std::endl;
     
-//     //the first one is always our noise-model
     
+    is.precision ( numeric_limits<double>::digits10 + 1 );
+       
     
     bool b_endOfBlock ( false ) ;
     
@@ -1363,9 +1219,18 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
       
       tmp = this->removeStartTag ( tmp );
       
-      std::cerr << " currently restore setcion " << tmp << " in FMKGPHyperparameterOptimization" << std::endl;
+      if ( b_restoreVerbose )
+	std::cerr << " currently restore section " << tmp << " in FMKGPHyperparameterOptimization" << std::endl;
       
-      if ( tmp.compare("precomputedA") == 0 )
+      if ( tmp.compare("fmk") == 0 )
+      {
+	fmk = new FastMinKernel;
+        fmk->restore( is, format );
+
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("precomputedA") == 0 )
       {
         is >> tmp; // size
         int preCompSize ( 0 );
@@ -1383,6 +1248,9 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
           pct.restore ( is, format );
           precomputedA.insert ( std::pair<int, PrecomputedType> ( nr, pct ) );
         }
+        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }        
       else if ( tmp.compare("precomputedB") == 0 )
       {
@@ -1402,6 +1270,9 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
           pct.restore ( is, format );
           precomputedB.insert ( std::pair<int, PrecomputedType> ( nr, pct ) );
         }    
+        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }       
       else if ( tmp.compare("precomputedT") == 0 )
       {
@@ -1439,7 +1310,10 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
         {
           if ( b_restoreVerbose ) 
             std::cerr << " skip restoring precomputedT" << std::endl;
-        }   
+        }
+        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }      
       else if ( tmp.compare("precomputedAForVarEst") == 0 )
       {
@@ -1454,9 +1328,11 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
           precomputedAForVarEst.clear();
           
           precomputedAForVarEst.setIoUntilEndOfFile ( false );
-          std::cerr << "restore precomputedAForVarEst" << std::endl;
           precomputedAForVarEst.restore ( is, format );
-        }     
+        }
+        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }        
       else if ( tmp.compare("precomputedTForVarEst") == 0 )
       {
@@ -1483,15 +1359,22 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
             std::cerr << "skip restoring of precomputedTForVarEst" << std::endl;
           if (precomputedTForVarEst != NULL)
             delete precomputedTForVarEst;
-        } 
+        }
+        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }       
       else if ( tmp.compare("eigenMax") == 0 )
       {
-        is >> eigenMax;     
+        is >> eigenMax;
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }    
       else if ( tmp.compare("eigenMaxVectors") == 0 )
       {
-        is >> eigenMaxVectors;     
+        is >> eigenMaxVectors;
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }    
       else if ( tmp.compare("ikmsum") == 0 )
       {
@@ -1518,28 +1401,37 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
             ikmsum->addModel ( ikmnoise );        
           }
           else
-          {}
-          is >> tmp; // end of block 
-          tmp = this->removeEndTag ( tmp );           
+          { 
+	    std::cerr << "WARNING -- unexpected ikmsum object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	    throw;
+	  }         
         }
-        std::cerr  << " ended restoring ikmsum " << std::endl;
       }
       else if ( tmp.compare("binaryLabelPositive") == 0 )
       {
-        is >> binaryLabelPositive;     
+        is >> binaryLabelPositive;
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }
       else if  ( tmp.compare("binaryLabelNegative") == 0 )
       {
         is >> binaryLabelNegative;        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }
       else if  ( tmp.compare("labels") == 0 )
       {
         is >> labels;        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
       }       
-      else{ }
+      else
+      {
+	std::cerr << "WARNING -- unexpected FMKGPHyper object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	throw;	
+      }
       
-      is >> tmp; // end of block 
-      tmp = this->removeEndTag ( tmp );  
+ 
     }
 
     
@@ -1548,7 +1440,6 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
     //NOTE are there any more models you added? then add them here respectively in the correct order
     //.....  
 
-
     //the last one is the GHIK - which we do not have to restore, but simply reset it
     if ( b_restoreVerbose ) 
       std::cerr << " add GMHIKernel" << std::endl;
@@ -1583,6 +1474,7 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
   else
   {
     std::cerr << "InStream not initialized - restoring not possible!" << std::endl;
+    throw;
   }
 }
 
@@ -1593,7 +1485,9 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
     // show starting point
     os << this->createStartTag( "FMKGPHyperparameterOptimization" ) << std::endl;
     
+    os << this->createStartTag( "fmk" ) << std::endl;
     fmk->store ( os, format );
+    os << this->createEndTag( "fmk" ) << std::endl;
 
     os.precision ( numeric_limits<double>::digits10 + 1 );
 
@@ -1689,8 +1583,6 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
     os << eigenMaxVectors << std::endl;
     os << this->createEndTag( "eigenMaxVectors" ) << std::endl;       
 
-    //store the ikmsum object
-//     os << "numberOfModels: " << ikmsum->getNumberOfModels() << std::endl;
 
     os << this->createStartTag( "ikmsum" ) << std::endl;
     for ( int j = 0; j < ikmsum->getNumberOfModels() - 1; j++ )

+ 3 - 0
FMKGPHyperparameterOptimization.h

@@ -8,10 +8,12 @@
 #ifndef _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
 #define _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
 
+// STL includes
 #include <vector>
 #include <set>
 #include <map>
 
+// NICE-core includes
 #include <core/algebra/EigValues.h>
 #include <core/algebra/IterativeLinearSolver.h>
 #include <core/basics/Config.h>
@@ -22,6 +24,7 @@
 #include <core/matlabAccess/MatFileIO.h>
 #endif
 
+// gp-hik-core includes
 #include "FastMinKernel.h"
 #include "GPLikelihoodApprox.h"
 #include "IKMLinearCombination.h"

+ 109 - 32
FastMinKernel.cpp

@@ -4,11 +4,15 @@
  * @author Alexander Freytag
  * @date 06-12-2011 (dd-mm-yyyy)
 */
+
+// STL includes
 #include <iostream>
-//#include "tools.h"
 
-#include "core/basics/vectorio.h"
-#include "core/basics/Timer.h"
+// NICE-core includes
+#include <core/basics/vectorio.h>
+#include <core/basics/Timer.h>
+
+// gp-hik-core includes
 #include "FastMinKernel.h"
 
 using namespace std;
@@ -1375,49 +1379,122 @@ void FastMinKernel::hikComputeKernelVector( const NICE::Vector & xstar, NICE::Ve
 
 void FastMinKernel::restore ( std::istream & is, int format )
 {
-  if (is.good())
+  bool b_restoreVerbose ( false );
+  if ( is.good() )
   {
-    std::cerr << "FastMinKernel::restore  " << std::endl;
-    is.precision (numeric_limits<double>::digits10 + 1);  
-    
-    string tmp;
-    is >> tmp; //class name
+    if ( b_restoreVerbose ) 
+      std::cerr << " restore FastMinKernel" << std::endl;
     
-    is >> tmp;
-    is >> n;
+    std::string tmp;
+    is >> tmp; //class name 
     
-    is >> tmp;
-    is >> d;
+    if ( ! this->isStartTag( tmp, "FastMinKernel" ) )
+    {
+        std::cerr << " WARNING - attempt to restore FastMinKernel, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+	throw;
+    }   
+        
+    is.precision (numeric_limits<double>::digits10 + 1);
     
-    is >> tmp;
-    is >> noise;
+    bool b_endOfBlock ( false ) ;
     
-    is >> tmp;
-    int approxSchemeInt;
-    is >> approxSchemeInt;
-    setApproximationScheme(approxSchemeInt);
-   
-    std::cerr << "start restoring X_sorted  " << std::endl;
-    X_sorted.restore(is,format);
-    std::cerr << " done :) " << std::endl;
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "FastMinKernel" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( b_restoreVerbose )
+	std::cerr << " currently restore section " << tmp << " in FastMinKernel" << std::endl;
+      
+      if ( tmp.compare("n") == 0 )
+      {
+        is >> n;        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("d") == 0 )
+      {
+        is >> d;        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
+      } 
+      else if ( tmp.compare("noise") == 0 )
+      {
+        is >> noise;
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("approxScheme") == 0 )
+      {
+	int approxSchemeInt;
+	is >> approxSchemeInt;
+	setApproximationScheme(approxSchemeInt);
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );	
+      }
+      else if ( tmp.compare("X_sorted") == 0 )
+      {
+	X_sorted.restore(is,format);
+	
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );
+      }       
+      else
+      {
+	std::cerr << "WARNING -- unexpected FastMinKernel object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	throw;	
+      }
+    }
    }
   else
   {
     std::cerr << "FastMinKernel::restore -- InStream not initialized - restoring not possible!" << std::endl;
-  }  
-  std::cerr << " FMK restore ended " << std::endl;
+  }
 }
+
 void FastMinKernel::store ( std::ostream & os, int format ) const
 {
   if (os.good())
-  {
+  {    
+    // show starting point
+    os << this->createStartTag( "FastMinKernel" ) << std::endl;    
+    
     os.precision (numeric_limits<double>::digits10 + 1);
-    os << "FastMinKernel" << std::endl;
-    os << "n: " << n << std::endl;
-    os << "d: " << d << std::endl;
-    os << "noise: " << noise << std::endl;
-    os << "approxScheme: " << approxScheme << std::endl;    
-    X_sorted.store(os,format);  
+
+    os << this->createStartTag( "n" ) << std::endl;
+    os << n << std::endl;
+    os << this->createEndTag( "n" ) << std::endl;
+    
+    
+    os << this->createStartTag( "d" ) << std::endl;
+    os << d << std::endl;
+    os << this->createEndTag( "d" ) << std::endl;
+
+    
+    os << this->createStartTag( "noise" ) << std::endl;
+    os << noise << std::endl;
+    os << this->createEndTag( "noise" ) << std::endl;
+
+    
+    os << this->createStartTag( "approxScheme" ) << std::endl;
+    os << approxScheme << std::endl;
+    os << this->createEndTag( "approxScheme" ) << std::endl;
+    
+    os << this->createStartTag( "X_sorted" ) << std::endl;
+    //store the underlying data
+    X_sorted.store(os, format);
+    os << this->createEndTag( "X_sorted" ) << std::endl;   
+    
+    
+    // done
+    os << this->createEndTag( "FastMinKernel" ) << std::endl;        
   }
   else
   {

+ 6 - 2
FastMinKernel.h

@@ -7,14 +7,18 @@
 #ifndef FASTMINKERNELINCLUDE
 #define FASTMINKERNELINCLUDE
 
+// STL includes
 #include <iostream>
 
+// NICE-core includes
+#include <core/basics/Exception.h>
+#include <core/basics/Persistent.h>
+// 
 #include <core/vector/MatrixT.h>
 #include <core/vector/SparseVectorT.h>
 #include <core/vector/VVector.h>
-#include <core/basics/Exception.h>
-#include "core/basics/Persistent.h"
 
+// gp-hik-core includes
 #include "FeatureMatrixT.h"
 #include "Quantization.h"
 #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"

+ 6 - 4
FeatureMatrixT.h

@@ -7,23 +7,25 @@
 #ifndef FEATUREMATRIXINCLUDE
 #define FEATUREMATRIXINCLUDE
 
+// STL includes
 #include <vector>
 #include <set>
 #include <map>
 #include <iostream>
 #include <limits>
 
+// NICE-core includes
 #include <core/basics/Exception.h>
-#include "core/basics/Persistent.h"
-
+#include <core/basics/Persistent.h>
+// 
 #include <core/vector/MatrixT.h>
 #include <core/vector/SparseVectorT.h>
-
+// 
 #ifdef NICE_USELIB_MATIO
   #include <core/matlabAccess/MatFileIO.h> 
 #endif
   
-
+// gp-hik-core includes
 #include "SortedVectorSparse.h"
 #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
 

+ 91 - 38
FeatureMatrixT.tcc

@@ -7,7 +7,7 @@
 // #ifndef FEATUREMATRIX_TCC
 // #define FEATUREMATRIX_TCC
 
-
+// gp-hik-core includes
 #include "FeatureMatrixT.h"
 
 namespace NICE {
@@ -881,40 +881,79 @@ namespace NICE {
     template <typename T>
     void FeatureMatrixT<T>::restore ( std::istream & is, int format )
     {
-      if (is.good())
-      {
-        is.precision (std::numeric_limits<double>::digits10 + 1);
-        std::string tmp;
-        
-        is >> tmp; //classname
-        
-        is >> tmp;
-        is >> n;
-
-        
-        is >> tmp;
-        is >> d;
-        
-        features.resize(d);
-        //now read features for every dimension
-        for (int dim = 0; dim < d; dim++)
-        {
-          NICE::SortedVectorSparse<T> svs;
-          features[dim] = svs;          
-          features[dim].restore(is,format);
-        }
-        
-        if (verbose)
-        {
-          std::cerr << "FeatureMatrixT<T>::restore" << std::endl;
-          std::cerr << "n: " << n << std::endl;          
-          std::cerr << "d: " << d << std::endl;
-          this->print(std::cerr);
-        }
+      bool b_restoreVerbose ( false );
+      if ( is.good() )
+      {
+	if ( b_restoreVerbose ) 
+	  std::cerr << " restore FeatureMatrixT" << std::endl;
+	
+	std::string tmp;
+	is >> tmp; //class name 
+	
+	if ( ! this->isStartTag( tmp, "FeatureMatrixT" ) )
+	{
+	    std::cerr << " WARNING - attempt to restore FeatureMatrixT, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+	    throw;
+	}   
+	    
+	is.precision ( std::numeric_limits<double>::digits10 + 1);
+	
+	bool b_endOfBlock ( false ) ;
+	
+	while ( !b_endOfBlock )
+	{
+	  is >> tmp; // start of block 
+	  
+	  if ( this->isEndTag( tmp, "FeatureMatrixT" ) )
+	  {
+	    b_endOfBlock = true;
+	    continue;
+	  }      
+	  
+	  tmp = this->removeStartTag ( tmp );
+	  
+	  if ( b_restoreVerbose )
+	    std::cerr << " currently restore section " << tmp << " in FeatureMatrixT" << std::endl;
+	  
+	  if ( tmp.compare("n") == 0 )
+	  {
+	    is >> n;        
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	  }
+	  else if ( tmp.compare("d") == 0 )
+	  {
+	    is >> d;        
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	  } 
+	  else if ( tmp.compare("features") == 0 )
+	  {
+	    //NOTE assumes d to be read first!
+	    features.resize(d);
+	    //now read features for every dimension
+	    for (int dim = 0; dim < d; dim++)
+	    {
+	      NICE::SortedVectorSparse<T> svs;
+	      features[dim] = svs;          
+	      features[dim].restore(is,format);
+	    }
+	    
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	  }       
+	  else
+	  {
+	    std::cerr << "WARNING -- unexpected FeatureMatrixT object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	    throw;	
+	  }
+	}
+         
       }
       else
       {
         std::cerr << "FeatureMatrixT<T>::restore -- InStream not initialized - restoring not possible!" << std::endl;
+        throw;
       }
     }
 
@@ -923,16 +962,30 @@ namespace NICE {
     {
       if (os.good())
       {
+	// show starting point
+	os << this->createStartTag( "FeatureMatrixT" ) << std::endl;
+	
         os.precision (std::numeric_limits<double>::digits10 + 1);
-        os << "FeatureMatrixT" << std::endl;
-        os << "n: " << n << std::endl;
-        os << "d: " << d << std::endl;
+	
+	os << this->createStartTag( "n" ) << std::endl;
+	os << n << std::endl;
+	os << this->createEndTag( "n" ) << std::endl;
+	
+	
+	os << this->createStartTag( "d" ) << std::endl;
+	os << d << std::endl;
+	os << this->createEndTag( "d" ) << std::endl;
         
         //now write features for every dimension
-        for (int dim = 0; dim < d; dim++)
-        {
-          features[dim].store(os,format);
-        }
+	os << this->createStartTag( "features" ) << std::endl;
+	for (int dim = 0; dim < d; dim++)
+	{
+	  features[dim].store(os,format);
+	}
+        os << this->createEndTag( "features" ) << std::endl;
+        
+	// done
+	os << this->createEndTag( "FeatureMatrixT" ) << std::endl;       
       }
       else
       {

+ 180 - 60
GPHIKClassifier.cpp

@@ -5,11 +5,15 @@
 * @date 02/01/2012
 
 */
+
+// STL includes
 #include <iostream>
 
-#include "core/basics/numerictools.h"
+// NICE-core includes
+#include <core/basics/numerictools.h>
 #include <core/basics/Timer.h>
 
+// gp-hik-core includes
 #include "GPHIKClassifier.h"
 #include "gp-hik-core/parameterizedFunctions/PFAbsExp.h"
 #include "gp-hik-core/parameterizedFunctions/PFExp.h"
@@ -19,7 +23,7 @@ using namespace std;
 using namespace NICE;
 
 
-GPHIKClassifier::GPHIKClassifier( const Config *conf, const string & confSection ) 
+GPHIKClassifier::GPHIKClassifier( const Config *conf, const string & s_confSection ) 
 {
   //default settings, may be overwritten lateron
   gphyper = NULL;
@@ -28,11 +32,11 @@ GPHIKClassifier::GPHIKClassifier( const Config *conf, const string & confSection
   //just a default value
   uncertaintyPredictionForClassification = false;
   
-  if ( conf == NULL )
-  {
-     fthrow(Exception, "GPHIKClassifier: the config is NULL -- use a default config or the restore-function instaed!");
-  }
-  else
+  this->confSection = s_confSection;
+  
+  // if no config file was given, we either restore the classifier from an external file, or run ::init with 
+  // an emtpy config (using default values thereby) when calling the train-method
+  if ( conf != NULL )
     this->init(conf, confSection);
 }
 
@@ -48,9 +52,8 @@ GPHIKClassifier::~GPHIKClassifier()
     delete confCopy;
 }
 
-void GPHIKClassifier::init(const Config *conf, const string & confSection)
+void GPHIKClassifier::init(const Config *conf, const string & s_confSection)
 {
-  std::cerr << " init  method " << std::endl;
   double parameterUpperBound = conf->gD(confSection, "parameter_upper_bound", 5.0 );
   double parameterLowerBound = conf->gD(confSection, "parameter_lower_bound", 1.0 );  
 
@@ -60,7 +63,6 @@ void GPHIKClassifier::init(const Config *conf, const string & confSection)
   
   if (pf == NULL)
   {
-    std::cerr << " pf is currently NULL  " << std::endl;
     if ( transform == "absexp" )
     {
       this->pf = new PFAbsExp( 1.0, parameterLowerBound, parameterUpperBound );
@@ -74,9 +76,9 @@ void GPHIKClassifier::init(const Config *conf, const string & confSection)
       fthrow(Exception, "Transformation type is unknown " << transform);
     }
   }
-  else{
+  else
+  {
     //we already know the pf from the restore-function
-    std::cerr << " pf is already loaded" << std::endl;
   }
   this->confSection = confSection;
   this->verbose = conf->gB(confSection, "verbose", false);
@@ -84,8 +86,7 @@ void GPHIKClassifier::init(const Config *conf, const string & confSection)
   this->uncertaintyPredictionForClassification = conf->gB( confSection, "uncertaintyPredictionForClassification", false );
   
   if (confCopy != conf)
-  {  
-    std::cerr << " copy config" << std::endl;
+  {
     this->confCopy = new Config ( *conf );
     //we do not want to read until end of file for restoring    
     confCopy->setIoUntilEndOfFile(false);    
@@ -109,7 +110,9 @@ void GPHIKClassifier::init(const Config *conf, const string & confSection)
   {
     this->varianceApproximation = NONE;
   } 
-  std::cerr << "varianceApproximationStrategy: " << s_varianceApproximation  << std::endl;
+  
+  if ( this->verbose )
+    std::cerr << "varianceApproximationStrategy: " << s_varianceApproximation  << std::endl;
 }
 
 void GPHIKClassifier::classify ( const SparseVector * example,  int & result, SparseVector & scores )
@@ -199,6 +202,13 @@ void GPHIKClassifier::train ( const std::vector< NICE::SparseVector *> & example
   {
     std::cerr << "GPHIKClassifier::train" << std::endl;
   }
+  
+  if ( this->confCopy == NULL )
+  {
+    std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
+    NICE::Config tmpConfEmpty ;
+    this->init ( &tmpConfEmpty, this->confSection );
+  }
 
   Timer t;
   t.start();
@@ -259,6 +269,13 @@ void GPHIKClassifier::train ( const std::vector< SparseVector *> & examples, std
 { 
   if (verbose)
     std::cerr << "GPHIKClassifier::train" << std::endl;
+  
+  if ( this->confCopy == NULL )
+  {
+    std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
+    NICE::Config tmpConfEmpty ;
+    this->init ( &tmpConfEmpty, this->confSection );
+  }  
 
   Timer t;
   t.start();
@@ -314,8 +331,22 @@ void GPHIKClassifier::train ( const std::vector< SparseVector *> & examples, std
 void GPHIKClassifier::clear ()
 {
   if ( gphyper != NULL )
+  {
     delete gphyper;
-  gphyper = NULL;
+    gphyper = NULL;
+  }
+  
+  if (pf != NULL)
+  {
+    delete pf;
+    pf = NULL;
+  }
+
+  if ( confCopy != NULL )
+  {
+    delete confCopy; 
+    confCopy = NULL;
+  } 
 }
 
 GPHIKClassifier *GPHIKClassifier::clone () const
@@ -396,63 +427,138 @@ void GPHIKClassifier::predictUncertainty( const NICE::Vector * example, double &
 //---------------------------------------------------------------------
 void GPHIKClassifier::restore ( std::istream & is, int format )
 {
-  if (is.good())
+  //delete everything we knew so far...
+  this->clear();
+  
+  bool b_restoreVerbose ( false );
+  if ( is.good() )
   {
-    std::cerr << "restore GPHIKClassifier" << std::endl;
-    is.precision (numeric_limits<double>::digits10 + 1);
+    if ( b_restoreVerbose ) 
+      std::cerr << " restore GPHIKClassifier" << std::endl;
+    
+    std::string tmp;
+    is >> tmp; //class name 
     
-    string tmp;
-    is >> tmp;    
-    is >> confSection;
+    if ( ! this->isStartTag( tmp, "GPHIKClassifier" ) )
+    {
+        std::cerr << " WARNING - attempt to restore GPHIKClassifier, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+	throw;
+    }   
     
     if (pf != NULL)
     {
       delete pf;
+      pf = NULL;
     }
-    string transform;
-    is >> transform;
-    if ( transform == "absexp" )
+    if ( confCopy != NULL )
     {
-      this->pf = new PFAbsExp ();
-    } else if ( transform == "exp" ) {
-      this->pf = new PFExp ();
-    } else {
-      fthrow(Exception, "Transformation type is unknown " << transform);
+      delete confCopy;
+      confCopy = NULL;
+    }
+    if (gphyper != NULL)
+    {
+      delete gphyper;
+      gphyper = NULL;
     }    
-    pf->restore(is, format);
     
-    std::cerr << "pf restored" << std::endl;
-            
-    //load every options we determined explicitely
-    confCopy->clear();
-    //we do not want to read until the end of the file
-    confCopy->setIoUntilEndOfFile( false );
-    confCopy->restore(is, format);
+    is.precision (numeric_limits<double>::digits10 + 1);
+    
+    bool b_endOfBlock ( false ) ;
     
-    std::cerr << "conf restored" << std::endl;
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "GPHIKClassifier" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( b_restoreVerbose )
+	std::cerr << " currently restore section " << tmp << " in GPHIKClassifier" << std::endl;
+      
+      if ( tmp.compare("confSection") == 0 )
+      {
+        is >> confSection;        
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );	
+      }
+      else if ( tmp.compare("pf") == 0 )
+      {
+	
+	is >> tmp; // start of block 
+	if ( this->isEndTag( tmp, "pf" ) )
+	{
+	  std::cerr << " ParameterizedFunction object can not be restored. Aborting..." << std::endl;
+	  throw;
+	} 
+	
+	std::string transform = this->removeStartTag ( tmp );
+	
+
+	if ( transform == "PFAbsExp" )
+	{
+	  this->pf = new PFAbsExp ();
+	} else if ( transform == "PFExp" ) {
+	  this->pf = new PFExp ();
+	} else {
+	  fthrow(Exception, "Transformation type is unknown " << transform);
+	}
+	
+	pf->restore(is, format);
+	
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );	
+      } 
+      else if ( tmp.compare("ConfigCopy") == 0 )
+      {
+	// possibly obsolete safety checks
+	if ( confCopy == NULL )
+	  confCopy = new Config;
+	confCopy->clear();
+	
+	
+	//we do not want to read until the end of the file
+	confCopy->setIoUntilEndOfFile( false );
+	//load every options we determined explicitely
+	confCopy->restore(is, format);
+	
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );	
+      }
+      else if ( tmp.compare("gphyper") == 0 )
+      {
+	if ( gphyper == NULL )
+	  gphyper = new NICE::FMKGPHyperparameterOptimization();
+	
+	//then, load everything that we stored explicitely,
+	// including precomputed matrices, LUTs, eigenvalues, ... and all that stuff
+	gphyper->restore(is, format);  
+		
+	is >> tmp; // end of block 
+	tmp = this->removeEndTag ( tmp );	
+      }       
+      else
+      {
+	std::cerr << "WARNING -- unexpected GPHIKClassifier object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	throw;	
+      }
+    }
 
+	
     //load every settings as well as default options
-    this->init(confCopy, confSection); 
-    
-    std::cerr << "GPHIK initialized" << std::endl;
-  
-    //first read things from the config
-    if ( gphyper == NULL )
-      gphyper = new NICE::FMKGPHyperparameterOptimization();
-    
+    std::cerr << "run this->init" << std::endl;
+    this->init(confCopy, confSection);    
+    std::cerr << "run gphyper->initialize" << std::endl;
     gphyper->initialize ( confCopy, pf, NULL, confSection );
-    
-    std::cerr << "gphyper initialized" << std::endl;
-    
-    //then, load everything that we stored explicitely,
-    // including precomputed matrices, LUTs, eigenvalues, ... and all that stuff
-    gphyper->restore(is, format);    
-    
-    std::cerr << "gphyper restored" << std::endl;
   }
   else
   {
     std::cerr << "GPHIKClassifier::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
   }
 }
 
@@ -463,21 +569,35 @@ void GPHIKClassifier::store ( std::ostream & os, int format ) const
   
   if (os.good())
   {
+    // show starting point
+    os << this->createStartTag( "GPHIKClassifier" ) << std::endl;    
+    
     os.precision (numeric_limits<double>::digits10 + 1);
     
-    os << "confSection: "<<  confSection << std::endl;
+    os << this->createStartTag( "confSection" ) << std::endl;
+    os << confSection << std::endl;
+    os << this->createEndTag( "confSection" ) << std::endl; 
     
-    os << pf->sayYourName() << std::endl;
+    os << this->createStartTag( "pf" ) << std::endl;
     pf->store(os, format);
-    
+    os << this->createEndTag( "pf" ) << std::endl; 
+
+    os << this->createStartTag( "ConfigCopy" ) << std::endl;
     //we do not want to read until end of file for restoring    
     confCopy->setIoUntilEndOfFile(false);
-    confCopy->store(os,format);  
+    confCopy->store(os,format);
+    os << this->createEndTag( "ConfigCopy" ) << std::endl; 
     
+    os << this->createStartTag( "gphyper" ) << std::endl;
     //store the underlying data
     //will be done in gphyper->store(of,format)
     //store the optimized parameter values and all that stuff
-    gphyper->store(os, format); 
+    gphyper->store(os, format);
+    os << this->createEndTag( "gphyper" ) << std::endl;   
+    
+    
+    // done
+    os << this->createEndTag( "GPHIKClassifier" ) << std::endl;    
   }
   else
   {

+ 8 - 3
GPHIKClassifier.h

@@ -8,12 +8,17 @@
 #ifndef _NICE_GPHIKCLASSIFIERINCLUDE
 #define _NICE_GPHIKCLASSIFIERINCLUDE
 
+// STL includes
 #include <string>
 #include <limits>
 
+// NICE-core includes
 #include <core/basics/Config.h>
+#include <core/basics/Persistent.h>
+// 
 #include <core/vector/SparseVectorT.h>
 
+// gp-hik-core includes
 #include "FMKGPHyperparameterOptimization.h"
 #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
 
@@ -25,7 +30,7 @@ namespace NICE {
  * @author Erik Rodner, Alexander Freytag
  */
  
-class GPHIKClassifier
+class GPHIKClassifier : NICE::Persistent
 {
 
   protected:
@@ -57,13 +62,13 @@ class GPHIKClassifier
     * @brief classify a given example with the previously learnt model
     * @param pe example to be classified given in a sparse representation
     */    
-    void init(const NICE::Config *conf, const std::string & confSection);
+    void init(const NICE::Config *conf, const std::string & s_confSection);
        
 
   public:
 
     /** simple constructor */
-    GPHIKClassifier( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
+    GPHIKClassifier( const NICE::Config *conf = NULL, const std::string & s_confSection = "GPHIKClassifier" );
       
     /** simple destructor */
     ~GPHIKClassifier();

+ 13 - 3
IKMNoise.cpp

@@ -3,11 +3,13 @@
 * @author Erik Rodner, Alexander Freytag
 * @brief Noise matrix (for model regularization) as an implicit kernel matrix (Implementation)
 * @date 02/14/2012
-
 */
+
+// STL includes
 #include <iostream>
 #include <limits>
 
+// NICE-core includes
 #include "IKMNoise.h"
 
 using namespace NICE;
@@ -238,11 +240,19 @@ void IKMNoise::restore ( std::istream & is, int format )
       {
           is >> labels;
       }
-      else{ }
+      else
+      {
+	std::cerr << "WARNING -- unexpected IKMNoise object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	throw;	
+      }
       
       is >> tmp; // end of block 
-      tmp = this->removeEndTag ( tmp );
+      tmp = this->removeEndTag ( tmp );      
     }
+   }
+  else
+  {
+    std::cerr << "IKMNoise::restore -- InStream not initialized - restoring not possible!" << std::endl;
   }
 }
 

+ 138 - 53
SortedVectorSparse.h

@@ -7,6 +7,7 @@
 #ifndef SORTEDVECTORSPARSEINCLUDE
 #define SORTEDVECTORSPARSEINCLUDE
 
+// STL includes
 #include <vector>
 #include <cmath>
 #include <map>
@@ -14,10 +15,13 @@
 #include <iostream>
 #include <limits>
 
+// NICE-core includes
 #include <core/basics/Exception.h>
+#include <core/basics/Persistent.h>
+// 
 #include <core/vector/VectorT.h>
 #include <core/vector/SparseVectorT.h>
-#include "core/basics/Persistent.h"
+
 
 namespace NICE {
 
@@ -587,70 +591,151 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     /** Persistent interface */
     virtual void restore ( std::istream & is, int format = 0 )
     {
-      if (is.good())
+      bool b_restoreVerbose ( false );
+      if ( is.good() )
       {
-        is.precision (std::numeric_limits<double>::digits10 + 1);
-        
-        std::string tmp;
-        is >> tmp; //class name
-        
-        is >> tmp;
-        is >> tolerance;
-               
-        is >> tmp;
-        is >> n;
-               
-        is >> tmp;
-        int size;
-        is >> size;
-        
-        is >> tmp;
-        
-        T origValue;
-        int origIndex;
-        T transformedValue;
-        
-        nzData.clear();
-        for (int i = 0; i < size; i++)
-        {
-         
-          is >> origValue;
-          is >> origIndex;
-          is >> transformedValue;
-        
-          std::pair<T, dataelement > p ( origValue, dataelement ( origIndex, transformedValue ) );
-          elementpointer it = nzData.insert ( p);
-          nonzero_indices.insert ( std::pair<int, elementpointer> ( origIndex, it ) );
-        }
-        
-        if (verbose)
-        {
-          std::cerr << "SortedVectorSparse::restore" << std::endl;      
-          std::cerr << "tolerance: " << tolerance << std::endl;          
-          std::cerr << "n: " << n << std::endl;          
-          std::cerr << "size: " << size << std::endl;          
-        }
+	if ( b_restoreVerbose ) 
+	  std::cerr << " restore SortedVectorSparse" << std::endl;
+	
+	std::string tmp;
+	is >> tmp; //class name 
+	
+	if ( ! this->isStartTag( tmp, "SortedVectorSparse" ) )
+	{
+	    std::cerr << " WARNING - attempt to restore SortedVectorSparse, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+	    throw;
+	}   
+	    
+	is.precision ( std::numeric_limits<double>::digits10 + 1);
+	
+	bool b_endOfBlock ( false ) ;
+	
+	while ( !b_endOfBlock )
+	{
+	  is >> tmp; // start of block 
+	  
+	  if ( this->isEndTag( tmp, "SortedVectorSparse" ) )
+	  {
+	    b_endOfBlock = true;
+	    continue;
+	  }      
+	  
+	  tmp = this->removeStartTag ( tmp );
+	  
+	  if ( b_restoreVerbose )
+	    std::cerr << " currently restore section " << tmp << " in SortedVectorSparse" << std::endl;
+	  
+	  if ( tmp.compare("tolerance") == 0 )
+	  {
+	    is >> tolerance;        
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	  }
+	  else if ( tmp.compare("n") == 0 )
+	  {
+	    is >> n;        
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	  }
+	  else if ( tmp.compare("underlying_data_(sorted)") == 0 )
+	  {
+	    is >> tmp; // start of block 
+	    
+	    int nonZeros;
+	    if ( ! this->isStartTag( tmp, "nonZeros" ) )
+	    {
+	      std::cerr << "Attempt to restore SortedVectorSparse, but found no information about nonZeros elements. Aborting..." << std::endl;
+	      throw;
+	    }
+	    else
+	    {
+	      is >> nonZeros;
+	      is >> tmp; // end of block 
+	      tmp = this->removeEndTag ( tmp );     
+	    }
+	    
+	    is >> tmp; // start of block 
+	    
+	    if ( ! this->isStartTag( tmp, "data" ) )
+	    {
+	      std::cerr << "Attempt to restore SortedVectorSparse, but found no data. Aborting..." << std::endl;
+	      throw;
+	    }
+	    else
+	    {	    
+	      T origValue;
+	      int origIndex;
+	      T transformedValue;
+	      
+	      nzData.clear();
+	      for (int i = 0; i < nonZeros; i++)
+	      {
+	      
+		is >> origValue;
+		is >> origIndex;
+		is >> transformedValue;
+	      
+		std::pair<T, dataelement > p ( origValue, dataelement ( origIndex, transformedValue ) );
+		elementpointer it = nzData.insert ( p);
+		nonzero_indices.insert ( std::pair<int, elementpointer> ( origIndex, it ) );
+	      }
+	      
+	      is >> tmp; // end of block 
+	      tmp = this->removeEndTag ( tmp );  
+	    }
+	    
+	    
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );	    
+	  }
+	  else
+	  {
+	    std::cerr << "WARNING -- unexpected SortedVectorSparse object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	    throw;	
+	  }
+	}        
+
       }
       else
       {
         std::cerr << "SortedVectorSparse::restore -- InStream not initialized - restoring not possible!" << std::endl;
+	throw;
       }      
     };
     virtual void store ( std::ostream & os, int format = 0 ) const
     {
       if (os.good())
       {
+	// show starting point
+	os << this->createStartTag( "SortedVectorSparse" ) << std::endl;
+	
         os.precision (std::numeric_limits<double>::digits10 + 1);
-        os << "SortedVectorSparse" << std::endl;
-        os << "tolerance: " << tolerance << std::endl;
-        os << "n: " << n << std::endl;
-        os << "nonZeros: " << nzData.size() << std::endl;
-        os << "underlying_data_(sorted)" << std::endl;
-        for (const_elementpointer elP = nzData.begin();  elP != nzData.end(); elP++)
-        {
-          os << elP->first << " " << elP->second.first << " " << elP->second.second << " ";
-        }
-        os << std::endl;
+	
+	os << this->createStartTag( "tolerance" ) << std::endl;
+	os << tolerance << std::endl;
+	os << this->createEndTag( "tolerance" ) << std::endl;
+	
+	os << this->createStartTag( "n" ) << std::endl;
+	os << n << std::endl;
+	os << this->createEndTag( "n" ) << std::endl;
+		
+
+        os << this->createStartTag( "underlying_data_(sorted)" ) << std::endl;
+	  os << this->createStartTag( "nonZeros" ) << std::endl;
+	  os << this->getNonZeros() << std::endl;
+	  os << this->createEndTag( "nonZeros" ) << std::endl;
+	  
+	  os << this->createStartTag( "data" ) << std::endl;  
+	  for (const_elementpointer elP = nzData.begin();  elP != nzData.end(); elP++)
+	  {
+	    os << elP->first << " " << elP->second.first << " " << elP->second.second << " ";
+	  }
+	  os << std::endl;
+	  os << this->createEndTag( "data" ) << std::endl;
+	os << this->createEndTag( "underlying_data_(sorted)" ) << std::endl;
+	
+	// done
+	os << this->createEndTag( "SortedVectorSparse" ) << std::endl;	
       }
       else
       {

+ 75 - 18
parameterizedFunctions/PFAbsExp.h

@@ -1,13 +1,19 @@
 /** 
 * @file PFAbsExp.h
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @brief Parameterized Function: absolute value and exponential operation -- pow(fabs(x), exponent) (Interface + Implementation)
 * @date 01/04/2012
 */
 #ifndef _NICE_PFABSEXPINCLUDE
 #define _NICE_PFABSEXPINCLUDE
 
+// STL includes
 #include <math.h>
+
+// NICE-core includes
+#include <core/vector/VectorT.h>
+
+// NICE-core includes
 #include "ParameterizedFunction.h"
 
 namespace NICE {
@@ -15,7 +21,7 @@ namespace NICE {
  /** 
  * @class PFAbsExp
  * @brief Parameterized Function: absolute value and exponential operation -- pow(fabs(x), exponent)
- * @author Erik Rodner
+ * @author Erik Rodner, Alexander Freytag
  */
  
 class PFAbsExp : public ParameterizedFunction
@@ -40,16 +46,13 @@ class PFAbsExp : public ParameterizedFunction
   ~PFAbsExp(){};
     
   double f ( uint index, double x ) const { 
-/*        std::cerr << "upperBound: " << upperBound << std::endl;
-    std::cerr << "lowerBound: " << lowerBound << std::endl;
-    std::cerr << "m_parameters: " << m_parameters << std::endl;   */ 
     return pow(fabs(x),m_parameters[0]); 
   }
 
   bool isOrderPreserving() const { return true; };
 
-  Vector getParameterUpperBounds() const { return Vector(1, upperBound); };
-  Vector getParameterLowerBounds() const { return Vector(1, lowerBound); };
+  Vector getParameterUpperBounds() const { return NICE::Vector(1, upperBound); };
+  Vector getParameterLowerBounds() const { return NICE::Vector(1, lowerBound); };
   
   void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
   void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
@@ -59,27 +62,81 @@ class PFAbsExp : public ParameterizedFunction
   {
     if (is.good())
     {
-      is.precision (std::numeric_limits<double>::digits10 + 1);
+      is.precision (std::numeric_limits<double>::digits10 + 1); 
+      
+      std::string tmp;    
+
+      bool b_endOfBlock ( false ) ;
+      
+      while ( !b_endOfBlock )
+      {
+	is >> tmp; // start of block 
+	
+	if ( this->isEndTag( tmp, "PFAbsExp" ) )
+	{
+	  b_endOfBlock = true;
+	  continue;
+	}
+		    
+	
+	tmp = this->removeStartTag ( tmp );
+	
+	if ( tmp.compare("upperBound") == 0 )
+	{
+	  is >> upperBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );
+	}
+	else if ( tmp.compare("lowerBound") == 0 )
+	{
+	  is >> lowerBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("ParameterizedFunction") == 0 )
+	{
+	  // restore parent object
+	  ParameterizedFunction::restore(is);
+	}	
+	else
+	{
+	  std::cerr << "WARNING -- unexpected PFAbsExp object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	  throw;	
+	}      
+      }
       
-      std::string tmp;
-      is >> tmp;
-      is >> upperBound;
 
-      is >> tmp;
-      is >> lowerBound;      
     }
-    ParameterizedFunction::restore(is);
-    
+    else
+    {
+      std::cerr << "PFAbsExp::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    }   
   };
+  
   virtual void store ( std::ostream & os, int format = 0 ) const
   {
     if (os.good())
     {
+      // show starting point
+      os << this->createStartTag( "PFAbsExp" ) << std::endl;      
+      
       os.precision (std::numeric_limits<double>::digits10 + 1); 
-      os << "upperBound: " << std::endl <<  upperBound << std::endl;
-      os << "lowerBound: " << std::endl <<  lowerBound << std::endl;
+
+      os << this->createStartTag( "upperBound" ) << std::endl;
+      os << upperBound << std::endl;
+      os << this->createEndTag( "upperBound" ) << std::endl; 
+      
+      os << this->createStartTag( "lowerBound" ) << std::endl;
+      os << lowerBound << std::endl;
+      os << this->createEndTag( "lowerBound" ) << std::endl;
+      
+      // store parent object
+      ParameterizedFunction::store(os);      
+      
+      // done
+      os << this->createEndTag( "PFAbsExp" ) << std::endl; 
     }
-    ParameterizedFunction::store(os);
+
   };
   
   virtual void clear () {};

+ 72 - 14
parameterizedFunctions/PFExp.h

@@ -1,12 +1,18 @@
 /** 
 * @file PFExp.h
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @brief Parameterized Function: exponential operation -- exp(fabs(x), exponent) (Interface + Implementation)
 */
 #ifndef _NICE_PFEXPINCLUDE
 #define _NICE_PFEXPINCLUDE
 
+// STL includes
 #include <math.h>
+
+// NICE-core includes
+#include <core/vector/VectorT.h>
+
+// NICE-core includes
 #include "ParameterizedFunction.h"
 
 namespace NICE {
@@ -14,7 +20,7 @@ namespace NICE {
  /** 
  * @class PFExp
  * @brief Parameterized Function: Parameterized Function: exponential operation -- exp(fabs(x), exponent)
- * @author Erik Rodner
+ * @author Erik Rodner, Alexander Freytag
  */
  
 class PFExp : public ParameterizedFunction
@@ -42,8 +48,8 @@ class PFExp : public ParameterizedFunction
 
   bool isOrderPreserving() const { return true; };
 
-  Vector getParameterUpperBounds() const { return Vector(1, upperBound); };
-  Vector getParameterLowerBounds() const { return Vector(1, lowerBound); };
+  Vector getParameterUpperBounds() const { return NICE::Vector(1, upperBound); };
+  Vector getParameterLowerBounds() const { return NICE::Vector(1, lowerBound); };
   
   void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
   void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
@@ -53,26 +59,78 @@ class PFExp : public ParameterizedFunction
   {
     if (is.good())
     {
-      is.precision (std::numeric_limits<double>::digits10 + 1);
+      is.precision (std::numeric_limits<double>::digits10 + 1); 
       
-      std::string tmp;
-      is >> tmp;
-      is >> upperBound;
+      std::string tmp;    
 
-      is >> tmp;
-      is >> lowerBound;      
+      bool b_endOfBlock ( false ) ;
+      
+      while ( !b_endOfBlock )
+      {
+	is >> tmp; // start of block 
+	
+	if ( this->isEndTag( tmp, "PFExp" ) )
+	{
+	  b_endOfBlock = true;
+	  continue;
+	}
+		    
+	
+	tmp = this->removeStartTag ( tmp );
+	
+	if ( tmp.compare("upperBound") == 0 )
+	{
+	  is >> upperBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("lowerBound") == 0 )
+	{
+	  is >> lowerBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );    	    
+	}
+	else if ( tmp.compare("ParameterizedFunction") == 0 )
+	{
+	  // restore parent object
+	  ParameterizedFunction::restore(is);
+	}
+	else
+	{
+	  std::cerr << "WARNING -- unexpected PFExp object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	  throw;	
+	}  
+      }
+    }
+    else
+    {
+      std::cerr << "PFExp::restore -- InStream not initialized - restoring not possible!" << std::endl;
     }
-    ParameterizedFunction::restore(is);
   };
   virtual void store ( std::ostream & os, int format = 0 ) const
   {
     if (os.good())
     {
+      // show starting point
+      os << this->createStartTag( "PFExp" ) << std::endl;      
+      
       os.precision (std::numeric_limits<double>::digits10 + 1); 
-      os << "upperBound: " << std::endl <<  upperBound << std::endl;
-      os << "lowerBound: " << std::endl <<  lowerBound << std::endl;
+
+      os << this->createStartTag( "upperBound" ) << std::endl;
+      os << upperBound << std::endl;
+      os << this->createEndTag( "upperBound" ) << std::endl; 
+      
+      os << this->createStartTag( "lowerBound" ) << std::endl;
+      os << lowerBound << std::endl;
+      os << this->createEndTag( "lowerBound" ) << std::endl;
+      
+      // store parent object
+      ParameterizedFunction::store(os); 
+      
+      // done
+      os << this->createEndTag( "PFExp" ) << std::endl;         
     }
-    ParameterizedFunction::store(os);
+
   };
   virtual void clear () {};
   

+ 131 - 12
parameterizedFunctions/PFMKL.h

@@ -7,7 +7,13 @@
 #ifndef _NICE_PFMULTIPLEKERNELLEARNINGINCLUDE
 #define _NICE_PFMULTIPLEKERNELLEARNINGINCLUDE
 
+// STL includes
 #include <math.h>
+
+// NICE-core includes
+#include <core/vector/VectorT.h>
+
+// NICE-core includes
 #include "ParameterizedFunction.h"
 
 namespace NICE {
@@ -58,8 +64,8 @@ class PFMKL : public ParameterizedFunction
 
   bool isOrderPreserving() const { return true; };
 
-  Vector getParameterUpperBounds() const { return Vector(m_parameters.size(), upperBound); };
-  Vector getParameterLowerBounds() const { return Vector(m_parameters.size(), lowerBound); };
+  Vector getParameterUpperBounds() const { return NICE::Vector(m_parameters.size(), upperBound); };
+  Vector getParameterLowerBounds() const { return NICE::Vector(m_parameters.size(), lowerBound); };
   
   void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
   void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
@@ -69,26 +75,139 @@ class PFMKL : public ParameterizedFunction
   {
     if (is.good())
     {
-      is.precision (std::numeric_limits<double>::digits10 + 1);
+      is.precision (std::numeric_limits<double>::digits10 + 1); 
       
-      std::string tmp;
-      is >> tmp;
-      is >> upperBound;
+      std::string tmp;    
 
-      is >> tmp;
-      is >> lowerBound;   
+      bool b_endOfBlock ( false ) ;
+      
+      while ( !b_endOfBlock )
+      {
+	is >> tmp; // start of block 
+	
+	if ( this->isEndTag( tmp, "PFMKL" ) )
+	{
+	  b_endOfBlock = true;
+	  continue;
+	}
+		    
+	
+	tmp = this->removeStartTag ( tmp );
+	
+	if ( tmp.compare("upperBound") == 0 )
+	{
+	  is >> upperBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("lowerBound") == 0 )
+	{
+	  is >> lowerBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("steps") == 0 )
+	{
+	    is >> tmp; // start of block 
+	    
+	    int numberOfSteps;
+	    if ( ! this->isStartTag( tmp, "numberOfSteps" ) )
+	    {
+	      std::cerr << "Attempt to restore PFMKL, but found no information about numberOfSteps elements. Aborting..." << std::endl;
+	      throw;
+	    }
+	    else
+	    {
+	      is >> numberOfSteps;
+	      is >> tmp; // end of block 
+	      tmp = this->removeEndTag ( tmp );     
+	    }
+	    
+	    is >> tmp; // start of block 
+	    
+	    if ( ! this->isStartTag( tmp, "stepInfo" ) )
+	    {
+	      std::cerr << "Attempt to restore PFMKL, but found no stepInfo. Aborting..." << std::endl;
+	      throw;
+	    }
+	    else
+	    {
+	      steps.clear();
+	      
+	      for ( int tmpCnt = 0; tmpCnt < numberOfSteps; tmpCnt++)
+	      {
+		int tmpStep;
+		is >> tmpStep;
+		steps.insert ( tmpStep ); 
+	      }
+	      
+	      is >> tmp; // end of block 
+	      tmp = this->removeEndTag ( tmp ); 	      
+	    }
+	    
+	    is >> tmp; // end of block 
+	    tmp = this->removeEndTag ( tmp );
+	    
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("ParameterizedFunction") == 0 )
+	{
+	  // restore parent object
+	  ParameterizedFunction::restore(is);
+	}	
+	else
+	{
+	  std::cerr << "WARNING -- unexpected PFMKL object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	  throw;	
+	}
+	
+      
+      }
+      
+      // restore parent object
+      ParameterizedFunction::restore(is);
+    }
+    else
+    {
+      std::cerr << "PFMKL::restore -- InStream not initialized - restoring not possible!" << std::endl;
     }
-    ParameterizedFunction::restore(is);
   };  
   virtual void store ( std::ostream & os, int format = 0 ) const
   {
     if (os.good())
     {
+      // show starting point
+      os << this->createStartTag( "PFMKL" ) << std::endl;      
+      
       os.precision (std::numeric_limits<double>::digits10 + 1); 
-      os << "upperBound: " << std::endl <<  upperBound << std::endl;
-      os << "lowerBound: " << std::endl <<  lowerBound << std::endl;
+
+      os << this->createStartTag( "upperBound" ) << std::endl;
+      os << upperBound << std::endl;
+      os << this->createEndTag( "upperBound" ) << std::endl; 
+      
+      os << this->createStartTag( "lowerBound" ) << std::endl;
+      os << lowerBound << std::endl;
+      os << this->createEndTag( "lowerBound" ) << std::endl;
+      
+      os << this->createStartTag( "steps" ) << std::endl;
+	os << this->createStartTag( "numberOfSteps" ) << std::endl;
+	os << steps.size() << std::endl;
+	os << this->createEndTag( "numberOfSteps" ) << std::endl;    
+	
+        os << this->createStartTag( "stepInfo" ) << std::endl;;
+        for ( std::set<int>::const_iterator mySetIt = steps.begin(); mySetIt != steps.end(); mySetIt++)
+	  os << *mySetIt << " ";
+        os << std::endl;
+	os << this->createEndTag( "stepInfo" ) << std::endl;
+      os << this->createEndTag( "steps" ) << std::endl;      
+
+      // store parent object
+      ParameterizedFunction::store(os);       
+      
+      // done
+      os << this->createEndTag( "PFMKL" ) << std::endl; 
     }
-    ParameterizedFunction::store(os);
   };  
   virtual void clear () {};
   

+ 72 - 19
parameterizedFunctions/PFWeightedDim.h

@@ -1,13 +1,19 @@
 /** 
 * @file PFWeightedDim.h
 * @brief Parameterized Function: weights for each dimension (Interface + Implementation)
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 
 */
 #ifndef _NICE_PFWEIGHTEDDIMINCLUDE
 #define _NICE_PFWEIGHTEDDIMINCLUDE
 
+// STL includes
 #include <math.h>
+
+// NICE-core includes
+#include <core/vector/VectorT.h>
+
+// NICE-core includes
 #include "ParameterizedFunction.h"
 
 namespace NICE {
@@ -15,7 +21,7 @@ namespace NICE {
  /** 
  * @class PFWeightedDim
  * @brief Parameterized Function: weights for each dimension
- * @author Erik Rodner
+ * @author Erik Rodner, Alexander Freytag
  */
  
 class PFWeightedDim : public ParameterizedFunction
@@ -24,7 +30,6 @@ class PFWeightedDim : public ParameterizedFunction
 
     double upperBound;
     double lowerBound;
-    uint dimension;
 
   public:
 
@@ -33,7 +38,6 @@ class PFWeightedDim : public ParameterizedFunction
             double uB = std::numeric_limits<double>::max() ) : 
             ParameterizedFunction(dimension) 
   { 
-    this->dimension = dimension;
     upperBound = uB;
     lowerBound = lB;
     if ( uB < 1.0 )
@@ -48,8 +52,8 @@ class PFWeightedDim : public ParameterizedFunction
 
   bool isOrderPreserving() const { return true; };
 
-  Vector getParameterUpperBounds() const { return Vector(m_parameters.size(), upperBound); };
-  Vector getParameterLowerBounds() const { return Vector(m_parameters.size(), lowerBound); };
+  Vector getParameterUpperBounds() const { return NICE::Vector(m_parameters.size(), upperBound); };
+  Vector getParameterLowerBounds() const { return NICE::Vector(m_parameters.size(), lowerBound); };
   
   void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
   void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
@@ -59,30 +63,79 @@ class PFWeightedDim : public ParameterizedFunction
   {
     if (is.good())
     {
-      is.precision (std::numeric_limits<double>::digits10 + 1);
+      is.precision (std::numeric_limits<double>::digits10 + 1); 
       
-      std::string tmp;
-      is >> tmp;
-      is >> upperBound;
+      std::string tmp;    
 
-      is >> tmp;
-      is >> lowerBound;   
+      bool b_endOfBlock ( false ) ;
       
-      is >> tmp;
-      is >> dimension;
+      while ( !b_endOfBlock )
+      {
+	is >> tmp; // start of block 
+	
+	if ( this->isEndTag( tmp, "PFWeightedDim" ) )
+	{
+	  b_endOfBlock = true;
+	  continue;
+	}
+		    
+	
+	tmp = this->removeStartTag ( tmp );
+	
+	if ( tmp.compare("upperBound") == 0 )
+	{
+	  is >> upperBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp );	    
+	}
+	else if ( tmp.compare("lowerBound") == 0 )
+	{
+	  is >> lowerBound;
+	  is >> tmp; // end of block 
+	  tmp = this->removeEndTag ( tmp ); 	    
+	}
+	else if ( tmp.compare("ParameterizedFunction") == 0 )
+	{
+	  // restore parent object
+	  ParameterizedFunction::restore(is);
+	}	
+	else
+	{
+	  std::cerr << "WARNING -- unexpected PFWeightedDim object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	  throw;	
+	}
+      }
+    }
+    else
+    {
+      std::cerr << "PFWeightedDim::restore -- InStream not initialized - restoring not possible!" << std::endl;
     }
-    ParameterizedFunction::restore(is);
   };  
   virtual void store ( std::ostream & os, int format = 0 ) const
   {
     if (os.good())
     {
+      // show starting point
+      os << this->createStartTag( "PFWeightedDim" ) << std::endl;      
+      
       os.precision (std::numeric_limits<double>::digits10 + 1); 
-      os << "upperBound: " << std::endl <<  upperBound << std::endl;
-      os << "lowerBound: " << std::endl <<  lowerBound << std::endl;
-      os << "dimension: " << std::endl << dimension << std::endl;
+
+      os << this->createStartTag( "upperBound" ) << std::endl;
+      os << upperBound << std::endl;
+      os << this->createEndTag( "upperBound" ) << std::endl; 
+      
+      os << this->createStartTag( "lowerBound" ) << std::endl;
+      os << lowerBound << std::endl;
+      os << this->createEndTag( "lowerBound" ) << std::endl;   
+      
+
+      // store parent object
+      ParameterizedFunction::store(os); 
+      
+      // done
+      os << this->createEndTag( "PFWeightedDim" ) << std::endl;
     }
-    ParameterizedFunction::store(os);
+
   };  
   virtual void clear () {};
   

+ 51 - 8
parameterizedFunctions/ParameterizedFunction.cpp

@@ -1,12 +1,14 @@
 /** 
 * @file ParameterizedFunction.cpp
 * @brief Simple parameterized multi-dimensional function (Implementation)
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 01/04/2012
-
 */
+
+// STL includes
 #include <iostream>
 
+// NICE-core includes
 #include "ParameterizedFunction.h"
 
 using namespace NICE;
@@ -36,11 +38,42 @@ void ParameterizedFunction::restore ( std::istream & is, int format )
 {
   if (is.good())
   {
-    is.precision (numeric_limits<double>::digits10 + 1);
+    is.precision (std::numeric_limits<double>::digits10 + 1); 
+    
+    std::string tmp;    
+
+    bool b_endOfBlock ( false ) ;
     
-    string tmp;
-    is >> tmp;
-    is >> m_parameters;
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "ParameterizedFunction" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }
+                  
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( tmp.compare("m_parameters") == 0 )
+      {
+          is >> m_parameters;
+      }
+      else
+      {
+	std::cerr << "WARNING -- unexpected ParameterizedFunction object -- " << tmp << " -- for restoration... aborting" << std::endl;
+	throw;	
+      }
+      
+      is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );      
+    }
+   }
+  else
+  {
+    std::cerr << "ParameterizedFunction::restore -- InStream not initialized - restoring not possible!" << std::endl;
   }
 }
 
@@ -48,7 +81,17 @@ void ParameterizedFunction::store ( std::ostream & os, int format ) const
 {
   if (os.good())
   {
-    os.precision (numeric_limits<double>::digits10 + 1); 
-    os << "m_parameters: " << std::endl << m_parameters << std::endl;
+    // show starting point
+    os << this->createStartTag( "ParameterizedFunction" ) << std::endl;
+    
+    os.precision (std::numeric_limits<double>::digits10 + 1);
+    
+    os << this->createStartTag( "m_parameters" ) << std::endl;
+    os << m_parameters;
+    os << this->createEndTag( "m_parameters" ) << std::endl;   
+    
+    
+    // done
+    os << this->createEndTag( "ParameterizedFunction" ) << std::endl;   
   }
 };

+ 8 - 5
parameterizedFunctions/ParameterizedFunction.h

@@ -1,16 +1,19 @@
 /** 
 * @file ParameterizedFunction.h
 * @brief Simple parameterized multi-dimensional function (Interface)
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 01/04/2012
 */
 #ifndef _NICE_PARAMETERIZEDFUNCTIONINCLUDE
 #define _NICE_PARAMETERIZEDFUNCTIONINCLUDE
 
+// STL includes
 #include <vector>
 #include <limits>
 
-#include "core/basics/Persistent.h"
+// NICE-core includes
+#include <core/basics/Persistent.h>
+// 
 #include <core/vector/VectorT.h>
 #include <core/vector/SparseVectorT.h>
 
@@ -25,15 +28,15 @@ namespace NICE {
  * (1) f(0) = 0
  * (2) f is monotonically increasing
  *
- * @author Erik Rodner
+ * @author Erik Rodner, Alexander Freytag
  */
-class ParameterizedFunction : NICE::Persistent
+class ParameterizedFunction : public NICE::Persistent
 {
 
   protected:
 
     /** parameters of the function */
-    Vector m_parameters;
+    NICE::Vector m_parameters;
 
 
   public: