iRoCS Toolbox  1.1.0
LoadSaveASCII.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2004-2015 Olaf Ronneberger, Florian Pigorsch, Jörg Mechnich,
4  * Thorsten Falk
5  *
6  * Image Analysis Lab, University of Freiburg, Germany
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  **************************************************************************/
23 
24 /**************************************************************************
25 ** Title: load/save policy for SVMApplication for ASCII files
26 ** $RCSfile$
27 ** $Revision: 759 $$Name$
28 ** $Date: 2005-10-26 09:15:47 +0200 (Wed, 26 Oct 2005) $
29 ** Copyright: GPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.5 2005/10/26 07:14:48 ronneber
38 ** - added getParamInfosForLoadSubsetLabels(),
39 ** checkParamsForLoadSubsetLabels() and loadSubsetLabels() for using
40 ** predefined subsets in cross validation
41 ** - classifcation details are now given in key-value pairs, which allows
42 ** more flexibility
43 ** - classification details are now saved to the extra file
44 ** <outpufilename>_details in the format "<uid>_<key> <value>" one per
45 ** line, where uid is the unique id of the feature vector and key,
46 ** value the given key value pair from the given details-vector
47 **
48 ** Revision 1.4 2004/09/09 14:38:41 ronneber
49 ** - cosmetic changes
50 **
51 ** Revision 1.3 2004/09/08 14:31:18 ronneber
52 ** - adapted to new ParamInfo class
53 **
54 ** Revision 1.2 2004/08/27 09:53:55 ronneber
55 ** - fixed bug in saving crossval results
56 **
57 ** Revision 1.1 2004/08/26 08:36:59 ronneber
58 ** initital import
59 **
60 **
61 **
62 **************************************************************************/
63 
64 #ifndef LOADSAVEASCII_HH
65 #define LOADSAVEASCII_HH
66 
67 #ifdef HAVE_CONFIG_H
68 #include <config.hh>
69 #endif
70 
71 #include <iostream>
72 #include <fstream>
73 #include <cerrno>
74 
75 #include "StDataASCIIFile.hh"
76 #include "StDataCmdLine.hh"
77 #include "PrettyOptionPrinter.hh"
78 #include "BasicSVMAdapter.hh"
79 #include "BasicSVMFactory.hh"
80 #include "ParamInfo.hh"
81 
82 namespace svt
83 {
85  {
86  public:
87 
89 
91  {}
92 
93  /*======================================================================*/
102  /*======================================================================*/
103  static void getParamInfosForLoadFeatureVectors( std::vector<ParamInfo>& p);
104 
105  /*======================================================================*/
113  /*======================================================================*/
114  void checkParamsForLoadFeatureVectors(StDataCmdLine& cmdline) const;
115 
116 
117  /*======================================================================*/
126  /*======================================================================*/
127  template< typename FV>
128  void loadFeatureVectors( StDataCmdLine& cmdline,
129  std::vector<FV>& featureVectors);
130 
131 
132  /*======================================================================*/
141  /*======================================================================*/
142  static void getParamInfosForLoadSubsetLabels( std::vector<ParamInfo>& p);
143 
144  /*======================================================================*/
152  /*======================================================================*/
153  bool checkParamsForLoadSubsetLabels(StDataCmdLine& cmdline) const;
154 
155 
156  /*======================================================================*/
166  /*======================================================================*/
167  void loadSubsetLabels( StDataCmdLine& cmdline,
168  std::vector<int>& subsetIndexByUID);
169 
170 
171  /*======================================================================*/
180  /*======================================================================*/
181  static void getParamInfosForSaveModel( std::vector<ParamInfo>& p);
182 
183 
184  /*======================================================================*/
192  /*======================================================================*/
193  void checkParamsForSaveModel(StDataCmdLine& cmdline) const;
194 
195 
196  /*======================================================================*/
209  /*======================================================================*/
210  template< typename FV>
211  void saveModel( StDataCmdLine& cmdline,
213  int detailLevel,
214  std::ostream& os);
215 
216 
217  /*======================================================================*/
226  /*======================================================================*/
228  std::vector<ParamInfo>& p);
229 
230 
231  /*======================================================================*/
245  /*======================================================================*/
246  template< typename FV, typename ALGORITHMS>
248  StDataCmdLine& cmdline);
249 
250 
251 
252  /*======================================================================*/
261  /*======================================================================*/
263  std::vector<ParamInfo>& p);
264 
265  /*======================================================================*/
273  /*======================================================================*/
275  StDataCmdLine& cmdline) const;
276 
277 
278  /*======================================================================*/
297  /*======================================================================*/
299  StDataCmdLine& cmdline,
300  const std::vector<double>& results,
301  const std::vector< StDataASCII>& details,
302  bool saveDetails,
303  std::ostream& os);
304 
305  };
306 }
307 
308 #include "LoadSaveASCII.icc"
309 
310 #endif
static void getParamInfosForLoadFeatureVectors(std::vector< ParamInfo > &p)
get information about the parameters, that are used in loadFeatureVectors().
static void getParamInfosForLoadSubsetLabels(std::vector< ParamInfo > &p)
get information about the parameters, that are used in loadSubsetLabels().
void saveClassificationResults(StDataCmdLine &cmdline, const std::vector< double > &results, const std::vector< StDataASCII > &details, bool saveDetails, std::ostream &os)
save classification results.
bool checkParamsForSaveClassificationResults(StDataCmdLine &cmdline) const
Just accesses all parameters, that are used in saveClassificationResults() so that they are no longer...
void loadFeatureVectors(StDataCmdLine &cmdline, std::vector< FV > &featureVectors)
load feature vectors
static void getParamInfosForSaveModel(std::vector< ParamInfo > &p)
get information about the parameters, that are used in saveModel().
void loadSubsetLabels(StDataCmdLine &cmdline, std::vector< int > &subsetIndexByUID)
load feature vectors
BasicSVMAdapter< FV, STDATA > * createSVMAndLoadModel(StDataCmdLine &cmdline)
create SVM from file and load Model data
static void getParamInfosForSaveClassificationResults(std::vector< ParamInfo > &p)
get information about the parameters, that are used in createSVMAndLoadModel().
void checkParamsForLoadFeatureVectors(StDataCmdLine &cmdline) const
Just accesses all parameters, that are used in loadFeatureVectors() so that they are no longer unknwo...
static void getParamInfosForCreateSVMAndLoadModel(std::vector< ParamInfo > &p)
get information about the parameters, that are used in createSVMAndLoadModel().
bool checkParamsForLoadSubsetLabels(StDataCmdLine &cmdline) const
checks wether the "--subset_att" parameter was given.
void saveModel(StDataCmdLine &cmdline, BasicSVMAdapter< FV, STDATA > *svm, int detailLevel, std::ostream &os)
save Model.
StDataASCIIFile STDATA
void checkParamsForSaveModel(StDataCmdLine &cmdline) const
Just accesses all parameters, that are used in saveModel() so that they are no longer unknwon to StDa...