Exemple #1
0
    def checkSeverity(self, target, prediction):
        error = prediction - target
        Sn, Zn = np.nan_to_num(severityMetric(error, self.mu, self.sigma, self.w, self.Sn_1))

        # Uses two-in-a-row counter similar to branch prediction
        if np.abs(Sn) <= self.THRESHOLD:
            self.alert_counter = 0
            anomaly_found = False
        elif np.abs(Sn) > self.THRESHOLD and self.alert_counter == 0:
            #print "Severity: %.3f" %(np.abs(Sn))
            self.alert_counter = 1
            anomaly_found = False
            Sn = self.Sn_1
        elif np.abs(Sn) > self.THRESHOLD and self.alert_counter == 1:
            #print "Severity: %.3f" %(np.abs(Sn))
            Sn = 0
            anomaly_found = True
            #print "ERROR: ANOMALY"
        else:
            print error
            print np.abs(Sn)
            print self.THRESHOLD
            print self.alert_counter

        self.Sn_1 = Sn
        return anomaly_found
Exemple #2
0
    def checkSeverity(self, target, prediction):
        error = prediction - target
        Sn, Zn = severityMetric(error, self.mu, self.sigma, self.w, self.Sn_1)

        # Uses two-in-a-row counter similar to branch prediction
        if np.abs(Sn) <= self.THRESHOLD:
            self.alert_counter = 0
            anomaly_found = False
        elif np.abs(Sn) > self.THRESHOLD and self.alert_counter == 0:
            #print "Severity: %.3f" %(np.abs(Sn))
            self.alert_counter = 1
            anomaly_found = False
            Sn = self.Sn_1
        elif np.abs(Sn) > self.THRESHOLD and self.alert_counter == 1:
            #print "Severity: %.3f" %(np.abs(Sn))
            Sn = 0
            anomaly_found = True
            #print "ERROR: ANOMALY"

        self.Sn_1 = Sn
        return anomaly_found
        #log the new result
        logging.info("Target: " + str(target) + ",  Prediction: " + str(prediction))

        # Not currently used but will be necessary to flag user:
        error = (prediction-target)
        sigma = np.sqrt(1/b_opt + np.dot(np.transpose(x_n),np.dot(S_N, x_n)))

        # Catching pathogenic cases where variance (ie, sigma)
        # gets really really small
        if sigma < 1:
            sigma = 1

        # Update severity metric
        mu = mu; sigma = sigma
        Sn, Zn = severityMetric(error, mu, sigma, w, Sn_1)

        #flag the user if necessary (error is greater than allowance)
        #two-in-a-row counter, much like branch prediction
        anomaly_found = False
        if np.abs(Sn) <= THRESHOLD:
            alert_counter = 0
        elif np.abs(Sn) > THRESHOLD and alert_counter == 0:
            alert_counter = 1
            Sn = Sn_1
        elif np.abs(Sn) > THRESHOLD and alert_counter == 1:
            Sn = 0
            anomaly_found = True
            logging.error("ANOMALY FOUND!")
            if __debug__:
                print "ERROR: ANOMALY"
Exemple #4
0
                     str(prediction))

        # Not currently used but will be necessary to flag user:
        error = (prediction - target)
        sigma = np.sqrt(1 / b_opt +
                        np.dot(np.transpose(x_n), np.dot(S_N, x_n)))

        # Catching pathogenic cases where variance (ie, sigma)
        # gets really really small
        if sigma < 1:
            sigma = 1

        # Update severity metric
        mu = mu
        sigma = sigma
        Sn, Zn = severityMetric(error, mu, sigma, w, Sn_1)

        #flag the user if necessary (error is greater than allowance)
        #two-in-a-row counter, much like branch prediction
        anomaly_found = False
        if np.abs(Sn) <= THRESHOLD:
            alert_counter = 0
        elif np.abs(Sn) > THRESHOLD and alert_counter == 0:
            alert_counter = 1
            Sn = Sn_1
        elif np.abs(Sn) > THRESHOLD and alert_counter == 1:
            Sn = 0
            anomaly_found = True
            logging.error("ANOMALY FOUND!")
            if __debug__:
                print "ERROR: ANOMALY"