Browse Source

towards xml-like store and restore fct, not finished yet

Alexander Freytag 11 years ago
parent
commit
8034802468
7 changed files with 524 additions and 229 deletions
  1. 390 191
      FMKGPHyperparameterOptimization.cpp
  2. 1 1
      GPHIKClassifier.cpp
  3. 46 0
      IKMLinearCombination.cpp
  4. 2 2
      IKMLinearCombination.h
  5. 76 26
      IKMNoise.cpp
  6. 8 8
      IKMNoise.h
  7. 1 1
      ImplicitKernelMatrix.h

+ 390 - 191
FMKGPHyperparameterOptimization.cpp

@@ -1172,6 +1172,22 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
     //load the underlying data
     if (fmk != NULL)
       delete fmk;
+    
+    if ( ikmsum == NULL )
+    {
+        ikmsum = new IKMLinearCombination (); 
+        if ( b_restoreVerbose ) 
+          std::cerr << "ikmsum object created" << std::endl;
+    }
+    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;
@@ -1182,183 +1198,352 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
       std::cerr << "fmk->restore done " << std::endl;
     
     is.precision ( numeric_limits<double>::digits10 + 1 );
-
-    string tmp;
-    is >> tmp; //class name
     
-    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;
+//     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;
+//     
+    
+//     //the first one is always our noise-model
     
-    int precomputedTSize ( 0 );
-    is >> precomputedTSize;
-
-    precomputedT.clear();
     
-    if ( b_restoreVerbose ) 
-      std::cerr << "restore precomputedT with size: " << precomputedTSize << std::endl;
-
-    if ( precomputedTSize > 0 )
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
     {
-      if ( b_restoreVerbose ) 
-        std::cerr << " restore precomputedT" << std::endl;
-      is >> tmp;
-      int sizeOfLUT;
-      is >> sizeOfLUT;    
+      is >> tmp; // start of block 
       
-      for (int i = 0; i < precomputedTSize; i++)
+      if ( this->isEndTag( tmp, "FMKGPHyperparameterOptimization" ) )
       {
-        is >> tmp;
-        int index;
-        is >> index;        
-        double * array = new double [ sizeOfLUT];
-        for ( int i = 0; i < sizeOfLUT; i++ )
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      std::cerr << " currently restore setcion " << tmp << " in FMKGPHyperparameterOptimization" << std::endl;
+      
+      if ( tmp.compare("precomputedA") == 0 )
+      {
+        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++ )
         {
-          is >> array[i];
+          int nr;
+          is >> nr;
+          PrecomputedType pct;
+          pct.setIoUntilEndOfFile ( false );
+          pct.restore ( is, format );
+          precomputedA.insert ( std::pair<int, PrecomputedType> ( nr, pct ) );
         }
-        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 );
-    }    
+      }        
+      else if ( tmp.compare("precomputedB") == 0 )
+      {
+        is >> tmp; // size
+        int preCompSize ( 0 );
+        is >> preCompSize;
+        precomputedB.clear();
 
-    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++ )
+        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 ) );
+        }    
+      }       
+      else if ( tmp.compare("precomputedT") == 0 )
       {
-        is >> precomputedTForVarEst[i];
+        is >> tmp; // size
+        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;
+        }   
       }      
-    }
-    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;
-    
-    //restore eigenvalues and eigenvectors
-    is >> tmp; //"eigenmax:"
-    if ( b_restoreVerbose ) 
-      std::cerr << "content of tmp: " << tmp << std::endl;
-    is >> eigenMax;
-    if ( b_restoreVerbose ) 
-      std::cerr << "loaded the following eigenMax: " << eigenMax << std::endl;
-    is >> tmp; //"eigenMaxVectors:"
-    if ( b_restoreVerbose ) 
-      std::cerr << "content of tmp: " << tmp << std::endl;
-    is >> eigenMaxVectors;
-    if ( b_restoreVerbose ) 
-      std::cerr << "loaded the following eigenMaxVectors: " << eigenMaxVectors << std::endl;
-    
-    if ( b_restoreVerbose ) 
-      std::cerr << " create ikmsum object" << std::endl;
-    
-    if ( ikmsum == NULL )
-    {
-        ikmsum = new IKMLinearCombination (); 
+      else if ( tmp.compare("precomputedAForVarEst") == 0 )
+      {
+        int sizeOfAForVarEst;
+        is >> sizeOfAForVarEst;
+        
         if ( b_restoreVerbose ) 
-          std::cerr << "ikmsum object created" << std::endl;
-    }
-    else
-    {
-      if ( b_restoreVerbose ) 
-        std::cerr << "ikmsum object already existing" << std::endl;
-    }
+          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 );
+        }     
+      }        
+      else if ( tmp.compare("precomputedTForVarEst") == 0 )
+      {
+        std::string isNull;
+        is >> isNull; // NOTNULL or NULL
+        if ( b_restoreVerbose ) 
+          std::cerr << "content of isNull: " << isNull << std::endl;    
+        if (isNull.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;
+        } 
+      }       
+      else if ( tmp.compare("eigenMax") == 0 )
+      {
+        is >> eigenMax;     
+      }    
+      else if ( tmp.compare("eigenMaxVectors") == 0 )
+      {
+        is >> eigenMaxVectors;     
+      }    
+      else if ( tmp.compare("ikmsum") == 0 )
+      {
+        bool b_endOfBlock ( false ) ;
+        
+        while ( !b_endOfBlock )
+        {
+          is >> tmp; // start of block 
+          
+          if ( this->isEndTag( tmp, "ikmsum" ) )
+          {
+            b_endOfBlock = true;
+            continue;
+          }      
+          
+          tmp = this->removeStartTag ( tmp );        
+          if ( tmp.compare("IKMNoise") == 0 )
+          {
+            IKMNoise * ikmnoise = new IKMNoise ();
+            ikmnoise->restore ( is, format );
+            
+            if ( b_restoreVerbose ) 
+              std::cerr << " add ikmnoise to ikmsum object " << std::endl;
+            ikmsum->addModel ( ikmnoise );        
+          }
+          else
+          {}
+          is >> tmp; // end of block 
+          tmp = this->removeEndTag ( tmp );           
+        }
+        std::cerr  << " ended restoring ikmsum " << std::endl;
+      }
+      else if ( tmp.compare("binaryLabelPositive") == 0 )
+      {
+        is >> binaryLabelPositive;     
+      }
+      else if  ( tmp.compare("binaryLabelNegative") == 0 )
+      {
+        is >> binaryLabelNegative;        
+      }
+      else if  ( tmp.compare("labels") == 0 )
+      {
+        is >> labels;        
+      }       
+      else{ }
       
+      is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );  
+    }
 
-    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;
-    
-    //the first one is always our noise-model
-    IKMNoise * ikmnoise = new IKMNoise ();
-    ikmnoise->restore ( is, format );
 
-    
-    if ( b_restoreVerbose ) 
-      std::cerr << " add ikmnoise to ikmsum object " << std::endl;
-    ikmsum->addModel ( ikmnoise );
 
     //NOTE are there any more models you added? then add them here respectively in the correct order
     //.....  
@@ -1373,26 +1558,7 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & is, int format )
       std::cerr << " restore positive and negative label" << std::endl;
 
       
-    //restore the class numbers for binary settings (if mc-settings, these values will be negative by default)
-    is >> tmp; // "binaryLabelPositive: " 
-    if ( b_restoreVerbose ) 
-      std::cerr << " content of tmp: " << tmp << std::endl; 
-    is >> binaryLabelPositive;
-    if ( b_restoreVerbose ) 
-      std::cerr << " content of binaryLabelPositive: " << binaryLabelPositive << std::endl; 
-    is >> tmp; // " binaryLabelNegative: "
-    if ( b_restoreVerbose ) 
-      std::cerr << " content of tmp: " << tmp << std::endl; 
-    is >> binaryLabelNegative;
-    if ( b_restoreVerbose ) 
-      std::cerr << " content of binaryLabelNegative: " << binaryLabelNegative << std::endl; 
-    
-    is >> tmp; // "labels: "
-    if ( b_restoreVerbose ) 
-      std::cerr << " content of tmp: " << tmp << std::endl;
-    is >> this->labels;    
-    if ( b_restoreVerbose ) 
-      std::cerr << " restored labels: " << labels << std::endl;
+
 
     knownClasses.clear();
     
@@ -1424,25 +1590,31 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
 {
   if ( os.good() )
   {
+    // show starting point
+    os << this->createStartTag( "FMKGPHyperparameterOptimization" ) << std::endl;
+    
     fmk->store ( os, format );
 
     os.precision ( numeric_limits<double>::digits10 + 1 );
 
-    os << "FMKGPHyperparameterOptimization" << std::endl;
 
 
     //we only have to store the things we computed, since the remaining settings come with the config file afterwards
     
-    os << "precomputedA: size: " << precomputedA.size() << std::endl;
+    os << this->createStartTag( "precomputedA" ) << std::endl;
+    os << "size: " << precomputedA.size() << std::endl;
     std::map< int, PrecomputedType >::const_iterator preCompIt = precomputedA.begin();
     for ( uint i = 0; i < precomputedA.size(); i++ )
     {
       os << preCompIt->first << std::endl;
       ( preCompIt->second ).store ( os, format );
       preCompIt++;
-    }
+    }    
+    os << this->createEndTag( "precomputedA" ) << std::endl;  
+    
     
-    os << "precomputedB: size: " << precomputedB.size() << std::endl;
+    os << this->createStartTag( "precomputedB" ) << std::endl;
+    os << "size: " << precomputedB.size() << std::endl;
     preCompIt = precomputedB.begin();
     for ( uint i = 0; i < precomputedB.size(); i++ )
     {
@@ -1450,9 +1622,12 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
       ( preCompIt->second ).store ( os, format );
       preCompIt++;
     }    
+    os << this->createEndTag( "precomputedB" ) << std::endl; 
+      
     
     
-    os << "precomputedT: size: " << precomputedT.size() << std::endl;
+    os << this->createStartTag( "precomputedT" ) << std::endl;
+    os << "size: " << precomputedT.size() << std::endl;
     if ( precomputedT.size() > 0 )
     {
       int sizeOfLUT ( 0 );
@@ -1468,21 +1643,26 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
         }
         os << std::endl;
       }
-    }    
+    } 
+    os << this->createEndTag( "precomputedT" ) << std::endl; 
 
     //now store the things needed for the variance estimation
     
-    os << "precomputedAForVarEst.size(): "<< precomputedAForVarEst.size() << std::endl;
+    os << this->createStartTag( "precomputedAForVarEst" ) << std::endl;
+    os << precomputedAForVarEst.size() << std::endl;
     
     if (precomputedAForVarEst.size() > 0)
     {
       precomputedAForVarEst.store ( os, format );
       os << std::endl; 
     }
+    os << this->createEndTag( "precomputedAForVarEst" ) << std::endl;
     
+    
+    os << this->createStartTag( "precomputedTForVarEst" ) << std::endl;
     if ( precomputedTForVarEst != NULL )
     {
-      os << "precomputedTForVarEst NOTNULL" << std::endl;
+      os << "NOTNULL" << std::endl;
       int sizeOfLUT ( 0 );
       if ( q != NULL )
         sizeOfLUT = q->size() * this->fmk->get_d();
@@ -1496,28 +1676,47 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & os, int format ) co
     }
     else
     {
-      os << "precomputedTForVarEst NULL" << std::endl;
+      os << "NULL" << std::endl;
     }
+    os << this->createEndTag( "precomputedTForVarEst" ) << std::endl;
     
     //store the eigenvalues and eigenvectors
-    os << "eigenMax" << std::endl;
+    os << this->createStartTag( "eigenMax" ) << std::endl;
     os << eigenMax << std::endl;
-    os << "eigenMaxVectors" << std::endl;
+    os << this->createEndTag( "eigenMax" ) << std::endl;   
+
+    os << this->createStartTag( "eigenMaxVectors" ) << std::endl;
     os << eigenMaxVectors << std::endl;
+    os << this->createEndTag( "eigenMaxVectors" ) << std::endl;       
 
     //store the ikmsum object
-    os << "numberOfModels: " << ikmsum->getNumberOfModels() << std::endl;
+//     os << "numberOfModels: " << ikmsum->getNumberOfModels() << std::endl;
 
+    os << this->createStartTag( "ikmsum" ) << std::endl;
     for ( int j = 0; j < ikmsum->getNumberOfModels() - 1; j++ )
     {
       ( ikmsum->getModel ( j ) )->store ( os, format );
     }
+    os << this->createEndTag( "ikmsum" ) << std::endl;
 
     
     //store the class numbers for binary settings (if mc-settings, these values will be negative by default)
-    os << "binaryLabelPositive: " << binaryLabelPositive << " binaryLabelNegative: " << binaryLabelNegative << std::endl;
+    os << this->createStartTag( "binaryLabelPositive" ) << std::endl;
+    os << binaryLabelPositive << std::endl;
+    os << this->createEndTag( "binaryLabelPositive" ) << std::endl; 
+    
+    os << this->createStartTag( "binaryLabelNegative" ) << std::endl;
+    os << binaryLabelNegative << std::endl;
+    os << this->createEndTag( "binaryLabelNegative" ) << std::endl; 
+    
+    
+    os << this->createStartTag( "labels" ) << std::endl;
+    os << labels << std::endl;
+    os << this->createEndTag( "labels" ) << std::endl;     
+
     
-    os << "labels: " << this->labels << std::endl;    
+    // done
+    os << this->createEndTag( "FMKGPHyperparameterOptimization" ) << std::endl;    
   }
   else
   {

+ 1 - 1
GPHIKClassifier.cpp

@@ -51,8 +51,8 @@ GPHIKClassifier::~GPHIKClassifier()
 void GPHIKClassifier::init(const Config *conf, const string & confSection)
 {
   std::cerr << " init  method " << std::endl;
-  double parameterLowerBound = conf->gD(confSection, "parameter_lower_bound", 1.0 );
   double parameterUpperBound = conf->gD(confSection, "parameter_upper_bound", 5.0 );
+  double parameterLowerBound = conf->gD(confSection, "parameter_lower_bound", 1.0 );  
 
   this->noise = conf->gD(confSection, "noise", 0.01);
 

+ 46 - 0
IKMLinearCombination.cpp

@@ -218,3 +218,49 @@ ImplicitKernelMatrix * IKMLinearCombination::getModel(const uint & idx) const
   else
     return NULL;
 }
+
+// ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
+
+void IKMLinearCombination::restore ( std::istream & is, int format )
+{
+  if (is.good())
+  {
+    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, "IKMLinearCombination" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }                  
+      
+      tmp = this->removeStartTag ( tmp );
+            
+      is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );
+    }
+  }
+}      
+
+void IKMLinearCombination::store ( std::ostream & os, int format ) const
+{
+  if ( os.good() )
+  {
+    // show starting point
+    os << this->createStartTag( "IKMLinearCombination" ) << std::endl;
+      
+    // done
+    os << this->createEndTag( "IKMLinearCombination" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }  
+}

+ 2 - 2
IKMLinearCombination.h

@@ -68,8 +68,8 @@ class IKMLinearCombination : public ImplicitKernelMatrix
     inline int getNumberOfModels(){return matrices.size();};
     
     /** Persistent interface */
-    virtual void restore ( std::istream & is, int format = 0 ) {};
-    virtual void store ( std::ostream & os, int format = 0 ) const {};  
+    virtual void restore ( std::istream & is, int format = 0 ) ;
+    virtual void store ( std::ostream & os, int format = 0 ) const;  
     virtual void clear () {};
 
 };

+ 76 - 26
IKMNoise.cpp

@@ -197,36 +197,86 @@ void IKMNoise::restore ( std::istream & is, int format )
   {
     is.precision (std::numeric_limits<double>::digits10 + 1); 
     
-    std::string tmp;
-    is >> tmp; //class name
-    
-    is >> tmp;
-    is >> size;
-    
-    is >> tmp;
-    is >> noise;
-    
-    is >> tmp;
-    is >> optimizeNoise;
-    
-    is >> tmp;
-    is >> np;
-    
-    is >> tmp;
-    is >> nn;
+    std::string tmp;    
+
+    bool b_endOfBlock ( false ) ;
     
-    is >> tmp;
-    is >> labels;
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "IKMNoise" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }
+                  
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( tmp.compare("size") == 0 )
+      {
+          is >> size;
+      }
+      else if ( tmp.compare("noise") == 0 )
+      {
+          is >> noise;
+      }
+      else if ( tmp.compare("optimizeNoise") == 0 )
+      {
+          is >> optimizeNoise;
+      }
+      else if ( tmp.compare("np") == 0 )
+      {
+          is >> np;
+      }
+      else if ( tmp.compare("nn") == 0 )
+      {
+          is >> nn;
+      }
+      else if ( tmp.compare("labels") == 0 )
+      {
+          is >> labels;
+      }
+      else{ }
+      
+      is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );
+    }
   }
 }
 
 void IKMNoise::store ( std::ostream & os, int format ) const
 {
-  os << "IKMNoise" << std::endl;
-  os << "size: " << size << std::endl;
-  os << "noise: " << noise << std::endl;
-  os << "optimizeNoise: " <<  optimizeNoise << std::endl;
-  os << "np: " << np  << std::endl;
-  os << "nn: " << nn << std::endl;
-  os << "labels: " << labels << std::endl;
+  // show starting point
+  os << this->createStartTag( "IKMNoise" ) << std::endl;
+  
+  
+  
+  os << this->createStartTag( "size" ) << std::endl;
+  os << size << std::endl;
+  os << this->createEndTag( "size" ) << std::endl;
+  
+  os << this->createStartTag( "noise" ) << std::endl;
+  os << noise << std::endl;
+  os << this->createEndTag( "noise" ) << std::endl;
+  
+  os << this->createStartTag( "optimizeNoise" ) << std::endl;
+  os << optimizeNoise << std::endl;
+  os << this->createEndTag( "optimizeNoise" ) << std::endl;
+  
+  os << this->createStartTag( "np" ) << std::endl;
+  os << np << std::endl;
+  os << this->createEndTag( "np" ) << std::endl;
+  
+  os << this->createStartTag( "nn" ) << std::endl;
+  os << nn << std::endl;
+  os << this->createEndTag( "nn" ) << std::endl;
+  
+  os << this->createStartTag( "labels" ) << std::endl;
+  os << labels << std::endl;
+  os << this->createEndTag( "labels" ) << std::endl;   
+  
+  // done
+  os << this->createEndTag( "IKMNoise" ) << std::endl;
 }

+ 8 - 8
IKMNoise.h

@@ -23,7 +23,7 @@ class IKMNoise : public ImplicitKernelMatrix
 {
 
   protected:
-    Vector labels;
+    NICE::Vector labels;
 
     uint size;
 
@@ -43,20 +43,20 @@ class IKMNoise : public ImplicitKernelMatrix
     
     IKMNoise( uint size, double noise, bool optimizeNoise );
     
-    IKMNoise( const Vector & labels, double noise, bool optimizeNoise );
+    IKMNoise( const NICE::Vector & labels, double noise, bool optimizeNoise );
       
     virtual ~IKMNoise();
 
-    virtual void getDiagonalElements ( Vector & diagonalElements ) const;
+    virtual void getDiagonalElements ( NICE::Vector & diagonalElements ) const;
     virtual void getFirstDiagonalElement ( double & diagonalElement ) const;
     virtual uint getNumParameters() const;
     
-    virtual void getParameters(Vector & parameters) const;
-    virtual void setParameters(const Vector & parameters);
-    virtual bool outOfBounds(const Vector & parameters) const;
+    virtual void getParameters( NICE::Vector & parameters) const;
+    virtual void setParameters(const NICE::Vector & parameters);
+    virtual bool outOfBounds(const NICE::Vector & parameters) const;
 
-    virtual Vector getParameterLowerBounds() const;
-    virtual Vector getParameterUpperBounds() const;
+    virtual NICE::Vector getParameterLowerBounds() const;
+    virtual NICE::Vector getParameterUpperBounds() const;
 
     /** multiply with a vector: A*x = y */
     virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;

+ 1 - 1
ImplicitKernelMatrix.h

@@ -22,7 +22,7 @@ namespace NICE {
  * @date 02/14/2012
  */
 
-class ImplicitKernelMatrix : public GenericMatrix, NICE::Persistent
+class ImplicitKernelMatrix : public GenericMatrix, public NICE::Persistent
 {
 
   protected: