Exemplo n.º 1
0
        public void TestDistributionNormal()
        {
            IDoubleDistribution dist = new NormalDistribution(m_model, "NormalDistribution", Guid.NewGuid(), 5, 1);

            Assert.IsTrue(dist.GetValueWithCumulativeProbability(0.50) == 5.0);
            dist.SetCDFInterval(0.5, 0.5);
            Assert.IsTrue(dist.GetNext() == 5.0);
            dist.SetCDFInterval(0.0, 1.0);

            System.IO.StreamWriter tw = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("TEMP") + "\\DistributionNormal.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, 7.5, 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++)
            {
                tw.WriteLine(hist.GetLabel(new int[] { i }) + ", " + bins[i]);
            }
            tw.Flush();
            tw.Close();


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