[Scipy-svn] r2079 - trunk/Lib/sandbox/svm

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Jul 11 15:14:21 EDT 2006


Author: fullung
Date: 2006-07-11 14:13:55 -0500 (Tue, 11 Jul 2006)
New Revision: 2079

Modified:
   trunk/Lib/sandbox/svm/classification.py
   trunk/Lib/sandbox/svm/model.py
   trunk/Lib/sandbox/svm/regression.py
Log:
Let ctypes handle references to the contents of the svm_problem.


Modified: trunk/Lib/sandbox/svm/classification.py
===================================================================
--- trunk/Lib/sandbox/svm/classification.py	2006-07-11 17:47:07 UTC (rev 2078)
+++ trunk/Lib/sandbox/svm/classification.py	2006-07-11 19:13:55 UTC (rev 2079)
@@ -130,7 +130,7 @@
         This function returns the percentage of data that was
         classified correctly over all the experiments.
         """
-        problem, y, x = self._create_problem(dataset)
+        problem = self._create_problem(dataset)
         target = N.empty((len(dataset.data),), dtype=N.float64)
         tp = cast(target.ctypes.data, POINTER(c_double))
         libsvm.svm_cross_validation(problem, self.param, nr_fold, tp)

Modified: trunk/Lib/sandbox/svm/model.py
===================================================================
--- trunk/Lib/sandbox/svm/model.py	2006-07-11 17:47:07 UTC (rev 2078)
+++ trunk/Lib/sandbox/svm/model.py	2006-07-11 19:13:55 UTC (rev 2079)
@@ -66,15 +66,13 @@
         for i, (yi, xi) in enumerate(dataset.data):
             y[i] = yi
             x[i] = cast(xi.ctypes.data, POINTER(libsvm.svm_node))
-        problem.x = cast(addressof(x), POINTER(POINTER(libsvm.svm_node)))
-        problem.y = cast(addressof(y), POINTER(c_double))
+        problem.x = x
+        problem.y = y
         self._check_problem_param(problem, self.param)
-        # XXX keep references to y and x inside problem, if ctypes allows
-        # it (need to confirm this)
-        return problem, y, x
+        return problem
 
     def fit(self, dataset):
-        problem, y, x = self._create_problem(dataset)
+        problem = self._create_problem(dataset)
 
         model = libsvm.svm_train(problem, self.param)
 

Modified: trunk/Lib/sandbox/svm/regression.py
===================================================================
--- trunk/Lib/sandbox/svm/regression.py	2006-07-11 17:47:07 UTC (rev 2078)
+++ trunk/Lib/sandbox/svm/regression.py	2006-07-11 19:13:55 UTC (rev 2079)
@@ -66,7 +66,7 @@
         error and the squared correlation coefficient.
         """
 
-        problem, y, x = self._create_problem(dataset)
+        problem = self._create_problem(dataset)
         target = N.empty((len(dataset.data),), dtype=N.float64)
         tp = cast(target.ctypes.data, POINTER(c_double))
         libsvm.svm_cross_validation(problem, self.param, nr_fold, tp)




More information about the Scipy-svn mailing list