當前位置: 首頁>>代碼示例>>Python>>正文


Python Markov.predict方法代碼示例

本文整理匯總了Python中markov.Markov.predict方法的典型用法代碼示例。如果您正苦於以下問題:Python Markov.predict方法的具體用法?Python Markov.predict怎麽用?Python Markov.predict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在markov.Markov的用法示例。


在下文中一共展示了Markov.predict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: featureList

# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import predict [as 別名]
def featureList(pairs):
  features = list()

  markov = Markov()

  # go from the feature representation of the data (features) to the original data (pairs)
  dataFeatToData = {}

  for bar in pairs:
    seq = pairs[bar]
    isoFeatures = {}
    isoFeaturesOrig = {}
    rootScores = {}

    # each data element should have as a features all the features of the previous and subsequent tslices
    for i in range(len(seq)):
      data,label = seq[i]
      chordKey = data[8]

      # isolated features
      isoFeatures[i] = (getIsoFeatures(data),label)
      isoFeaturesOrig[i] = isoFeatures[i]
      rootScores[i] = [int(dat) for dat in data[:7]]
  
    for i in range(len(seq)):
      
      # subsequent measure
      subBar = bar.split('_')[0] + str(int(bar.split('_')[1])+1)
      if i < len(seq) - 1:
        subFeats = dict([('S_' + key, val) for (key,val) in isoFeaturesOrig[i+1][0].items()])
        isoFeatures[i] = (dict(isoFeatures[i][0].items() + subFeats.items()) , isoFeatures[i][1])
       
      
      elif subBar in pairs:
        subFeats = dict([('S_' + key, val) for (kev,val) in getIsoFeatures(pairs[subBar][0][0]).items()])
        isoFeatures[i] = (dict(isoFeatures[i][0].items() + subFeats.items()) , isoFeatures[i][1])

      # prev measure
      prevBar = bar.split('_')[0] + str(int(bar.split('_')[1])-1)
      if i > 0:
        prevFeats = dict([('P_' + key, val) for (key,val) in isoFeaturesOrig[i-1][0].items()])
        #markovPred = markov.predict(chordKey, tuple([rootScores[i-1]]), markov.markov2)
        markovFeats = [('markov2', markov.predict(chordKey, tuple([rootScores[i-1]]), markov.markov2))]

        if i > 1:
          markovFeats += [('markov3', markov.predict(chordKey, tuple([rootScores[i-2], rootScores[i-1]]), markov.markov3))]

        if i > 2:
          markovFeats += [('markov4', markov.predict(chordKey, tuple([rootScores[i-3], rootScores[i-2], rootScores[i-1]]), markov.markov4))]

        isoFeatures[i] = (dict(isoFeatures[i][0].items() + prevFeats.items() + markovFeats) , isoFeatures[i][1])
        #isoFeatures[i] = (dict(isoFeatures[i][0].items() + prevFeats.items()) , isoFeatures[i][1])

      elif prevBar in pairs:
        prevFeats = dict([('P_' + key, val) for (kev,val) in getIsoFeatures(pairs[prevBar][-1][0]).items()])
        isoFeatures[i] = (dict(isoFeatures[i][0].items() + subFeats.items()) , isoFeatures[i][1])
    
      dataFeatToData[str(isoFeatures[i])] = seq[i]
    
    features += isoFeatures.values()

  
  return dataFeatToData, features
開發者ID:dimuthk,項目名稱:Dimuth_Projects,代碼行數:65,代碼來源:linreg.py


注:本文中的markov.Markov.predict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。