Esempio n. 1
0
  def test5Bug29(self):
    """ a more extensive test of the cmp stuff using hand-built trees """
    import copy

    t1 = QuantTreeNode(None, 't1')
    t1.SetQuantBounds([1.])
    c1 = QuantTreeNode(t1, 'c1')
    c1.SetQuantBounds([2.])
    t1.AddChildNode(c1)
    c2 = QuantTreeNode(t1, 'c2')
    c2.SetQuantBounds([2.])
    t1.AddChildNode(c2)
    c11 = QuantTreeNode(c1, 'c11')
    c11.SetQuantBounds([3.])
    c1.AddChildNode(c11)
    c12 = QuantTreeNode(c1, 'c12')
    c12.SetQuantBounds([3.])
    c1.AddChildNode(c12)
    assert not cmp(t1, copy.deepcopy(t1)), 'self equality failed'

    t2 = QuantTreeNode(None, 't1')
    t2.SetQuantBounds([1.])
    c1 = QuantTreeNode(t2, 'c1')
    c1.SetQuantBounds([2.])
    t2.AddChildNode(c1)
    c2 = QuantTreeNode(t2, 'c2')
    c2.SetQuantBounds([2.])
    t2.AddChildNode(c2)
    c11 = QuantTreeNode(c1, 'c11')
    c11.SetQuantBounds([3.])
    c1.AddChildNode(c11)
    c12 = QuantTreeNode(c1, 'c12')
    c12.SetQuantBounds([3.00003])
    c1.AddChildNode(c12)
    assert cmp(t1, t2), 'inequality failed'
Esempio n. 2
0
    def test5Bug29(self):
        """ a more extensive test of the cmp stuff using hand-built trees """
        import copy

        t1 = QuantTreeNode(None, 't1')
        t1.SetQuantBounds([1.])
        c1 = QuantTreeNode(t1, 'c1')
        c1.SetQuantBounds([2.])
        t1.AddChildNode(c1)
        c2 = QuantTreeNode(t1, 'c2')
        c2.SetQuantBounds([2.])
        t1.AddChildNode(c2)
        c11 = QuantTreeNode(c1, 'c11')
        c11.SetQuantBounds([3.])
        c1.AddChildNode(c11)
        c12 = QuantTreeNode(c1, 'c12')
        c12.SetQuantBounds([3.])
        c1.AddChildNode(c12)
        assert not cmp(t1, copy.deepcopy(t1)), 'self equality failed'

        t2 = QuantTreeNode(None, 't1')
        t2.SetQuantBounds([1.])
        c1 = QuantTreeNode(t2, 'c1')
        c1.SetQuantBounds([2.])
        t2.AddChildNode(c1)
        c2 = QuantTreeNode(t2, 'c2')
        c2.SetQuantBounds([2.])
        t2.AddChildNode(c2)
        c11 = QuantTreeNode(c1, 'c11')
        c11.SetQuantBounds([3.])
        c1.AddChildNode(c11)
        c12 = QuantTreeNode(c1, 'c12')
        c12.SetQuantBounds([3.00003])
        c1.AddChildNode(c12)
        assert cmp(t1, t2), 'inequality failed'
Esempio n. 3
0
 def test6Bug29_2(self):
   """ a more extensive test of the cmp stuff using pickled trees"""
   import os
   with open(os.path.join(RDConfig.RDCodeDir,'ML','DecTree','test_data','CmpTree1.pkl'),'rb') as t1File:
     t1 = cPickle.load(t1File)
   with open(os.path.join(RDConfig.RDCodeDir,'ML','DecTree','test_data','CmpTree2.pkl'),'rb') as t2File:
     t2 = cPickle.load(t2File)
   assert cmp(t1,t2),'equality failed'
Esempio n. 4
0
 def _getBondAttachmentCoordinates(self, p1, p2, labelSize):
     newpos = [None, None]
     if labelSize != None:
         labelSizeOffset = [
             labelSize[0][0] / 2 + (cmp(p2[0], p1[0]) * labelSize[0][2]),
             labelSize[0][1] / 2
         ]
         if p1[1] == p2[1]:
             newpos[0] = p1[0] + cmp(p2[0], p1[0]) * labelSizeOffset[0]
         else:
             if abs(labelSizeOffset[1] * (p2[0] - p1[0]) /
                    (p2[1] - p1[1])) < labelSizeOffset[0]:
                 newpos[0] = p1[0] + cmp(p2[0], p1[0]) * abs(
                     labelSizeOffset[1] * (p2[0] - p1[0]) / (p2[1] - p1[1]))
             else:
                 newpos[0] = p1[0] + cmp(p2[0], p1[0]) * labelSizeOffset[0]
         if p1[0] == p2[0]:
             newpos[1] = p1[1] + cmp(p2[1], p1[1]) * labelSizeOffset[1]
         else:
             if abs(labelSizeOffset[0] * (p1[1] - p2[1]) /
                    (p2[0] - p1[0])) < labelSizeOffset[1]:
                 newpos[1] = p1[1] + cmp(p2[1], p1[1]) * abs(
                     labelSizeOffset[0] * (p1[1] - p2[1]) / (p2[0] - p1[0]))
             else:
                 newpos[1] = p1[1] + cmp(p2[1], p1[1]) * labelSizeOffset[1]
     else:
         newpos = copy.deepcopy(p1)
     return newpos
Esempio n. 5
0
  def Compare(self, other, ignoreExtras=1):
    """ not as choosy as self==other

    """
    tv1, tv2 = str(type(self)), str(type(other))
    tv = cmp(tv1, tv2)
    if tv:
      return tv
    tv1, tv2 = len(self), len(other)
    tv = cmp(tv1, tv2)
    if tv:
      return tv

    if not ignoreExtras:
      m1, m2 = self.GetMetric(), other.GetMetric()
      if abs(m1 - m2) > CMPTOL:
        return cmp(m1, m2)

      if cmp(self.GetName(), other.GetName()):
        return cmp(self.GetName(), other.GetName())

      sP = self.GetPosition()
      oP = other.GetPosition()
      try:
        r = cmp(len(sP), len(oP))
      except Exception:
        pass
      else:
        if r:
          return r

      try:
        r = cmp(sP, oP)
      except Exception:
        r = sum(sP - oP)
      if r:
        return r

    c1, c2 = self.GetChildren(), other.GetChildren()
    if cmp(len(c1), len(c2)):
      return cmp(len(c1), len(c2))
    for i in range(len(c1)):
      t = c1[i].Compare(c2[i], ignoreExtras=ignoreExtras)
      if t:
        return t

    return 0
Esempio n. 6
0
  def Compare(self,other,ignoreExtras=1):
    """ not as choosy as self==other

    """
    tv1,tv2 = str(type(self)),str(type(other))
    tv = cmp(tv1,tv2)
    if tv:
      return tv
    tv1,tv2 = len(self),len(other)
    tv = cmp(tv1,tv2)
    if tv:
      return tv
      
    if not ignoreExtras:
      m1,m2=self.GetMetric(),other.GetMetric()
      if abs(m1-m2)>CMPTOL:
        return cmp(m1,m2)

      if cmp(self.GetName(),other.GetName()):
        return cmp(self.GetName(),other.GetName())

      sP = self.GetPosition()
      oP = other.GetPosition()
      try:
        r = cmp(len(sP),len(oP))
      except Exception:
        pass
      else:
        if r:
          return r

      try:
        r = cmp(sP,oP) 
      except Exception:
        r = sum(sP-oP)
      if r:
        return r
        
    c1,c2=self.GetChildren(),other.GetChildren()
    if cmp(len(c1),len(c2)):
      return cmp(len(c1),len(c2))
    for i in range(len(c1)):
      t = c1[i].Compare(c2[i],ignoreExtras=ignoreExtras)
      if t:
        return t
      
    return 0
Esempio n. 7
0
 def test6Bug29_2(self):
     """ a more extensive test of the cmp stuff using pickled trees"""
     import os
     with open(
             os.path.join(RDConfig.RDCodeDir, 'ML', 'DecTree', 'test_data',
                          'CmpTree1.pkl'), 'rb') as t1File:
         t1 = cPickle.load(t1File)
     with open(
             os.path.join(RDConfig.RDCodeDir, 'ML', 'DecTree', 'test_data',
                          'CmpTree2.pkl'), 'rb') as t2File:
         t2 = cPickle.load(t2File)
     assert cmp(t1, t2), 'equality failed'
Esempio n. 8
0
 def test6Bug29_2(self):
   """ a more extensive test of the cmp stuff using pickled trees"""
   import os
   with open(os.path.join(RDConfig.RDCodeDir,'ML','DecTree','test_data','CmpTree1.pkl'),'r') as t1TFile:
     buf = t1TFile.read().replace('\r\n', '\n').encode('utf-8')
     t1TFile.close()
   with io.BytesIO(buf) as t1File:
     t1 = cPickle.load(t1File)
   with open(os.path.join(RDConfig.RDCodeDir,'ML','DecTree','test_data','CmpTree2.pkl'),'r') as t2TFile:
     buf = t2TFile.read().replace('\r\n', '\n').encode('utf-8')
     t2TFile.close()
   with io.BytesIO(buf) as t2File:
     t2 = cPickle.load(t2File)
   assert cmp(t1,t2),'equality failed'
Esempio n. 9
0
 def test6Bug29_2(self):
     """ a more extensive test of the cmp stuff using pickled trees"""
     import os
     with open(
             os.path.join(RDConfig.RDCodeDir, 'ML', 'DecTree', 'test_data',
                          'CmpTree1.pkl'), 'r') as t1TFile:
         buf = t1TFile.read().replace('\r\n', '\n').encode('utf-8')
         t1TFile.close()
     with io.BytesIO(buf) as t1File:
         t1 = cPickle.load(t1File)
     with open(
             os.path.join(RDConfig.RDCodeDir, 'ML', 'DecTree', 'test_data',
                          'CmpTree2.pkl'), 'r') as t2TFile:
         buf = t2TFile.read().replace('\r\n', '\n').encode('utf-8')
         t2TFile.close()
     with io.BytesIO(buf) as t2File:
         t2 = cPickle.load(t2File)
     assert cmp(t1, t2), 'equality failed'
Esempio n. 10
0
  def __cmp__(self, other):
    """ allows _cluster1 == cluster2_ to work

    """
    if cmp(type(self), type(other)):
      return cmp(type(self), type(other))

    m1, m2 = self.GetMetric(), other.GetMetric()
    if abs(m1 - m2) > CMPTOL:
      return cmp(m1, m2)

    if cmp(self.GetName(), other.GetName()):
      return cmp(self.GetName(), other.GetName())

    c1, c2 = self.GetChildren(), other.GetChildren()
    return cmp(c1, c2)
Esempio n. 11
0
  def __cmp__(self,other):
    """ allows _cluster1 == cluster2_ to work

    """
    if cmp(type(self),type(other)):
      return cmp(type(self),type(other))

    m1,m2=self.GetMetric(),other.GetMetric()
    if abs(m1-m2)>CMPTOL:
      return cmp(m1,m2)
    
    if cmp(self.GetName(),other.GetName()):
      return cmp(self.GetName(),other.GetName())

    c1,c2=self.GetChildren(),other.GetChildren()
    return cmp(c1,c2)
Esempio n. 12
0
def AccumulateCounts(predictions, thresh=0, sortIt=1):
    """  Accumulates the data for the enrichment plot for a single model

    **Arguments**

      - predictions: a list of 3-tuples (as returned by _ScreenModels_)

      - thresh: a threshold for the confidence level.  Anything below
        this threshold will not be considered

      - sortIt: toggles sorting on confidence levels


    **Returns**

      - a list of 3-tuples:

        - the id of the active picked here
        
        - num actives found so far

        - number of picks made so far

  """
    if sortIt:
        predictions.sort(lambda x, y: cmp(y[3], x[3]))
    res = []
    nCorrect = 0
    nPts = 0
    for i in range(len(predictions)):
        id, real, pred, conf = predictions[i]
        if conf > thresh:
            if pred == real:
                nCorrect += 1
            nPts += 1
            res.append((id, nCorrect, nPts))

    return res
Esempio n. 13
0
 def _getBondAttachmentCoordinates(self, p1, p2, labelSize):
   newpos = [None, None]
   if labelSize != None:
     labelSizeOffset = [labelSize[0][0]/2 + (cmp(p2[0], p1[0]) * labelSize[0][2]), labelSize[0][1]/2]
     if p1[1] == p2[1]:
       newpos[0] = p1[0] + cmp(p2[0], p1[0]) * labelSizeOffset[0]
     else:
       if abs(labelSizeOffset[1] * (p2[0] - p1[0]) / (p2[1] - p1[1])) < labelSizeOffset[0]:
         newpos[0] = p1[0] + cmp(p2[0], p1[0]) * abs(labelSizeOffset[1] * (p2[0] - p1[0]) / (p2[1] - p1[1]))
       else:
         newpos[0] = p1[0] + cmp(p2[0], p1[0]) * labelSizeOffset[0]
     if p1[0] == p2[0]:
       newpos[1] = p1[1] + cmp(p2[1], p1[1]) * labelSizeOffset[1]
     else:
       if abs(labelSizeOffset[0] * (p1[1] - p2[1]) / (p2[0] - p1[0])) < labelSizeOffset[1]:
         newpos[1] = p1[1] + cmp(p2[1], p1[1]) * abs(labelSizeOffset[0] * (p1[1] - p2[1]) / (p2[0] - p1[0]))
       else:
         newpos[1] = p1[1] + cmp(p2[1], p1[1]) * labelSizeOffset[1]
   else:
     newpos = copy.deepcopy(p1)
   return newpos
Esempio n. 14
0
def AccumulateCounts(predictions,thresh=0,sortIt=1):
  """  Accumulates the data for the enrichment plot for a single model

    **Arguments**

      - predictions: a list of 3-tuples (as returned by _ScreenModels_)

      - thresh: a threshold for the confidence level.  Anything below
        this threshold will not be considered

      - sortIt: toggles sorting on confidence levels


    **Returns**

      - a list of 3-tuples:

        - the id of the active picked here
        
        - num actives found so far

        - number of picks made so far

  """
  if sortIt:
    predictions.sort(lambda x,y:cmp(y[3],x[3]))
  res = []
  nCorrect = 0
  nPts = 0
  for i in range(len(predictions)):
    id,real,pred,conf = predictions[i]
    if conf > thresh:
      if pred == real:
        nCorrect += 1
      nPts += 1
      res.append((id,nCorrect,nPts))

  return res    
Esempio n. 15
0
 def sortHelp(x, y):
   if x[2] == y[2]:
     return cmp(x[1], y[1])
   else:
     return cmp(x[2], y[2])
Esempio n. 16
0
 def sortHelp(x, y):
     if x[2] == y[2]:
         return cmp(x[1], y[1])
     else:
         return cmp(x[2], y[2])