示例#1
0
文件: runner.py 项目: breznak/NAB
  def optimize(self, detectorNames):
    """Optimize the threshold for each combination of detector and profile.

    @param detectorNames  (list)  List of detector names.

    @return thresholds    (dict)  Dictionary of dictionaries with detector names
                                  then usernames as keys followed by another
                                  dictionary containing the score and the
                                  threshold used to obtained that score.
    """
    print "\nOptimizing anomaly Scores"

    thresholds = dict()

    for detector in detectorNames:
      resultsDetectorDir = os.path.join(self.resultsDir, detector)
      resultsCorpus = Corpus(resultsDetectorDir)

      thresholds[detector] = dict()

      for username, profile in self.profiles.iteritems():
        costMatrix = profile["CostMatrix"]

        thresholds[detector][username] = optimizeThreshold(
          (self.pool,
          detector,
          username,
          costMatrix,
          resultsCorpus,
          self.corpusLabel,
          self.probationaryPercent))

    updateThresholds(thresholds, self.thresholdPath)

    return thresholds
示例#2
0
文件: runner.py 项目: pmenn36/NAB
  def optimize(self, detectorNames):
    """Optimize the threshold for each combination of detector and profile.

    @param detectorNames  (list)  List of detector names.

    @return thresholds    (dict)  Dictionary of dictionaries with detector names
                                  then profile names as keys followed by another
                                  dictionary containing the score and the
                                  threshold used to obtained that score.
    """
    print("\nRunning optimize step")

    scoreFlag = False
    thresholds = {}

    for detectorName in detectorNames:
      resultsDetectorDir = os.path.join(self.resultsDir, detectorName)
      resultsCorpus = Corpus(resultsDetectorDir)

      thresholds[detectorName] = {}

      for profileName, profile in self.profiles.items():
        thresholds[detectorName][profileName] = optimizeThreshold(
          (detectorName,
           profile["CostMatrix"],
           resultsCorpus,
           self.corpusLabel,
           self.probationaryPercent))

    updateThresholds(thresholds, self.thresholdPath)

    return thresholds
示例#3
0
文件: runner.py 项目: numenta/NAB
  def optimize(self, detectorNames):
    """Optimize the threshold for each combination of detector and profile.

    @param detectorNames  (list)  List of detector names.

    @return thresholds    (dict)  Dictionary of dictionaries with detector names
                                  then profile names as keys followed by another
                                  dictionary containing the score and the
                                  threshold used to obtained that score.
    """
    print "\nRunning optimize step"

    scoreFlag = False
    thresholds = {}

    for detectorName in detectorNames:
      resultsDetectorDir = os.path.join(self.resultsDir, detectorName)
      resultsCorpus = Corpus(resultsDetectorDir)

      thresholds[detectorName] = {}

      for profileName, profile in self.profiles.iteritems():
        thresholds[detectorName][profileName] = optimizeThreshold(
          (detectorName,
           profile["CostMatrix"],
           resultsCorpus,
           self.corpusLabel,
           self.probationaryPercent))

    updateThresholds(thresholds, self.thresholdPath)

    return thresholds
    def testThresholdUpdateDifferentScores(self):
        """Thresholds should be overwritten regardless of new scores."""
        newThresholds = {
            "lucky_detector": {
                "standard": {
                    "score": 23.0,
                    "threshold": 0.77
                }
            },
            "deep_thought": {
                "standard": {
                    "score": 32.0,
                    "threshold": 0.99
                }
            }
        }

        updateThresholds(newThresholds, self.thresholdsPath)

        with open(self.thresholdsPath) as inFile:
            threshDict = json.load(inFile)

        self.assertDictEqual(
            newThresholds, threshDict,
            "The updated threshold dict does not match the expected dict.")
    def testThresholdUpdateNewDetector(self):
        newThresholds = {
            "bad_detector": {
                "standard": {
                    "score": -1.0,
                    "threshold": 0.5
                }
            }
        }

        updateThresholds(newThresholds, self.thresholdsPath)

        with open(self.thresholdsPath) as inFile:
            threshDict = json.load(inFile)

        expectedDict = {
            "lucky_detector": {
                "standard": {
                    "score": 13.0,
                    "threshold": 0.7
                }
            },
            "deep_thought": {
                "standard": {
                    "score": 42.0,
                    "threshold": 0.9
                }
            },
            "bad_detector": {
                "standard": {
                    "score": -1.0,
                    "threshold": 0.5
                }
            }
        }

        self.assertDictEqual(
            expectedDict, threshDict,
            "The updated threshold dict does not match the expected dict.")
示例#6
0
  def testThresholdUpdateNewDetector(self):
    newThresholds = {
      "bad_detector": {
        "standard": {
          "score": -1.0,
          "threshold": 0.5
        }
      }
    }

    updateThresholds(newThresholds, self.thresholdsPath)

    with open(self.thresholdsPath) as inFile:
      threshDict = json.load(inFile)

    expectedDict = {
      "lucky_detector": {
        "standard": {
          "score": 13.0,
          "threshold": 0.7
        }
      },
      "deep_thought": {
        "standard": {
          "score": 42.0,
          "threshold": 0.9
        }
      },
      "bad_detector": {
        "standard": {
          "score": -1.0,
          "threshold": 0.5
        }
      }
    }

    self.assertDictEqual(expectedDict, threshDict,
      "The updated threshold dict does not match the expected dict.")
示例#7
0
  def testThresholdUpdateDifferentScores(self):
    """Thresholds should be overwritten regardless of new scores."""
    newThresholds = {
      "lucky_detector": {
        "standard": {
          "score": 23.0,
          "threshold": 0.77
        }
      },
      "deep_thought": {
        "standard": {
          "score": 32.0,
          "threshold": 0.99
        }
      }
    }

    updateThresholds(newThresholds, self.thresholdsPath)

    with open(self.thresholdsPath) as inFile:
      threshDict = json.load(inFile)

    self.assertDictEqual(newThresholds, threshDict,
      "The updated threshold dict does not match the expected dict.")