コード例 #1
0
    def testCalcSweepScoreWindowScoreInteraction(self):
        """Scores inside a window should be positive; all others should be negative."""
        numRows = 100
        fakeAnomalyScores = [1 for _ in range(numRows)]
        fakeTimestamps = [
            i for i in range(numRows)
        ]  # We'll use numbers, even though real data uses dates
        fakeName = "TestDataSet"

        windowA = (30, 39)
        windowB = (75, 95)
        windowLimits = [windowA, windowB]
        expectedInWindowCount = (windowA[1] - windowA[0] +
                                 1) + (windowB[1] - windowB[0] + 1)

        # Standard profile
        costMatrix = {
            "tpWeight": 1.0,
            "fnWeight": 1.0,
            "fpWeight": 0.11,
        }
        probationPercent = 0.1
        o = Sweeper(probationPercent=probationPercent, costMatrix=costMatrix)
        scoredAnomalies = o.calcSweepScore(fakeTimestamps, fakeAnomalyScores,
                                           windowLimits, fakeName)

        # Check that correct number of AnomalyPoints returned
        assert len(scoredAnomalies) == numRows
        assert all(isinstance(x, AnomalyPoint) for x in scoredAnomalies)

        # Expected number of points marked 'probationary'
        probationary = [
            x for x in scoredAnomalies if x.windowName == "probationary"
        ]
        assert len(probationary) == o._getProbationaryLength(numRows)

        # Expected number of points marked 'in window'
        inWindow = [
            x for x in scoredAnomalies
            if x.windowName not in ("probationary", None)
        ]
        assert len(inWindow) == expectedInWindowCount

        # Points in window have positive score; others have negative score
        for point in scoredAnomalies:
            if point.windowName not in ("probationary", None):
                assert point.sweepScore > 0
            else:
                assert point.sweepScore < 0
コード例 #2
0
ファイル: sweeper_test.py プロジェクト: numenta/NAB
  def testCalcSweepScoreWindowScoreInteraction(self):
    """Scores inside a window should be positive; all others should be negative."""
    numRows = 100
    fakeAnomalyScores = [1 for _ in range(numRows)]
    fakeTimestamps = [i for i in range(numRows)]  # We'll use numbers, even though real data uses dates
    fakeName = "TestDataSet"

    windowA = (30, 39)
    windowB = (75, 95)
    windowLimits = [windowA, windowB]
    expectedInWindowCount = (windowA[1] - windowA[0] + 1) + (windowB[1] - windowB[0] + 1)

    # Standard profile
    costMatrix = {
      "tpWeight": 1.0,
      "fnWeight": 1.0,
      "fpWeight": 0.11,
    }
    probationPercent = 0.1
    o = Sweeper(probationPercent=probationPercent, costMatrix=costMatrix)
    scoredAnomalies = o.calcSweepScore(fakeTimestamps, fakeAnomalyScores, windowLimits, fakeName)

    # Check that correct number of AnomalyPoints returned
    assert len(scoredAnomalies) == numRows
    assert all(isinstance(x, AnomalyPoint) for x in scoredAnomalies)

    # Expected number of points marked 'probationary'
    probationary = [x for x in scoredAnomalies if x.windowName == "probationary"]
    assert len(probationary) == o._getProbationaryLength(numRows)

    # Expected number of points marked 'in window'
    inWindow = [x for x in scoredAnomalies if x.windowName not in ("probationary", None)]
    assert len(inWindow) == expectedInWindowCount

    # Points in window have positive score; others have negative score
    for point in scoredAnomalies:
      if point.windowName not in ("probationary", None):
        assert point.sweepScore > 0
      else:
        assert point.sweepScore < 0
コード例 #3
0
ファイル: sweeper_test.py プロジェクト: numenta/NAB
 def testGetProbationaryLength(self, numRows, probationaryPercent, expectedLength):
   o = Sweeper(probationPercent=probationaryPercent)
   actualLength = o._getProbationaryLength(numRows)
   assert actualLength == expectedLength
コード例 #4
0
 def testGetProbationaryLength(self, numRows, probationaryPercent,
                               expectedLength):
     o = Sweeper(probationPercent=probationaryPercent)
     actualLength = o._getProbationaryLength(numRows)
     assert actualLength == expectedLength