Changeset 1506:beecaafe2d7f in orange-bioinformatics


Ignore:
Timestamp:
10/30/11 12:30:44 (2 years ago)
Author:
markotoplak
Branch:
default
Convert:
4aa5585556f9f2f585378031d205960b89483fc7
Message:

obiProb: FDR now allows unsorted lists on input. Regain old performance with ordered=True.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • obiProb.py

    r1146 r1506  
    9999    c.append( c[-1] + 1.0/m) 
    100100 
    101 def FDR(p_values, dependent=False, m=None): 
     101def is_sorted(l): 
     102    return all(l[i] <= l[i+1] for i in xrange(len(l)-1)) 
     103 
     104def FDR(p_values, dependent=False, m=None, ordered=False): 
     105    """ 
     106    If the user is sure that pvalues as already sorted nondescendingly 
     107    setting ordered=True will make the computation faster. 
     108    """ 
     109 
     110    if not ordered: 
     111        ordered = is_sorted(p_values) 
     112 
     113    if not ordered: 
     114        joined = [ (v,i) for i,v in enumerate(p_values) ] 
     115        joined.sort() 
     116        p_values = [ p[0] for p in joined ] 
     117        indices = [ p[1] for p in joined ] 
     118 
    102119    if not m: 
    103120        m = len(p_values) 
     
    116133        fdrs.append( cmin) 
    117134    fdrs.reverse() 
     135 
     136    if not ordered: 
     137        new = [ None ] * len(fdrs) 
     138        for v,i in zip(fdrs, indices): 
     139            new[i] = v 
     140        fdrs = new 
     141 
    118142    return fdrs 
    119143 
Note: See TracChangeset for help on using the changeset viewer.