Beispiel #1
0
func NewDetector(normalCount int, consensus, minSupport, errorTolerance float64, fingerprinters []Fingerprinter) *Detector {
	//TODO perform sanity check on minsupport and normalcount to make sure
	// its still possible to mark something as anomalous
	counters := make([]fingerprinterCounter, len(fingerprinters))
	for i, fingerprinter := range fingerprinters {
		counters[i] = fingerprinterCounter{
			fingerprinter,
			counter.NewLossyCounter(minSupport, errorTolerance),
		}
	}
	return &Detector{
		normalCount:    normalCount,
		consensus:      consensus,
		minSupport:     minSupport,
		errorTolerance: errorTolerance,
		counters:       counters,
	}
}
Beispiel #2
0
// Create a new Lossy couting based detector
// The consensus is a percentage of the fingerprinters that must agree in order to flag a window as anomalous.
// If the consensus is -1 then the average support from each fingerprinter is compared to minSupport instead of using a consensus.
// The minSupport defines a minimum frequency as a percentage for a window to be considered normal.
// The errorTolerance defines a frequency as a precentage for the smallest frequency that will be retained in memory.
// The errorTolerance must be less than the minSupport.
func NewDetector(consensus, minSupport, errorTolerance float64, fingerprinters []Fingerprinter) (*Detector, error) {
	if (consensus != -1 && consensus < 0) || consensus > 1 {
		return nil, errors.New("consensus must be in the range [0,1) or equal to -1")
	}
	if minSupport <= errorTolerance {
		return nil, errors.New("minSupport must be greater than errorTolerance")
	}
	counters := make([]fingerprinterCounter, len(fingerprinters))
	for i, fingerprinter := range fingerprinters {
		counters[i] = fingerprinterCounter{
			fingerprinter,
			counter.NewLossyCounter(errorTolerance),
		}
	}
	return &Detector{
		consensus:      consensus,
		minSupport:     minSupport,
		errorTolerance: errorTolerance,
		counters:       counters,
	}, nil
}