Changeset 9805:6b1b33eddc91 in orange


Ignore:
Timestamp:
02/06/12 18:19:54 (2 years ago)
Author:
markotoplak
Branch:
default
Children:
9806:01ddd2a2ff48, 9824:2923e3d2c90a, 9883:33c19621e154
rebase_source:
a0c6b340d0ac77bb5784df9ad20e20966f5fbdbb
Message:

Worked on Orange.distance documentation.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/distance/__init__.py

    r9759 r9805  
    2727 
    2828class PearsonR(DistanceConstructor): 
    29     """Constructs an instance of :obj:`PearsonRDistance`. Not all the data needs to be given.""" 
    3029     
    3130    def __new__(cls, data=None, **argkw): 
     
    4645    `Pearson correlation coefficient 
    4746    <http://en.wikipedia.org/wiki/Pearson_product-moment\ 
    48     _correlation_coefficient>`_ 
     47    _correlation_coefficient>`_. 
    4948    """ 
    5049 
     
    5857         
    5958        Returns Pearson's disimilarity between e1 and e2, 
    60         i.e. (1-r)/2 where r is Sprearman's rank coefficient. 
     59        i.e. (1-r)/2 where r is Pearson's rank coefficient. 
    6160        """ 
    6261        X1 = [] 
     
    7473 
    7574class SpearmanR(DistanceConstructor): 
    76     """Constructs an instance of SpearmanR. Not all the data needs to be given.""" 
    7775     
    7876    def __new__(cls, data=None, **argkw): 
     
    9391    """`Spearman's rank correlation coefficient 
    9492    <http://en.wikipedia.org/wiki/Spearman%27s_rank_\ 
    95     correlation_coefficient>`_""" 
     93    correlation_coefficient>`_.""" 
    9694 
    9795    def __init__(self, **argkw): 
     
    119117 
    120118class Mahalanobis(DistanceConstructor): 
    121     """ Construct instance of Mahalanobis. """ 
    122119     
    123120    def __new__(cls, data=None, **argkw): 
  • docs/reference/rst/Orange.distance.rst

    r9752 r9805  
    55########################################## 
    66 
     7The following example demonstrates how to compute distances between two instances: 
     8 
     9.. literalinclude:: code/distance-simple.py 
     10    :lines: 1-7 
     11 
     12A matrix with all pairwise distances can be computed with :obj:`distance_matrix`: 
     13 
     14.. literalinclude:: code/distance-simple.py 
     15    :lines: 9-11 
     16 
     17Unknown values are treated correctly only by Euclidean and Relief 
     18distance.  For other measures, a distance between unknown and known or 
     19between two unknown values is always 0.5. 
     20 
     21=================== 
     22Computing distances  
     23=================== 
     24 
    725Distance measures typically have to be adjusted to the data. For instance, 
    826when the data set contains continuous features, the distances between 
     
    1028similar impats, e.g. by dividing the distance with the range. 
    1129 
    12 Distance measures thus appear in pairs - a class that measures 
    13 the distance (:obj:`Distance`) and a class that constructs it based on the 
    14 data (:obj:`DistanceConstructor`). 
     30Distance measures thus appear in pairs: 
    1531 
    16 Since most measures work on normalized distances between corresponding 
    17 features, an abstract class `DistanceNormalized` takes care of 
    18 normalizing. 
    19  
    20 Unknown values are treated correctly only by Euclidean and Relief 
    21 distance.  For other measures, a distance between unknown and known or 
    22 between two unknown values is always 0.5. 
    23  
    24 .. autofunction:: distance_matrix 
    25  
    26 .. class:: Distance 
    27  
    28     .. method:: __call__(instance1, instance2) 
    29  
    30         Return a distance between the given instances (as a floating point number). 
     32- a class that constructs the distance measure based on the 
     33  data (subclass of :obj:`DistanceConstructor`, for 
     34  example :obj:`Euclidean`), and returns is as 
     35- a class that measures the distance between two instances 
     36  (subclass of :obj:`Distance`, for example :obj:`EuclideanDistance`). 
    3137 
    3238.. class:: DistanceConstructor 
     
    3844        not given, instances or distributions can be used. 
    3945 
    40 .. class:: DistanceNormalized 
     46.. class:: Distance 
    4147 
    42     An abstract class that provides normalization. 
     48    .. method:: __call__(instance1, instance2) 
    4349 
    44     .. attribute:: normalizers 
     50        Return a distance between the given instances (as a floating point number). 
    4551 
    46         A precomputed list of normalizing factors for feature values. They are: 
     52Pairwise distances 
     53================== 
    4754 
    48         - 1/(max_value-min_value) for continuous and 1/number_of_values 
    49           for ordinal features. 
    50           If either feature is unknown, the distance is 0.5. Such factors 
    51           are used to multiply differences in feature's values. 
    52         - ``-1`` for nominal features; the distance 
    53           between two values is 0 if they are same (or at least one is 
    54           unknown) and 1 if they are different. 
    55         - ``0`` for ignored features. 
     55.. autofunction:: distance_matrix 
    5656 
    57     .. attribute:: bases, averages, variances 
     57========= 
     58Measures 
     59========= 
    5860 
    59         The minimal values, averages and variances 
    60         (continuous features only). 
    61  
    62     .. attribute:: domain_version 
    63  
    64         The domain version changes each time a domain description is 
    65         changed (i.e. features are added or removed). 
    66  
    67     .. method:: feature_distances(instance1, instance2) 
    68  
    69         Return a list of floats representing normalized distances between 
    70         pairs of feature values of the two instances. 
     61Distance measures are defined with two classes: a subclass of obj:`DistanceConstructor` 
     62and a subclass of :obj:`Distance`. 
    7163 
    7264.. class:: Hamming 
     
    8173    The maximal distance 
    8274    between two feature values. If dist is the result of 
    83     ~:obj:`DistanceNormalized.feature_distances`, 
     75    :obj:`~DistanceNormalized.feature_distances`, 
    8476    then :class:`Maximal` returns ``max(dist)``. 
    8577 
     
    8981    The sum of absolute values 
    9082    of distances between pairs of features, e.g. ``sum(abs(x) for x in dist)`` 
    91     where dist is the result of ~:obj:`DistanceNormalized.feature_distances`. 
     83    where dist is the result of :obj:`~DistanceNormalized.feature_distances`. 
    9284 
    9385.. class:: Euclidean 
     
    9688    The square root of sum of squared per-feature distances, 
    9789    i.e. ``sqrt(sum(x*x for x in dist))``, where dist is the result of 
    98     ~:obj:`DistanceNormalized.feature_distances`. 
     90    :obj:`~DistanceNormalized.feature_distances`. 
    9991 
    10092    .. method:: distributions 
     
    137129    This class is derived directly from :obj:`Distance`. 
    138130 
    139  
    140131.. autoclass:: PearsonR 
    141132    :members: 
     
    147138    :members: 
    148139 
    149 .. autoclass:: SpearmanRConstructor 
     140.. autoclass:: SpearmanRDistance 
    150141    :members: 
    151142 
     143.. autoclass:: Mahalanobis 
     144    :members: 
    152145 
     146.. autoclass:: MahalanobisDistance 
     147    :members: 
     148 
     149========= 
     150Utilities 
     151========= 
     152 
     153.. class:: DistanceNormalized 
     154 
     155    An abstract class that provides normalization. 
     156 
     157    .. attribute:: normalizers 
     158 
     159        A precomputed list of normalizing factors for feature values. They are: 
     160 
     161        - 1/(max_value-min_value) for continuous and 1/number_of_values 
     162          for ordinal features. 
     163          If either feature is unknown, the distance is 0.5. Such factors 
     164          are used to multiply differences in feature's values. 
     165        - ``-1`` for nominal features; the distance 
     166          between two values is 0 if they are same (or at least one is 
     167          unknown) and 1 if they are different. 
     168        - ``0`` for ignored features. 
     169 
     170    .. attribute:: bases, averages, variances 
     171 
     172        The minimal values, averages and variances 
     173        (continuous features only). 
     174 
     175    .. attribute:: domain_version 
     176 
     177        The domain version changes each time a domain description is 
     178        changed (i.e. features are added or removed). 
     179 
     180    .. method:: feature_distances(instance1, instance2) 
     181 
     182        Return a list of floats representing normalized distances between 
     183        pairs of feature values of the two instances. 
     184 
     185 
Note: See TracChangeset for help on using the changeset viewer.