Ignore:
Timestamp:
02/06/12 16:41:46 (2 years ago)
Author:
markotoplak
Branch:
default
Parents:
9751:dbf6becb1937 (diff), 9752:cbd6f6f10f06 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
rebase_source:
074a5aa54622deb46fa951196b548f00f9b3cd52
Message:

Merge. Fixed orangeqt Makefile.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/distance/__init__.py

    r9725 r9753  
    11import Orange 
    2  
    3 #%s/ExamplesDistanceConstructor/DistanceConstructor/gc 
    4 #%s/ExamplesDistance_Normalized/DistanceNormalized/gc 
    5 #ExampleDistance -> Distance 
    6 #Hamming -> HammingDistance 
    7 #DTW -> DTWDistance 
    8 #Euclidean -> EuclideanDistance 
    9 #Manhattan -> ... 
    10 #Maximal -> ... 
    11 #Relief -> .. 
    12 #DTWConstructor 
    13 #EuclideanConstructor 
    14 #HammingConstructor 
    15 #ManhattanConstructor 
    16 #MaximalConstructor 
    17 #ReliefConstructor 
    18 #PearsonRConstructor -> PearsonR 
    19 #PearsonR -> PearsonRDistance 
    20 #SpearmanRConstructor -> SpearmanR 
    21 #SpearmanR -> SpearmanRDistance 
    22 #MahalanobisConstructor ->  Mahalanobis 
    23 #Mahalanobis -> MahalanobisDistance 
    242 
    253from Orange.core import \ 
     
    4220    ExamplesDistanceConstructor_Relief as Relief 
    4321 
     22<<<<<<< local 
    4423from Orange import statc 
     24======= 
     25from Orange.misc import progress_bar_milestones 
     26 
     27import statc 
     28>>>>>>> other 
    4529import numpy 
    4630from numpy import linalg 
     
    260244            return 1.0 
    261245     
    262      
    263 def distance_matrix(data, distance_constructor, progress_callback=None): 
    264     """ A helper function that computes an obj:`Orange.core.SymMatrix` of all 
     246def _pairs(seq, same = False): 
     247    """ Return all pairs from elements of `seq`. 
     248    """ 
     249    seq = list(seq) 
     250    same = 0 if same else 1 
     251    for i in range(len(seq)): 
     252        for j in range(i + same, len(seq)): 
     253            yield seq[i], seq[j] 
     254    
     255def distance_matrix(data, distance_constructor=Euclidean, progress_callback=None): 
     256    """ A helper function that computes an :obj:`Orange.data.SymMatrix` of all 
    265257    pairwise distances between instances in `data`. 
    266258     
     
    268260    :type data: :obj:`Orange.data.Table` 
    269261     
    270     :param distance_constructor: An DistanceConstructor instance. 
     262    :param distance_constructor: An DistanceConstructor instance (defaults to :obj:`Euclidean`). 
    271263    :type distance_constructor: :obj:`Orange.distances.DistanceConstructor` 
    272      
    273     """ 
    274     from Orange.misc import progressBarMilestones as progress_milestones 
    275     matrix = Orange.core.SymMatrix(len(data)) 
     264 
     265    :param progress_callback: A function (taking one argument) to use for 
     266        reporting the on the progress. 
     267    :type progress_callback: function 
     268     
     269    :rtype: :class:`Orange.data.SymMatrix` 
     270     
     271    """ 
     272    matrix = Orange.data.SymMatrix(len(data)) 
    276273    dist = distance_constructor(data) 
    277      
    278     msize = len(data)*(len(data) - 1)/2 
    279     milestones = progress_milestones(msize, 100) 
    280     count = 0 
    281     for i in range(len(data)): 
    282         for j in range(i + 1, len(data)): 
    283             matrix[i, j] = dist(data[i], data[j]) 
     274 
     275    iter_count = matrix.dim * (matrix.dim - 1) / 2 
     276    milestones = progress_bar_milestones(iter_count, 100) 
     277     
     278    for count, ((i, ex1), (j, ex2)) in enumerate(_pairs(enumerate(data))): 
     279        matrix[i, j] = dist(ex1, ex2) 
     280        if progress_callback and count in milestones: 
     281            progress_callback(100.0 * count / iter_count) 
    284282             
    285             if progress_callback and count in milestones: 
    286                 progress_callback(100.0 * count / msize) 
    287             count += 1 
    288              
    289     return matrix 
     283    return matrix  
  • Orange/distance/__init__.py

    r9752 r9753  
    2020    ExamplesDistanceConstructor_Relief as Relief 
    2121 
     22<<<<<<< local 
     23from Orange import statc 
     24======= 
    2225from Orange.misc import progress_bar_milestones 
    2326 
    2427import statc 
     28>>>>>>> other 
    2529import numpy 
    2630from numpy import linalg 
Note: See TracChangeset for help on using the changeset viewer.