コード例 #1
0
ファイル: TestDistributions.cs プロジェクト: sjvannTMU/Sage
        public void TestDistributionExponential()
        {
            IDoubleDistribution dist = new ExponentialDistribution(m_model, "ExponentialDistribution", Guid.NewGuid(), 3.0, 3.0);

            Assert.IsTrue(dist.GetValueWithCumulativeProbability(0.50) == 5.0794415416798362, "Failure in TestDistributionExponential()");
            dist.SetCDFInterval(0.5, 0.5);
            Assert.IsTrue(dist.GetNext() == 5.0794415416798362);
            dist.SetCDFInterval(0.0, 1.0);

            System.IO.StreamWriter tw = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("TEMP") + "\\DistributionExponential.csv");
            Debug.WriteLine("Generating raw data.");
            int DATASETSIZE = 1500000;

            double[] rawData = new double[DATASETSIZE];
            for (int x = 0; x < DATASETSIZE; x++)
            {
                rawData[x] = dist.GetNext();
                //tw.WriteLine(rawData[x]);
            }

            Debug.WriteLine("Performing histogram analysis.");
            Histogram1D_Double hist = new Histogram1D_Double(rawData, 0, 30.0, 100, "distribution");

            hist.LabelProvider = new LabelProvider(((Histogram1D_Double)hist).DefaultLabelProvider);
            hist.Recalculate();

            Debug.WriteLine("Writing data dump file.");
            int[] bins = (int[])hist.Bins;
            for (int i = 0; i < bins.Length; i++)
            {
                //Debug.WriteLine(hist.GetLabel(new int[]{i}) + ", " + bins[i]);
                tw.WriteLine(hist.GetLabel(new int[] { i }) + ", " + bins[i]);
            }

            tw.WriteLine("Sum of off-scale-high : " + (((double)hist.SumEntries(HistogramBinCategory.OffScaleHigh))));
            tw.WriteLine("Average value : " + (((double)hist.SumEntries(HistogramBinCategory.All)) / ((double)hist.RawData.Length)));
            tw.Flush();
            tw.Close();

            if (m_visuallyVerify)
            {
                System.Diagnostics.Process.Start("excel.exe", Environment.GetEnvironmentVariable("TEMP") + "\\DistributionExponential.csv");
            }
        }