Skip to content
Browse files

Added PyML

  • Loading branch information...
1 parent f0d6be9 commit d767c9f2bfa8cce523201f104f3de5ad296f7db9 @pranjalv123 pranjalv123 committed Jan 11, 2012
Showing with 91,532 additions and 0 deletions.
  1. BIN PyML-0.7.9/._LICENSE
  2. BIN PyML-0.7.9/._setup.py
  3. +19 −0 PyML-0.7.9/LICENSE
  4. +10 −0 PyML-0.7.9/PKG-INFO
  5. BIN PyML-0.7.9/PyML/.___init__.py
  6. +8 −0 PyML-0.7.9/PyML/__init__.py
  7. BIN PyML-0.7.9/PyML/base/._pymlObject.py
  8. +2 −0 PyML-0.7.9/PyML/base/__init__.py
  9. +19 −0 PyML-0.7.9/PyML/base/pymlObject.py
  10. BIN PyML-0.7.9/PyML/classifiers/._baseClassifiers.py
  11. BIN PyML-0.7.9/PyML/classifiers/._composite.py
  12. BIN PyML-0.7.9/PyML/classifiers/._knn.py
  13. BIN PyML-0.7.9/PyML/classifiers/._libsvmWrap.py
  14. BIN PyML-0.7.9/PyML/classifiers/._multi.py
  15. BIN PyML-0.7.9/PyML/classifiers/._platt.py
  16. BIN PyML-0.7.9/PyML/classifiers/._ridgeRegression.py
  17. BIN PyML-0.7.9/PyML/classifiers/._svm.py
  18. +6 −0 PyML-0.7.9/PyML/classifiers/__init__.py
  19. +153 −0 PyML-0.7.9/PyML/classifiers/baseClassifiers.py
  20. +290 −0 PyML-0.7.9/PyML/classifiers/composite.py
  21. BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.cpp
  22. BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.h
  23. BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.i
  24. BIN PyML-0.7.9/PyML/classifiers/ext/._Makefile
  25. BIN PyML-0.7.9/PyML/classifiers/ext/._SMO.h
  26. BIN PyML-0.7.9/PyML/classifiers/ext/._SMO.i
  27. BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.cpp
  28. BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.h
  29. BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.i
  30. BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.cpp
  31. BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.h
  32. BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.i
  33. BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.cpp
  34. BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.h
  35. BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.i
  36. +297 −0 PyML-0.7.9/PyML/classifiers/ext/Gist.cpp
  37. +122 −0 PyML-0.7.9/PyML/classifiers/ext/Gist.h
  38. +25 −0 PyML-0.7.9/PyML/classifiers/ext/Gist.i
  39. +9,539 −0 PyML-0.7.9/PyML/classifiers/ext/Gist_wrap.cpp
  40. +157 −0 PyML-0.7.9/PyML/classifiers/ext/KNN.cpp
  41. +30 −0 PyML-0.7.9/PyML/classifiers/ext/KNN.h
  42. +14 −0 PyML-0.7.9/PyML/classifiers/ext/KNN.i
  43. +9,825 −0 PyML-0.7.9/PyML/classifiers/ext/KNN_wrap.cpp
  44. +59 −0 PyML-0.7.9/PyML/classifiers/ext/KernelCache.cpp
  45. +50 −0 PyML-0.7.9/PyML/classifiers/ext/KernelCache.h
  46. +21 −0 PyML-0.7.9/PyML/classifiers/ext/Makefile
  47. +324 −0 PyML-0.7.9/PyML/classifiers/ext/SMO.cpp
  48. +73 −0 PyML-0.7.9/PyML/classifiers/ext/SMO.h
  49. +18 −0 PyML-0.7.9/PyML/classifiers/ext/SMO.i
  50. +9,451 −0 PyML-0.7.9/PyML/classifiers/ext/SMO_wrap.cpp
  51. +111 −0 PyML-0.7.9/PyML/classifiers/ext/SVModel.cpp
  52. +76 −0 PyML-0.7.9/PyML/classifiers/ext/SVModel.h
  53. +15 −0 PyML-0.7.9/PyML/classifiers/ext/SVModel.i
  54. +10,837 −0 PyML-0.7.9/PyML/classifiers/ext/SVModel_wrap.cpp
  55. +1 −0 PyML-0.7.9/PyML/classifiers/ext/__init__.py
  56. +201 −0 PyML-0.7.9/PyML/classifiers/ext/cgist.py
  57. +197 −0 PyML-0.7.9/PyML/classifiers/ext/csmo.py
  58. +275 −0 PyML-0.7.9/PyML/classifiers/ext/csvmodel.py
  59. +222 −0 PyML-0.7.9/PyML/classifiers/ext/knn.py
  60. +3,148 −0 PyML-0.7.9/PyML/classifiers/ext/libsvm.cpp
  61. +96 −0 PyML-0.7.9/PyML/classifiers/ext/libsvm.h
  62. +71 −0 PyML-0.7.9/PyML/classifiers/ext/libsvm.i
  63. +296 −0 PyML-0.7.9/PyML/classifiers/ext/libsvm.py
  64. +6,701 −0 PyML-0.7.9/PyML/classifiers/ext/libsvm_wrap.cpp
  65. +13 −0 PyML-0.7.9/PyML/classifiers/ext/mylibsvm.cpp
  66. +27 −0 PyML-0.7.9/PyML/classifiers/ext/mylibsvm.h
  67. +8 −0 PyML-0.7.9/PyML/classifiers/ext/mylibsvm.i
  68. +74 −0 PyML-0.7.9/PyML/classifiers/ext/mylibsvm.py
  69. +3,433 −0 PyML-0.7.9/PyML/classifiers/ext/mylibsvm_wrap.cpp
  70. +104 −0 PyML-0.7.9/PyML/classifiers/knn.py
  71. +48 −0 PyML-0.7.9/PyML/classifiers/lazyclass.py
  72. BIN PyML-0.7.9/PyML/classifiers/liblinear/._Makefile
  73. +21 −0 PyML-0.7.9/PyML/classifiers/liblinear/Makefile
  74. +2 −0 PyML-0.7.9/PyML/classifiers/liblinear/__init__.py
  75. +301 −0 PyML-0.7.9/PyML/classifiers/liblinear/mylinear.cpp
  76. +12 −0 PyML-0.7.9/PyML/classifiers/liblinear/mylinear.h
  77. +16 −0 PyML-0.7.9/PyML/classifiers/liblinear/mylinear.i
  78. +197 −0 PyML-0.7.9/PyML/classifiers/liblinear/mylinear.py
  79. +9,466 −0 PyML-0.7.9/PyML/classifiers/liblinear/mylinear_wrap.cpp
  80. +29 −0 PyML-0.7.9/PyML/classifiers/libsvmWrap.py
  81. +308 −0 PyML-0.7.9/PyML/classifiers/modelSelection.py
  82. +156 −0 PyML-0.7.9/PyML/classifiers/multi.py
  83. +459 −0 PyML-0.7.9/PyML/classifiers/platt.py
  84. +317 −0 PyML-0.7.9/PyML/classifiers/random_forests.py
  85. +65 −0 PyML-0.7.9/PyML/classifiers/ridgeRegression.py
  86. +576 −0 PyML-0.7.9/PyML/classifiers/svm.py
  87. +31 −0 PyML-0.7.9/PyML/classifiers/template.py
  88. BIN PyML-0.7.9/PyML/clusterers/._baseClusterer.py
  89. BIN PyML-0.7.9/PyML/clusterers/._kmeans.py
  90. +4 −0 PyML-0.7.9/PyML/clusterers/__init__.py
  91. +59 −0 PyML-0.7.9/PyML/clusterers/baseClusterer.py
  92. BIN PyML-0.7.9/PyML/clusterers/ext/._Makefile
  93. BIN PyML-0.7.9/PyML/clusterers/ext/._kmeans.cpp
  94. BIN PyML-0.7.9/PyML/clusterers/ext/._kmeans.h
  95. BIN PyML-0.7.9/PyML/clusterers/ext/._kmeans.i
  96. +17 −0 PyML-0.7.9/PyML/clusterers/ext/Makefile
  97. +1 −0 PyML-0.7.9/PyML/clusterers/ext/__init__.py
  98. +205 −0 PyML-0.7.9/PyML/clusterers/ext/ckmeans.py
  99. +124 −0 PyML-0.7.9/PyML/clusterers/ext/kmeans.cpp
  100. +41 −0 PyML-0.7.9/PyML/clusterers/ext/kmeans.h
  101. +15 −0 PyML-0.7.9/PyML/clusterers/ext/kmeans.i
  102. +9,396 −0 PyML-0.7.9/PyML/clusterers/ext/kmeans_wrap.cpp
  103. +53 −0 PyML-0.7.9/PyML/clusterers/kmeans.py
  104. BIN PyML-0.7.9/PyML/containers/._aggregate.py
  105. BIN PyML-0.7.9/PyML/containers/._baseDatasets.py
  106. BIN PyML-0.7.9/PyML/containers/._datafunc.py
  107. BIN PyML-0.7.9/PyML/containers/._ker.py
  108. BIN PyML-0.7.9/PyML/containers/._kernelData.py
  109. BIN PyML-0.7.9/PyML/containers/._labels.py
  110. BIN PyML-0.7.9/PyML/containers/._pairData.py
  111. BIN PyML-0.7.9/PyML/containers/._parsers.py
  112. BIN PyML-0.7.9/PyML/containers/._sequenceData.py
  113. BIN PyML-0.7.9/PyML/containers/._vectorDatasets.py
  114. +12 −0 PyML-0.7.9/PyML/containers/__init__.py
  115. +130 −0 PyML-0.7.9/PyML/containers/aggregate.py
  116. +553 −0 PyML-0.7.9/PyML/containers/baseDatasets.py
  117. +531 −0 PyML-0.7.9/PyML/containers/datafunc.py
  118. BIN PyML-0.7.9/PyML/containers/ext/._Aggregate.cpp
  119. BIN PyML-0.7.9/PyML/containers/ext/._Aggregate.h
  120. BIN PyML-0.7.9/PyML/containers/ext/._Aggregate.i
  121. BIN PyML-0.7.9/PyML/containers/ext/._DataSet.cpp
  122. BIN PyML-0.7.9/PyML/containers/ext/._DataSet.h
  123. BIN PyML-0.7.9/PyML/containers/ext/._Feature.h
  124. BIN PyML-0.7.9/PyML/containers/ext/._FeatureVector.cpp
  125. BIN PyML-0.7.9/PyML/containers/ext/._FeatureVector.h
  126. BIN PyML-0.7.9/PyML/containers/ext/._Kernel.cpp
  127. BIN PyML-0.7.9/PyML/containers/ext/._Kernel.h
  128. BIN PyML-0.7.9/PyML/containers/ext/._Kernel.i
  129. BIN PyML-0.7.9/PyML/containers/ext/._KernelData.cpp
  130. BIN PyML-0.7.9/PyML/containers/ext/._KernelData.h
  131. BIN PyML-0.7.9/PyML/containers/ext/._KernelData.i
  132. BIN PyML-0.7.9/PyML/containers/ext/._Makefile
  133. BIN PyML-0.7.9/PyML/containers/ext/._PairDataSet.h
  134. BIN PyML-0.7.9/PyML/containers/ext/._PairDataSet.i
  135. BIN PyML-0.7.9/PyML/containers/ext/._SequenceData.cpp
  136. BIN PyML-0.7.9/PyML/containers/ext/._SequenceData.h
  137. BIN PyML-0.7.9/PyML/containers/ext/._SequenceData.i
  138. BIN PyML-0.7.9/PyML/containers/ext/._SetData.h
  139. BIN PyML-0.7.9/PyML/containers/ext/._SetData.i
  140. BIN PyML-0.7.9/PyML/containers/ext/._SparseDataSet.cpp
  141. BIN PyML-0.7.9/PyML/containers/ext/._SparseDataSet.h
  142. BIN PyML-0.7.9/PyML/containers/ext/._SparseDataSet.i
  143. BIN PyML-0.7.9/PyML/containers/ext/._SparseFeatureVector.cpp
  144. BIN PyML-0.7.9/PyML/containers/ext/._SparseFeatureVector.h
  145. BIN PyML-0.7.9/PyML/containers/ext/._SparseFeatureVector.i
  146. BIN PyML-0.7.9/PyML/containers/ext/._StringKernel.cpp
  147. BIN PyML-0.7.9/PyML/containers/ext/._StringKernel.h
  148. BIN PyML-0.7.9/PyML/containers/ext/._StringKernels.cpp
  149. BIN PyML-0.7.9/PyML/containers/ext/._VectorDataSet.cpp
  150. BIN PyML-0.7.9/PyML/containers/ext/._VectorDataSet.h
  151. BIN PyML-0.7.9/PyML/containers/ext/._VectorDataSet.i
  152. +62 −0 PyML-0.7.9/PyML/containers/ext/Aggregate.cpp
  153. +50 −0 PyML-0.7.9/PyML/containers/ext/Aggregate.h
  154. +17 −0 PyML-0.7.9/PyML/containers/ext/Aggregate.i
  155. +10,876 −0 PyML-0.7.9/PyML/containers/ext/Aggregate_wrap.cpp
  156. +73 −0 PyML-0.7.9/PyML/containers/ext/DataSet.cpp
  157. +57 −0 PyML-0.7.9/PyML/containers/ext/DataSet.h
  158. +17 −0 PyML-0.7.9/PyML/containers/ext/Feature.h
  159. +37 −0 PyML-0.7.9/PyML/containers/ext/FeatureListIterator.h
  160. +116 −0 PyML-0.7.9/PyML/containers/ext/FeatureVector.cpp
  161. +41 −0 PyML-0.7.9/PyML/containers/ext/FeatureVector.h
  162. +40 −0 PyML-0.7.9/PyML/containers/ext/FeatureVectorIterator.h
  163. +216 −0 PyML-0.7.9/PyML/containers/ext/Kernel.cpp
  164. +146 −0 PyML-0.7.9/PyML/containers/ext/Kernel.h
  165. +16 −0 PyML-0.7.9/PyML/containers/ext/Kernel.i
  166. +67 −0 PyML-0.7.9/PyML/containers/ext/KernelData.cpp
  167. +51 −0 PyML-0.7.9/PyML/containers/ext/KernelData.h
  168. +87 −0 PyML-0.7.9/PyML/containers/ext/KernelData.i
Sorry, we could not display the entire diff because too many files (1,038) changed.
View
BIN PyML-0.7.9/._LICENSE
Binary file not shown.
View
BIN PyML-0.7.9/._setup.py
Binary file not shown.
View
19 PyML-0.7.9/LICENSE
@@ -0,0 +1,19 @@
+
+PyML -- a machine learning library in python.
+
+Copyright (C) 2004-2011 Asa Ben-Hur
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
View
10 PyML-0.7.9/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: PyML
+Version: 0.7.9
+Summary: PyML - a Python machine learning package
+Home-page: http://pyml.sourceforge.net
+Author: Asa Ben-Hur
+Author-email: myfirstname@cs.colostate.edu
+License: GPL
+Description: UNKNOWN
+Platform: UNKNOWN
View
BIN PyML-0.7.9/PyML/.___init__.py
Binary file not shown.
View
8 PyML-0.7.9/PyML/__init__.py
@@ -0,0 +1,8 @@
+
+__version__ = '0.7.9'
+
+from PyML.containers import *
+from PyML.classifiers import *
+from PyML.preproc import *
+from PyML.demo import *
+from PyML.feature_selection import *
View
BIN PyML-0.7.9/PyML/base/._pymlObject.py
Binary file not shown.
View
2 PyML-0.7.9/PyML/base/__init__.py
@@ -0,0 +1,2 @@
+
+#PyMLobject = __import__('base.pymlObject').pymlObject.PyMLobject
View
19 PyML-0.7.9/PyML/base/pymlObject.py
@@ -0,0 +1,19 @@
+
+class PyMLobject (object) :
+
+ def __init__(self, arg=None, **args) :
+ """
+ Takes care of keyword arguments that are defined in the attributes
+ class attribute
+ """
+ if not hasattr(self, 'attributes') : return
+ if self.__class__ == arg.__class__ :
+ for attribute in self.attributes :
+ setattr(self, attribute, getattr(arg, attribute))
+ else :
+ for attribute in self.attributes :
+ if attribute in args :
+ setattr(self, attribute, args[attribute])
+ else :
+ setattr(self, attribute, self.attributes[attribute])
+
View
BIN PyML-0.7.9/PyML/classifiers/._baseClassifiers.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._composite.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._knn.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._libsvmWrap.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._multi.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._platt.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._ridgeRegression.py
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/._svm.py
Binary file not shown.
View
6 PyML-0.7.9/PyML/classifiers/__init__.py
@@ -0,0 +1,6 @@
+
+SVM = __import__('PyML.classifiers.svm', fromlist=['']).SVM
+KNN = __import__('PyML.classifiers.knn', fromlist=['']).KNN
+RidgeRegression = __import__('PyML.classifiers.ridgeRegression', fromlist=['']).RidgeRegression
+import modelSelection
+
View
153 PyML-0.7.9/PyML/classifiers/baseClassifiers.py
@@ -0,0 +1,153 @@
+import numpy
+import time
+import copy
+
+from PyML.evaluators import assess,resultsObjects
+from PyML.utils import misc
+from PyML.base.pymlObject import PyMLobject
+
+"""base class for for PyML classifiers"""
+
+__docformat__ = "restructuredtext en"
+
+containersRequiringProjection = ['VectorDataSet']
+
+class Classifier (PyMLobject) :
+
+ """base class for PyML classifiers, specifying the classifier api"""
+
+ type = 'classifier'
+ deepcopy = False
+
+ # the type of Results object returned by testing a classifier:
+ resultsObject = resultsObjects.ClassificationResults
+
+ test = assess.test
+ cv = assess.cv
+ stratifiedCV = assess.stratifiedCV
+ loo = assess.loo
+ trainTest = assess.trainTest
+ nCV = assess.nCV
+
+ def __init__(self, arg = None, **args) :
+
+ PyMLobject.__init__(self, arg, **args)
+ if type(arg) == type('') :
+ self.load(arg)
+ self.log = misc.Container()
+
+ def logger(self) :
+
+ pass
+
+ def __repr__(self) :
+
+ return '<' + self.__class__.__name__ + ' instance>\n'
+
+ def verifyData(self, data) :
+ """
+ verify that for a VectorDataSet the test examples refer to the same
+ features used in training.
+ """
+
+ if data.__class__.__name__ != 'VectorDataSet' :
+ return
+ if len(misc.intersect(self.featureID, data.featureID)) != len(self.featureID) :
+ raise ValueError, 'missing features in test data'
+
+
+ def save(self, fileHandle) :
+
+ raise NotImplementedError, 'your classifier does not implement this function'
+
+ def train(self, data, **args) :
+
+ # store the current cpu time:
+ self._clock = time.clock()
+
+ if not data.labels.numericLabels :
+ # check if there is a class that is not represented in the training data:
+ if min(data.labels.classSize) == 0 :
+ raise ValueError, 'there is a class with no data'
+
+ # store just as much about the labels as is needed:
+ self.labels = misc.Container()
+ self.labels.addAttributes(data.labels, ['numClasses', 'classLabels'])
+ # if dealing with a VectorDataSet test data needs to have the same features
+ if data.__class__.__name__ == 'VectorDataSet' :
+ self.featureID = data.featureID[:]
+
+ data.train(**args)
+ # if there is some testing done on the data, it requires the training data:
+ if data.testingFunc is not None :
+ self.trainingData = data
+
+ def trainFinalize(self) :
+
+ self.log.trainingTime = self.getTrainingTime()
+
+ def getTrainingTime(self) :
+
+ return time.clock() - self._clock
+
+ def classify(self, data, i) :
+
+ raise NotImplementedError
+
+ def twoClassClassify(self, data, i) :
+
+ val = self.decisionFunc(data, i)
+ if val > 0 :
+ return (1, val)
+ else:
+ return (0, val)
+
+class IteratorClassifier (Classifier) :
+
+ def __iter__(self) :
+
+ self._classifierIdx = -1
+ return self
+
+ def getClassifier(self) :
+
+ if self._classifierIdx < 0 :
+ return None
+ return self.classifiers[self._classifierIdx]
+
+ def next(self) :
+
+ self._classifierIdx += 1
+ if self._classifierIdx == len(self.classifiers) :
+ raise StopIteration
+ func = getattr(self.classifiers[self._classifierIdx], self._method)
+
+ return func(self._data, **self._args)
+
+ def test(self, data, **args) :
+
+ self._method = 'test'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def cv(self, data, **args) :
+
+ self._method = 'cv'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def stratifiedCV(self, data, **args) :
+
+ self._method = 'stratifiedCV'
+ self._data = data
+ self._args = args
+ return iter(self)
+
+ def loo(self, data, **args) :
+
+ self._method = 'loo'
+ self._data = data
+ self._args = args
+ return iter(self)
View
290 PyML-0.7.9/PyML/classifiers/composite.py
@@ -0,0 +1,290 @@
+
+import numpy
+import math
+
+from PyML.utils import misc
+from PyML.datagen import sample
+from PyML.evaluators import assess
+from baseClassifiers import Classifier, IteratorClassifier
+import svm
+
+__docformat__ = "restructuredtext en"
+
+class CompositeClassifier (Classifier) :
+
+ '''A base class for creating composite classifiers
+
+ A composite classifier has an attribute called "classifier", and by default
+ requests are forwarded to the appropriate function of the classifier
+ (including the "test" function).
+ For logging purposes, use the log attribute of the classifier rather
+ than the composite log.
+ See for example the FeatureSelect object.'''
+
+ deepcopy = True
+
+ def __init__(self, classifier, **args) :
+
+ Classifier.__init__(self, classifier, **args)
+ if type(classifier) == type('') : return
+ if (not hasattr(classifier, 'type')) or classifier.type != 'classifier' :
+ raise ValueError, 'argument should be a classifier'
+ if classifier.__class__ == self.__class__ :
+ self.classifier = classifier.classifier.__class__(
+ classifier.classifier)
+ else :
+ self.classifier = classifier.__class__(classifier)
+
+ def __repr__(self) :
+ rep = '<' + self.__class__.__name__ + ' instance>\n'
+ rep += 'Classifier:\n'
+ rep += self.classifier.__repr__()
+
+ return rep
+
+ def preproject(self, data) :
+
+ self.classifier.preproject(data)
+
+ def decisionFunc(self, data, i) :
+
+ return self.classifier.decisionFunc(data, i)
+
+ def classify(self, data, i) :
+
+ return self.classifier.classify(data, i)
+
+
+ #def preprocess(self, data) :
+
+ # self.classifier.preprocess(data)
+
+ def getTest(self) :
+
+ return self.classifier.test
+
+ def setTest(self) :
+
+ raise ValueError, 'do not call this function'
+
+ # if the classifier used by the composite implements a test function -
+ # use it rather than the default assess.test
+ test = property (getTest, setTest,
+ None, 'the test function of the underlying classifier')
+
+
+
+class Chain (CompositeClassifier) :
+ '''A chain is a list of actions to be performed on a dataset,
+ the last of which is assumed to be a classifier.
+ The actions can be for example a chain of preprocessing steps or
+ a step of feature selection (same as using the FeatureSelect class)
+ Each action in the chain is assumed to have a "train" method and is
+ assumed to have a copy constructor'''
+
+ deepcopy = True
+
+ def __init__(self, arg) :
+ """
+ :Parameters:
+ - `arg` - a Chain object of a list of objects, each of which implements
+ a 'train', 'test' and has a copy constructor
+
+ """
+ Classifier.__init__(self)
+
+ if arg.__class__ == self.__class__ :
+ other = arg
+ self.classifier = other.classifier.__class__(other.classifier)
+ self.chain = [component.__class__(component)
+ for component in other.chain]
+
+ elif type(arg) == type([]) :
+ self.classifier = arg[-1].__class__(arg[-1])
+ self.chain = [arg[i].__class__(arg[i])
+ for i in range(len(arg) - 1)]
+
+
+ def train(self, data, **args) :
+
+ Classifier.train(self, data, **args)
+
+ for component in self.chain :
+ component.train(data, **args)
+
+ self.classifier.train(data, **args)
+ self.log.trainingTime = self.getTrainingTime()
+
+ def test(self, data, **args) :
+
+ for component in self.chain :
+ component.test(data, **args)
+
+ print 'I am testing',self.classifier
+ print 'testing function', self.classifier.test
+ print 'the data is :', data
+ return self.classifier.test(data, **args)
+
+class FeatureSelect (CompositeClassifier) :
+
+ """A method for combining a feature selector and classifier;
+ training consists of performing feature selection and afterwards training
+ the classifier on the selected features;
+ use this classifier to test the accuracy of a feature selector/classifier
+ combination.
+ USAGE:
+ construction :
+ featureSelect(classifier, featureSelector)
+ featureSelect(otherFeatureSelectInstance) - copy construction
+ """
+
+ deepcopy = True
+
+ def __init__(self, arg1, arg2 = None) :
+
+ Classifier.__init__(self)
+
+ if arg1.__class__ == self.__class__ :
+ other = arg1
+ self.classifier = other.classifier.__class__(other.classifier)
+ self.featureSelector = other.featureSelector.__class__(
+ other.featureSelector)
+ else :
+ for arg in (arg1, arg2) :
+ if arg.type == 'classifier' :
+ self.classifier = arg.__class__(arg)
+ elif arg.type == 'featureSelector' :
+ self.featureSelector = arg.__class__(arg)
+ else :
+ raise ValueError, \
+ 'argument should be either classifier or featureSelector'
+
+
+ def __repr__(self) :
+
+ rep = '<' + self.__class__.__name__ + ' instance>\n'
+ if hasattr(self, 'numFeatures') :
+ rep += 'number of features trained on:' + str(self.numFeatures) + '\n'
+ rep += 'Classifier:\n'
+ rep += self.classifier.__repr__()
+ rep += 'Feature Selector:\n'
+ rep += self.featureSelector.__repr__()
+
+ return rep
+
+
+ def train(self, data, **args) :
+
+ Classifier.train(self, data, **args)
+
+ self.featureSelector.select(data, **args)
+ #self.numFeatures = data.numFeatures
+ self.classifier.log.numFeatures = data.numFeatures
+ self.classifier.log.features = data.featureID[:]
+
+ self.classifier.train(data, **args)
+ self.classifier.log.trainingTime = self.getTrainingTime()
+
+
+class FeatureSelectAll (IteratorClassifier) :
+
+ '''A method for combining a feature selector and classifier;
+ the difference from FeatureSelect is that it is specifically
+ designed for computing the accuracy while varying the
+ number of features.
+ '''
+
+ deepcopy = True
+
+ def __init__(self, arg1, arg2 = None) :
+
+ Classifier.__init__(self)
+
+ if arg1.__class__ == self.__class__ :
+ other = arg1
+ self.classifier = other.classifier.__class__(other.classifier)
+ self.featureSelector = other.featureSelector.__class__(
+ other.featureSelector)
+ else :
+ for arg in (arg1, arg2) :
+ if arg.type == 'classifier' :
+ self.classifier = arg.__class__(arg)
+ elif arg.type == 'featureSelector' :
+ self.featureSelector = arg.__class__(arg)
+ else :
+ raise ValueError, \
+ 'argument should be either classifier or featureSelector'
+
+
+ def train(self, data, **args) :
+
+ Classifier.train(self, data, **args)
+
+ numFeatures = []
+ n = 1
+ while n < data.numFeatures :
+ numFeatures.append(n)
+ n *=2
+
+ self.classifiers = [self.classifier.__class__(self.classifier)
+ for i in range(len(numFeatures))]
+
+ featureSelector = self.featureSelector.__class__(self.featureSelector)
+ rankedFeatures = featureSelector.rank(data)
+
+ for i in range(len(numFeatures)) :
+ selectedData = data.__class__(data)
+ selectedData.keepFeatures(rankedFeatures[:numFeatures[i]])
+ self.classifiers[i].train(selectedData)
+ self.classifiers[i].log.numFeatures = selectedData.numFeatures
+
+ self.classifier.log.trainingTime = self.getTrainingTime()
+
+
+
+class AggregateClassifier (Classifier) :
+
+ """
+ classifier combines the predictions of classifiers trained on
+ different datasets.
+ The datasets are presented as a DataAggregate dataset container.
+ """
+
+ def __init__ (self, arg) :
+
+ Classifier.__init__(self)
+ if arg.__class__ == self.__class__ :
+ self.classifiers = [classifier.__class__(classifier)
+ for classifier in arg.classifiers]
+ elif type(arg) == type([]) :
+ self.classifiers = [classifier.__class__(classifier)
+ for classifier in arg]
+
+ def train(self, data, **args) :
+
+ Classifier.train(self, data, **args)
+ if not data.__class__.__name__ == 'DataAggregate' :
+ raise ValueError, 'train requires a DataAggregate dataset'
+
+ for i in range(len(self.classifiers)) :
+ self.classifiers[i].train(data.datas[i], **args)
+ self.log.trainingTime = self.getTrainingTime()
+
+ def classify(self, data, p) :
+
+ if not data.__class__.__name__ == 'DataAggregate' :
+ raise ValueError, 'classify requires a DataAggregate dataset'
+
+ decisionFuncs = [self.classifiers[i].decisionFunc(data.datas[i], p)
+ for i in range(len(self.classifiers))]
+ #decisionFunc = numpy.sum(decisionFuncs)
+ #if decisionFunc > 0 :
+ # return (1, decisionFunc)
+ #else :
+ # return (0, decisionFunc)
+ if decisionFuncs[0] > 0 and decisionFuncs[1] > 0 :
+ return 1, numpy.sum(decisionFuncs)
+ else :
+ return 0, min(decisionFuncs)
+
+
View
BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.cpp
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.h
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._KNN.i
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._Makefile
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._SMO.h
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._SMO.i
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.cpp
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.h
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._SVModel.i
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.cpp
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.h
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._libsvm.i
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.cpp
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.h
Binary file not shown.
View
BIN PyML-0.7.9/PyML/classifiers/ext/._mylibsvm.i
Binary file not shown.
View
297 PyML-0.7.9/PyML/classifiers/ext/Gist.cpp
@@ -0,0 +1,297 @@
+# include "Gist.h"
+# include <math.h>
+
+Gist::Gist(DataSet *_data,
+ const std::vector<double> &C_,
+ const int _cacheSize,
+ const int _maxiter) :
+ data(_data),
+ C(C_),
+ maxiter(_maxiter),
+ eps(0.001),
+ tolerance(0.001),
+ convergenceThreshold(1e-4),
+ alpha(_data->size()),
+ isLinear(false),
+ Y(_data->size()),
+ cache(_data, _cacheSize)
+{
+ cout << "constructing gist object" << endl;
+ for (int i = 0; i < data->size(); i++) {
+ //Kdiag[i] = data->kernel->eval(data, i, i);
+ Y[i] = double(data->Y[i]) * 2.0 - 1.0;
+ }
+ cout << "constructed GIST object" << endl;
+
+}
+
+Gist::~Gist()
+{
+ cout << "in Gist::~Gist" << endl;
+ //delete data;
+}
+
+bool Gist::optimize()
+{
+ int iter = 0;
+
+ while (!converged()) {
+ if (iter % 100 == 1) {
+ cout << iter << " iterations" << endl;
+ }
+ vector<int> patterns(size());
+ for (int i = 0; i < size(); ++i)
+ patterns[i] = i;
+ random_shuffle(patterns.begin(), patterns.end());
+
+ for (int i = 0; i < size(); ++i) {
+ int pattern = patterns[i];
+ alpha[pattern] = updateAlpha(pattern);
+ }
+ ++iter;
+ if ((maxiter != 0) && (iter >=maxiter)) {
+ cout << "Warning: svm did not converge after " << iter << endl;
+ return false;
+ }
+
+ }
+ return true;
+}
+
+double Gist::decisionFunc(int pattern, vector<float> &kernelRow)
+{
+ double val = 0;
+ for (int i = 0; i < size(); ++i) {
+ val += alpha[i] * Y[i] * kernelRow[i];
+ }
+ return val;
+}
+
+double Gist::updateAlpha(int pattern)
+{
+ vector<float> &currentRow = cache.getRow(pattern);
+
+ double decisionFuncVal = decisionFunc(pattern, currentRow);
+ double newAlpha = 1.0 - Y[pattern] * decisionFuncVal +
+ alpha[pattern] * currentRow[pattern];
+ newAlpha /= currentRow[pattern];
+ //cout << "new alpha before constraint:" << newAlpha << endl;
+ if (newAlpha > C[pattern]) {
+ newAlpha = C[pattern];
+ }
+ else if (newAlpha < 0) {
+ newAlpha = 0.0;
+ }
+ //cout << "new alpha:" << newAlpha << endl;
+
+ return newAlpha;
+
+}
+
+double Gist::objectiveFunction()
+{
+ double obj = 0.0;
+
+ for (int i = 0; i < size(); ++i) {
+ vector<float> &kernelRow = cache.getRow(i);
+ obj += 2.0 * alpha[i] + Y[i] * decisionFunc(i, kernelRow);
+ }
+
+ return obj;
+}
+
+bool Gist::converged()
+{
+ static double prevObjective = 0.0;
+ static int iteration = 0;
+
+ iteration++;
+ if (iteration == 1) {
+ return false;
+ }
+ double obj = objectiveFunction();
+ //cout << "obj: " << obj << endl;
+ double delta = obj - prevObjective;
+ //cout << "delta: " << delta << endl;
+ prevObjective = obj;
+
+
+ if ((delta < 0.0) && (iteration != 1)) {
+ //cout << "Negative delta" << endl;
+ return false;
+ }
+ return (fabs(delta) < convergenceThreshold);
+
+}
+
+void Gist::show() {
+
+ cout << "b: " << b << endl;
+ cout << "alpha:" << endl;
+ for (int i = 0; i < data->size(); i++) {
+ cout << alpha[i] << " " << endl;
+ }
+ cout << endl;
+
+}
+
+void runGist(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations)
+{
+
+ cout << "running gist" << endl;
+ Gist g(data, C, cacheSize, iterations);
+ g.optimize();
+ alpha = g.alpha;
+
+}
+
+
+GradientDescent::GradientDescent(DataSet *_data,
+ const std::vector<double> &C_,
+ const int _cacheSize,
+ const int _maxiter) :
+ data(_data),
+ C(C_),
+ maxiter(_maxiter),
+ eps(0.001),
+ tolerance(0.001),
+ convergenceThreshold(1e-4),
+ learningRate(0.1),
+ alpha(_data->size()),
+ isLinear(false),
+ Y(_data->size()),
+ cache(_data, _cacheSize)
+{
+ for (int i = 0; i < data->size(); i++) {
+ //Kdiag[i] = data->kernel->eval(data, i, i);
+ Y[i] = double(data->Y[i]) * 2.0 - 1.0;
+ }
+ cout << "constructed GradientDescent object" << endl;
+
+}
+
+GradientDescent::~GradientDescent()
+{
+ cout << "in GradientDescent::~GradientDescent" << endl;
+ //delete data;
+}
+
+bool GradientDescent::optimize()
+{
+ int iter = 0;
+
+ while (!converged()) {
+ if (iter % 100 == 1) {
+ cout << iter << " iterations" << endl;
+ }
+ vector<int> patterns(size());
+ for (int i = 0; i < size(); ++i)
+ patterns[i] = i;
+ random_shuffle(patterns.begin(), patterns.end());
+
+ for (int i = 0; i < size(); ++i) {
+ int pattern = patterns[i];
+ alpha[pattern] = updateAlpha(pattern);
+ }
+ ++iter;
+ if ((maxiter != 0) && (iter >=maxiter)) {
+ cout << "Warning: svm did not converge after " << iter << endl;
+ return false;
+ }
+
+ }
+ return true;
+}
+
+double GradientDescent::decisionFunc(int pattern, vector<float> &kernelRow)
+{
+ double val = 0;
+ for (int i = 0; i < size(); ++i) {
+ val += alpha[i] * Y[i] * kernelRow[i];
+ }
+ return val;
+}
+
+double GradientDescent::updateAlpha(int pattern)
+{
+ vector<float> &currentRow = cache.getRow(pattern);
+ double decisionFuncVal = decisionFunc(pattern, currentRow);
+ double newAlpha = alpha[pattern] +
+ learningRate * (1 - Y[pattern] * decisionFuncVal);
+
+ if (newAlpha > C[pattern]) {
+ newAlpha = C[pattern];
+ }
+ else if (newAlpha < 0) {
+ newAlpha = 0.0;
+ }
+ //cout << "new alpha:" << newAlpha << endl;
+
+ return newAlpha;
+
+}
+
+double GradientDescent::objectiveFunction()
+{
+ double obj = 0.0;
+
+ for (int i = 0; i < size(); ++i) {
+ vector<float> &kernelRow = cache.getRow(i);
+ obj += 2.0 * alpha[i] + Y[i] * decisionFunc(i, kernelRow);
+ }
+
+ return obj;
+}
+
+bool GradientDescent::converged()
+{
+ static double prevObjective = 0.0;
+ static int iteration = 0;
+
+ iteration++;
+ if (iteration == 1) {
+ return false;
+ }
+ double obj = objectiveFunction();
+ //cout << "obj: " << obj << endl;
+ double delta = obj - prevObjective;
+ //cout << "delta: " << delta << endl;
+ prevObjective = obj;
+
+
+ if ((delta < 0.0) && (iteration != 1)) {
+ //cout << "Negative delta" << endl;
+ return false;
+ }
+ return (fabs(delta) < convergenceThreshold);
+
+}
+
+void GradientDescent::show() {
+
+ cout << "b: " << b << endl;
+ cout << "alpha:" << endl;
+ for (int i = 0; i < data->size(); i++) {
+ cout << alpha[i] << " " << endl;
+ }
+ cout << endl;
+
+}
+
+void runGradientDescent(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations)
+{
+
+ cout << "running gradient descent" << endl;
+ GradientDescent g(data, C, cacheSize, iterations);
+ g.optimize();
+ alpha = g.alpha;
+
+}
View
122 PyML-0.7.9/PyML/classifiers/ext/Gist.h
@@ -0,0 +1,122 @@
+# ifndef GIST_H
+# define GIST_H
+
+# include "../../containers/ext/SparseDataSet.h"
+# include "../../containers/ext/Kernel.h"
+# include "KernelCache.h"
+
+# include <set>
+# include <ext/hash_set>
+# include <vector>
+# include <algorithm>
+# include <functional>
+#include <string>
+#include <iostream>
+#include <fstream>
+# include <cmath>
+
+#define INF HUGE_VAL
+
+using namespace std;
+
+
+class Gist {
+ public:
+ DataSet *data;
+ std::vector<double> Y;
+ std::vector<double> alpha;
+ double b;
+ double objectiveValue;
+ std::vector<double> C;
+ int maxiter;
+ double eps;
+ double tolerance;
+ double convergenceThreshold;
+
+ KernelCache cache;
+
+ //std::vector<double> Kdiag;
+ bool isLinear;
+
+ int size() { return data->size(); }
+ bool isUpperBound(int i) { return alpha[i] >= C[i]; }
+ bool isLowerBound(int i) { return alpha[i] <= 0; }
+ bool isFree(int i) { return (alpha[i] > 0 && alpha[i] < C[i]);}
+
+ double decisionFunc(int pattern, vector<float> &kernelRow);
+ double objectiveFunction();
+
+ bool optimize();
+ bool converged();
+ double updateAlpha(int pattern);
+
+
+ Gist(DataSet *_data,
+ const std::vector<double> &C_,
+ const int cacheSize,
+ const int maxiter);
+
+ ~Gist();
+
+ void show();
+
+};
+
+void runGist(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations);
+
+class GradientDescent {
+ public:
+ DataSet *data;
+ std::vector<double> Y;
+ std::vector<double> alpha;
+ double b;
+ double objectiveValue;
+ std::vector<double> C;
+ int maxiter;
+ double eps;
+ double tolerance;
+ double convergenceThreshold;
+ double learningRate;
+
+ KernelCache cache;
+
+ bool isLinear;
+
+ int size() { return data->size(); }
+ bool isUpperBound(int i) { return alpha[i] >= C[i]; }
+ bool isLowerBound(int i) { return alpha[i] <= 0; }
+ bool isFree(int i) { return (alpha[i] > 0 && alpha[i] < C[i]);}
+
+ double decisionFunc(int pattern, vector<float> &kernelRow);
+ double objectiveFunction();
+
+ bool optimize();
+ bool converged();
+ double updateAlpha(int pattern);
+
+
+ GradientDescent(DataSet *_data,
+ const std::vector<double> &C_,
+ const int cacheSize,
+ const int maxiter);
+
+ ~GradientDescent();
+
+ void show();
+
+};
+
+void runGradientDescent(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations);
+
+
+
+
+# endif
View
25 PyML-0.7.9/PyML/classifiers/ext/Gist.i
@@ -0,0 +1,25 @@
+%module cgist
+%{
+#include "Gist.h"
+%}
+
+%include "std_vector.i"
+
+namespace std
+{
+ %template(IntVector) vector<int>;
+ %template(DoubleVector) vector<double>;
+};
+
+
+void runGist(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations);
+
+void runGradientDescent(DataSet *data,
+ const std::vector<double> &C,
+ std::vector<double> &alpha,
+ int cacheSize,
+ int iterations);
View
9,539 PyML-0.7.9/PyML/classifiers/ext/Gist_wrap.cpp
9,539 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
157 PyML-0.7.9/PyML/classifiers/ext/KNN.cpp
@@ -0,0 +1,157 @@
+
+# include "KNN.h"
+
+KNN::KNN(int _k = 3) : k(_k)
+{
+}
+
+void KNN::train(DataSet* _data)
+{
+ data = _data;
+
+ numClasses = 0;
+ // xxx use a MAXIMUM function
+ for (unsigned int i = 0; i < data->Y.size(); i++){
+ if (data->Y[i] > numClasses) {
+ numClasses = int(data->Y[i]);
+ }
+ }
+ ++numClasses;
+
+}
+
+
+std::vector<double> KNN::test(DataSet& testdata)
+{
+ int p;
+
+ std::vector<int> labels(testdata.size());
+ std::vector<double> decisionFunction(testdata.size());
+ //decisionFunction.reserve(testdata.size());
+
+ vector<vector<int> > classes(numClasses);
+ for (int i = 0; i < data->size(); i++) {
+ classes[int(data->Y[i])].push_back(i);
+ }
+
+ for (unsigned int i = 0; i < testdata.size(); i++) {
+ //labels.push_back(0);
+ vector<double> classSim(numClasses,0);
+ for (int c = 0; c < numClasses; c++) {
+ vector<double> similarities(classes[c].size());
+ for (unsigned int j = 0; j < classes[c].size(); j++) {
+ p = classes[c][j];
+ //cout << "about to compute kernel" << endl;
+ similarities[j] = data->kernel->eval(data, p, i, &testdata);
+ //cout << "computed kernel" << endl;
+ }
+ partial_sort(similarities.begin(),
+ similarities.begin() + k,
+ similarities.end(),
+ greater<double>());
+ for (int j = 0; j < k; j++) {
+ classSim[c] += similarities[j];
+ }
+ }
+ double largestSimilarity = -1e10;
+ for (int c = 0; c < numClasses; c++) {
+ if (classSim[c] > largestSimilarity) {
+ largestSimilarity = classSim[c];
+ labels[i] = c;
+ }
+ }
+ // find the second largest similarity:
+ double secondLargestSimilarity = -1e10;
+ for (int c = 0; c < numClasses; c++) {
+ if (!(c == labels[i])){
+ if (classSim[c] > secondLargestSimilarity) {
+ secondLargestSimilarity = classSim[c];
+ }
+ }
+ }
+ decisionFunction[i] = largestSimilarity - secondLargestSimilarity;
+ if (numClasses == 2) {
+ decisionFunction[i] = decisionFunction[i] * (labels[i] * 2 - 1);
+ }
+ }
+ cout << labels.size() << " " << decisionFunction.size() << endl;
+ for (int i = 0; i<labels.size(); ++i){
+ decisionFunction.push_back(labels[i]);
+ }
+ cout << "done testing KNN*****************************" << endl;
+
+ return decisionFunction;
+
+}
+
+std::vector<int> KNN::nearestNeighbors(DataSet& testdata, int p)
+{
+ std::vector<int> neighbors;
+
+ vector<double> similarities(data->size());
+ for (int i = 0; i < data->size(); ++i) {
+ similarities[i] = data->kernel->eval(data, i, p, &testdata);
+ }
+ std::vector<double> unorderedSim(similarities);
+ partial_sort(similarities.begin(),
+ similarities.begin() + k,
+ similarities.end(),
+ greater<double>());
+ for (int j = 0; j < k; ++j) {
+ for (int i = 0; i < data->size(); ++i) {
+ if (unorderedSim[j] == similarities[i]) {
+ neighbors.push_back(i);
+ }
+ }
+ }
+
+ return neighbors;
+
+}
+
+
+
+std::vector<double> KNN::classScores(DataSet& testdata, int p)
+{
+ vector<vector<int> > classes(numClasses);
+ for (int i = 0; i < data->size(); i++) {
+ classes[int(data->Y[i])].push_back(i);
+ }
+
+ vector<double> classSim(numClasses, 0);
+ //cout << "i: " << i << endl;
+ for (int c = 0; c < numClasses; c++) {
+ vector<double> similarities(classes[c].size());
+ for (unsigned int j = 0; j < classes[c].size(); j++) {
+ p = classes[c][j];
+ similarities[j] = data->kernel->eval(data, classes[c][j], p, &testdata);
+ }
+ partial_sort(similarities.begin(),
+ similarities.begin() + k,
+ similarities.end(),
+ greater<double>());
+ for (int j = 0; j < k; j++) {
+ classSim[c] += similarities[j];
+ }
+ }
+ return classSim;
+}
+
+int KNN::nearestNeighbor(DataSet& data, int pattern)
+{
+ double maxSim = -1e10;
+ double sim;
+ int nn = 0;
+
+ for (int i = 0; i < data.size(); i++) {
+ if (i != pattern) {
+ sim = data.kernel->eval(&data, pattern, i, &data);
+ if (sim > maxSim) {
+ maxSim = sim;
+ nn = i;
+
+ }
+ }
+ }
+ return nn;
+}
View
30 PyML-0.7.9/PyML/classifiers/ext/KNN.h
@@ -0,0 +1,30 @@
+
+# ifndef KNN_H
+# define KNN_H
+
+# include <vector>
+# include <algorithm>
+# include <iostream>
+# include <functional>
+
+# include "../../containers/ext/DataSet.h"
+
+class KNN {
+ public :
+
+ KNN(int k);
+ DataSet* data;
+ int k;
+ int numClasses;
+
+ void train(DataSet* _data);
+ std::vector<double> test(DataSet& testdata);
+
+ std::vector<double> classScores(DataSet& testdata, int p);
+ int nearestNeighbor(DataSet& data, int pattern);
+ std::vector<int> nearestNeighbors(DataSet& testdata, int p);
+
+};
+
+#endif
+
View
14 PyML-0.7.9/PyML/classifiers/ext/KNN.i
@@ -0,0 +1,14 @@
+%module knn
+%{
+#include "KNN.h"
+%}
+
+%include "std_vector.i"
+
+namespace std
+{
+ %template(IntVector) vector<int>;
+ %template(DoubleVector) vector<double>;
+}
+
+%include "KNN.h"
View
9,825 PyML-0.7.9/PyML/classifiers/ext/KNN_wrap.cpp
9,825 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
59 PyML-0.7.9/PyML/classifiers/ext/KernelCache.cpp
@@ -0,0 +1,59 @@
+# include "KernelCache.h"
+
+KernelCache::KernelCache(DataSet *data_, int cacheMemorySize_) :
+ data(data_),
+ length(data->size()),
+ cacheMemorySize(cacheMemorySize_),
+ numCached(0),
+ _cached(data->size(), false),
+ rows(data->size()),
+ rowPtr(data->size(), 0),
+ lruPtr(data->size())
+{
+ numCacheable = int(float(cacheMemorySize) * 1024.0 * 1024.0 /
+ float(sizeof(float) * length));
+ cout << "numCacheable " << numCacheable << endl;
+}
+
+KernelCache::~KernelCache()
+{
+ //delete data;
+}
+
+vector<float>& KernelCache::getRow(int i)
+{
+ //cout << "gettingRow " << i << endl;
+ if (isCached(i)) {
+ //cout << "cached" << endl;
+ // remove pattern i from its current position in the list
+ lru.erase(lruPtr[i]);
+ }
+ else {
+ //cout << "numCached: " << numCached << endl;
+ if (numCached >= numCacheable) { // need to erase something
+ //cout << "erasing..." << endl;
+ int elementToErase = lru.back();
+ setCached(elementToErase, false);
+ rowPtr[i] = rowPtr[elementToErase];
+ lru.pop_back();
+ }
+ else {
+ // create the new row:
+ //cout << "creating row..." << endl;
+ rowPtr[i] = numCached;
+ rows[numCached] = vector<float>(length);
+ ++numCached;
+ }
+ setCached(i, true);
+ for (int j = 0; j < length; j++) {
+ rows[rowPtr[i]][j] = data->kernel->eval(data, i, j, data);
+ }
+ }
+ lru.insert(lru.begin(), i);
+ lruPtr[i] = lru.begin();
+ //cout << "finished get row" << endl;
+
+ vector<float> &retval = rows[rowPtr[i]];
+ return retval;
+}
+
View
50 PyML-0.7.9/PyML/classifiers/ext/KernelCache.h
@@ -0,0 +1,50 @@
+# ifndef KERNELCACHE_H
+# define KERNELCACHE_H
+
+# include "../../containers/ext/DataSet.h"
+# include "../../containers/ext/Kernel.h"
+
+# include <list>
+# include <set>
+# include <ext/hash_set>
+# include <vector>
+# include <algorithm>
+# include <functional>
+#include <string>
+#include <iostream>
+#include <fstream>
+# include <cmath>
+
+#define INF HUGE_VAL
+
+using namespace std;
+
+class KernelCache {
+ public:
+ DataSet *data;
+ vector<vector<float> > rows; // the rows of the kernel matrix
+ list<int> lru; // a list whose head is the most recently accessed row
+ vector<list<int>::iterator > lruPtr;
+ // a vector that tells the position of each row in the priority list
+ vector<int> rowPtr; // which row in the cache a row in the matrix is stored in
+
+ int cacheMemorySize; //size of cache in MB
+ int length; //number of patterns in dataset
+ int numCacheable; //number of rows that can fit in the cache
+ int numCached;
+
+ // number of patterns in cache
+ int size() { return rows.size(); }
+
+ vector<bool> _cached;
+ bool isCached(int i) { return _cached[i]; }
+ void setCached(int i, bool state) { _cached[i] = state; }
+
+ vector<float>& getRow(int i);
+
+ KernelCache(DataSet *data_, int cacheMemorySize_);
+ ~KernelCache();
+
+};
+
+# endif
View
21 PyML-0.7.9/PyML/classifiers/ext/Makefile
@@ -0,0 +1,21 @@
+
+SWIG=/usr/local/bin/swig
+#PYTHON_INCLUDEDIR=/usr/include/python2.4/
+PYTHON_INCLUDEDIR=/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4
+PYTHON_INCLUDEDIR=/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/
+PYTHON_INCLUDEDIR=/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/
+
+#PYTHON_INCLUDEDIR=/s/chopin/c/proj/protfun/python/x86_64/include/python2.5
+
+HEADERFILES=mylibsvm.i libsvm.i SVModel.i SMO.i Gist.i KNN.i
+
+WRAPPERFILES=$(HEADERFILES:.i=_wrap.cpp)
+
+wrap: $(WRAPPERFILES)
+all: $(WRAPPERFILES)
+
+%_wrap.cpp : %.i %.h
+ $(SWIG) -python -shadow -c++ -o $@ $<
+
+clean:
+ rm -f *.o *.so *wrap*
View
324 PyML-0.7.9/PyML/classifiers/ext/SMO.cpp
@@ -0,0 +1,324 @@
+# include "SMO.h"
+
+SMO::SMO(DataSet *_data, const std::vector<double> &C_, const int _cacheSize) :
+ data(_data),
+ C(C_),
+ eps(0.001),
+ tolerance(0.001),
+ alpha(_data->size()),
+ b(0.0),
+ isLinear(false),
+ Kdiag(_data->size()),
+ Y(_data->size()),
+ G(_data->size(), -1),
+ Gbar(_data->size(), 0),
+ unshrinked(false),
+ shrinking(false),
+ cache(_data, _cacheSize)
+{
+ for (int i = 0; i < data->size(); i++) {
+ Kdiag[i] = data->kernel->eval(data, i, i, data);
+ Y[i] = double(data->Y[i]) * 2.0 - 1.0;
+ //activeSet.insert(i);
+ activeSet.push_back(i);
+ }
+
+}
+
+SMO::~SMO()
+{
+ //delete data;
+}
+
+void SMO::optimize()
+{
+
+ int iter = 0;
+ int counter = min(data->size(), 1000);
+
+ while (1) {
+
+ if (--counter == 0) {
+ counter = min(data->size(), 1000);
+ if (shrinking) shrink();
+ cout << ".";
+ }
+ int i,j;
+ bool kktViolation = selectWorkingSet(i, j);
+ //cout << "kktViolation " << kktViolation << endl;
+ //cout << "indices " << i << " " << j << endl;
+ if (!kktViolation) { // && !shrinking) {
+ break;
+ }
+ else if (!kktViolation) {
+ reconstructGradient();
+ for (int k=0; k < size(); k++)
+ //activeSet.insert(k);
+ cout << "*";
+ kktViolation = selectWorkingSet(i, j);
+ if (!kktViolation) {
+ break;
+ }
+ }
+ ++iter;
+
+ update(i, j);
+ }
+
+ b = compute_b();
+}
+
+void SMO::update(int i, int j)
+{
+ double C_i = C[i];
+ double C_j = C[j];
+
+ double old_alpha_i = alpha[i];
+ double old_alpha_j = alpha[j];
+
+ double kii = Kdiag[i];
+ double kij = data->kernel->eval(data, i, j, data);
+ double kjj = Kdiag[j];
+
+ //cout << "updating... " << endl;
+
+ if(Y[i] != Y[j]) {
+ //cout << "Y[i] != Y[j]" << endl;
+ double delta = (-G[i]-G[j]) / max((kii + kjj - 2 * kij), 0.0);
+ //cout << "delta " << delta << endl;
+ double diff = alpha[i] - alpha[j];
+ alpha[i] += delta;
+ alpha[j] += delta;
+
+ if(diff > 0) {
+ if(alpha[j] < 0) {
+ alpha[j] = 0;
+ alpha[i] = diff;
+ }
+ }
+ else {
+ if(alpha[i] < 0) {
+ alpha[i] = 0;
+ alpha[j] = -diff;
+ }
+ }
+ if(diff > C_i - C_j) {
+ if(alpha[i] > C_i) {
+ alpha[i] = C_i;
+ alpha[j] = C_i - diff;
+ }
+ }
+ else {
+ if(alpha[j] > C_j) {
+ alpha[j] = C_j;
+ alpha[i] = C_j + diff;
+ }
+ }
+ }
+ else {
+ double delta = (G[i]-G[j]) / max((kii + kjj - 2 * kij), 0.0);
+ double sum = alpha[i] + alpha[j];
+ alpha[i] -= delta;
+ alpha[j] += delta;
+ if(sum > C_i) {
+ if(alpha[i] > C_i) {
+ alpha[i] = C_i;
+ alpha[j] = sum - C_i;
+ }
+ }
+ else {
+ if(alpha[j] < 0) {
+ alpha[j] = 0;
+ alpha[i] = sum;
+ }
+ }
+ if(sum > C_j) {
+ if(alpha[j] > C_j) {
+ alpha[j] = C_j;
+ alpha[i] = sum - C_j;
+ }
+ }
+ else {
+ if(alpha[i] < 0) {
+ alpha[i] = 0;
+ alpha[j] = sum;
+ }
+ }
+ }
+
+ //cout << "alpha[i] " << alpha[i] << endl;
+ //cout << "alpha[j] " << alpha[j] << endl;
+
+ // update G
+
+ double delta_alpha_i = alpha[i] - old_alpha_i;
+ double delta_alpha_j = alpha[j] - old_alpha_j;
+
+ int k;
+ vector<float> &irow = cache.getRow(i);
+ vector<float> &jrow = cache.getRow(j);
+
+ for (IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) {
+ k = (*itr);
+ //G[k] += data->kernel->eval(data->X[i], data->X[k]) * delta_alpha_i * Y[i] * Y[k] +
+ //data->kernel->eval(data->X[j], data->X[k]) * Y[j] * Y[k] * delta_alpha_j;
+ G[k] += irow[k] * delta_alpha_i * Y[i] * Y[k] +
+ jrow[k] * Y[j] * Y[k] * delta_alpha_j;
+
+ }
+
+ // update G_bar
+
+}
+
+void SMO::reconstructGradient()
+{
+ // reconstruct inactive elements of G from G_bar and free variables
+ if (activeSet.size() == data->size()) return;
+
+ int i;
+ for(IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) {
+ i = (*itr);
+ G[i] = Gbar[i] + 1.0; /// 1 instead of b[i];
+ }
+
+ for(IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) {
+ i = *itr;
+ if (isFree(i)) {
+ vector<float> &irow = cache.getRow(i);
+ double alpha_i = alpha[i];
+ for (int j = 0; j < size(); j++) {
+ //if (activeSet.find(j) != activeSet.end())
+ // continue;
+ /// there is some waste here since we don't need all the entries;
+ /// does not matter yet since we are not doing shrinking...
+ G[j] += alpha_i * Y[i] * Y[j] * irow[j];
+ }
+ }
+ }
+}
+
+bool SMO::selectWorkingSet(int &iOut, int &jOut)
+{
+
+ double Gmax1 = -INF; // max { -grad(f)_i * d | y_i*d = +1 }
+ int Gmax1_idx = -1;
+
+ double Gmax2 = -INF; // max { -grad(f)_i * d | y_i*d = -1 }
+ int Gmax2_idx = -1;
+
+ //cout << "in select working set" << endl;
+ int i;
+ for(IndexSetItr itr = activeSet.begin(); itr != activeSet.end(); ++itr){
+ i = *itr;
+ if(Y[i]==1) {
+ //cout << "Y[i] " << Y[i] << endl;
+ if(!isUpperBound(i)) { // d = +1
+ //cout << "not upper 1 " << G[i] << endl;
+ if(-G[i] > Gmax1) {
+ Gmax1 = -G[i];
+ Gmax1_idx = i;
+ }
+ }
+ if(!isLowerBound(i)) { // d = -1
+ if(G[i] > Gmax2) {
+ Gmax2 = G[i];
+ Gmax2_idx = i;
+ }
+ }
+ }
+ else { // y = -1
+ //cout << "Y[i] " << Y[i] << endl;
+ if(!isUpperBound(i)) { // d = +1
+ //cout << "not upper -1 " << G[i] << endl;
+ if(-G[i] > Gmax2) {
+ Gmax2 = -G[i];
+ Gmax2_idx = i;
+ }
+ }
+ if(!isLowerBound(i)) { // d = -1
+ if(G[i] > Gmax1) {
+ Gmax1 = G[i];
+ Gmax1_idx = i;
+ }
+ }
+ }
+ }
+ //KKT conditions are satisfied:
+ if(Gmax1+Gmax2 < eps) {
+ return false;
+ }
+
+ //return the pair that has the largest KKT violation:
+ iOut = Gmax1_idx;
+ jOut = Gmax2_idx;
+
+ //cout << " iOut " << iOut << " jOut " << jOut << endl;
+
+ return true;
+}
+
+void SMO::shrink()
+{
+}
+
+double SMO::compute_b()
+{
+ double r;
+ int nr_free = 0;
+ double ub = INF, lb = -INF, sum_free = 0;
+
+ int i;
+ for(IndexSetItr itr=activeSet.begin(); itr!=activeSet.end(); ++itr) {
+ i = *itr;
+ double yG = Y[i]*G[i];
+ if (isLowerBound(i)) {
+ if(Y[i] > 0)
+ ub = min(ub,yG);
+ else
+ lb = max(lb,yG);
+ }
+ else if (isUpperBound(i)) {
+ if(Y[i] < 0)
+ ub = min(ub,yG);
+ else
+ lb = max(lb,yG);
+ }
+ else {
+ ++nr_free;
+ sum_free += yG;
+ }
+ }
+ if(nr_free>0) {
+ r = sum_free / double(nr_free);
+ }
+ else
+ r = (ub+lb)/2;
+
+ return r;
+
+}
+
+void SMO::show() {
+
+ cout << "b: " << b << endl;
+ cout << "alpha:" << endl;
+ for (int i = 0; i < data->size(); i++) {
+ cout << alpha[i] << " " << endl;
+ }
+ cout << endl;
+
+}
+
+std::vector<double> runSMO(DataSet *data,
+ const std::vector<double> &C,
+ // std::vector<double> &alpha,
+ int cacheSize)
+{
+
+ SMO s(data, C, cacheSize);
+ s.optimize();
+ //alpha = s.alpha;
+ s.alpha.push_back(s.b);
+ return s.alpha;
+}
View
73 PyML-0.7.9/PyML/classifiers/ext/SMO.h
@@ -0,0 +1,73 @@
+# ifndef SMO_H
+# define SMO_H
+
+# include "../../containers/ext/DataSet.h"
+# include "../../containers/ext/Kernel.h"
+# include "KernelCache.h"
+
+# include <set>
+# include <ext/hash_set>
+# include <vector>
+# include <algorithm>
+# include <functional>
+#include <string>
+#include <iostream>
+#include <fstream>
+# include <cmath>
+
+#define INF HUGE_VAL
+
+using namespace std;
+
+using __gnu_cxx::hash_set;
+
+typedef vector<int> IndexSet;
+typedef vector<int>::iterator IndexSetItr;
+
+class SMO {
+ public:
+ DataSet *data;
+ std::vector<double> Y;
+ std::vector<double> alpha;
+ double b;
+ std::vector<double> C;
+ double eps;
+ double tolerance;
+
+ KernelCache cache;
+
+ std::vector<double> Kdiag;
+ bool isLinear;
+
+ std::vector<double> G;
+ std::vector<double> Gbar;
+
+ IndexSet activeSet;
+ bool shrinking;
+ bool unshrinked;
+
+ int size() { return data->size(); }
+ bool isUpperBound(int i) { return alpha[i] >= C[i]; }
+ bool isLowerBound(int i) { return alpha[i] <= 0; }
+ bool isFree(int i) { return (alpha[i] > 0 && alpha[i] < C[i]);}
+
+ bool selectWorkingSet(int &iOut, int &jOut);
+ void update(int i, int j);
+ void reconstructGradient();
+ void shrink();
+ void optimize();
+
+ SMO(DataSet *_data, const std::vector<double> &C_, const int cacheSize);
+ ~SMO();
+
+ double compute_b();
+
+ void show();
+
+};
+
+std::vector<double> runSMO(DataSet *data,
+ const std::vector<double> &C,
+ int cacheSize);
+
+# endif
View
18 PyML-0.7.9/PyML/classifiers/ext/SMO.i
@@ -0,0 +1,18 @@
+%module csmo
+%{
+#include "SMO.h"
+%}
+
+%include "std_vector.i"
+
+namespace std
+{
+ %template(IntVector) vector<int>;
+ %template(DoubleVector) vector<double>;
+};
+
+
+std::vector<double> runSMO(DataSet *data,
+ const std::vector<double> &C,
+ //std::vector<double> &alpha,
+ int cacheSize);
View
9,451 PyML-0.7.9/PyML/classifiers/ext/SMO_wrap.cpp
9,451 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
111 PyML-0.7.9/PyML/classifiers/ext/SVModel.cpp
@@ -0,0 +1,111 @@
+
+# include "SVModel.h"
+
+SVModel::SVModel (DataSet &data,
+ const std::vector<int>& svID,
+ const std::vector<double>& alpha_, double b_) :
+ svdata(data.duplicate(svID)),
+ numSV(svID.size()),
+ alpha(alpha_),
+ b(b_)
+{ }
+
+SVModel::~SVModel()
+{
+ delete svdata;
+}
+
+double SVModel::decisionFunc (DataSet *data, int i) {
+
+ double sum = b;
+ for (int j = 0; j < svdata->size(); j++) {
+ sum += alpha[j] * svdata->kernel->eval(data, i, j, svdata);
+ }
+
+ return sum;
+
+}
+
+LinearSVModel::LinearSVModel (VectorDataSet &data,
+ const std::vector<int> &svID,
+ const std::vector<double>& alpha_, double b_) :
+ b(b_), wVec(data.numFeatures, 0)
+{
+ cout << "in Linear SVModel" << endl;
+ data.weightedSum(w, svID, alpha_);
+ for (long int i = 0; i < w.size(); ++i) {
+ wVec[i] = w[i];
+ }
+ cout << "done Linear SVModel" << endl;
+}
+
+LinearSVModel::~LinearSVModel ()
+{
+}
+
+void LinearSVModel::getW(std::vector<double> &values)
+{
+ w.get(values);
+}
+std::vector<double> LinearSVModel::getWvec()
+{
+ return wVec;
+}
+
+double LinearSVModel::decisionFunc (VectorDataSet &data, int i)
+{
+ return decisionFunc(data.X[i]);
+}
+
+double LinearSVModel::decisionFunc (FeatureVector &x)
+{
+ return w.dotProduct(x) + b;
+}
+
+LinearSparseSVModel::LinearSparseSVModel (SparseDataSet &data,
+ const std::vector<int> &svID,
+ const std::vector<double>& alpha_, double b_)
+ : b(b_), wVec(data.numFeatures, 0)
+{
+
+ data.weightedSum(w, svID, alpha_);
+
+ for (featureIterator jiter = w.features.begin();
+ jiter != w.features.end(); ++jiter) {
+ wVec[data.featureIDmap[(*jiter).index]] = (*jiter).value;
+ }
+}
+
+LinearSparseSVModel::LinearSparseSVModel(SparseDataSet& data, const std::vector<double>& w_, double b_)
+ :b(b_), wVec(w_)
+{
+ w.initialize(data.getFeatureID(), w_);
+}
+
+LinearSparseSVModel::~LinearSparseSVModel ()
+{
+}
+
+void LinearSparseSVModel::getW(std::vector<double> &values, std::vector<long> &ids)
+{
+ w.get(values, ids);
+}
+
+std::vector<double> LinearSparseSVModel::getWvec()
+{
+ return wVec;
+}
+
+double LinearSparseSVModel::decisionFunc (SparseDataSet &data, int i)
+{
+ return decisionFunc(data.X[i]);
+}
+
+double LinearSparseSVModel::decisionFunc (SparseFeatureVector &x)
+{
+ return w.dotProduct(x) + b;
+}
+
+
+
+
View
76 PyML-0.7.9/PyML/classifiers/ext/SVModel.h
@@ -0,0 +1,76 @@
+
+# ifndef SVMODEL_H
+# define SVMODEL_H
+
+# include "../../containers/ext/DataSet.h"
+# include "../../containers/ext/SparseDataSet.h"
+# include "../../containers/ext/SparseFeatureVector.h"
+# include "../../containers/ext/VectorDataSet.h"
+# include "../../containers/ext/FeatureVector.h"
+# include "../../containers/ext/Kernel.h"
+
+# include <vector>
+
+using namespace std;
+
+class SVModel {
+ public:
+ DataSet *svdata;
+ vector<double> alpha;
+ double b;
+ int numSV;
+
+ double decisionFunc (DataSet *data, int i);
+
+ SVModel(DataSet &data, const std::vector<int>& svID,
+ const std::vector<double>& alpha_, double b_);
+
+ ~SVModel();
+
+};
+
+class LinearSVModel {
+ public:
+
+ LinearSVModel(VectorDataSet& data, const std::vector<int>& svID,
+ const std::vector<double>& alpha_, double b_);
+
+ ~LinearSVModel();
+
+ //ASA: why both w and wVec?
+
+ FeatureVector w;
+ std::vector<double> wVec;
+ double b;
+
+ void getW(std::vector<double> &values);
+ std::vector<double> getWvec();
+
+ double decisionFunc (FeatureVector &x);
+ double decisionFunc (VectorDataSet &data, int i);
+
+};
+
+
+class LinearSparseSVModel {
+ public:
+
+ LinearSparseSVModel(SparseDataSet& data, const std::vector<int>& svID,
+ const std::vector<double>& alpha_, double b_);
+ LinearSparseSVModel(SparseDataSet& data, const std::vector<double>& w_, double b_);
+
+ ~LinearSparseSVModel();
+
+ SparseFeatureVector w;
+ std::vector<double> wVec;
+ double b;
+
+ void getW(std::vector<double> &values, std::vector<long> &ids);
+ std::vector<double> getWvec();
+
+ double decisionFunc (SparseFeatureVector &x);
+ double decisionFunc (SparseDataSet &data, int i);
+
+};
+
+# endif
View
15 PyML-0.7.9/PyML/classifiers/ext/SVModel.i
@@ -0,0 +1,15 @@
+%module csvmodel
+%{
+#include "SVModel.h"
+%}
+
+%include "std_vector.i"
+
+namespace std
+{
+ %template(IntVector) vector<int>;
+ %template(DoubleVector) vector<double>;
+};
+
+%include "SVModel.h"
+
View
10,837 PyML-0.7.9/PyML/classifiers/ext/SVModel_wrap.cpp
10,837 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
1 PyML-0.7.9/PyML/classifiers/ext/__init__.py
@@ -0,0 +1 @@
+
View
201 PyML-0.7.9/PyML/classifiers/ext/cgist.py
@@ -0,0 +1,201 @@
+# This file was automatically generated by SWIG (http://www.swig.org).
+# Version 2.0.0
+#
+# Do not make changes to this file unless you know what you are doing--modify
+# the SWIG interface file instead.
+# This file is compatible with both classic and new-style classes.
+
+from sys import version_info
+if version_info >= (2,6,0):
+ def swig_import_helper():
+ from os.path import dirname
+ import imp
+ fp = None
+ try:
+ fp, pathname, description = imp.find_module('_cgist', [dirname(__file__)])
+ except ImportError:
+ import _cgist
+ return _cgist
+ if fp is not None:
+ try:
+ _mod = imp.load_module('_cgist', fp, pathname, description)
+ finally:
+ fp.close()
+ return _mod
+ _cgist = swig_import_helper()
+ del swig_import_helper
+else:
+ import _cgist
+del version_info
+try:
+ _swig_property = property
+except NameError:
+ pass # Python < 2.2 doesn't have 'property'.
+def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
+ if (name == "thisown"): return self.this.own(value)
+ if (name == "this"):
+ if type(value).__name__ == 'SwigPyObject':
+ self.__dict__[name] = value
+ return
+ method = class_type.__swig_setmethods__.get(name,None)
+ if method: return method(self,value)
+ if (not static) or hasattr(self,name):
+ self.__dict__[name] = value
+ else:
+ raise AttributeError("You cannot add attributes to %s" % self)
+
+def _swig_setattr(self,class_type,name,value):
+ return _swig_setattr_nondynamic(self,class_type,name,value,0)
+
+def _swig_getattr(self,class_type,name):
+ if (name == "thisown"): return self.this.own()
+ method = class_type.__swig_getmethods__.get(name,None)
+ if method: return method(self)
+ raise AttributeError(name)
+
+def _swig_repr(self):
+ try: strthis = "proxy of " + self.this.__repr__()
+ except: strthis = ""
+ return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
+
+try:
+ _object = object
+ _newclass = 1
+except AttributeError:
+ class _object : pass
+ _newclass = 0
+
+
+class SwigPyIterator(_object):
+ __swig_setmethods__ = {}
+ __setattr__ = lambda