Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }