Changeset 20846 in project


Ignore:
Timestamp:
10/14/10 13:38:05 (9 years ago)
Author:
petercrlane
Message:

version 0.2: allows defining problems in scheme

Location:
release/4/libsvm
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/libsvm/trunk/libsvm.meta

    r20789 r20846  
    1 ((author "Peter Lane")
     1((author "[[http://wiki.call-cc.org/users/peter lane|Peter Lane]]")
    22 (synopsis "Chicken bindings for libsvm")
    33 (license "GPL-3")
  • release/4/libsvm/trunk/libsvm.scm

    r20835 r20846  
    3030    problem-num-instances
    3131    read-problem
     32    svm-no-print-function
    3233    svm-train
    3334    svm-save-model
     
    6869  ;; - label (index value) (index value) ...      (TODO)
    6970  (define (make-problem definition)
    70     (let ((problem (create-svm-problem (length definition) (- (length (car definition)) 1)))
    71           (i 0))
    72       (for-each (lambda (instance)
    73                   (problem-set-label! problem i (exact->inexact (car instance)))
    74                   (let ((j 0))
    75                     (for-each (lambda (value)
    76                                 (problem-set-value! problem i j (exact->inexact value))
    77                                 (set! j (+ 1 j)))
    78                               (cdr instance))
    79                     (problem-set-end-value! problem i j))
    80                   (set! i (+ 1 i)))
    81                 definition)
    82       problem))
     71    (unless (and (list? definition)
     72                 (> (length definition) 0) ; must be at least one instance
     73                 (list? (car definition))
     74                 (> (length (car definition)) 1) ; instance must have a label and at least one feature
     75                 )
     76      (error "make-problem: invalid definition"))
     77    (if (list? (cadar definition))
     78      ; handle sparse vector definition
     79      (let* ((max-feature-index (apply max (map car (apply append (map cdr definition)))))
     80             (problem (create-svm-problem (length definition) max-feature-index))
     81             (i 0))
     82        (for-each (lambda (instance)
     83                    (problem-set-label! problem i (exact->inexact (car instance)))
     84                    (let ((j 0)) ; to record the end value position
     85                      (for-each (lambda (feature-defn)
     86                                  (problem-set-value! problem i (car feature-defn) (exact->inexact (cadr feature-defn)))
     87                                  (set! j (+ 1 j)))
     88                                (cdr instance))
     89                      (problem-set-end-value! problem i j))
     90                    (set! i (+ 1 i)))
     91                  definition)
     92        problem)
     93      (let ((problem (create-svm-problem (length definition) (- (length (car definition)) 1)))
     94            (i 0))
     95        (for-each (lambda (instance)
     96                    (problem-set-label! problem i (exact->inexact (car instance)))
     97                    (let ((j 0))
     98                      (for-each (lambda (value)
     99                                  (problem-set-value! problem i j (exact->inexact value))
     100                                  (set! j (+ 1 j)))
     101                                (cdr instance))
     102                      (problem-set-end-value! problem i j))
     103                    (set! i (+ 1 i)))
     104                  definition)
     105        problem)))
    83106
    84107  (define create-svm-problem
     
    321344      ;; functions from svm.cpp
    322345
     346      (foreign-declare "void print_null(const char *s) {}")
     347
     348      ;; clear the print function, so training is done 'quietly'
     349      (define svm-no-print-function
     350        (foreign-lambda* void ()
     351                         "svm_set_print_string_function(&print_null);"))
     352
    323353      ;; input: const struct svm_problem *, const struct svm_parameter *
    324354      ;; output: struct svm_model *
  • release/4/libsvm/trunk/libsvm.setup

    r20789 r20846  
    11(compile -s -O3 -d1 "libsvm.scm" -j libsvm -lsvm)
     2(compile -c -O3 -d1 "libsvm.scm" -unit libsvm -lsvm)
    23(compile -s -O3 -d0 "libsvm.import.scm" -lsvm)
    34
    45(install-extension
    56 'libsvm
    6  '("libsvm.so" "libsvm.import.so")
    7  '((version trunk)))
     7 '("libsvm.o" "libsvm.so" "libsvm.import.so")
     8 '((version trunk)
     9   (static "libsvm.o")))
Note: See TracChangeset for help on using the changeset viewer.