iRoCS Toolbox  1.1.0
SVR_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 SVR_Q_HH
45 #define SVR_Q_HH
46 
47 #ifdef HAVE_CONFIG_H
48 #include <config.hh>
49 #endif
50 
51 namespace svt
52 {
53  template< typename FV, typename KF>
54  class SVR_Q: public Kernel
55  {
56  public:
57  SVR_Q(const KF& kernel, const SVM_Problem<FV,KF>& prob)
58  :Kernel( kernel, prob.l, prob.x)
59  {
60  l = prob.l;
61  cache = new Cache(l,(int)(param.cache_size*(1<<20)));
62  sign = new schar[2*l];
63  index = new int[2*l];
64  for(int k=0;k<l;k++)
65  {
66  sign[k] = 1;
67  sign[k+l] = -1;
68  index[k] = k;
69  index[k+l] = k;
70  }
71  buffer[0] = new Qfloat[2*l];
72  buffer[1] = new Qfloat[2*l];
73  next_buffer = 0;
74  }
75 
76  void swap_index(int i, int j) const
77  {
78  swap(sign[i],sign[j]);
79  swap(index[i],index[j]);
80  }
81 
82  Qfloat *get_Q(int i, int len) const
83  {
84  Qfloat *data;
85  int real_i = index[i];
86  if(cache->get_data(real_i,&data,l) < l)
87  {
88  for(int j=0;j<l;j++)
89  data[j] = (Qfloat)kernel_function(real_i,j);
90  }
91 
92  // reorder and copy
93  Qfloat *buf = buffer[next_buffer];
94  next_buffer = 1 - next_buffer;
95  schar si = sign[i];
96  for(int j=0;j<len;j++)
97  buf[j] = si * sign[j] * data[index[j]];
98  return buf;
99  }
100 
102  {
103  delete cache;
104  delete[] sign;
105  delete[] index;
106  delete[] buffer[0];
107  delete[] buffer[1];
108  }
109  private:
110  int l;
111  Cache *cache;
112  schar *sign;
113  int *index;
114  mutable int next_buffer;
115  Qfloat* buffer[2];
116  };
117 
118 }
119 
120 #endif
void swap_index(int i, int j) const
Definition: SVR_Q.hh:76
long get_data(const long index, Qfloat **data, long len)
SVR_Q(const KF &kernel, const SVM_Problem< FV, KF > &prob)
Definition: SVR_Q.hh:57
~SVR_Q()
Definition: SVR_Q.hh:101
signed char schar
Definition: svm_defines.hh:67
Qfloat * get_Q(int i, int len) const
Definition: SVR_Q.hh:82
double kernel_function(int i, int j) const
Definition: Kernel.hh:92
float Qfloat
Definition: svm_defines.hh:66