wolffd@0: /************************************************************************/ wolffd@0: /* */ wolffd@0: /* kernel.h */ wolffd@0: /* */ wolffd@0: /* User defined kernel function. Feel free to plug in your own. */ wolffd@0: /* */ wolffd@0: /* Copyright: Thorsten Joachims */ wolffd@0: /* Date: 16.12.97 */ wolffd@0: /* */ wolffd@0: /************************************************************************/ wolffd@0: wolffd@0: /* KERNEL_PARM is defined in svm_common.h The field 'custom' is reserved for */ wolffd@0: /* parameters of the user defined kernel. You can also access and use */ wolffd@0: /* the parameters of the other kernels. Just replace the line wolffd@0: return((double)(1.0)); wolffd@0: with your own kernel. */ wolffd@0: wolffd@0: /* Example: The following computes the polynomial kernel. sprod_ss wolffd@0: computes the inner product between two sparse vectors. wolffd@0: wolffd@0: return((CFLOAT)pow(kernel_parm->coef_lin*sprod_ss(a->words,b->words) wolffd@0: +kernel_parm->coef_const,(double)kernel_parm->poly_degree)); wolffd@0: */ wolffd@0: wolffd@0: /* If you are implementing a kernel that is not based on a wolffd@0: feature/value representation, you might want to make use of the wolffd@0: field "userdefined" in SVECTOR. By default, this field will contain wolffd@0: whatever string you put behind a # sign in the example file. So, if wolffd@0: a line in your training file looks like wolffd@0: wolffd@0: -1 1:3 5:6 #abcdefg wolffd@0: wolffd@0: then the SVECTOR field "words" will contain the vector 1:3 5:6, and wolffd@0: "userdefined" will contain the string "abcdefg". */ wolffd@0: wolffd@0: double custom_kernel(KERNEL_PARM *kernel_parm, SVECTOR *a, SVECTOR *b) wolffd@0: /* plug in you favorite kernel */ wolffd@0: { wolffd@0: return((double)(1.0)); wolffd@0: }