iRoCS Toolbox  1.1.0
BasicSVMFactoryOneClass.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:
26 ** $RCSfile$
27 ** $Revision: 512 $$Name$
28 ** $Date: 2004-09-08 16:16:52 +0200 (Wed, 08 Sep 2004) $
29 ** Copyright: GPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.2 2004/09/08 14:16:52 ronneber
38 ** - changed key for two class svm selection from "svm_type" to "two_class_type"
39 **
40 ** Revision 1.1 2004/08/26 08:36:58 ronneber
41 ** initital import
42 **
43 **
44 **
45 **************************************************************************/
46 #ifndef BASICSVMFACTORYONECLASS_HH
47 #define BASICSVMFACTORYONECLASS_HH
48 
49 #ifdef HAVE_CONFIG_H
50 #include <config.hh>
51 #endif
52 
53 #include "BasicFV.hh"
54 #include "TList.hh"
55 #include "BasicSVMAdapter.hh"
56 
57 namespace svt
58 {
59  template< typename FV,
60  typename STDATA,
61  typename OC_ITER,
62  typename KF_ITER>
64  {
65  static BasicSVMAdapter<FV,STDATA>* search( const std::string& ocName,
66  const std::string& kfName)
67  {
68 
69  /*-----------------------------------------------------------------
70  * extract the oneclass and kernelfunction
71  * types from the iterators. Because Oneclass types are
72  * templated, 'int' is taken as dummy
73  * template argument
74  *-----------------------------------------------------------------*/
75  typedef typename OC_ITER::Traits<int>::val_t OCTYPE;
76  typedef typename KF_ITER::val_t KFTYPE;
77 
78  /*-----------------------------------------------------------------
79  * Check if current OneClass type has the correct name,
80  * otherwise instantiate SVMFinder with the next OneClass type
81  *-----------------------------------------------------------------*/
82  if( ocName != "" && ocName != OCTYPE::name())
83  {
84  return SVMFinderOneClass<
85  FV,
86  STDATA,
87  typename OC_ITER::next_t,
88  KF_ITER
89  >::search( pcName, kfName);
90  }
91  /*-----------------------------------------------------------------
92  * Check if current Kernel type has the correct name,
93  * otherwise instantiate SVMFinder with the next Kernel type
94  *-----------------------------------------------------------------*/
95  else if( kfName != "" && kfName != KFTYPE::name())
96  {
97  return SVMFinder<
98  FV,
99  STDATA,
100  OC_ITER,
101  typename KF_ITER::next_t
102  >::search( ocName, kfName);
103  }
104  /*-----------------------------------------------------------------
105  * Ok, current MultiClass type, TwoClass type and Kernel
106  * type have the correct name. Instatiate an
107  * BasicSVMAdapterTempl with the given types
108  *-----------------------------------------------------------------*/
109  else
110  {
111  typedef typename OC_ITER::Traits<
112  typename KF_ITER::val_t >::val_t SVMTYPE;
113 
115  }
116  }
117  };
118 
119 
120  /*-------------------------------------------------------------------------
121  * partial specializations for SVMFinderOneClass, when it has reached the
122  * end of given List, without having found the requested name
123  *-------------------------------------------------------------------------*/
124  template< typename FV,
125  typename STDATA,
126  typename X,
127  typename KF_ITER>
128  struct SVMFinderOneClass<FV, STDATA, TTList<TTList_end,X>, KF_ITER>
129  {
130  static BasicSVMAdapter<FV,STDATA>* search( const std::string& ocName,
131  const std::string& kfName)
132  {
134  err << "One-Class type `" << tcName << "' does not exist!";
135  throw err;
136  }
137  };
138 
139  template< typename FV,
140  typename STDATA,
141  typename OC_ITER ,
142  typename X>
143  struct SVMFinderOneClass<FV, STDATA, OC_ITER, TList<TList_end,X> >
144  {
145  static BasicSVMAdapter<FV,STDATA>* search( const std::string& ocName,
146  const std::string& kfName)
147  {
149  err << "Kernel type `" << kfName << "' does not exist!";
150  throw err;
151  }
152  };
153 
154 
155 
156 
157 
158 
159  /*======================================================================*/
176  /*======================================================================*/
177  template< typename FV, typename STDATA,
178  typename OCLIST, typename KFLIST>
180  {
181  public:
182 
183  /*======================================================================*/
200  /*======================================================================*/
201  static BasicSVMAdapter<FV,STDATA>* create( const std::string& ocName,
202  const std::string& kfName)
203  {
204  return SVMFinder<
205  FV,
206  STDATA,
207  typename OCLIST::the_list,
208  typename KFLIST::the_list
209  >::search( ocName, kfName);
210  }
211 
212 
213 
214  /*======================================================================*/
224  /*======================================================================*/
225  static BasicSVMAdapter<FV,STDATA>* createFromStData( const STDATA& stData)
226  {
227  std::string ocName;
228  std::string kfName;
229  stData.getValue( "two_class_type", ocName);
230  stData.getValue( "kernel_type", kfName);
231 
232  return create( ocName, kfName);
233  }
234 
235 
236  };
237 
238 }
239 
240 #endif
static BasicSVMAdapter< FV, STDATA > * createFromStData(const STDATA &stData)
(description)
static BasicSVMAdapter< FV, STDATA > * search(const std::string &ocName, const std::string &kfName)
static BasicSVMAdapter< FV, STDATA > * search(const std::string &ocName, const std::string &kfName)
static BasicSVMAdapter< FV, STDATA > * create(const std::string &ocName, const std::string &kfName)
create an BasicSVMAdapterTempl with the requested types.
The BasicSVMFactoryOneClass class is a factory, that creates the appropriate template class from give...
static BasicSVMAdapter< FV, STDATA > * search(const std::string &ocName, const std::string &kfName)