Changeset 7786:3b405c771916 in orange


Ignore:
Timestamp:
03/30/11 17:08:45 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
2d9d47e629aa0ac81ba517d2d524ad41fdd915d6
Message:

Added progressCallback parameter to computeCorrelactionBetweenAttributes.
Commented out a call to fixIntersectingPairs (can enter an endless cycle).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/orngVisFuncts.py

    r6538 r7786  
    11import orange, orngFSS, statc, random 
     2from orngMisc import progressBarMilestones 
    23import copy 
    34from math import ceil 
     
    554555 
    555556        if len(proj) == numberOfAttributes: 
    556             proj, projVal = fixIntersectingPairs(proj, projVal, attrInfo) 
     557            # I (Ales) commented this out because fixItersectingPairs can enter an endless cycle  
     558            #proj, projVal = fixIntersectingPairs(proj, projVal, attrInfo) 
    557559            for i in range(len(proj)-1): 
    558560                removeAttributePair(proj[i], proj[i+1], attrInfo) 
     
    566568def fixIntersectingPairs(proj, projVal, attrInfo): 
    567569    changed = 1 
     570    allprojections = set() 
    568571    while changed: 
    569572        changed = 0 
     
    582585                    proj = tempProj 
    583586                    changed = 1     # we rotated the projection. start checking from the begining 
     587         
     588        tproj = tuple(proj)  
     589        assert(tproj not in allprojections) 
     590        allprojections.add(tproj) 
     591                 
    584592    return proj, projVal 
    585593 
     
    633641    return proj, projVal, 0 
    634642 
    635 def computeCorrelationBetweenAttributes(data, attrList, minCorrelation = 0.0): 
     643def computeCorrelationBetweenAttributes(data, attrList, minCorrelation = 0.0, progressCallback=None): 
    636644    correlations = [] 
     645    attrListLen = len(attrList) 
     646    iterCount = attrListLen * (attrListLen - 1) / 2 
     647    iter = 0 
     648    milestones = progressBarMilestones(iterCount) 
    637649    for i in range(len(attrList)): 
    638         if data.domain.attributes[i].varType != orange.VarTypes.Continuous: continue 
     650        if data.domain.attributes[i].varType != orange.VarTypes.Continuous: 
     651            continue 
    639652        for j in range(i+1, len(attrList)): 
    640             if data.domain.attributes[j].varType != orange.VarTypes.Continuous: continue 
     653            if data.domain.attributes[j].varType != orange.VarTypes.Continuous: 
     654                continue 
    641655            val = abs(computeCorrelation(data, attrList[i], attrList[j])) 
    642             if val >= minCorrelation: correlations.append((val, attrList[i], attrList[j])) 
    643  
    644     correlations.sort() 
    645     correlations.reverse() 
    646     return correlations 
    647  
    648  
    649 def computeCorrelationInsideClassesBetweenAttributes(data, attrList, minCorrelation = 0.0): 
    650     if not data.domain.classVar or data.domain.classVar.varType == orange.VarTypes.Continuous: return [] 
     656            if val >= minCorrelation: 
     657                correlations.append((val, attrList[i], attrList[j])) 
     658            iter += 1 
     659            if progressCallback and iter in milestones: 
     660                progressCallback(100.0 * iter / iterCount) 
     661                 
     662    return sorted(correlations, reverse=True) 
     663 
     664 
     665def computeCorrelationInsideClassesBetweenAttributes(data, attrList, minCorrelation = 0.0, progressCallback=None): 
     666    if not data.domain.classVar or data.domain.classVar.varType == orange.VarTypes.Continuous: 
     667        return [] 
    651668    correlations = [] 
     669    attrListLen = len(attrList) 
     670    iterCount = attrListLen * (attrListLen - 1) / 2 
     671    iter = 0 
     672    milestones = progressBarMilestones(iterCount) 
    652673    for i in range(len(attrList)): 
    653         if data.domain.attributes[i].varType != orange.VarTypes.Continuous: continue 
     674        if data.domain.attributes[i].varType != orange.VarTypes.Continuous: 
     675            continue 
    654676        for j in range(i+1, len(attrList)): 
    655             if data.domain.attributes[j].varType != orange.VarTypes.Continuous: continue 
     677            if data.domain.attributes[j].varType != orange.VarTypes.Continuous: 
     678                continue 
    656679            corr, corrs, lengths = computeCorrelationInsideClasses(data, attrList[i], attrList[j]) 
    657             if corr >= minCorrelation: correlations.append((corr, attrList[i], attrList[j])) 
    658  
    659     correlations.sort() 
    660     correlations.reverse() 
    661     return correlations 
     680            if corr >= minCorrelation: 
     681                correlations.append((corr, attrList[i], attrList[j])) 
     682            iter += 1 
     683            if progressCallback and iter in milestones: 
     684                progressCallback(100.0 * iter / iterCount) 
     685                 
     686    return sorted(correlations, reverse=True) 
    662687 
    663688 
Note: See TracChangeset for help on using the changeset viewer.