As I said, it's easy to change libsvm for what you need, and here is the explanation: http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#f418
Since I am not familiar with these two kernels, I just copied the formulas from Google. I hope I understood them correctly: D
a. Histogram intersection core (too bad SO does not display latex): SUM (min (x_i, y_i)) → we can just change the linear core and convert it to this, so basically in version 3.12 (latest version), in svm.cpp:
-> line 233 returns the point (x [i], x [j]); - you just need to copy the code from the Kernel :: dot method and change it accordingly, so something like this:
double sum = 0; while(x->index != -1 && y->index != -1) { if(x->index == y->index) { sum += min(x->value, y->value); ++x; ++y; } else { if(x->index > y->index) ++x; else ++y; } } return sum;
(for regular test files, x should be the same length as y. I think the else branch exists for special cases where the test or model file contains attributes with a value of 0 that can be omitted, but if libsvm produces the expected results with linear core, then it will also work with this modified)
-> line 322 return dot (x, y); - same as above
B. The core of chi-square: SUM ((2 x_i y_i)) (well, let me see ... I think we can try changing the linear core again (maybe some of the optimizations for RBF can be used in this case, but this time ignore):
-> line 233 becomes:
double sum = 0; while(x->index != -1 && y->index != -1) { if(x->index == y->index) { sum += 2 * x->value * y->value / (x->value + y->value); ++x; ++y; } else { if(x->index > y->index) ++x; else ++y; } } return sum;
-> line 322 - same as above
PS: The above code is written in notepad and untested. Please don’t kill me if it doesn’t work, and you should spend two weeks debugging the cryptic C code. [Sarcasm] For me, this worked on the first try. [/ sarcasm] However, you can easily debug it as soon as you understand the workflow by setting breakpoints in these two places. If you have any problems, I would be happy to provide additional help, so just let me know if you are stuck.