当前位置: 首页>>代码示例>>Python>>正文


Python moves.xrange函数代码示例

本文整理汇总了Python中rdkit.six.moves.xrange函数的典型用法代码示例。如果您正苦于以下问题:Python xrange函数的具体用法?Python xrange怎么用?Python xrange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xrange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GenVarTable

def GenVarTable(examples,nPossibleVals,vars):
  """Generates a list of variable tables for the examples passed in.

    The table for a given variable records the number of times each possible value
    of that variable appears for each possible result of the function.

  **Arguments**
  
    - examples: a list (nInstances long) of lists of variable values + instance
              values

    - nPossibleVals: a list containing the number of possible values of
                   each variable + the number of values of the function.

    - vars:  a list of the variables to include in the var table


  **Returns**

      a list of variable result tables. Each table is a Numeric array
        which is varValues x nResults
  """
  nVars = len(vars)
  res = [None]*nVars
  nFuncVals = nPossibleVals[-1]

  for i in xrange(nVars):
    res[i] = numpy.zeros((nPossibleVals[vars[i]],nFuncVals),'i')
  for example in examples:
    val = int(example[-1])
    for i in xrange(nVars):
      res[i][int(example[vars[i]]),val] += 1

  return res
开发者ID:ASKCOS,项目名称:rdkit,代码行数:34,代码来源:ID3.py

示例2: ClassifyExample

  def ClassifyExample(self,example,appendExamples=0):
    """ classifies a given example and returns the results of the output layer.

      **Arguments**

        - example: the example to be classified

      **NOTE:**

        if the output layer is only one element long,
        a scalar (not a list) will be returned.  This is why a lot of the other
        network code claims to only support single valued outputs.

    """
    if len(example) > self.numInputNodes:
      if len(example)-self.numInputNodes > self.numOutputNodes:
        example = example[1:-self.numOutputNodes]
      else:
        example = example[:-self.numOutputNodes]
    assert len(example) == self.numInputNodes
    totNumNodes = sum(self.nodeCounts)
    results = numpy.zeros(totNumNodes,numpy.float64)
    for i in xrange(self.numInputNodes):
      results[i] = example[i]
    for i in xrange(self.numInputNodes,totNumNodes):
      self.nodeList[i].Eval(results)
    self.lastResults = results[:]
    if self.numOutputNodes == 1:
      return results[-1]
    else:
      return results
开发者ID:ASKCOS,项目名称:rdkit,代码行数:31,代码来源:Network.py

示例3: ConstructNodes

  def ConstructNodes(self,nodeCounts,actFunc,actFuncParms):
    """ build an unconnected network and set node counts

      **Arguments**

        - nodeCounts: a list containing the number of nodes to be in each layer.
           the ordering is:
            (nInput,nHidden1,nHidden2, ... , nHiddenN, nOutput)

    """
    self.nodeCounts = nodeCounts
    self.numInputNodes = nodeCounts[0]
    self.numOutputNodes = nodeCounts[-1]
    self.numHiddenLayers = len(nodeCounts)-2
    self.numInHidden = [None]*self.numHiddenLayers
    for i in xrange(self.numHiddenLayers):
      self.numInHidden[i] = nodeCounts[i+1]

    numNodes = sum(self.nodeCounts)
    self.nodeList = [None]*(numNodes)
    for i in xrange(numNodes):
      self.nodeList[i] = NetNode.NetNode(i,self.nodeList,
                                         actFunc=actFunc,
                                         actFuncParms=actFuncParms)

    self.layerIndices = [None]*len(nodeCounts)
    start = 0
    for i in xrange(len(nodeCounts)):
      end = start + nodeCounts[i]
      self.layerIndices[i] = range(start,end)
      start = end
开发者ID:ASKCOS,项目名称:rdkit,代码行数:31,代码来源:Network.py

示例4: CalcNPossibleUsingMap

def CalcNPossibleUsingMap(data,order,qBounds,nQBounds=None):
  """ calculates the number of possible values for each variable in a data set

   **Arguments**

     - data: a list of examples

     - order: the ordering map between the variables in _data_ and _qBounds_

     - qBounds: the quantization bounds for the variables

   **Returns**

      a list with the number of possible values each variable takes on in the data set

   **Notes**

     - variables present in _qBounds_ will have their _nPossible_ number read
       from _qbounds

     - _nPossible_ for other numeric variables will be calculated

  """
  numericTypes = [int, float]
  if six.PY2:
    numericTypes.append(long)
    
  print('order:',order, len(order))
  print('qB:',qBounds)
  #print('nQB:',nQBounds, len(nQBounds))
  assert (qBounds and len(order)==len(qBounds)) or (nQBounds and len(order)==len(nQBounds)),\
         'order/qBounds mismatch'
  nVars = len(order)
  nPossible = [-1]*nVars
  cols = range(nVars)
  for i in xrange(nVars):
    if nQBounds and nQBounds[i] != 0:
      nPossible[i] = -1
      cols.remove(i)
    elif len(qBounds[i])>0:
      nPossible[i] = len(qBounds[i])
      cols.remove(i)

  nPts = len(data)
  for i in xrange(nPts):
    for col in cols[:]:
      d = data[i][order[col]]
      if type(d) in numericTypes:
        if int(d) == d:
          nPossible[col] = max(int(d),nPossible[col])
        else:
          nPossible[col] = -1
          cols.remove(col)
      else:
        print('bye bye col %d: %s'%(col,repr(d)))
        nPossible[col] = -1
        cols.remove(col)

  return list(map(lambda x:int(x)+1,nPossible))
开发者ID:ASKCOS,项目名称:rdkit,代码行数:59,代码来源:DataUtils.py

示例5: test3Classify

 def test3Classify(self):
   " testing classification "
   self._setupTree1()
   self._setupTree2()
   for i in xrange(len(self.examples1)):
     assert self.t1.ClassifyExample(self.examples1[i])==self.examples1[i][-1],\
            'examples1[%d] misclassified'%i
   for i in xrange(len(self.examples2)):
     assert self.t2.ClassifyExample(self.examples2[i])==self.examples2[i][-1],\
            'examples2[%d] misclassified'%i
开发者ID:abradle,项目名称:rdkit,代码行数:10,代码来源:UnitTestQuantTree.py

示例6: CrossValidate

def CrossValidate(tree, testExamples, appendExamples=0):
  """ Determines the classification error for the testExamples

    **Arguments**

      - tree: a decision tree (or anything supporting a _ClassifyExample()_ method)

      - testExamples: a list of examples to be used for testing

      - appendExamples: a toggle which is passed along to the tree as it does
        the classification. The trees can use this to store the examples they
        classify locally.

    **Returns**

      a 2-tuple consisting of:

        1) the percent error of the tree

        2) a list of misclassified examples
        
  """
  nTest = len(testExamples)
  nBad = 0
  badExamples = []
  for i in xrange(nTest):
    testEx = testExamples[i]
    trueRes = testEx[-1]
    res = tree.ClassifyExample(testEx, appendExamples)
    if (trueRes != res).any():
      badExamples.append(testEx)
      nBad += 1

  return float(nBad) / nTest, badExamples
开发者ID:abradle,项目名称:rdkit,代码行数:34,代码来源:CrossValidate.py

示例7: ChooseOptimalRoot

def ChooseOptimalRoot(examples, trainExamples, testExamples, attrs, nPossibleVals, treeBuilder,
                      nQuantBounds=[], **kwargs):
  """ loops through all possible tree roots and chooses the one which produces the best tree

  **Arguments**

    - examples: the full set of examples

    - trainExamples: the training examples

    - testExamples: the testing examples

    - attrs: a list of attributes to consider in the tree building

    - nPossibleVals: a list of the number of possible values each variable can adopt

    - treeBuilder: the function to be used to actually build the tree

    - nQuantBounds: an optional list.  If present, it's assumed that the builder
      algorithm takes this argument as well (for building QuantTrees)

  **Returns**

    The best tree found
    
  **Notes**

    1) Trees are built using _trainExamples_

    2) Testing of each tree (to determine which is best) is done using _CrossValidate_ and
       the entire set of data (i.e. all of _examples_)

    3) _trainExamples_ is not used at all, which immediately raises the question of
       why it's even being passed in

  """
  attrs = attrs[:]
  if nQuantBounds:
    for i in range(len(nQuantBounds)):
      if nQuantBounds[i] == -1 and i in attrs:
        attrs.remove(i)
  nAttrs = len(attrs)
  trees = [None] * nAttrs
  errs = [0] * nAttrs
  errs[0] = 1e6

  for i in xrange(1, nAttrs):
    argD = {'initialVar': attrs[i]}
    argD.update(kwargs)
    if nQuantBounds is None or nQuantBounds == []:
      trees[i] = treeBuilder(trainExamples, attrs, nPossibleVals, **argd)
    else:
      trees[i] = treeBuilder(trainExamples, attrs, nPossibleVals, nQuantBounds, **argD)
    if trees[i]:
      errs[i], foo = CrossValidate(trees[i], examples, appendExamples=0)
    else:
      errs[i] = 1e6
  best = numpy.argmin(errs)
  # FIX: this used to say 'trees[i]', could that possibly have been right?
  return trees[best]
开发者ID:abradle,项目名称:rdkit,代码行数:60,代码来源:CrossValidate.py

示例8: CalcCompoundDescriptorsForComposition

  def CalcCompoundDescriptorsForComposition(self, compos='', composList=None, propDict={}):
    """ calculates all simple descriptors for a given composition

      **Arguments**

        - compos: a string representation of the composition

        - composList: a *composVect*

        - propDict: a dictionary containing the properties of the composition
          as a whole (e.g. structural variables, etc.)

        The client must provide either _compos_ or _composList_.  If both are
        provided, _composList_ takes priority.

      **Returns**
        the list of descriptor values

      **Notes**

        - when _compos_ is provided, this uses _chemutils.SplitComposition_
          to split the composition into its individual pieces

    """
    if composList is None:
      composList = chemutils.SplitComposition(compos)
    res = []
    for i in xrange(len(self.compoundList)):
      val = Parser.CalcSingleCompoundDescriptor(composList, self.compoundList[i][1:], self.atomDict,
                                                propDict)
      res.append(val)
    return res
开发者ID:abradle,项目名称:rdkit,代码行数:32,代码来源:CompoundDescriptors.py

示例9: ProcessSimpleList

  def ProcessSimpleList(self):
    """ Handles the list of simple descriptors

      This constructs the list of _nonZeroDescriptors_ and _requiredDescriptors_.

      There's some other magic going on that I can't decipher at the moment.

    """
    global countOptions

    self.nonZeroDescriptors = []
    lCopy = self.simpleList[:]
    tList = map(lambda x: x[0], countOptions)
    for i in xrange(len(lCopy)):
      entry = lCopy[i]
      if 'NONZERO' in entry[1]:
        if entry[0] not in tList:
          self.nonZeroDescriptors.append('%s != 0' % entry[0])
        if len(entry[1]) == 1:
          self.simpleList.remove(entry)
        else:
          self.simpleList[self.simpleList.index(entry)][1].remove('NONZERO')
    self.requiredDescriptors = map(lambda x: x[0], self.simpleList)
    for entry in tList:
      if entry in self.requiredDescriptors:
        self.requiredDescriptors.remove(entry)
开发者ID:abradle,项目名称:rdkit,代码行数:26,代码来源:CompoundDescriptors.py

示例10: testSingleCalcs

 def testSingleCalcs(self):
   " testing calculation of a single descriptor "
   for i in xrange(len(self.cExprs)):
     cExpr = self.cExprs[i]
     argVect = self.piece1 + [cExpr]
     res = Parser.CalcSingleCompoundDescriptor(self.compos, argVect, self.aDict, self.pDict)
     self.assertAlmostEqual(res, self.results[i], 2)
开发者ID:abradle,项目名称:rdkit,代码行数:7,代码来源:UnitTestParser.py

示例11: _CalcNPossible

  def _CalcNPossible(self, data):
    """calculates the number of possible values of each variable (where possible)

      **Arguments**

         -data: a list of examples to be used

      **Returns**

         a list of nPossible values for each variable

    """
    nVars = self.GetNVars() + self.nResults
    nPossible = [-1] * nVars
    cols = list(xrange(nVars))
    for i, bounds in enumerate(self.qBounds):
      if len(bounds) > 0:
        nPossible[i] = len(bounds)
        cols.remove(i)

    nPts = self.GetNPts()
    for i, pt in enumerate(self.data):
      for col in cols[:]:
        d = pt[col]
        if type(d) in numericTypes:
          if math.floor(d) == d:
            nPossible[col] = max(math.floor(d), nPossible[col])
          else:
            nPossible[col] = -1
            cols.remove(col)
        else:
          nPossible[col] = -1
          cols.remove(col)
    return [int(x) + 1 for x in nPossible]
开发者ID:abradle,项目名称:rdkit,代码行数:34,代码来源:MLData.py

示例12: ReadVars

def ReadVars(inFile):
  """ reads the variables and quantization bounds from a .qdat or .dat file

    **Arguments**

      - inFile: a file object

    **Returns**

      a 2-tuple containing:

        1) varNames: a list of the variable names

        2) qbounds: the list of quantization bounds for each variable

  """
  varNames = []
  qBounds = []
  fileutils.MoveToMatchingLine(inFile,'Variable Table')
  inLine = inFile.readline()
  while inLine.find('# ----') == -1:
    splitLine = inLine[2:].split('[')
    varNames.append(splitLine[0].strip())
    qBounds.append(splitLine[1][:-2])
    inLine = inFile.readline()
  for i in xrange(len(qBounds)):
    
    if qBounds[i] != '':
      l = qBounds[i].split(',')
      qBounds[i] = []
      for item in l:
        qBounds[i].append(float(item))
    else:
      qBounds[i] = []
  return varNames,qBounds
开发者ID:ASKCOS,项目名称:rdkit,代码行数:35,代码来源:DataUtils.py

示例13: CharacteristicPolynomial

def CharacteristicPolynomial(mol,mat=None):
  """ calculates the characteristic polynomial for a molecular graph

    if mat is not passed in, the molecule's Weighted Adjacency Matrix will
    be used.

    The approach used is the Le Verrier-Faddeev-Frame method described
    in _Chemical Graph Theory, 2nd Edition_ by Nenad Trinajstic (CRC Press,
    1992), pg 76.
    
  """
  nAtoms = mol.GetNumAtoms()
  if mat is None:
    # FIX: complete this:
    #A = mol.GetWeightedAdjacencyMatrix()
    pass
  else:
    A = mat
  I = 1.*numpy.identity(nAtoms)
  An = A
  res = numpy.zeros(nAtoms+1,numpy.float)
  res[0] = 1.0
  for n in xrange(1,nAtoms+1):
    res[n] = 1./n*numpy.trace(An)
    Bn = An - res[n]*I
    An = numpy.dot(A,Bn)

  res[1:] *= -1
  return res  
开发者ID:ASKCOS,项目名称:rdkit,代码行数:29,代码来源:Graphs.py

示例14: testTreeGrow

    def testTreeGrow(self):
        " testing tree-based composite "
        with open(RDConfig.RDCodeDir + "/ML/Composite/test_data/composite_base.pkl", "r") as pklTF:
            buf = pklTF.read().replace("\r\n", "\n").encode("utf-8")
            pklTF.close()
        with io.BytesIO(buf) as pklF:
            self.refCompos = cPickle.load(pklF)

        composite = Composite.Composite()
        composite._varNames = self.varNames
        composite.SetQuantBounds(self.qBounds, self.nPoss)
        from rdkit.ML.DecTree import CrossValidate

        driver = CrossValidate.CrossValidationDriver
        pruner = None
        composite.Grow(self.examples, self.attrs, [], buildDriver=driver, pruner=pruner, nTries=100, silent=1)
        composite.AverageErrors()
        composite.SortModels()

        # with open(RDConfig.RDCodeDir+'/ML/Composite/test_data/composite_base.pkl','wb') as pklF:
        #  cPickle.dump(composite,pklF)

        self.treeComposite = composite
        self.assertEqual(len(composite), len(self.refCompos))
        for i in xrange(len(composite)):
            t1, c1, e1 = composite[i]
            t2, c2, e2 = self.refCompos[i]
            self.assertEqual(e1, e2)
开发者ID:jandom,项目名称:rdkit,代码行数:28,代码来源:UnitTestComposite.py

示例15: PyInfoGain

def PyInfoGain(varMat):
  """ calculates the information gain for a variable

    **Arguments**

      varMat is a Numeric array with the number of possible occurances
        of each result for reach possible value of the given variable.

      So, for a variable which adopts 4 possible values and a result which
        has 3 possible values, varMat would be 4x3

    **Returns**

      The expected information gain
  """
  variableRes = numpy.sum(varMat, 1)  # indexed by variable, Sv in Mitchell's notation
  overallRes = numpy.sum(varMat, 0)  # indexed by result, S in Mitchell's notation

  term2 = 0
  for i in xrange(len(variableRes)):
    term2 = term2 + variableRes[i] * InfoEntropy(varMat[i])
  tSum = sum(overallRes)
  if tSum != 0.0:
    term2 = 1. / tSum * term2
    gain = InfoEntropy(overallRes) - term2
  else:
    gain = 0
  return gain
开发者ID:abradle,项目名称:rdkit,代码行数:28,代码来源:entropy.py


注:本文中的rdkit.six.moves.xrange函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。