iRoCS Toolbox  1.1.0
ONE_CLASS_Q.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: 476 $$Name$
28 ** $Date: 2004-08-26 10:36:59 +0200 (Thu, 26 Aug 2004) $
29 ** Copyright: LGPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.1 2004/08/26 08:36:59 ronneber
38 ** initital import
39 **
40 **
41 **
42 **************************************************************************/
43 
44 #ifndef ONE_CLASS_Q_HH
45 #define ONE_CLASS_Q_HH
46 
47 #ifdef HAVE_CONFIG_H
48 #include <config.hh>
49 #endif
50 
51 #include "SVM_Problem.hh"
52 #include "Kernel.hh"
53 #include "Cache.hh"
54 
55 namespace svt
56 {
57  template< typename FV, typename KF>
58  class ONE_CLASS_Q: public Kernel<FV,KF>
59  {
60  public:
61  ONE_CLASS_Q( const KF& kernel, const SVM_Problem<FV,KF>& prob)
62  :Kernel( kernel, prob.l, prob.x)
63  {
64  cache = new Cache(prob.l,(int)(param.cache_size*(1<<20)));
65  }
66 
67  Qfloat *get_Q(int i, int len) const
68  {
69  Qfloat *data;
70  int start;
71  if((start = cache->get_data(i,&data,len)) < len)
72  {
73  for(int j=start;j<len;j++)
74  data[j] = (Qfloat)kernel_function(i,j);
75  }
76  return data;
77  }
78 
79  void swap_index(int i, int j) const
80  {
81  cache->swap_index(i,j);
82  Kernel::swap_index(i,j);
83  }
84 
86  {
87  delete cache;
88  }
89 private:
90  Cache *cache;
91  };
92 }
93 
94 #endif
ONE_CLASS_Q(const KF &kernel, const SVM_Problem< FV, KF > &prob)
Definition: ONE_CLASS_Q.hh:61
Qfloat * get_Q(int i, int len) const
Definition: ONE_CLASS_Q.hh:67
long get_data(const long index, Qfloat **data, long len)
void swap_index(long i, long j)
void swap_index(int i, int j) const
Definition: ONE_CLASS_Q.hh:79
double kernel_function(int i, int j) const
Definition: Kernel.hh:92
float Qfloat
Definition: svm_defines.hh:66
virtual void swap_index(int i, int j) const
Definition: Kernel.hh:86