public HypothesisTest GetHypothesisTestResult() { // We are comparing the mean of sample means for a significant difference between the distributions // H0: there is no difference in the distribution of packets between marked and unmarked batches // H1: there is a difference between the batches /******************************************************************************************* * * Note: we need a test to verify that the following data (DisplayStatistic) has been updated * *******************************************************************************************/ HypothesisTest ht = new HypothesisTest(); //// Update the K-S statistics object //_KsStatistics.MarkedMean = markedMeanOfMeans; //_KsStatistics.MarkedStdDev = markedStdDevMeanOfMeans; ////_KsStatistics.MarkedMean = markedCumulativeStats.PacketCountMean; ////_KsStatistics.MarkedStdDev = markedCumulativeStats.PacketCountStandardDeviation; //_KsStatistics.MarkedIntervalCount = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed : markedCumulativeStats.IntervalCount; //_KsStatistics.UnmarkedMean = unmarkedMeanOfMeans; //_KsStatistics.UnmarkedStdDev = unmarkedStdDevMeanOfMeans; ////_KsStatistics.UnmarkedMean = unmarkedCumulativeStats.PacketCountMean; ////_KsStatistics.UnmarkedStdDev = unmarkedCumulativeStats.PacketCountStandardDeviation; //_KsStatistics.UnmarkedIntervalCount = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed : unmarkedCumulativeStats.IntervalCount; ProcessCapturePackets pcp = new ProcessCapturePackets(); DisplayStatistic markedStatistics = new DisplayStatistic(); DisplayStatistic unmarkedStatistics = new DisplayStatistic(); markedStatistics = pcp.GetCumulativeMarkedDisplayStatistics(); unmarkedStatistics = pcp.GetCumulativeUnmarkedDisplayStatistics(); MeansTestStatistic _MeansTestStatistic = new MeansTestStatistic(AnalysisConfiguration.Alpha, AnalysisConfiguration.Zvalue); if (markedStatistics != null) { _MeansTestStatistic.MarkedMean = markedStatistics.MeanOfMeans; _MeansTestStatistic.MarkedStdDev = markedStatistics.MeanOfMeansStandardDeviation; _MeansTestStatistic.MarkedIntervalCount = _TrimZeroPacketIntervals == true ? markedStatistics.TrimmedIntervalCount : markedStatistics.IntervalCount; } if (unmarkedStatistics != null) { _MeansTestStatistic.UnmarkedMean = unmarkedStatistics.MeanOfMeans; _MeansTestStatistic.UnmarkedStdDev = unmarkedStatistics.MeanOfMeansStandardDeviation; _MeansTestStatistic.UnmarkedIntervalCount = _TrimZeroPacketIntervals == true ? unmarkedStatistics.TrimmedIntervalCount : unmarkedStatistics.IntervalCount; } // Test the difference in the distribution means decimal meanDifference = _MeansTestStatistic.MeanDifference; decimal sigmaDifference = _MeansTestStatistic.SigmaDifference; // Single-tail test (if there is a difference in the means it will be a positive value) // Z value for alpha = 5% significance level: // Test result: true = reject H0 - difference of means has only 5% probability of occurring if H0 is true // Note: standard deviation = SigmaDifference * Zvalue ht.MeansTestResult = _MeansTestStatistic.MeanDifference > _MeansTestStatistic.StandardDeviation ? true : false; ht.MeansVarianceStandardDeviation = _MeansTestStatistic.StandardDeviation; ht.MeanOfMeansVariance = _MeansTestStatistic.MeanDifference; return ht; }
public DisplayStatistic GetCumulativeMarkedDisplayStatistics() { DisplayStatistic statistics = new DisplayStatistic(); using (var context = new PacketAnalysisEntity()) { var data = (from d in context.DisplayStatistics where d.Marked == true && d.BatchType == 2 select d).FirstOrDefault(); statistics = data; } return statistics; }
private void RefreshSingleBatchStatistics() { //// Get the last marked and unmarked batches //BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>(); //ProcessCapturePackets pcp = new ProcessCapturePackets(); //lastBatchIds = pcp.GetLastCaptureBatchIds(); //// Get the batch intervals //BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>(); //BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>(); //foreach (CurrentCaptureFile file in lastBatchIds) //{ // if (file.CaptureState == CaptureState.Marked) // { // markedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); // } // else if(file.CaptureState == CaptureState.Unmarked) // { // unmarkedBatchIntervals = pcp.GetMarkedBatchIntervals(file.CaptureBatchId); // } // else // { // MessageBox.Show("Error retrieving batch intervals: capture state is unknown!", "GetMarkedBatchIntervals by CaptureBatchId", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} //BatchStatistics markedSingleStats = new BatchStatistics(); //BatchStatistics unmarkedSingleStats = new BatchStatistics(); //// Get this data from DisplayStatistics table; except on refresh... ////AnalysisEngine ae = new AnalysisEngine(); ////markedSingleStats = ae.GetBatchStatistics(markedBatchIntervals, CaptureState.Marked, BatchType.Single); ////unmarkedSingleStats = ae.GetBatchStatistics(unmarkedBatchIntervals, CaptureState.Unmarked, BatchType.Single); // Get the display statistics from the database ProcessCapturePackets pcp = new ProcessCapturePackets(); DisplayStatistic unmarkedSingleStats = new DisplayStatistic(); unmarkedSingleStats = pcp.GetLastSingleUnmarkedDisplayStatistics(); // Load up the table // Single unmarked column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[1].Value = TrimIntervals == true ? unmarkedSingleStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[1].Value = string.Format("{0:N2}", unmarkedSingleStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[1].Value = unmarkedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[1].Value = "N/A"; DisplayStatistic markedSingleStats = new DisplayStatistic(); markedSingleStats = pcp.GetLastSingleMarkedDisplayStatistics(); // Single marked column row = 0; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[2].Value = TrimIntervals == true ? markedSingleStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[2].Value = string.Format("{0:N2}", markedSingleStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[2].Value = markedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[2].Value = "N/A"; // Single variance column row = 0; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.IntervalCount - markedSingleStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[3].Value = TrimIntervals == true ? (unmarkedSingleStats.TrimmedIntervalCount - markedSingleStats.TrimmedIntervalCount).ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}", (unmarkedSingleStats.MeanPacketsPerInterval - markedSingleStats.MeanPacketsPerInterval)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = string.Format("{0:N2}",(unmarkedSingleStats.StandardDeviation - markedSingleStats.StandardDeviation)); _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.MinPacketsPerInterval - markedSingleStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[3].Value = unmarkedSingleStats.MaxPacketsPerInterval - markedSingleStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[3].Value = "N/A"; }
private void RefreshCumulativeBatchStatistics() { // Get the cumulative interval counts ProcessCapturePackets pcp = new ProcessCapturePackets(); //BindingList<CumulativeInterval> cumulativeIntervals = new BindingList<CumulativeInterval>(); //cumulativeIntervals = pcp.GetCumulativeIntervals(); //// Get the batch intervals //BindingList<BatchIntervalMarked> unmarkedBatchIntervals = new BindingList<BatchIntervalMarked>(); //BindingList<BatchIntervalMarked> markedBatchIntervals = new BindingList<BatchIntervalMarked>(); //foreach (CumulativeInterval ci in cumulativeIntervals) //{ // if (ci.Marked) // { // BatchIntervalMarked bim = new BatchIntervalMarked(); // bim.BatchIntervalId = 0; // bim.CaptureBatchId = 0; // bim.IntervalNumber = ci.CumulativeIntervalNumber; // bim.Marked = CaptureState.Marked; // bim.PacketCount = ci.PacketCount; // markedBatchIntervals.Add(bim); // } // else // { // BatchIntervalMarked bim = new BatchIntervalMarked(); // bim.BatchIntervalId = 0; // bim.CaptureBatchId = 0; // bim.IntervalNumber = ci.CumulativeIntervalNumber; // bim.Marked = CaptureState.Unmarked; // bim.PacketCount = ci.PacketCount; // unmarkedBatchIntervals.Add(bim); // } //} //BatchStatistics markedCumulativeStats = new BatchStatistics(); //BatchStatistics unmarkedCumulativeStats = new BatchStatistics(); //decimal markedMeanOfMeans = 0; //decimal markedStdDevMeanOfMeans = 0; //decimal unmarkedMeanOfMeans = 0; //decimal unmarkedStdDevMeanOfMeans = 0; //AnalysisEngine ae = new AnalysisEngine(); // Get the marked cumulative statistics DisplayStatistic markedCumulativeStats = new DisplayStatistic(); markedCumulativeStats = pcp.GetCumulativeMarkedDisplayStatistics(); if (markedCumulativeStats != null) { //if(markedBatchIntervals.Count > 0) //{ // markedCumulativeStats = ae.CalculateBatchStatistics(markedBatchIntervals,CaptureState.Marked, BatchType.Cumulative); // markedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false); // markedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Marked, TrimIntervals ? true : false); // Load up the table // Cumulative marked column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[5].Value = TrimIntervals == true ? markedCumulativeStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[5].Value = markedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[5].Value = string.Format("{0:N2}", markedCumulativeStats.MeanOfMeans); _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[5].Value = "N/A"; //} } // Get the marked cumulative statistics DisplayStatistic unmarkedCumulativeStats = new DisplayStatistic(); unmarkedCumulativeStats = pcp.GetCumulativeUnmarkedDisplayStatistics(); if (unmarkedCumulativeStats != null) { //if (unmarkedBatchIntervals.Count > 0) //{ // unmarkedCumulativeStats = ae.CalculateBatchStatistics(unmarkedBatchIntervals, CaptureState.Marked, BatchType.Cumulative); // unmarkedMeanOfMeans = pcp.CalculateMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false); // unmarkedStdDevMeanOfMeans = pcp.CalculateStdDevForMeanOfMeans(CaptureState.Unmarked, TrimIntervals ? true : false); // Load up the table // Cumulative unmarked column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[4].Value = TrimIntervals == true ? unmarkedCumulativeStats.TrimmedIntervalCount.ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.MeanPacketsPerInterval); _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.StandardDeviation); _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[4].Value = unmarkedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[4].Value = string.Format("{0:N2}", unmarkedCumulativeStats.MeanOfMeans); _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A"; _AnalysisDataGridView.Rows[row++].Cells[4].Value = "N/A"; //} } //if (markedBatchIntervals.Count > 0 && unmarkedBatchIntervals.Count > 0) if (markedCumulativeStats != null && unmarkedCumulativeStats != null) { // Get the Hypothesis Test results HypothesisTest ht = new HypothesisTest(); ht = pcp.GetHypothesisTestResults(); // Specify font for hypothesis test result fields Font font = new Font(_AnalysisDataGridView.DefaultCellStyle.Font.FontFamily, _AnalysisDataGridView.Font.Size, FontStyle.Bold); // Cumulative variance column int row = 0; _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.IntervalCount - markedCumulativeStats.IntervalCount; _AnalysisDataGridView.Rows[row++].Cells[6].Value = TrimIntervals == true ? (unmarkedCumulativeStats.TrimmedIntervalCount - markedCumulativeStats.TrimmedIntervalCount).ToString() : "N/A"; _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.MeanPacketsPerInterval - markedCumulativeStats.MeanPacketsPerInterval)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.StandardDeviation - markedCumulativeStats.StandardDeviation)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.MinPacketsPerInterval - markedCumulativeStats.MinPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[6].Value = unmarkedCumulativeStats.MaxPacketsPerInterval - markedCumulativeStats.MaxPacketsPerInterval; _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:N2}", (unmarkedCumulativeStats.MeanOfMeans - markedCumulativeStats.MeanOfMeans)); _AnalysisDataGridView.Rows[row++].Cells[6].Value = string.Format("{0:P1}", AnalysisConfiguration.Alpha); // Means test results _AnalysisDataGridView.Rows[row].Cells[6].Style.Font = font; _AnalysisDataGridView.Rows[row].Cells[6].Value = ht.MeansTestResult == true ? "True" : "False"; _AnalysisDataGridView.Rows[row].Cells[6].Style.BackColor = ht.MeansTestResult == true ? Color.LightGreen : Color.LightCoral; //// Update the K-S statistics column //row = 0; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.MeansVarianceStandardDeviation); //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = "N/A"; //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:N2}", ht.MeanOfMeansVariance); //_AnalysisDataGridView.Rows[row++].Cells[7].Value = string.Format("{0:P1}", AnalysisConfiguration.Alpha); //// K-S test results //_AnalysisDataGridView.Rows[row].Cells[7].Style.Font = font; //_AnalysisDataGridView.Rows[row].Cells[7].Value = ht.KsTestResult == true ? "True" : "False"; //_AnalysisDataGridView.Rows[row].Cells[7].Style.BackColor = ht.KsTestResult == true ? Color.LightGreen : Color.LightCoral; } //// Update the K-S statistics object //_KsStatistics.MarkedMean = markedMeanOfMeans; //_KsStatistics.MarkedStdDev = markedStdDevMeanOfMeans; ////_KsStatistics.MarkedMean = markedCumulativeStats.PacketCountMean; ////_KsStatistics.MarkedStdDev = markedCumulativeStats.PacketCountStandardDeviation; //_KsStatistics.MarkedIntervalCount = TrimIntervals == true ? markedCumulativeStats.IntervalCountTrimmed : markedCumulativeStats.IntervalCount; //_KsStatistics.UnmarkedMean = unmarkedMeanOfMeans; //_KsStatistics.UnmarkedStdDev = unmarkedStdDevMeanOfMeans; ////_KsStatistics.UnmarkedMean = unmarkedCumulativeStats.PacketCountMean; ////_KsStatistics.UnmarkedStdDev = unmarkedCumulativeStats.PacketCountStandardDeviation; //_KsStatistics.UnmarkedIntervalCount = TrimIntervals == true ? unmarkedCumulativeStats.IntervalCountTrimmed : unmarkedCumulativeStats.IntervalCount; }
public DisplayStatistic GetLastSingleUnmarkedDisplayStatistics() { DisplayStatistic statistics = new DisplayStatistic(); DisplayStatisticsData dsd = new DisplayStatisticsData(); statistics = dsd.GetLastSingleUnmarkedDisplayStatistics(); return statistics; }
public DisplayStatistic GetCumulativeUnmarkedDisplayStatistics() { DisplayStatistic statistics = new DisplayStatistic(); DisplayStatisticsData dsd = new DisplayStatisticsData(); statistics = dsd.GetCumulativeUnmarkedDisplayStatistics(); return statistics; }
public DisplayStatistic GetLastSingleUnmarkedDisplayStatistics() { DisplayStatistic statistics = new DisplayStatistic(); if (GetSingleUnmarkedDisplayStatistics().Count > 0) { using (var context = new PacketAnalysisEntity()) { // Get the last Id value for single unmarked statistic data var maxid = (from m in context.DisplayStatistics where m.Marked == false && m.BatchType == 1 select m.DisplayStatisticId).Max(); var data = (from d in context.DisplayStatistics where d.DisplayStatisticId == maxid select d).FirstOrDefault(); statistics = data; } } return statistics; }