Changeset 9719:782cfec5fe88 in orange


Ignore:
Timestamp:
02/06/12 10:56:22 (2 years ago)
Author:
markotoplak
Branch:
default
Message:

Orange.distance renames.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/Orange.distance.rst

    r9663 r9719  
     1.. py:currentmodule:: Orange.distance 
     2 
    13.. automodule:: Orange.distance 
    24 
     
    57########################################## 
    68 
    7 This page describes a bunch of classes for different metrics for measure 
    8 distances (dissimilarities) between instances. 
     9Distance measures typically have to be adjusted to the data. For instance, 
     10when the data set contains continuous features, the distances between 
     11continuous values should be normalized to ensure that all features have 
     12similar impats, e.g. by dividing the distance with the range. 
    913 
    10 Typical (although not all) measures of distance between instances require 
    11 some "learning" - adjusting the measure to the data. For instance, when 
    12 the dataset contains continuous features, the distances between continuous 
    13 values should be normalized, e.g. by dividing the distance with the range 
    14 of possible values or with some interquartile distance to ensure that all 
    15 features have, in principle, similar impacts. 
    16  
    17 Different measures of distance thus appear in pairs - a class that measures 
    18 the distance and a class that constructs it based on the data. The abstract 
    19 classes representing such a pair are `ExamplesDistance` and 
    20 `ExamplesDistanceConstructor`. 
     14Distance measures thus appear in pairs - a class that measures 
     15the distance (:obj:`Distance`) and a class that constructs it based on the 
     16data (:obj:`DistanceConstructor`). 
    2117 
    2218Since most measures work on normalized distances between corresponding 
    23 features, there is an abstract intermediate class 
    24 `ExamplesDistance_Normalized` that takes care of normalizing. 
    25 The remaining classes correspond to different ways of defining the distances, 
    26 such as Manhattan or Euclidean distance. 
     19features, an abstract class `DistanceNormalized` takes care of 
     20normalizing. 
    2721 
    28 Unknown values are treated correctly only by Euclidean and Relief distance. 
    29 For other measure of distance, a distance between unknown and known or between 
    30 two unknown values is always 0.5. 
     22Unknown values are treated correctly only by Euclidean and Relief 
     23distance.  For other measures, a distance between unknown and known or 
     24between two unknown values is always 0.5. 
    3125 
    32 .. class:: ExamplesDistance 
     26.. class:: Distance 
    3327 
    3428    .. method:: __call__(instance1, instance2) 
    3529 
    36         Returns a distance between the given instances as floating point number. 
     30        Return a distance between the given instances (as a floating point number). 
    3731 
    38 .. class:: ExamplesDistanceConstructor 
     32.. class:: DistanceConstructor 
    3933 
    4034    .. method:: __call__([instances, weightID][, distributions][, basic_var_stat]) 
    4135 
    42         Constructs an instance of ExamplesDistance. 
    43         Not all the data needs to be given. Most measures can be constructed 
    44         from basic_var_stat; if it is not given, they can help themselves 
    45         either by instances or distributions. 
    46         Some (e.g. ExamplesDistance_Hamming) even do not need any arguments. 
     36        Constructs an :obj:`Distance`.  Not all the data needs to be 
     37        given. Most measures can be constructed from basic_var_stat; 
     38        if it is not given, they can help themselves either by instances 
     39        or distributions. Some do not need any arguments. 
    4740 
    48 .. class:: ExamplesDistance_Normalized 
     41.. class:: DistanceNormalized 
    4942 
    5043    This abstract class provides a function which is given two instances 
  • orange/Orange/distance/__init__.py

    r9663 r9719  
    11import 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 
    224 
    325from Orange.core import \ 
     
    830     ExampleDistBySorting, \ 
    931     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 DTWConstructor 
    22 from Orange.core import ExamplesDistanceConstructor_Euclidean as EuclideanConstructor 
    23 from Orange.core import ExamplesDistanceConstructor_Hamming as HammingConstructor 
    24 from Orange.core import ExamplesDistanceConstructor_Manhattan as ManhattanConstructor 
    25 from Orange.core import ExamplesDistanceConstructor_Maximal as MaximalConstructor 
    26 from Orange.core import ExamplesDistanceConstructor_Relief as ReliefConstructor 
     32     ExamplesDistance as Distance, \ 
     33     ExamplesDistance_Normalized as DistanceNormalized, \ 
     34     ExamplesDistanceConstructor as DistanceConstructor 
     35 
     36from Orange.core import ExamplesDistance_Hamming as HammingDistance 
     37from Orange.core import ExamplesDistance_DTW as DTWDistance 
     38from Orange.core import ExamplesDistance_Euclidean as EuclideanDistance 
     39from Orange.core import ExamplesDistance_Manhattan as ManhattanDistance 
     40from Orange.core import ExamplesDistance_Maximal as MaximalDistance 
     41from Orange.core import ExamplesDistance_Relief as ReliefDistance 
     42 
     43from Orange.core import ExamplesDistanceConstructor_DTW as DTW 
     44from Orange.core import ExamplesDistanceConstructor_Euclidean as Euclidean 
     45from Orange.core import ExamplesDistanceConstructor_Hamming as Hamming 
     46from Orange.core import ExamplesDistanceConstructor_Manhattan as Manhattan 
     47from Orange.core import ExamplesDistanceConstructor_Maximal as Maximal 
     48from Orange.core import ExamplesDistanceConstructor_Relief as Relief 
    2749 
    2850import statc 
     
    3052from numpy import linalg 
    3153 
    32 class PearsonRConstructor(ExamplesDistanceConstructor): 
    33     """Constructs an instance of PearsonR. Not all the data needs to be given.""" 
     54class PearsonR(DistanceConstructor): 
     55    """Constructs an instance of :obj:`PearsonRDistance`. Not all the data needs to be given.""" 
    3456     
    3557    def __new__(cls, data=None, **argkw): 
     
    4466        indxs = [i for i, a in enumerate(table.domain.attributes) \ 
    4567                 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 
     70class PearsonRDistance(Distance): 
    4971    """ 
    5072    `Pearson correlation coefficient 
     
    7799            return 1.0 
    78100 
    79 class SpearmanRConstructor(ExamplesDistanceConstructor): 
     101class SpearmanR(DistanceConstructor): 
    80102    """Constructs an instance of SpearmanR. Not all the data needs to be given.""" 
    81103     
    82104    def __new__(cls, data=None, **argkw): 
    83         self = ExamplesDistanceConstructor.__new__(cls, **argkw) 
     105        self = DistanceConstructor.__new__(cls, **argkw) 
    84106        self.__dict__.update(argkw) 
    85107        if data: 
     
    91113        indxs = [i for i, a in enumerate(table.domain.attributes) \ 
    92114                 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 
     117class SpearmanRDistance(Distance):   
    96118 
    97119    """`Spearman's rank correlation coefficient 
     
    122144            return 1.0 
    123145 
    124 class MahalanobisConstructor(ExamplesDistanceConstructor): 
     146class Mahalanobis(DistanceConstructor): 
    125147    """ Construct instance of Mahalanobis. """ 
    126148     
     
    149171        inverse_covariance_matrix = linalg.pinv(covariance_matrix, rcond=1e-10) 
    150172         
    151         return Mahalanobis(domain=newdomain, icm=inverse_covariance_matrix) 
    152  
    153 class Mahalanobis(ExamplesDistance): 
     173        return MahalanobisDistance(domain=newdomain, icm=inverse_covariance_matrix) 
     174 
     175class MahalanobisDistance(Distance): 
    154176    """`Mahalanobis distance 
    155177    <http://en.wikipedia.org/wiki/Mahalanobis_distance>`_""" 
     
    178200     
    179201     
    180 class PearsonRAbsoluteConstructor(PearsonRConstructor): 
     202class PearsonRAbsolute(PearsonRConstructor): 
    181203    """ Construct an instance of PearsonRAbsolute example distance estimator. 
    182204    """ 
     
    184206        indxs = [i for i, a in enumerate(data.domain.attributes) \ 
    185207                 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     
     211class PearsonRAbsoluteDistance(PearsonR): 
    190212    """ An example distance estimator using absolute value of Pearson 
    191213    correlation coefficient. 
     
    213235         
    214236         
    215 class SpearmanRAbsoluteConstructor(SpearmanRConstructor): 
     237class SpearmanRAbsolute(SpearmanRConstructor): 
    216238    """ Construct an instance of SpearmanRAbsolute example distance estimator. 
    217239    """ 
     
    219241        indxs = [i for i, a in enumerate(data.domain.attributes) \ 
    220242                 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     
     246class SpearmanRAbsoluteDistance(SpearmanR): 
    225247    def __call__(self, e1, e2): 
    226248        """ 
Note: See TracChangeset for help on using the changeset viewer.