You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
461 lines
14 KiB
461 lines
14 KiB
diff -up ./java/Makefile.orig ./java/Makefile
|
|
--- ./java/Makefile.orig 2009-02-18 10:41:04.000000000 +1000
|
|
+++ ./java/Makefile 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -4,13 +4,21 @@ FILES = libsvm/svm.class libsvm/svm_mode
|
|
libsvm/svm_print_interface.class \
|
|
svm_train.class svm_predict.class svm_toy.class svm_scale.class
|
|
|
|
+JAVA_DOC_DIR=${INSTDIR}/share/javadoc/libsvm-${LIBSVM_VER}
|
|
+CLASSPATH = .
|
|
#JAVAC = jikes
|
|
-JAVAC_FLAGS = -target 1.5 -source 1.5
|
|
+JAVAC_FLAGS = -target 1.5 -source 1.5 -classpath ${CLASSPATH}
|
|
+ifndef JAVAC
|
|
JAVAC = javac
|
|
+endif
|
|
# JAVAC_FLAGS =
|
|
|
|
+ifndef JAR
|
|
+JAR=jar
|
|
+endif
|
|
+
|
|
all: $(FILES)
|
|
- jar cvf libsvm.jar *.class libsvm/*.class
|
|
+ ${JAR} cvf libsvm.jar *.class libsvm/*.class
|
|
|
|
.java.class:
|
|
$(JAVAC) $(JAVAC_FLAGS) $<
|
|
@@ -18,8 +26,23 @@ all: $(FILES)
|
|
libsvm/svm.java: libsvm/svm.m4
|
|
m4 libsvm/svm.m4 > libsvm/svm.java
|
|
|
|
+javadoc: docs/index.html
|
|
+
|
|
+docs/index.html: $(FILES)
|
|
+ javadoc -d docs *.java libsvm/*.java
|
|
+
|
|
+install:
|
|
+ mkdir -p ${JAVA_TARGET_DIR}
|
|
+ install -m 644 libsvm.jar ${JAVA_TARGET_DIR}
|
|
+# mkdir -p ${JAVA_DOC_DIR}
|
|
+# cd docs; cp -R * ${JAVA_DOC_DIR}
|
|
+uninstall:
|
|
+ rm -fr ${JAVA_TARGETDIR}
|
|
+# rm -fr ${JAVA_DOC_DIR}
|
|
+
|
|
clean:
|
|
rm -f libsvm/*.class *.class *.jar libsvm/*~ *~ libsvm/svm.java
|
|
+ rm -rf docs
|
|
|
|
dist: clean all
|
|
rm *.class libsvm/*.class
|
|
diff -up ./java/test_applet.html.orig ./java/test_applet.html
|
|
--- ./java/test_applet.html.orig 2003-07-12 14:07:32.000000000 +1000
|
|
+++ ./java/test_applet.html 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -1 +1,3 @@
|
|
-<APPLET code="svm_toy.class" archive="libsvm.jar" width=300 height=350></APPLET>
|
|
+<html>
|
|
+<applet code="svm_toy.class" archive="libsvm.jar" width=300 height=350></applet>
|
|
+</html>
|
|
diff -up ./Makefile.orig ./Makefile
|
|
--- ./Makefile.orig 2009-07-01 07:13:50.000000000 +1000
|
|
+++ ./Makefile 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -1,11 +1,40 @@
|
|
-CXX ?= g++
|
|
-CFLAGS = -Wall -Wconversion -O3 -fPIC
|
|
+CXX ? = g++
|
|
+CFLAGS = ${RPM_CFLAGS} -Wall -Wconversion -O3 -fPIC
|
|
SHVER = 1
|
|
+MAKE = make
|
|
+DOT_LIBS=.libs
|
|
+LIBS= -L${DOT_LIBS} -lsvm
|
|
+export LIBSVM_VER
|
|
|
|
-all: svm-train svm-predict svm-scale
|
|
+ifndef DESTDIR
|
|
+INSTDIR=/usr
|
|
+else
|
|
+INSTDIR=${DESTDIR}/usr
|
|
+endif
|
|
+
|
|
+export INSTDIR
|
|
+
|
|
+IS_64=$(shell /bin/uname -i | awk '/64/ {print 64}')
|
|
+
|
|
+ifndef LIBDIR
|
|
+LIB_INSTDIR=${INSTDIR}/lib${IS_64}
|
|
+else
|
|
+LIB_INSTDIR=${INSTDIR}/..${LIBDIR}
|
|
+endif
|
|
+
|
|
+ifndef LIBDIR
|
|
+LIBDIR=/usr/lib${IS_64}
|
|
+endif
|
|
+
|
|
+export LIBDIR
|
|
+export LIB_INSTDIR
|
|
+
|
|
+
|
|
+all: lib svm-train svm-predict svm-scale svm-python svm-java svm-toy-gtk svm-toy-qt
|
|
|
|
lib: svm.o
|
|
- $(CXX) -shared svm.o -o libsvm.so.$(SHVER)
|
|
+ $(CXX) -shared -Wl,-soname,libsvm.so.$(SHVER) svm.o -o libsvm.so.$(SHVER)
|
|
+ ln -sf libsvm.so.$(SHVER) libsvm.so
|
|
|
|
svm-predict: svm-predict.c svm.o
|
|
$(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm
|
|
@@ -16,4 +45,65 @@ svm-scale: svm-scale.c
|
|
svm.o: svm.cpp svm.h
|
|
$(CXX) $(CFLAGS) -c svm.cpp
|
|
clean:
|
|
- rm -f *~ svm.o svm-train svm-predict svm-scale
|
|
+ rm -f *~ svm.o svm-train svm-predict svm-scale svm-toy/gtk/svm-toy-gtk svm-toy/qt/svm-toy-qt
|
|
+ ${MAKE} -C python clean
|
|
+ ${MAKE} -C java clean
|
|
+svm-python:
|
|
+ ${MAKE} -C python
|
|
+svm-java:
|
|
+ifneq ("${NO_JAVA}","NO_JAVA")
|
|
+ ${MAKE} -C java
|
|
+endif
|
|
+svm-toy-gtk:
|
|
+ ${MAKE} -C svm-toy/gtk
|
|
+svm-toy-qt:
|
|
+ ${MAKE} -C svm-toy/qt
|
|
+
|
|
+install: all
|
|
+ mkdir -p ${INSTDIR}/bin
|
|
+ install -m 755 svm-train ${INSTDIR}/bin
|
|
+ install -m 755 svm-predict ${INSTDIR}/bin
|
|
+ install -m 755 svm-scale ${INSTDIR}/bin
|
|
+ mkdir -p ${LIB_INSTDIR}
|
|
+ install -m 755 libsvm.so.$(SHVER) ${LIB_INSTDIR}
|
|
+# install package libsvm-devel
|
|
+ mkdir -p ${INSTDIR}/include/libsvm
|
|
+ install -m 644 svm.h ${INSTDIR}/include/libsvm
|
|
+ mkdir -p ${INSTDIR}/share/libsvm/src/java/libsvm
|
|
+ install -m 644 *.h ${INSTDIR}/share/libsvm/src
|
|
+ install -m 644 *.c ${INSTDIR}/share/libsvm/src
|
|
+ install -m 644 *.cpp ${INSTDIR}/share/libsvm/src
|
|
+ install -m 644 Makefile ${INSTDIR}/share/libsvm/src
|
|
+ifneq ("${NO_JAVA}","NO_JAVA")
|
|
+ install -m 644 java/*.java ${INSTDIR}/share/libsvm/src/java
|
|
+ install -m 644 java/Makefile ${INSTDIR}/share/libsvm/src/java
|
|
+ install -m 644 java/libsvm/*.java ${INSTDIR}/share/libsvm/src/java/libsvm
|
|
+ install -m 644 java/libsvm/*.m4 ${INSTDIR}/share/libsvm/src/java/libsvm
|
|
+# install package libsvm-java
|
|
+ ${MAKE} -C java install
|
|
+endif
|
|
+# install package libsvm-python
|
|
+ ${MAKE} -C python install
|
|
+# install package svm-toy
|
|
+ install -m 755 svm-toy/gtk/svm-toy-gtk ${INSTDIR}/bin
|
|
+ install -m 755 svm-toy/qt/svm-toy-qt ${INSTDIR}/bin
|
|
+# install examples
|
|
+ mkdir -p ${INSTDIR}/share/libsvm/examples
|
|
+ install -m 644 heart_scale ${INSTDIR}/share/libsvm/examples
|
|
+uninstall:
|
|
+ rm -f ${INSTDIR}/bin/svm-train
|
|
+ rm -f ${INSTDIR}/bin/svm-predict
|
|
+ rm -f ${INSTDIR}/bin/svm-scale
|
|
+ rm -fr ${INSTDIR}/libsvm/examples
|
|
+ rm -f ${INSTDIR}/include/libsvm/svm.h
|
|
+ rm -f ${LIB_INSTDIR}/libsvm/svm.o
|
|
+ rm -fr ${INSTDIR}/libsvm/src
|
|
+ rm -fr ${INSTDIR}/libsvm
|
|
+ ${MAKE} -C python uninstall
|
|
+ifneq ("${NO_JAVA}","NO_JAVA")
|
|
+ ${MAKE} -C java uninstall
|
|
+endif
|
|
+ rm -f ${INSTDIR}/bin/svm-toy-gtk
|
|
+ rm -f ${INSTDIR}/bin/svm-toy-qt
|
|
+
|
|
+
|
|
diff -up ./python/Makefile.orig ./python/Makefile
|
|
--- ./python/Makefile.orig 2009-09-16 23:37:45.000000000 +1000
|
|
+++ ./python/Makefile 2009-11-04 14:15:06.000000000 +1000
|
|
@@ -1,10 +1,12 @@
|
|
-CXX ?= g++
|
|
+CXX ? = g++
|
|
SWIG ?= swig
|
|
|
|
#Windows: see ../README ../Makefile.win
|
|
-PYTHON_INCLUDEDIR ?= /usr/include/python2.5
|
|
+PYTHON_INCLUDEDIR ?= /usr/include/python${PYTHON_VERSION}
|
|
+PYTHON_TARGETDIR=${LIB_INSTDIR}/python${PYTHON_VERSION}/site-packages/libsvm
|
|
|
|
CFLAGS = -O3 -I$(PYTHON_INCLUDEDIR) -I..
|
|
+CFLAGS_PYTHON = ${CFLAGS} -O3 -I$(PYTHON_INCLUDEDIR) -I..
|
|
LDFLAGS = -shared
|
|
# Mac OS
|
|
# LDFLAGS = -framework Python -bundle
|
|
@@ -15,16 +17,31 @@ svmc.so: svmc_wrap.o ../svm.o
|
|
$(CXX) $(LDFLAGS) -o svmc.so svmc_wrap.o ../svm.o
|
|
|
|
svmc_wrap.o: svmc_wrap.c ../svm.h
|
|
- $(CXX) $(CFLAGS) -fPIC -c svmc_wrap.c
|
|
+ $(CXX) $(CFLAGS_PYTHON) -fPIC -c svmc_wrap.c
|
|
|
|
svmc_wrap.c: svmc.i
|
|
$(SWIG) -python -noproxy svmc.i
|
|
|
|
../svm.o: ../svm.cpp ../svm.h
|
|
- cd ..; $(CXX) $(CFLAGS) -fPIC -c svm.cpp
|
|
+ cd ..; $(CXX) $(CFLAGS_PYTHON) -fPIC -c svm.cpp
|
|
|
|
clean:
|
|
rm -f *~ *.o *.so *.pyc *.pyo
|
|
|
|
-cleaner: clean
|
|
+cleaner: clean
|
|
rm -f svmc_wrap.c
|
|
+
|
|
+
|
|
+install: all
|
|
+ mkdir -p ${PYTHON_TARGETDIR}
|
|
+ install -m 755 cross_validation.py ${PYTHON_TARGETDIR}
|
|
+ install -m 644 svm.py ${PYTHON_TARGETDIR}
|
|
+ install -m 755 svm_test.py ${PYTHON_TARGETDIR}
|
|
+ install -m 755 test_cross_validation.py ${PYTHON_TARGETDIR}
|
|
+ install -m 644 *.i ${PYTHON_TARGETDIR}
|
|
+ install -m 755 *.so ${PYTHON_TARGETDIR}
|
|
+ install -m 755 ../tools/*.py ${PYTHON_TARGETDIR}
|
|
+
|
|
+uninstall:
|
|
+ rm -fr ${LIBDIR}/python${PYTHON_VERSION}/site-packages/libsvm
|
|
+
|
|
diff -up ./svm-toy/gtk/callbacks.cpp.orig ./svm-toy/gtk/callbacks.cpp
|
|
--- ./svm-toy/gtk/callbacks.cpp.orig 2006-03-04 17:40:12.000000000 +1000
|
|
+++ ./svm-toy/gtk/callbacks.cpp 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -2,6 +2,7 @@
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <list>
|
|
+#include <cstdlib>
|
|
#include "callbacks.h"
|
|
#include "interface.h"
|
|
#include "../../svm.h"
|
|
diff -up ./svm-toy/gtk/Makefile.orig ./svm-toy/gtk/Makefile
|
|
--- ./svm-toy/gtk/Makefile.orig 2007-10-14 16:29:12.000000000 +1000
|
|
+++ ./svm-toy/gtk/Makefile 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -2,21 +2,27 @@ CC? = gcc
|
|
CXX? = g++
|
|
CFLAGS = -Wall -O3 -g `gtk-config --cflags`
|
|
LIBS = `gtk-config --libs`
|
|
+COPT = -Wall -O3 -g `pkg-config --cflags --libs gtk+-2.0`
|
|
+LOCAL_LIBDIR=../../
|
|
+LIBS= -L${LOCAL_LIBDIR} -lsvm
|
|
|
|
-svm-toy: main.o interface.o callbacks.o ../../svm.o
|
|
- $(CXX) $(CFLAGS) main.o interface.o callbacks.o ../../svm.o -o svm-toy $(LIBS)
|
|
+
|
|
+all: svm-toy-gtk
|
|
+
|
|
+svm-toy-gtk: main.o interface.o callbacks.o
|
|
+ $(CXX) $(COPT) main.o interface.o callbacks.o ${LIBS} -o svm-toy-gtk
|
|
|
|
main.o: main.c
|
|
- $(CC) $(CFLAGS) -c main.c
|
|
+ $(CC) $(COPT) -c main.c
|
|
|
|
interface.o: interface.c interface.h
|
|
- $(CC) $(CFLAGS) -c interface.c
|
|
+ $(CC) $(COPT) -c interface.c
|
|
|
|
callbacks.o: callbacks.cpp callbacks.h
|
|
- $(CXX) $(CFLAGS) -c callbacks.cpp
|
|
+ $(CXX) $(COPT) -c callbacks.cpp
|
|
|
|
-../../svm.o:
|
|
- cd ../..; make svm.o
|
|
+#../../svm.o:
|
|
+# cd ../..; make svm.o
|
|
|
|
clean:
|
|
- rm -f *~ callbacks.o svm-toy main.o interface.o callbacks.o ../../svm.o
|
|
+ rm -f *~ callbacks.o svm-toy-gtk main.o interface.o callbacks.o
|
|
diff -up ./svm-toy/qt/Makefile.orig ./svm-toy/qt/Makefile
|
|
--- ./svm-toy/qt/Makefile.orig 2008-12-19 16:42:05.000000000 +1000
|
|
+++ ./svm-toy/qt/Makefile 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -1,17 +1,21 @@
|
|
CXX? = g++
|
|
-CFLAGS = -Wall -O3 -I$(INCLUDE) -I$(INCLUDE)/QtGui -lQtGui
|
|
+CFLAGS = -Wall -O3
|
|
+FLAGS:=${CFLAGS} `pkg-config --cflags --libs QtGui`
|
|
+LOCAL_LIBDIR=../../
|
|
+LIBS= -L${LOCAL_LIBDIR} -lsvm
|
|
+
|
|
INCLUDE = /usr/include/qt4
|
|
-MOC = /usr/bin/moc-qt4
|
|
|
|
-svm-toy: svm-toy.cpp svm-toy.moc ../../svm.o
|
|
- $(CXX) $(CFLAGS) svm-toy.cpp ../../svm.o -o svm-toy
|
|
+MOC=${MOC_PATH}
|
|
+
|
|
+all: svm-toy-qt
|
|
+
|
|
+svm-toy-qt: svm-toy.cpp svm-toy.moc
|
|
+ $(CXX) $(FLAGS) svm-toy.cpp ${LIBS} -o svm-toy-qt
|
|
|
|
svm-toy.moc: svm-toy.cpp
|
|
$(MOC) svm-toy.cpp -o svm-toy.moc
|
|
|
|
-../../svm.o:
|
|
- cd ../..; make svm.o
|
|
-
|
|
clean:
|
|
- rm -f *~ svm-toy svm-toy.moc ../../svm.o
|
|
+ rm -f *~ svm-toy-qt svm-toy.moc ../../svm.o
|
|
|
|
diff -up ./tools/easy.py.orig ./tools/easy.py
|
|
--- ./tools/easy.py.orig 2009-05-14 15:09:29.000000000 +1000
|
|
+++ ./tools/easy.py 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -2,6 +2,7 @@
|
|
|
|
import sys
|
|
import os
|
|
+from distutils.sysconfig import get_python_lib
|
|
from subprocess import *
|
|
|
|
if len(sys.argv) <= 1:
|
|
@@ -12,10 +13,10 @@ if len(sys.argv) <= 1:
|
|
|
|
is_win32 = (sys.platform == 'win32')
|
|
if not is_win32:
|
|
- svmscale_exe = "../svm-scale"
|
|
- svmtrain_exe = "../svm-train"
|
|
- svmpredict_exe = "../svm-predict"
|
|
- grid_py = "./grid.py"
|
|
+ svmscale_exe = "/usr/bin/svm-scale"
|
|
+ svmtrain_exe = "/usr/bin/svm-train"
|
|
+ svmpredict_exe = "/usr/bin/svm-predict"
|
|
+ grid_py = get_python_lib(1)+"/libsvm/grid.py"
|
|
gnuplot_exe = "/usr/bin/gnuplot"
|
|
else:
|
|
# example for windows
|
|
diff -up ./tools/grid.py.orig ./tools/grid.py
|
|
--- ./tools/grid.py.orig 2009-05-14 15:09:29.000000000 +1000
|
|
+++ ./tools/grid.py 2009-11-04 14:13:41.000000000 +1000
|
|
@@ -1,7 +1,5 @@
|
|
#!/usr/bin/env python
|
|
|
|
-
|
|
-
|
|
import os, sys, traceback
|
|
import getpass
|
|
from threading import Thread
|
|
@@ -17,7 +15,7 @@ else:
|
|
|
|
is_win32 = (sys.platform == 'win32')
|
|
if not is_win32:
|
|
- svmtrain_exe = "../svm-train"
|
|
+ svmtrain_exe = "/usr/bin/svm-train"
|
|
gnuplot_exe = "/usr/bin/gnuplot"
|
|
else:
|
|
# example for windows
|
|
@@ -74,7 +72,7 @@ Usage: grid.py [-log2c begin,end,step] [
|
|
i = i + 1
|
|
fold = argv[i]
|
|
elif argv[i] in ('-c','-g'):
|
|
- print("Option -c and -g are renamed.")
|
|
+ print "Option -c and -g are renamed."
|
|
print(usage)
|
|
sys.exit(1)
|
|
elif argv[i] == '-svmtrain':
|
|
@@ -93,7 +91,8 @@ Usage: grid.py [-log2c begin,end,step] [
|
|
pass_through_options.append(argv[i])
|
|
i = i + 1
|
|
|
|
- pass_through_string = " ".join(pass_through_options)
|
|
+ pass_through_string = " ".join(pass_through_options," ")
|
|
+ print 'dataset_pathname=%s' % dataset_pathname
|
|
assert os.path.exists(svmtrain_exe),"svm-train executable not found"
|
|
assert os.path.exists(gnuplot_exe),"gnuplot executable not found"
|
|
assert os.path.exists(dataset_pathname),"dataset not found"
|
|
@@ -127,7 +126,9 @@ def permute_sequence(seq):
|
|
|
|
def redraw(db,best_param,tofile=False):
|
|
if len(db) == 0: return
|
|
- begin_level = round(max(x[2] for x in db)) - 3
|
|
+ begin_level = round(max(x[2] for x in db)) - 3
|
|
+
|
|
+ begin_level = round(max(map(lambda(x):x[2],db))) - 3
|
|
step_size = 0.5
|
|
|
|
best_log2c,best_log2g,best_rate = best_param
|
|
@@ -158,12 +159,12 @@ def redraw(db,best_param,tofile=False):
|
|
gnuplot.write(("set label \"C = %s gamma = %s\""
|
|
" at screen 0.5,0.8 center\n" % (2**best_log2c, 2**best_log2g)).encode())
|
|
gnuplot.write("splot \"-\" with lines\n".encode())
|
|
-
|
|
-
|
|
-
|
|
-
|
|
+
|
|
+
|
|
+
|
|
+
|
|
db.sort(key = lambda x:(x[0], -x[1]))
|
|
-
|
|
+
|
|
prevc = db[0][0]
|
|
for line in db:
|
|
if prevc != line[0]:
|
|
@@ -222,9 +223,7 @@ class Worker(Thread):
|
|
if rate is None: raise "get no rate"
|
|
except:
|
|
# we failed, let others do that and we just quit
|
|
-
|
|
traceback.print_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])
|
|
-
|
|
self.job_queue.put((cexp,gexp))
|
|
print('worker %s quit.' % self.name)
|
|
break
|
|
@@ -251,8 +250,8 @@ class SSHWorker(Worker):
|
|
svmtrain_exe,c,g,fold,pass_through_string,dataset_pathname)
|
|
result = Popen(cmdline,shell=True,stdout=PIPE).stdout
|
|
for line in result.readlines():
|
|
- if str(line).find("Cross") != -1:
|
|
- return float(line.split()[-1][0:-1])
|
|
+ if find(line,"Cross") != -1:
|
|
+ return float(split(line)[-1][0:-1])
|
|
|
|
class TelnetWorker(Worker):
|
|
def __init__(self,name,job_queue,result_queue,host,username,password):
|
|
@@ -302,7 +301,6 @@ def main():
|
|
|
|
job_queue._put = job_queue.queue.appendleft
|
|
|
|
-
|
|
# fire telnet workers
|
|
|
|
if telnet_workers:
|
|
@@ -328,10 +326,8 @@ def main():
|
|
|
|
done_jobs = {}
|
|
|
|
-
|
|
result_file = open(out_filename, 'w')
|
|
|
|
-
|
|
db = []
|
|
best_rate = -1
|
|
best_c1,best_g1 = None,None
|
|
@@ -343,13 +339,14 @@ def main():
|
|
done_jobs[(c1,g1)] = rate
|
|
result_file.write('%s %s %s\n' %(c1,g1,rate))
|
|
result_file.flush()
|
|
+ print "[%s] %s %s %s" % (worker,c1,g1,rate),
|
|
if (rate > best_rate) or (rate==best_rate and g1==best_g1 and c1<best_c1):
|
|
best_rate = rate
|
|
best_c1,best_g1=c1,g1
|
|
best_c = 2.0**c1
|
|
best_g = 2.0**g1
|
|
print("[%s] %s %s %s (best c=%s, g=%s, rate=%s)" % \
|
|
- (worker,c1,g1,rate, best_c, best_g, best_rate))
|
|
+ (worker,c1,g1,rate, best_c, best_g, best_rate))
|
|
db.append((c,g,done_jobs[(c,g)]))
|
|
redraw(db,[best_c1, best_g1, best_rate])
|
|
redraw(db,[best_c1, best_g1, best_rate],True)
|