41 #ifndef KERNEL_FILE_HH 42 #define KERNEL_FILE_HH 64 template<
typename FILETYPE>
79 _cacheIsUpToDate(false)
86 #ifdef ALLOW_KERNEL_MATRIX_COPY 102 _cacheIsUpToDate(
false)
109 _cacheIsUpToDate = orig._cacheIsUpToDate;
113 orig._maxgID1, orig._maxgID2);
116 if (orig._gIDCache1 != 0) std::copy(orig._gIDCache1,
117 _gIDCache1+_maxgID1+1,
126 if (orig._gIDCache2 != 0) std::copy(orig._gIDCache2,
127 _gIDCache2+_maxgID2+1,
135 if( orig._height !=0 && orig._width != 0)
137 unsigned int size = _height*_width;
138 std::copy( orig._data, orig._data + size, _data);
151 unsigned int maxgID1,
unsigned int maxgID2)
const 161 if( _width != 0 && _height != 0)
163 _data =
new float[height*width];
164 _rowStarts =
new float*[height];
166 for(
unsigned int i = 0; i < height; ++i)
168 _rowStarts[i] = _data + i*width;
177 _gIDCache1 =
new unsigned int[maxgID1+1];
178 _gIDCache2 =
new unsigned int[maxgID2+1];
211 _cacheIsUpToDate =
false;
216 template<
typename ForwardIter,
typename Accessor>
218 const ForwardIter& fvEnd,
222 updateCache(fvBegin,fvEnd,accessor,fvBegin,fvEnd,accessor,pr);
227 template<
typename ForwardIter1,
typename Accessor1,
228 typename ForwardIter2,
typename Accessor2>
230 const ForwardIter1& fvEnd1,
232 const ForwardIter2& fvBegin2,
233 const ForwardIter2& fvEnd2,
238 std::vector<unsigned int> gIDs1;
239 std::vector<unsigned int> gIDs2;
240 std::vector<unsigned int>::iterator git;
242 for (ForwardIter1 fi = fvBegin1; fi != fvEnd1; fi++)
243 gIDs1.push_back(accessor1(fi).getGlobalID());
244 std::sort(gIDs1.begin(),gIDs1.end());
246 for (ForwardIter2 fi = fvBegin2; fi != fvEnd2; fi++)
247 gIDs2.push_back(accessor2(fi).getGlobalID());
248 std::sort(gIDs2.begin(),gIDs2.end());
254 if (gIDs1.begin() != gIDs1.end())
255 _maxgID1 = *(gIDs1.end()-1);
256 if (gIDs2.begin() != gIDs2.end())
257 _maxgID2 = *(gIDs2.end()-1);
259 resizeCache(gIDs1.size(),gIDs2.size(),_maxgID1,_maxgID2);
263 for (git=gIDs1.begin();
264 git!=gIDs1.end();git++,i++)
268 for (git=gIDs2.begin();
269 git!=gIDs2.end();git++,i++)
273 _file.load_matrix(_rowStarts,gIDs1,gIDs2);
278 "full kernel matrix read", 1.0,
305 _cacheIsUpToDate =
true;
309 template<
typename FV>
315 unsigned int gID1 = x.getGlobalID();
316 unsigned int gID2 = y.getGlobalID();
321 return _rowStarts[ _gIDCache1[gID1] ][ _gIDCache2[gID2] ];
324 template<
typename STDATA>
327 _file.loadParameters( stData);
330 template<
typename STDATA>
334 _file.saveParameters( stData);
335 stData.setValue(
"kernel_type",
name());
340 return std::string(
"file_")+ FILETYPE::name();
345 return std::string(
"cached kernel matrix file, ")+
346 FILETYPE::description();
351 FILETYPE::getParamInfos( p);
355 mutable FILETYPE _file;
356 mutable float* _data;
357 mutable float** _rowStarts;
358 mutable unsigned int* _gIDCache1;
359 mutable unsigned int* _gIDCache2;
360 mutable unsigned int _maxgID1;
361 mutable unsigned int _maxgID2;
362 mutable unsigned int _height;
363 mutable unsigned int _width;
364 mutable bool _cacheIsUpToDate;
void loadParameters(STDATA &stData)
#define CHECK_MEMBER_TEMPLATE(c)
#define SVM_ASSERT(condition)
static std::string name()
void saveParameters(STDATA &stData) const
void updateCache(const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor, ProgressReporter *pr=0) const
void updateCache(const ForwardIter1 &fvBegin1, const ForwardIter1 &fvEnd1, Accessor1 accessor1, const ForwardIter2 &fvBegin2, const ForwardIter2 &fvEnd2, Accessor2 accessor2, ProgressReporter *pr=0) const
static std::string description()
const int TASK_LEVEL_CROSS_VAL
double k_function(const FV &x, const FV &y) const
void resizeCache(unsigned int height, unsigned int width, unsigned int maxgID1, unsigned int maxgID2) const
static void getParamInfos(std::vector< ParamInfo > &p)