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


Python KNNClassifierRegion.__setstate__方法代碼示例

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


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

示例1: KNNAnomalyClassifierRegion

# 需要導入模塊: from KNNClassifierRegion import KNNClassifierRegion [as 別名]
# 或者: from KNNClassifierRegion.KNNClassifierRegion import __setstate__ [as 別名]

#.........這裏部分代碼省略.........
    self._deleteRecordsFromKNN(recordsToDelete)

    # Remove records not in cache
    self._deleteRangeFromKNN(start, end)

    # Recompute [clippedEnd, ...)
    for state in self._recordsCache[clippedEnd:]:
      self.classifyState(state)


  #############################################################################
  #
  # Methods to support serialization
  #
  #############################################################################


  #############################################################################
  def __getstate__(self):
    """
    Return serializable state.  This function will return a version of the
    __dict__ with all "ephemeral" members stripped out.  "Ephemeral" members
    are defined as those that do not need to be (nor should be) stored
    in any kind of persistent file (e.g., NuPIC network XML file.)
    """
    state = self.__dict__.copy()

    # Save knnclassifier properties
    state['_knnclassifierProps'] = state['_knnclassifier'].__getstate__()
    state.pop('_knnclassifier')
    return state

  #############################################################################
  def __setstate__(self, state):
    """
    Set the state of ourself from a serialized state.
    """
    if '_version' not in state or state['_version'] == 1:

      knnclassifierProps = state.pop('_knnclassifierProps')

      self.__dict__.update(state)
      self._knnclassifier = KNNClassifierRegion(**self._knnclassifierArgs)
      self._knnclassifier.__setstate__(knnclassifierProps)

      self._version = KNNAnomalyClassifierRegion.__VERSION__
    else:
      raise Exception("Invalid KNNAnomalyClassifierRegion version. Current "
          "version: %s" % (KNNAnomalyClassifierRegion.__VERSION__))


    # --------------------------------------------------------------------------
    # Migrate from when Anomaly was separated to stand-alone class
    if not hasattr(self, "_anomaly"):
      self._anomaly = Anomaly()

  
  def diff(self, knnRegion2):
    diff = []
    toCheck = [((), self.__getstate__(), knnRegion2.__getstate__())]
    while toCheck:
      keys, a, b = toCheck.pop()
      if type(a) != type(b):
        diff.append((keys, a, b))
      elif 'saved_categories' in keys:
        cats1 = set(a)
開發者ID:pjpan,項目名稱:nupic,代碼行數:70,代碼來源:KNNAnomalyClassifierRegion.py


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