svm_Dlearn and svm_Dclassify behave exactly as T. Joachims' svm_learn and svm_classify, but accept an extra option (-D) for loading a custom dynamic library that supports a particular data type with an associated kernel function.SVMDlight is more a recipe for writing new plugins than something interesting per se. You may find it useful if you wish to use SVMLight with your own data types and kernels.
http://www.dsi.unifi.it/neural/src/svm-Dlight/svm-Dlight.tgz
svm_Dlearn and svm_Dclassify accept the same options as svm_learn and svm_classify. Without the -D option they behave exactly in the same way when dealing with sparse vector data.Suppose you have a new interesting data type, say 'gnats', and have just found a kernel function on gnats. To program your kernel in SVMDlight you need to take the following steps:
struct Gnat { ... };void* plugin_parse_document(char*, double*, long*,long*, double*, long*, long, char**); that is going to replace the similar function in SVMLight (see comments in the file plugin.c for details) and that returns a void pointer to the constructed struct.void plugin_write(FILE*, void*);double plugin_kernel(void* a, void* b); At run time, the SVMLight optimizer will call this function passing two pointers to the SVM-Light struct SVECTOR. In turn this struct has a pointer member called words that points to your own data structure. For example, you can use a code fragment like: struct Gnat* my_ptr_a = (struct Gnat*)(((SVECTOR*)a)->words) to access your own datavoid* plugin_copy_constructor(void *words) for making a runtime copy of your data typevoid plugin_destructor(void*) for deallocating itvoid* plugin_null(void) for returning a null instance (the feature space's zero);gnats.so under LinuxAt this point you can run SVMDlight as follows
svm_Dlearn -D /path/to/your/lib/gnats.so [other opts] mygnats.trainset model
All usual svm_learn options can be still given. When using -D, the kernel type option (-t) has a special meaning:
-t 4 (default when -D is given) means using your own kernel-t 1, -t 2, -t 3 means kernel composition with a polynomial or Gaussian or sigmoidal kernel (hyperparameters can be given as usual)-t 0 is unsupported when -D is given and will abort the program (this is due to the fact that SVMLight tries to construct the solution W,b in the primal space to optimize calculations, and clearly this is only possible for finitely numerable input spaces)Test goes as ususal:
svm_Dclassify -D /path/to/your/lib/gnats.so [other opts] mygnats.testset model
Additionally you may pass parameters to your kernel by using the -u command line switch. For example
svm_Dlearn -D /path/to/your/lib/gnats.so -u "2 true" mygnats.trainset model
will pass the string "2 true" containing hyperparameters specific of your own kernel. To parse this string write some code in the function void plugin_kernel_setparm(char*);
The files helloworld.h and helloworld.c contain a very simple plugin example where the 'arbitrary' datum consists of a single real number and the kernel k(a,b) is either a*b or min(a,b) depending on the parameter passed with -u
dlopen(), dlsym() etc.
1.5.1