320{
321 switch(param.kernel_type)
322 {
323 case LINEAR:
324 return dot(x,y);
325 case POLY:
326 return powi(param.gamma*dot(x,y)+param.coef0,param.degree);
327 case RBF:
328 {
329 double sum = 0;
330 while(x->index != -1 && y->index !=-1)
331 {
332 if(x->index == y->index)
333 {
334 double d = x->value - y->value;
335 sum += d*d;
336 ++x;
337 ++y;
338 }
339 else
340 {
341 if(x->index > y->index)
342 {
343 sum += y->value * y->value;
344 ++y;
345 }
346 else
347 {
348 sum += x->value * x->value;
349 ++x;
350 }
351 }
352 }
353
354 while(x->index != -1)
355 {
356 sum += x->value * x->value;
357 ++x;
358 }
359
360 while(y->index != -1)
361 {
362 sum += y->value * y->value;
363 ++y;
364 }
365
366 return exp(-param.gamma*sum);
367 }
368 case SIGMOID:
369 return tanh(param.gamma*dot(x,y)+param.coef0);
370 case PRECOMPUTED:
371 return x[(int)(y->value)].value;
372 default:
373 return 0;
374 }
375}