pysvmlight / svmlight / svmlight.py

from ctypes import *

svm = CDLL("./svmlight.so")

class WORD(Structure):
	_fields_ = [("wnum", c_long),
			    ("weight", c_float)]

class SVECTOR(Structure):
	_fields_ = [("words", WORD * 4),
			    ("twonorm_sq", c_double)]


class DOC(Structure):
	_fields_ = [("docnum", c_long),
			    ("queryid", c_long)]


if __name__ == "__main__":
	svec = SVECTOR()
	for i, word in enumerate(svec.words):
		word.wnum = i

	print svec.words

	resize(svec.words, 64)

	for word in svec.words:
		print word.wnum

'''
def svm_learn2(*args, **kwds):



static PyObject *svm_learn(PyObject *self, PyObject *args, PyObject *kwds)
{
    #DOC **docs;
    double* target;
    int totwords, totdoc;
    KERNEL_CACHE *kernel_cache;
    LEARN_PARM learn_parm;
    KERNEL_PARM kernel_parm;
    long verbosity;
    PyObject *doclist;
    MODEL *model;
    MODEL_AND_DOCS *result;

    if(!PyArg_ParseTuple(args, "O", &doclist))
        return NULL;
    read_learning_parameters(kwds, &verbosity, &learn_parm, &kernel_parm);
    if(!unpack_doclist(doclist, &docs, &target, &totwords, &totdoc))
        return NULL;

    model = malloc(sizeof(MODEL));
    if(kernel_parm.kernel_type == LINEAR)
        kernel_cache = NULL;
    else
        kernel_cache = kernel_cache_init(totdoc, learn_parm.kernel_cache_size);

    if(learn_parm.type == CLASSIFICATION) {
        svm_learn_classification(docs, target, totdoc, totwords, &learn_parm,
                                 &kernel_parm, kernel_cache, model, NULL /* alpha_in */);
    }
    else if(learn_parm.type == REGRESSION) {
        svm_learn_regression(docs, target, totdoc, totwords, &learn_parm,
                             &kernel_parm, &kernel_cache, model);
    }
    else if(learn_parm.type == RANKING) {
        svm_learn_ranking(docs, target, totdoc, totwords, &learn_parm,
                          &kernel_parm, &kernel_cache, model);
    }
    else if(learn_parm.type == OPTIMIZATION) {
        svm_learn_optimization(docs, target, totdoc, totwords, &learn_parm,
                               &kernel_parm, kernel_cache, model, NULL /* alpha_in */);
    }
'''
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.