Changeset 9719:782cfec5fe88 in orange for orange/Orange/distance/__init__.py
 Timestamp:
 02/06/12 10:56:22 (2 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/distance/__init__.py
r9663 r9719 1 1 import Orange 2 3 #ExampleDistance > Distance 4 #ExampleDistanceConstructor > DistanceConstructor 5 #Hamming > HammingDistance 6 #DTW > DTWDistance 7 #Euclidean > EuclideanDistance 8 #Manhattan > ... 9 #Maximal > ... 10 #Relief > .. 11 #DTWConstructor 12 #EuclideanConstructor 13 #HammingConstructor 14 #ManhattanConstructor 15 #MaximalConstructor 16 #ReliefConstructor 17 #PearsonRConstructor > PearsonR 18 #PearsonR > PearsonRDistance 19 #SpearmanRConstructor > SpearmanR 20 #SpearmanR > SpearmanRDistance 21 #MahalanobisConstructor > Mahalanobis 22 #Mahalanobis > MahalanobisDistance 23 #ExamplesDistance_Normalized > Distance_Normalized 2 24 3 25 from Orange.core import \ … … 8 30 ExampleDistBySorting, \ 9 31 ExampleDistVector, \ 10 ExamplesDistance , \11 ExamplesDistance_Normalized , \12 ExamplesDistanceConstructor 13 14 from Orange.core import ExamplesDistance_Hamming as Hamming 15 from Orange.core import ExamplesDistance_DTW as DTW 16 from Orange.core import ExamplesDistance_Euclidean as Euclidean 17 from Orange.core import ExamplesDistance_Manhattan as Manhattan 18 from Orange.core import ExamplesDistance_Maximal as Maximal 19 from Orange.core import ExamplesDistance_Relief as Relief 20 21 from Orange.core import ExamplesDistanceConstructor_DTW as DTW Constructor22 from Orange.core import ExamplesDistanceConstructor_Euclidean as Euclidean Constructor23 from Orange.core import ExamplesDistanceConstructor_Hamming as Hamming Constructor24 from Orange.core import ExamplesDistanceConstructor_Manhattan as Manhattan Constructor25 from Orange.core import ExamplesDistanceConstructor_Maximal as Maximal Constructor26 from Orange.core import ExamplesDistanceConstructor_Relief as Relief Constructor32 ExamplesDistance as Distance, \ 33 ExamplesDistance_Normalized as DistanceNormalized, \ 34 ExamplesDistanceConstructor as DistanceConstructor 35 36 from Orange.core import ExamplesDistance_Hamming as HammingDistance 37 from Orange.core import ExamplesDistance_DTW as DTWDistance 38 from Orange.core import ExamplesDistance_Euclidean as EuclideanDistance 39 from Orange.core import ExamplesDistance_Manhattan as ManhattanDistance 40 from Orange.core import ExamplesDistance_Maximal as MaximalDistance 41 from Orange.core import ExamplesDistance_Relief as ReliefDistance 42 43 from Orange.core import ExamplesDistanceConstructor_DTW as DTW 44 from Orange.core import ExamplesDistanceConstructor_Euclidean as Euclidean 45 from Orange.core import ExamplesDistanceConstructor_Hamming as Hamming 46 from Orange.core import ExamplesDistanceConstructor_Manhattan as Manhattan 47 from Orange.core import ExamplesDistanceConstructor_Maximal as Maximal 48 from Orange.core import ExamplesDistanceConstructor_Relief as Relief 27 49 28 50 import statc … … 30 52 from numpy import linalg 31 53 32 class PearsonR Constructor(ExamplesDistanceConstructor):33 """Constructs an instance of PearsonR. Not all the data needs to be given."""54 class PearsonR(DistanceConstructor): 55 """Constructs an instance of :obj:`PearsonRDistance`. Not all the data needs to be given.""" 34 56 35 57 def __new__(cls, data=None, **argkw): … … 44 66 indxs = [i for i, a in enumerate(table.domain.attributes) \ 45 67 if a.varType==Orange.data.Type.Continuous] 46 return PearsonR (domain=table.domain, indxs=indxs)47 48 class PearsonR (ExamplesDistance):68 return PearsonRDistance(domain=table.domain, indxs=indxs) 69 70 class PearsonRDistance(Distance): 49 71 """ 50 72 `Pearson correlation coefficient … … 77 99 return 1.0 78 100 79 class SpearmanR Constructor(ExamplesDistanceConstructor):101 class SpearmanR(DistanceConstructor): 80 102 """Constructs an instance of SpearmanR. Not all the data needs to be given.""" 81 103 82 104 def __new__(cls, data=None, **argkw): 83 self = ExamplesDistanceConstructor.__new__(cls, **argkw)105 self = DistanceConstructor.__new__(cls, **argkw) 84 106 self.__dict__.update(argkw) 85 107 if data: … … 91 113 indxs = [i for i, a in enumerate(table.domain.attributes) \ 92 114 if a.varType==Orange.data.Type.Continuous] 93 return SpearmanR (domain=table.domain, indxs=indxs)94 95 class SpearmanR (ExamplesDistance):115 return SpearmanRDistance(domain=table.domain, indxs=indxs) 116 117 class SpearmanRDistance(Distance): 96 118 97 119 """`Spearman's rank correlation coefficient … … 122 144 return 1.0 123 145 124 class Mahalanobis Constructor(ExamplesDistanceConstructor):146 class Mahalanobis(DistanceConstructor): 125 147 """ Construct instance of Mahalanobis. """ 126 148 … … 149 171 inverse_covariance_matrix = linalg.pinv(covariance_matrix, rcond=1e10) 150 172 151 return Mahalanobis (domain=newdomain, icm=inverse_covariance_matrix)152 153 class Mahalanobis (ExamplesDistance):173 return MahalanobisDistance(domain=newdomain, icm=inverse_covariance_matrix) 174 175 class MahalanobisDistance(Distance): 154 176 """`Mahalanobis distance 155 177 <http://en.wikipedia.org/wiki/Mahalanobis_distance>`_""" … … 178 200 179 201 180 class PearsonRAbsolute Constructor(PearsonRConstructor):202 class PearsonRAbsolute(PearsonRConstructor): 181 203 """ Construct an instance of PearsonRAbsolute example distance estimator. 182 204 """ … … 184 206 indxs = [i for i, a in enumerate(data.domain.attributes) \ 185 207 if a.varType==Orange.data.Type.Continuous] 186 return PearsonRAbsolute (domain=data.domain, indxs=indxs)187 188 189 class PearsonRAbsolute (PearsonR):208 return PearsonRAbsoluteDistance(domain=data.domain, indxs=indxs) 209 210 211 class PearsonRAbsoluteDistance(PearsonR): 190 212 """ An example distance estimator using absolute value of Pearson 191 213 correlation coefficient. … … 213 235 214 236 215 class SpearmanRAbsolute Constructor(SpearmanRConstructor):237 class SpearmanRAbsolute(SpearmanRConstructor): 216 238 """ Construct an instance of SpearmanRAbsolute example distance estimator. 217 239 """ … … 219 241 indxs = [i for i, a in enumerate(data.domain.attributes) \ 220 242 if a.varType==Orange.data.Type.Continuous] 221 return SpearmanRAbsolute (domain=data.domain, indxs=indxs)222 223 224 class SpearmanRAbsolute (SpearmanR):243 return SpearmanRAbsoluteDistance(domain=data.domain, indxs=indxs) 244 245 246 class SpearmanRAbsoluteDistance(SpearmanR): 225 247 def __call__(self, e1, e2): 226 248 """
Note: See TracChangeset
for help on using the changeset viewer.