public void ProcessOutliers() { if (OutlierTracker.Count < this.OutlierTrackingInterval) { return; } List <int> Outliers = new List <int>(); DateTime StartTime = new DateTime(); while (this.OutlierTracker.Count > 0) // Loop process samples { if ((Outliers.Count + this.OutlierTracker.Count) < this.OutlierTrackingInterval) { return; } // not enough for another sample Feature outlier = this.OutlierTracker.Dequeue(); if (StartTime == DateTime.MinValue) { StartTime = outlier.Keylog.Timestamp; } Outliers.Add(outlier.IsOutlier ? 1:0); // 1 if outlier if (Outliers.Count == OutlierTrackingInterval) { Tuple <double, double> ret = MeanHelper.FindMAD(Outliers.ToArray()); OutliersAverages.Add((float)ret.Item1); //Build our own sample as this feature is derived from a feature, not a keylog Sample FakeSample = new Sample($"{this.Name}_Outliers", ret.Item1, ret.Item2, StartTime, outlier.Keylog.Timestamp, OutliersAverages.Count(), OutlierTrackingInterval); this.CurrentOutlierSampleCollection.AddFakeSample(FakeSample); Outliers.Clear(); StartTime = DateTime.MinValue; } } }
public void ProcessFeatures() { Tuple <double, double> ret = MeanHelper.FindMAD(this.Features.ToArray()); this.MAD = ret.Item1; this.Mean = ret.Item2; }
public String PrintStats(int[] SessionAggregationCount) { //if (SessionAggregationCount.Length < 2) //{ throw new System.Exception("Need multiple Aggs to calc some stats"); } string ret = this.FeatureName + "," + this.Samples.Count + ","; foreach (int SampleSize in SessionAggregationCount) { List <Sample> buff = new List <Sample>(); List <Sample> aggregatedSamples = new List <Sample>(); foreach (Sample sample in Samples) { buff.Add(sample); if (buff.Count == SampleSize) { Sample Agg = new Sample(sample.FeatureName, MeanHelper.FindMean((buff.ToArray().Select(x => x.MAD)).ToArray()), MeanHelper.FindMean((buff.ToArray().Select(x => x.Mean)).ToArray()), buff.First().StartTime, buff.Last().EndTime, buff.Last().SampleID / SampleSize, buff.Last().SampleSize *SampleSize ); aggregatedSamples.Add(Agg); buff.Clear(); } } // aggregatedSamples is a list of our bigger samples, reasdy for num crunching double[] Values = aggregatedSamples.ToArray().Select(x => x.Mean).ToArray(); double min = Values.Min(); double max = Values.Max(); double range = max - min; double midpoint = (max + min) / 2; double variation = (100 / midpoint) * range; ret += midpoint.ToString("N1") + ","; ret += variation.ToString("N1") + ","; } ret.TrimEnd(','); ret += Environment.NewLine; return(ret); // StatsDict contains our midpoint and range }
public String Print(string format, int SessionAggregationCount, bool fromRange = false) { String ret = ""; if (!fromRange) { this.Close(); ret = CSV_Header + Environment.NewLine; } if (SessionAggregationCount > this.Samples.Count()) { return(""); } // Too big! List <Sample> buff = new List <Sample>(); List <Sample> aggregatedSamples = new List <Sample>(); foreach (Sample sample in Samples) { buff.Add(sample); if (buff.Count == SessionAggregationCount) { Sample Agg = new Sample(sample.FeatureName, MeanHelper.FindMean((buff.ToArray().Select(x => x.MAD)).ToArray()), MeanHelper.FindMean((buff.ToArray().Select(x => x.Mean)).ToArray()), buff.First().StartTime, buff.Last().EndTime, buff.Last().SampleID / SessionAggregationCount, buff.Last().SampleSize *SessionAggregationCount ); aggregatedSamples.Add(Agg); buff.Clear(); } } foreach (Sample Sample in aggregatedSamples) { ret += $"{this.FeatureName},{Sample.SampleID},{SessionAggregationCount},{Sample.SampleID * SessionAggregationCount},{Sample.Mean},{Sample.MAD}"; ret += Environment.NewLine; } return(ret); }