parameters: (models, details, callback=None, setup=None, appendExamples=0, goodVotes=None,
                        badVotes=None, noVotes=None, data=None, enrichments=None)
docstring: Screens a set of data using a a _CompositeRun.CompositeRun_
         instance to provide parameters
  
  # DOC
  
      The actual data to be used are extracted from the database and
      table specified in _details_
  
      Aside from dataset construction,  _ShowVoteResults()_ does most of
      the heavy lifting here.
  
    **Arguments**
  
        - model: a composite model
  
        - details:  a _CompositeRun.CompositeRun_ object containing details
          (options, parameters, etc.) about the run
  
        - callback: (optional)  if provided, this should be a function
          taking a single argument that is called after each example is
          screened with the number of examples screened so far as the
          argument.
  
        - setup: (optional) a function taking a single argument which is
          called at the start of screening with the number of points to
          be screened as the argument.
  
        - appendExamples: (optional)  this value is passed on to the
          composite's _ClassifyExample()_ method.
  
        - goodVotes,badVotes,noVotes: (optional)  if provided these should
          be lists (or anything supporting an _append()_ method) which
          will be used to pass the screening results back.
  
  
    **Returns**
  
      a 7-tuple:
  
        1) the number of good (correct) predictions
  
        2) the number of bad (incorrect) predictions
  
        3) the number of predictions skipped due to the _threshold_
  
        4) the average confidence in the good predictions
  
        5) the average confidence in the bad predictions
  
        6) the average confidence in the skipped predictions
  
        7) the results table
docstring_summary: Screens a set of data using a a _CompositeRun.CompositeRun_
         instance to provide parameters
docstring_tokens: Screens a set of data using a a _CompositeRun . CompositeRun_ instance to provide parameters
function: def ScreenFromDetails(models, details, callback=None, setup=None, appendExamples=0, goodVotes=None,
                        badVotes=None, noVotes=None, data=None, enrichments=None):
    """  Screens a set of data using a a _CompositeRun.CompositeRun_
         instance to provide parameters
  
  # DOC
  
      The actual data to be used are extracted from the database and
      table specified in _details_
  
      Aside from dataset construction,  _ShowVoteResults()_ does most of
      the heavy lifting here.
  
    **Arguments**
  
        - model: a composite model
  
        - details:  a _CompositeRun.CompositeRun_ object containing details
          (options, parameters, etc.) about the run
  
        - callback: (optional)  if provided, this should be a function
          taking a single argument that is called after each example is
          screened with the number of examples screened so far as the
          argument.
  
        - setup: (optional) a function taking a single argument which is
          called at the start of screening with the number of points to
          be screened as the argument.
  
        - appendExamples: (optional)  this value is passed on to the
          composite's _ClassifyExample()_ method.
  
        - goodVotes,badVotes,noVotes: (optional)  if provided these should
          be lists (or anything supporting an _append()_ method) which
          will be used to pass the screening results back.
  
  
    **Returns**
  
      a 7-tuple:
  
        1) the number of good (correct) predictions
  
        2) the number of bad (incorrect) predictions
  
        3) the number of predictions skipped due to the _threshold_
  
        4) the average confidence in the good predictions
  
        5) the average confidence in the bad predictions
  
        6) the average confidence in the skipped predictions
  
        7) the results table
  
    """
    if data is None:
      if hasattr(details, 'pickleCol'):
        data = details.GetDataSet(pickleCol=details.pickleCol,
                                  pickleClass=DataStructs.ExplicitBitVect)
      else:
        data = details.GetDataSet()
    if details.threshold > 0.0:
      details.partialVote = 1
    else:
      details.partialVote = 0
  
    if type(models) not in [list, tuple]:
      models = (models, )
  
    nModels = len(models)
  
    if setup is not None:
      setup(nModels * data.GetNPts())
  
    nGood = numpy.zeros(nModels, numpy.float)
    nBad = numpy.zeros(nModels, numpy.float)
    nSkip = numpy.zeros(nModels, numpy.float)
    confGood = numpy.zeros(nModels, numpy.float)
    confBad = numpy.zeros(nModels, numpy.float)
    confSkip = numpy.zeros(nModels, numpy.float)
    voteTab = None
    if goodVotes is None:
      goodVotes = []
    if badVotes is None:
      badVotes = []
    if noVotes is None:
      noVotes = []
    if enrichments is None:
      enrichments = [0.0] * nModels
    badVoteDict = {}
    noVoteDict = {}
  
    for i in range(nModels):
      if nModels > 1:
        goodVotes = []
        badVotes = []
        noVotes = []
      model = models[i]
  
      try:
        seed = model._randomSeed
      except AttributeError:
        pass
      else:
        DataUtils.InitRandomNumbers(seed)
  
      if (hasattr(details, 'shuffleActivities') and details.shuffleActivities) or \
         (hasattr(details, 'randomActivities') and details.randomActivities):
        if hasattr(details, 'shuffleActivities') and details.shuffleActivities:
          shuffle = True
        else:
          shuffle = False
        randomize = True
        DataUtils.RandomizeActivities(data, shuffle=shuffle, runDetails=details)
      else:
        randomize = False
        shuffle = False
  
      if hasattr(model, '_shuffleActivities') and \
         model._shuffleActivities and \
         not shuffle:
        message('*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*')
        message('******  WARNING: Shuffled model being screened with unshuffled data.')
        message('*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*')
      if hasattr(model, '_randomizeActivities') and \
         model._randomizeActivities and \
         not randomize:
        message('*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*')
        message('******  WARNING: Random model being screened with non-random data.')
        message('*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*')
  
      trainIdx, testIdx = PrepareDataFromDetails(model, details, data)
  
      nPossible = model.GetQuantBounds()[1]
      if callback:
        cb = lambda x, y=callback, z=i * data.GetNPts(): y(x + z)
      else:
        cb = None
      if not hasattr(details, 'errorEstimate') or not details.errorEstimate:
        errorEstimate = 0
      else:
        errorEstimate = 1
      g, b, s, aG, aB, aS, vT = ShowVoteResults(
        testIdx, data, model, nPossible[-1], details.threshold, verbose=0, callback=cb,
        appendExamples=appendExamples, goodVotes=goodVotes, badVotes=badVotes, noVotes=noVotes,
        errorEstimate=errorEstimate)
      if voteTab is None:
        voteTab = numpy.zeros(vT.shape, numpy.float)
      if hasattr(details, 'errorAnalysis') and details.errorAnalysis:
        for a, p, c, idx in badVotes:
          label = testIdx[idx]
          if hasattr(details, 'enrichTgt') and details.enrichTgt >= 0:
            if a == details.enrichTgt:
              badVoteDict[label] = badVoteDict.get(label, 0) + 1
          else:
            badVoteDict[label] = badVoteDict.get(label, 0) + 1
        for a, p, c, idx in noVotes:
          label = testIdx[idx]
          if hasattr(details, 'enrichTgt') and details.enrichTgt >= 0:
            if a == details.enrichTgt:
              noVoteDict[label] = noVoteDict.get(label, 0) + 1
          else:
            noVoteDict[label] = noVoteDict.get(label, 0) + 1
  
      voteTab += vT
      nGood[i] = g
      nBad[i] = b
      nSkip[i] = s
      confGood[i] = aG
      confBad[i] = aB
      confSkip[i] = aS
  
      if hasattr(details, 'enrichTgt') and details.enrichTgt >= 0:
        enrichments[i] = CalcEnrichment(vT, tgt=details.enrichTgt)
  
    if nModels == 1:
      return g, b, s, aG, aB, aS, vT
    else:
      voteTab /= nModels
  
      avgNBad = sum(nBad) / nModels
      devNBad = numpy.sqrt(sum((nBad - avgNBad)**2) / (nModels - 1))
  
      # bestIdx = numpy.argsort(nBad)[0]
  
      avgNGood = sum(nGood) / nModels
      devNGood = numpy.sqrt(sum((nGood - avgNGood)**2) / (nModels - 1))
  
      avgNSkip = sum(nSkip) / nModels
      devNSkip = numpy.sqrt(sum((nSkip - avgNSkip)**2) / (nModels - 1))
  
      avgConfBad = sum(confBad) / nModels
      devConfBad = numpy.sqrt(sum((confBad - avgConfBad)**2) / (nModels - 1))
  
      avgConfGood = sum(confGood) / nModels
      devConfGood = numpy.sqrt(sum((confGood - avgConfGood)**2) / (nModels - 1))
  
      avgConfSkip = sum(confSkip) / nModels
      devConfSkip = numpy.sqrt(sum((confSkip - avgConfSkip)**2) / (nModels - 1))
      return ((avgNGood, devNGood), (avgNBad, devNBad), (avgNSkip, devNSkip),
              (avgConfGood, devConfGood), (avgConfBad, devConfBad), (avgConfSkip, devConfSkip),
              voteTab)
function_tokens: def ScreenFromDetails ( models , details , callback = None , setup = None , appendExamples = 0 , goodVotes = None , badVotes = None , noVotes = None , data = None , enrichments = None ) : if data is None : if hasattr ( details , 'pickleCol' ) : data = details . GetDataSet ( pickleCol = details . pickleCol , pickleClass = DataStructs . ExplicitBitVect ) else : data = details . GetDataSet ( ) if details . threshold > 0.0 : details . partialVote = 1 else : details . partialVote = 0 if type ( models ) not in [ list , tuple ] : models = ( models , ) nModels = len ( models ) if setup is not None : setup ( nModels * data . GetNPts ( ) ) nGood = numpy . zeros ( nModels , numpy . float ) nBad = numpy . zeros ( nModels , numpy . float ) nSkip = numpy . zeros ( nModels , numpy . float ) confGood = numpy . zeros ( nModels , numpy . float ) confBad = numpy . zeros ( nModels , numpy . float ) confSkip = numpy . zeros ( nModels , numpy . float ) voteTab = None if goodVotes is None : goodVotes = [ ] if badVotes is None : badVotes = [ ] if noVotes is None : noVotes = [ ] if enrichments is None : enrichments = [ 0.0 ] * nModels badVoteDict = { } noVoteDict = { } for i in range ( nModels ) : if nModels > 1 : goodVotes = [ ] badVotes = [ ] noVotes = [ ] model = models [ i ] try : seed = model . _randomSeed except AttributeError : pass else : DataUtils . InitRandomNumbers ( seed ) if ( hasattr ( details , 'shuffleActivities' ) and details . shuffleActivities ) or ( hasattr ( details , 'randomActivities' ) and details . randomActivities ) : if hasattr ( details , 'shuffleActivities' ) and details . shuffleActivities : shuffle = True else : shuffle = False randomize = True DataUtils . RandomizeActivities ( data , shuffle = shuffle , runDetails = details ) else : randomize = False shuffle = False if hasattr ( model , '_shuffleActivities' ) and model . _shuffleActivities and not shuffle : message ( '*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*' ) message ( '******  WARNING: Shuffled model being screened with unshuffled data.' ) message ( '*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*' ) if hasattr ( model , '_randomizeActivities' ) and model . _randomizeActivities and not randomize : message ( '*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*' ) message ( '******  WARNING: Random model being screened with non-random data.' ) message ( '*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*' ) trainIdx , testIdx = PrepareDataFromDetails ( model , details , data ) nPossible = model . GetQuantBounds ( ) [ 1 ] if callback : cb = lambda x , y = callback , z = i * data . GetNPts ( ) : y ( x + z ) else : cb = None if not hasattr ( details , 'errorEstimate' ) or not details . errorEstimate : errorEstimate = 0 else : errorEstimate = 1 g , b , s , aG , aB , aS , vT = ShowVoteResults ( testIdx , data , model , nPossible [ - 1 ] , details . threshold , verbose = 0 , callback = cb , appendExamples = appendExamples , goodVotes = goodVotes , badVotes = badVotes , noVotes = noVotes , errorEstimate = errorEstimate ) if voteTab is None : voteTab = numpy . zeros ( vT . shape , numpy . float ) if hasattr ( details , 'errorAnalysis' ) and details . errorAnalysis : for a , p , c , idx in badVotes : label = testIdx [ idx ] if hasattr ( details , 'enrichTgt' ) and details . enrichTgt >= 0 : if a == details . enrichTgt : badVoteDict [ label ] = badVoteDict . get ( label , 0 ) + 1 else : badVoteDict [ label ] = badVoteDict . get ( label , 0 ) + 1 for a , p , c , idx in noVotes : label = testIdx [ idx ] if hasattr ( details , 'enrichTgt' ) and details . enrichTgt >= 0 : if a == details . enrichTgt : noVoteDict [ label ] = noVoteDict . get ( label , 0 ) + 1 else : noVoteDict [ label ] = noVoteDict . get ( label , 0 ) + 1 voteTab += vT nGood [ i ] = g nBad [ i ] = b nSkip [ i ] = s confGood [ i ] = aG confBad [ i ] = aB confSkip [ i ] = aS if hasattr ( details , 'enrichTgt' ) and details . enrichTgt >= 0 : enrichments [ i ] = CalcEnrichment ( vT , tgt = details . enrichTgt ) if nModels == 1 : return g , b , s , aG , aB , aS , vT else : voteTab /= nModels avgNBad = sum ( nBad ) / nModels devNBad = numpy . sqrt ( sum ( ( nBad - avgNBad ) ** 2 ) / ( nModels - 1 ) ) # bestIdx = numpy.argsort(nBad)[0] avgNGood = sum ( nGood ) / nModels devNGood = numpy . sqrt ( sum ( ( nGood - avgNGood ) ** 2 ) / ( nModels - 1 ) ) avgNSkip = sum ( nSkip ) / nModels devNSkip = numpy . sqrt ( sum ( ( nSkip - avgNSkip ) ** 2 ) / ( nModels - 1 ) ) avgConfBad = sum ( confBad ) / nModels devConfBad = numpy . sqrt ( sum ( ( confBad - avgConfBad ) ** 2 ) / ( nModels - 1 ) ) avgConfGood = sum ( confGood ) / nModels devConfGood = numpy . sqrt ( sum ( ( confGood - avgConfGood ) ** 2 ) / ( nModels - 1 ) ) avgConfSkip = sum ( confSkip ) / nModels devConfSkip = numpy . sqrt ( sum ( ( confSkip - avgConfSkip ) ** 2 ) / ( nModels - 1 ) ) return ( ( avgNGood , devNGood ) , ( avgNBad , devNBad ) , ( avgNSkip , devNSkip ) , ( avgConfGood , devConfGood ) , ( avgConfBad , devConfBad ) , ( avgConfSkip , devConfSkip ) , voteTab )