public void TestMethod()
        {
            /*
             * Exponential distribution.
             */

            PIDebug.TitleBig("Exponential distribution (1)");

            PIExponentialDistribution distribution = new PIExponentialDistribution();

            /* -- 1) Get probability */

            PIDebug.Title("1) Get probability for X");

            /* lambda=1 */
            PIDebug.Title("..lambda=1");

            Console.WriteLine("Probability for x=0.0 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(0.0, distribution.GetProbability(0.0), 0.001);
            Console.WriteLine("Probability for x=1.0 : " + distribution.GetProbability(1.0));
            Assert.AreEqual(0.632, distribution.GetProbability(1.0), 0.001);
            Console.WriteLine("Probability for x=2.0 : " + distribution.GetProbability(2.0));
            Assert.AreEqual(0.864, distribution.GetProbability(2.0), 0.001);
            Console.WriteLine("Probability for x=3.0 : " + distribution.GetProbability(3.0));
            Assert.AreEqual(0.950, distribution.GetProbability(3.0), 0.001);
            Console.WriteLine("Probability for x=5.0 : " + distribution.GetProbability(5.0));
            Assert.AreEqual(0.9932, distribution.GetProbability(5.0), 0.001);

            /* -- 2) Get T for probability */

            PIDebug.Title("2) Get X for probability", true);

            /* lambda=1  */
            PIDebug.Title("..lambda=1");

            Console.WriteLine("X value for probability for prob=0.0 : " + distribution.GetXForProbability(0.0));
            Assert.AreEqual(0.0, distribution.GetXForProbability(0.0), 0.001);
            Console.WriteLine("X value for probability for prob=0.632 : " + distribution.GetXForProbability(0.632));
            Assert.AreEqual(1.0, distribution.GetXForProbability(0.632), 0.001);
            Console.WriteLine("X value for probability for prob=0.864 : " + distribution.GetXForProbability(0.864));
            Assert.AreEqual(2.0, distribution.GetXForProbability(0.864), 0.01);
            Console.WriteLine("X value for probability for prob=0.950 : " + distribution.GetXForProbability(0.950));
            Assert.AreEqual(3.0, distribution.GetXForProbability(0.950), 0.01);
            Console.WriteLine("X value for probability for prob=0.9932 : " + distribution.GetXForProbability(0.9932));
            Assert.AreEqual(5.0, distribution.GetXForProbability(0.9932), 0.01);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density, lambda=1", true);

            Console.WriteLine("x=0.1 : " + distribution.GetPDF(0.1));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=1.0 : " + distribution.GetPDF(1.0));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=5.0 : " + distribution.GetPDF(5.0));
        }
Esempio n. 2
0
        public void TestMethod()
        {
            /* -- source 3f */

            PIDebug.TitleBig("Power regression");

            /* change decimal places count in formulas */
            PIConfiguration.REGRESSION_DECIMAL_PLACES = 6;

            /* - prepare X data for regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddValues(new double[] { 17.6, 26.0, 31.9, 38.9, 45.8 });
            X.AddValues(new double[] { 51.2, 58.1, 64.7, 66.7, 80.8, 82.9 });

            /* - prepare Y data for regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new double[] { 159.9, 206.9, 236.8, 269.9, 300.6 });
            Y.AddValues(new double[] { 323.6, 351.7, 377.6, 384.1, 437.2, 444.7 });

            /* - create and compute regression */

            PIPowerRegression regression = new PIPowerRegression(X, Y);

            Assert.IsNotNull(regression);

            regression.Calc();

            Console.WriteLine(regression.GetTextFormula());
            Console.WriteLine(regression.GetTextFormulaFilled());

            Assert.AreEqual((double)24.129, (double)regression.Get_A(), 0.001);
            Assert.AreEqual((double)0.659, (double)regression.Get_B(), 0.001);

            /* - calc prediction for X = 3.5 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=40 : " + regression.CalcPredictedY(40.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("R2 = " + regression.GetXYR2());
        }
Esempio n. 3
0
        public void TestMethod()
        {
            /* Source 6I. */

            PIDebug.TitleBig("Prime factorization - Fermat algorithm");

            FactorizeItem(123);
            FactorizeItem(501);
            Assert.AreEqual(3, factorization.Result.GetValue(0));
            Assert.AreEqual(167, factorization.Result.GetValue(1));
            FactorizeItem(54869);
            FactorizeItem(45486857);
            FactorizeItem(454868571);
        }
Esempio n. 4
0
        public void TestMethod()
        {
            /* -- source 3d/19 */

            PIDebug.TitleBig("Exponential modified regression");

            /* change decimal places count in formulas */
            PIConfiguration.REGRESSION_DECIMAL_PLACES = 6;

            /* - prepare X data for exponential modified regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddValues(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            /* - prepare Y data for exponential modified regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new double[] { 57.2, 62.8, 72.2, 81.5, 91.6, 97.1, 99.9, 100.4, 100.6 });

            /* - create and compute regression */

            PIExponentialModifiedRegression regression = new PIExponentialModifiedRegression(X, Y);

            Assert.IsNotNull(regression);

            regression.Calc();

            Console.WriteLine(regression.GetTextFormula());
            Console.WriteLine(regression.GetTextFormulaFilled());

            Assert.AreEqual((double)106.941, (double)regression.Get_gama(), 0.001);
            Assert.AreEqual((double)-77.322, (double)regression.Get_A(), 0.001);
            Assert.AreEqual((double)0.732, (double)regression.Get_B(), 0.001);

            /* - calc prediction for X = 5 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=5 : " + regression.CalcPredictedY(5.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression.GetErrors().AsString(5));
        }
Esempio n. 5
0
        public void TestMethod()
        {
            /* -- source 3a/113 */

            PIDebug.TitleBig("Exponential regression");

            /* change decimal places count in formulas */
            PIConfiguration.REGRESSION_DECIMAL_PLACES = 6;

            /* - prepare X data for exponential regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddValues(new int[] { 0, 1, 2, 3, 4, 5 });

            /* - prepare Y data for exponential regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new int[] { 3, 7, 10, 24, 50, 95 });

            /* - create and compute regression */

            PIExponentialRegression ExponentialRegression = new PIExponentialRegression(X, Y);

            Assert.IsNotNull(ExponentialRegression);

            ExponentialRegression.Calc();

            Console.WriteLine(ExponentialRegression.GetTextFormula());
            Console.WriteLine(ExponentialRegression.GetTextFormulaFilled());

            Assert.AreEqual((double)3.046, (double)ExponentialRegression.Get_A(), 0.001);
            Assert.AreEqual((double)1.988, (double)ExponentialRegression.Get_B(), 0.001);

            /* - calc prediction for X = 3.5 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=3.5 : " + ExponentialRegression.CalcPredictedY(3.5));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(ExponentialRegression.GetErrors().AsString(5));
        }
        public void TestMethod()
        {
            PIDebug.TitleBig("Beta function");

            Console.WriteLine("Beta x=1, y=1 = " + PIBeta.Calc(1, 1));
            Assert.AreEqual(1.0, PIBeta.Calc(1, 1), 0.00001);

            Console.WriteLine("Beta x=2, y=2 = " + PIBeta.Calc(2, 2));
            Assert.AreEqual(0.16667, PIBeta.Calc(2, 2), 0.00001);

            Console.WriteLine("Beta x=3, y=5 = " + PIBeta.Calc(3, 5));
            Assert.AreEqual(0.0095238, PIBeta.Calc(3, 5), 0.00001);

            Console.WriteLine("Beta x=7, y=8 = " + PIBeta.Calc(7, 8));
            Assert.AreEqual(0.000041625, PIBeta.Calc(7, 8), 0.00001);
        }
Esempio n. 7
0
        public void TestMethod()
        {
            /* Source 6I. */

            PIDebug.TitleBig("Prime factorization");

            FactorizeItem(2);
            FactorizeItem(123);
            FactorizeItem(500);
            FactorizeItem(54868);
            FactorizeItem(45486857);
            FactorizeItem(454868572);
            Assert.AreEqual(2, factorization.Result.GetValue(0));
            Assert.AreEqual(2, factorization.Result.GetValue(1));
            Assert.AreEqual(5743, factorization.Result.GetValue(2));
            Assert.AreEqual(19801, factorization.Result.GetValue(3));
        }
        public void TestMethod()
        {
            PIDebug.TitleBig("Gamma function");

            Console.WriteLine("Gamma x=0.3 => " + PIGamma.Calc(0.3));
            Assert.AreEqual(2.9915, (double)PIGamma.Calc(0.3), 0.0001);

            Console.WriteLine("Gamma x=1.0 => " + PIGamma.Calc(1.0));
            Assert.AreEqual(1.0, (double)PIGamma.Calc(1.0), 0.0001);

            Console.WriteLine("Gamma x=2.23 => " + PIGamma.Calc(2.23));
            Assert.AreEqual(1.1202, (double)PIGamma.Calc(2.23), 0.0001);

            Console.WriteLine("Gamma x=24.0 => " + PIGamma.Calc(24.0));
            Assert.AreEqual(2.585201673888503E22, (double)PIGamma.Calc(24.0), 0.0001);

            Console.WriteLine("Gamma x=25.5 => " + PIGamma.Calc(25.5));
            Assert.AreEqual(3.086770540528693E24, (double)PIGamma.Calc(25.5), 0.0001);
        }
Esempio n. 9
0
        public void TestMethod()
        {
            PIDebug.TitleBig("Numeric integration - Simpson`s method");

            PIDebug.TitleBig("Sin(x)^2 from 0..PI");

      #pragma warning disable IDE0017 // Simplify object initialization
            PINumericalIntegrationSimpson integration = new PINumericalIntegrationSimpson(0, Math.PI);
      #pragma warning restore IDE0017 // Simplify object initialization

            //integration.Expression = (x) => { return Math.Exp(1) - ( x*x); };
            integration.Expression = (x) => { return(Math.Sqrt(x * x + 1)); };

            integration.Expression = (x) => { return(Math.Pow(Math.Sin(x), 2)); };
            integration.SetStepsCount(100);

            double value = integration.Calc();
            Assert.AreEqual(1.5707, value, 0.0001);
            Console.WriteLine(value);

            /* ----------------------- */

            /* Source: 6J6 */

            PIDebug.TitleBig("Sqrt(x^2 + 1 ) from 0..1", true);

            integration.Expression = (x) => { return(Math.Sqrt(x * x + 1)); };

            integration.A    = 0;
            integration.B    = 1;
            integration.Step = 0.125;

            value = integration.Calc();
            Assert.AreEqual(1.1477, value, 0.0001);
            Console.WriteLine(value);

            PIDebug.Blank();
            Console.WriteLine("X starting interval positions: " + integration.VarX.AsString(3));
            Console.WriteLine("Y values: " + integration.VarY.AsString(3));
            Console.WriteLine("Y values cumulative: " + integration.VarYCumulative.AsString(3));
        }
        public void TestMethod()
        {
            /* Source 6G. */

            PIDebug.TitleBig("Error function");

            Console.WriteLine("Complementary error x=0.35 = " + PIError.Erfc(0.35));
            Assert.AreEqual(0.6206, PIError.Erfc(0.35), 0.001);

            Console.WriteLine("Complementary error x=0.72 = " + PIError.Erfc(0.72));
            Assert.AreEqual(0.3038, PIError.Erfc(0.72), 0.01);

            Console.WriteLine("Complementary error x=-0.5 = " + PIError.Erfc(-0.5));
            Assert.AreEqual(1.5205, PIError.Erfc(-0.5), 0.0001);

            Console.WriteLine("Complementary error x=0.0 = " + PIError.Erfc(0.0));
            Assert.AreEqual(1.0, PIError.Erfc(0.0), 0.0001);

            Console.WriteLine("Complementary error x=1.0 = " + PIError.Erfc(1.0));
            Assert.AreEqual(0.1572, PIError.Erfc(1.0), 0.0001);
        }
        public void TestMethod()
        {
            /* Source 9D4/1. */

            PIDebug.TitleBig("Shapiro-Wilk (expanded) test, 9D4,1");

            PIVariable var = new PIVariable();

            var.AddValues(new int[] { 65, 61, 63, 86, 70, 55, 74, 35, 72, 68, 45, 58 });

            PIShapiroWilkExpanded test = new PIShapiroWilkExpanded(var);

            test.Evaluate();

            Console.WriteLine("W value = " + test.W);
            Console.WriteLine("Z value = " + test.Z);
            Console.WriteLine("p-value = " + test.PValue);
            Console.WriteLine(test.ToString());

            Assert.AreEqual(0.9216, test.PValue, 0.001);

            /* Source 9D4/2. */

            PIDebug.TitleBig("Shapiro-Wilk (expanded) test, 9D4,2", true);

            PIVariable var1 = new PIVariable();

            var1.AddValues(new int[] { 12, 27, 18, 23, 72, 27, 27, 53, 3, 45, 53, 125, 50 });

            PIShapiroWilkExpanded test1 = new PIShapiroWilkExpanded(var1);

            test1.Evaluate();

            Console.WriteLine("W value = " + test1.W);
            Console.WriteLine("Z value = " + test1.Z);
            Console.WriteLine("p-value = " + test1.PValue);
            Console.WriteLine(test1.ToString());

            Assert.AreEqual(0.0440, test1.PValue, 0.001);
        }
        public void TestMethod()
        {
            /* Source 9D1/1. */

            PIDebug.TitleBig("Shapiro-Wilk (original) test, 9D1/1");

            PIVariable var = new PIVariable();

            var.AddValues(new int[] { 65, 61, 63, 86, 70, 55, 74, 35, 72, 68, 45, 58 });

            PIShapiroWilk test = new PIShapiroWilk(var);

            test.Evaluate();

            Console.WriteLine("W value = " + test.W);
            Console.WriteLine("p-value = " + test.PValue);
            Console.WriteLine(test.ToString());

            Assert.AreEqual(0.8736, test.PValue, 0.001);

            /* Source 9D1/2. */

            PIDebug.TitleBig("Shapiro-Wilk (original) test, 9D1/2", true);

            PIVariable var1 = new PIVariable();

            var1.AddValues(new double[] { 1.2, 1.6, 1.8, 1.9, 1.9, 2.0, 2.2, 2.6, 3.0, 3.5, 4.0, 4.8, 5.6, 6.6, 7.6 });

            PIShapiroWilk test1 = new PIShapiroWilk(var1);

            test1.Evaluate();

            Console.WriteLine("W value = " + test1.W);
            Console.WriteLine("p-value = " + test1.PValue);
            Console.WriteLine(test1.ToString());

            Assert.AreEqual(0.0418, test1.PValue, 0.001);
        }
        public void TestMethod()
        {
            /* Source 9D8. */

            PIDebug.TitleBig("Jarque-Bera test of normality, 9D8");

            PIVariable var = new PIVariable();

            var.AddValues(new int[] { 56, 58, 60, 64, 54, 52, 50, 40, 57, 53,
                                      65, 50, 53, 52, 66, 45, 55, 54, 65, 56,
                                      55, 57, 48, 63, 51, 55, 44, 58, 54, 60 });
            //var.SaveToFile( @"c:\\tmp\var.txt" );

            PIJarqueBera test = new PIJarqueBera(var);

            test.Evaluate();

            Console.WriteLine("Z value = " + test.Z);
            Console.WriteLine("p-value = " + test.PValue);
            Console.WriteLine(test.ToString());

            Assert.AreEqual(0.2487, test.Z, 0.001);
        }
Esempio n. 14
0
        public void TestMethod()
        {
            /* Source 9D4/1. */

            PIDebug.TitleBig("D`Agostino-Pearson test of normality, 9D7");

            PIVariable var = new PIVariable();

            var.AddValues(new int[] { 34, 56, 39, 71, 84, 92, 44, 67, 98, 49, 55, 73,
                                      50, 62, 75, 44, 88, 53, 61, 25, 36, 66, 77, 35 });

            PIDAgostinoPearson test = new PIDAgostinoPearson(var);

            test.Evaluate();

            Console.WriteLine("Z value = " + test.Z);
            Console.WriteLine("p-value = " + test.PValue);
            Console.WriteLine(test.ToString());

            Assert.AreEqual(0.6362, test.PValue, 0.001);

            /* Data source 9D4/2. This test with Shapiro-Wilk (expanded) rejects normality, try it with this test. */

            PIDebug.TitleBig("D`Agostino-Pearson test of normality, data from 9D4,2", true);

            PIVariable var1 = new PIVariable();

            var1.AddValues(new int[] { 12, 27, 18, 23, 72, 27, 27, 53, 3, 45, 53, 125, 50 });

            PIDAgostinoPearson test1 = new PIDAgostinoPearson(var1);

            test1.Evaluate();

            Console.WriteLine("Z value = " + test1.Z);
            Console.WriteLine("p-value = " + test1.PValue);
            Console.WriteLine(test1.ToString());
        }
        public void TestMethod()
        {
            /*
             * MEDIAN SMOOTHING.
             *
             * Source 4k.
             *
             */

            PIDebug.TitleBig("Median smoothing");

            /* - prepare variable for source data */

            PIVariable var = new PIVariable();

            Assert.IsNotNull(var);

            var.AddValues(new int[] { 37, 45, 39, 48, 47, 57, 52, 49, 56, 59, 62 });

            /* - calc median smoothing, length = 3 */

            PIMedianSmoothing medianSmoothing = new PIMedianSmoothing(var);

            medianSmoothing.SetWindowLength(3);
            //medianSmoothing.setOuterValuesNull( true );
            medianSmoothing.Calc();

            /* - show results */

            Console.WriteLine(medianSmoothing.GetOutputVariable().AsString(2));

            Assert.AreEqual(39.0, (double)medianSmoothing.GetOutputVariable().GetValue(1));
            Assert.AreEqual(45.0, (double)medianSmoothing.GetOutputVariable().GetValue(2));
            Assert.AreEqual(47.0, (double)medianSmoothing.GetOutputVariable().GetValue(3));
            /* ... */
        }
        public void TestMethod()
        {
            /*
             * SIMPLE CENTERED MOVING AVERAGE
             *
             * Source 4i.
             *
             */

            PIDebug.TitleBig("Moving average - SIMPLE CENTERED (4)");

            /* - prepare variable for source data */

            PIVariable var = new PIVariable();

            Assert.IsNotNull(var);

            var.AddValues(new int[] { 9, 8, 9, 12, 9, 12, 11 });

            /* - calc CENTERED moving average, length = 4 */

            PIMovingAverageSmoothing MA = new PIMovingAverageSmoothing(var);

            MA.SetCalculationType(CalculationType.SIMPLE_CENTERED);
            MA.SetWindowLength(4);
            MA.Calc();

            /* - show results */

            Console.WriteLine(MA.GetOutputVariable().AsString(2));

            Assert.AreEqual(9.5, (double)MA.GetOutputVariable().GetValue(2));
            Assert.AreEqual(10.0, (double)MA.GetOutputVariable().GetValue(3));
            Assert.AreEqual(10.75, (double)MA.GetOutputVariable().GetValue(4));

            /*
             * SIMPLE MOVING AVERAGE.
             *
             * Source 4P - correction 1.1.4.
             *
             */

            PIDebug.TitleBig("Moving average - SIMPLE (3)", true);

            /* - calc SIMPLE moving average, length = 3 */

            PIVariable var1 = new PIVariable();

            Assert.IsNotNull(var1);

            var1.AddValues(new int[] { 3, 5, 9, 20, 12, 17, 22, 23, 51, 41, 56, 75, 60, 75, 88 });

            PIMovingAverageSmoothing MA1 = new PIMovingAverageSmoothing(var1);

            MA1.SetCalculationType(CalculationType.SIMPLE);
            MA1.SetWindowLength(3);
            MA1.Calc();

            /* - show results (3) */

            Console.WriteLine(MA1.GetOutputVariable().AsString(2));

            Console.WriteLine("MAE = " + MA1.GetMAE());
            Console.WriteLine("MSE = " + MA1.GetMSE());

            Assert.AreEqual(5.67, (double)MA1.GetOutputVariable().GetValue(3), 0.01);
            Assert.AreEqual(11.33, (double)MA1.GetOutputVariable().GetValue(4), 0.01);
            Assert.AreEqual(13.67, (double)MA1.GetOutputVariable().GetValue(5), 0.01);
        }
        public void TestMethod()
        {
            /*
             * F distribution.
             */

            PIDebug.TitleBig("F distribution");

            PIFDistribution distribution = new PIFDistribution();

            /* -- 1) Get probability */

            PIDebug.TitleBig("Get probability");

            /* DF1=1, DF2=1 */

            PIDebug.Title("..df1=1, df2=1");

            distribution.SetDF1(1);
            distribution.SetDF2(1);

            Console.WriteLine("Probability for x=0.0 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, distribution.GetProbability(0.0), 0.001);

            Console.WriteLine("Probability for x=39.86 : " + distribution.GetProbability(39.86));
            Assert.AreEqual(0.1, distribution.GetProbability(39.86), 0.001);

            Console.WriteLine("Probability for x=161.45 : " + distribution.GetProbability(161.45));
            Assert.AreEqual(0.05, distribution.GetProbability(161.45), 0.001);

            Console.WriteLine("Probability for x=4052.2 : " + distribution.GetProbability(4052.2));
            Assert.AreEqual(0.01, distribution.GetProbability(4052.2), 0.001);

            Console.WriteLine("Probability for x=405284 : " + distribution.GetProbability(405284));
            Assert.AreEqual(0.001, distribution.GetProbability(405284), 0.001);

            /* DF1=3, DF2=3 */

            PIDebug.Title("..df1=3, df2=3", true);

            distribution.SetDF1(3);
            distribution.SetDF2(3);

            Console.WriteLine("Probability for x=5.39 : " + distribution.GetProbability(5.39));
            Assert.AreEqual(0.1, distribution.GetProbability(5.39), 0.001);

            Console.WriteLine("Probability for x=9.28 : " + distribution.GetProbability(9.28));
            Assert.AreEqual(0.05, distribution.GetProbability(9.28), 0.001);

            Console.WriteLine("Probability for x=15.44 : " + distribution.GetProbability(15.44));
            Assert.AreEqual(0.025, distribution.GetProbability(15.44), 0.001);

            Console.WriteLine("Probability for x=29.46 : " + distribution.GetProbability(29.46));
            Assert.AreEqual(0.01, distribution.GetProbability(29.46), 0.001);

            Console.WriteLine("Probability for x=141.11 : " + distribution.GetProbability(141.11));
            Assert.AreEqual(0.001, distribution.GetProbability(141.11), 0.001);

            /* DF1=5, DF2=5 */

            PIDebug.Title("..df1=5, df2=5", true);

            distribution.SetDF1(5);
            distribution.SetDF2(5);

            Console.WriteLine("Probability for x=3.45 : " + distribution.GetProbability(3.45));
            Assert.AreEqual(0.1, distribution.GetProbability(3.45), 0.001);

            Console.WriteLine("Probability for x=5.05 : " + distribution.GetProbability(5.05));
            Assert.AreEqual(0.05, distribution.GetProbability(5.05), 0.001);

            Console.WriteLine("Probability for x=7.15 : " + distribution.GetProbability(7.15));
            Assert.AreEqual(0.025, distribution.GetProbability(7.15), 0.001);

            Console.WriteLine("Probability for x=10.97 : " + distribution.GetProbability(10.97));
            Assert.AreEqual(0.01, distribution.GetProbability(10.97), 0.001);

            Console.WriteLine("Probability for x=29.75 : " + distribution.GetProbability(29.75));
            Assert.AreEqual(0.001, distribution.GetProbability(29.75), 0.001);

            /* -- 2) Get X for probability */

            PIDebug.Title("2) Get X for probability", true);

            /* DF1=1, DF2=1 */

            PIDebug.Title("..df1=1, df2=1");

            distribution.SetDF1(1);
            distribution.SetDF2(1);

            Console.WriteLine("X value for probability for prop=1.0 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, distribution.GetXForProbability(1.0), 0.01);

            Console.WriteLine("X value for probability for prop=0.1 : " + distribution.GetXForProbability(0.1));
            Assert.AreEqual(39.86, distribution.GetXForProbability(0.1), 0.01);

            Console.WriteLine("X value for probability for prop=0.05 : " + distribution.GetXForProbability(0.05));
            Assert.AreEqual(161.45, distribution.GetXForProbability(0.05), 0.01);

            Console.WriteLine("X value for probability for prop=0.01 : " + distribution.GetXForProbability(0.01));
            Assert.AreEqual(4052.2, distribution.GetXForProbability(0.01), 0.02);

            Console.WriteLine("X value for probability for prop=0.001 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(405284, distribution.GetXForProbability(0.001), 0.1);

            /* DF1=3, DF2=3 */

            PIDebug.Title("..df1=3, df2=3", true);

            distribution.SetDF1(3);
            distribution.SetDF2(3);

            Console.WriteLine("X value for probability for prop=0.1 : " + distribution.GetXForProbability(0.1));
            Assert.AreEqual(5.39, distribution.GetXForProbability(0.1), 0.01);

            Console.WriteLine("X value for probability for prop=0.05 : " + distribution.GetXForProbability(0.05));
            Assert.AreEqual(9.28, distribution.GetXForProbability(0.05), 0.01);

            Console.WriteLine("X value for probability for prop=0.025 : " + distribution.GetXForProbability(0.025));
            Assert.AreEqual(15.44, distribution.GetXForProbability(0.025), 0.01);

            Console.WriteLine("X value for probability for prop=0.01 : " + distribution.GetXForProbability(0.01));
            Assert.AreEqual(29.46, distribution.GetXForProbability(0.01), 0.01);

            Console.WriteLine("X value for probability for prop=0.001 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(141.11, distribution.GetXForProbability(0.001), 0.01);

            /* DF1=5, DF2=5 */

            PIDebug.Title("..df1=5, df2=5", true);

            distribution.SetDF1(5);
            distribution.SetDF2(5);

            Console.WriteLine("X value for probability for prop=0.1 : " + distribution.GetXForProbability(0.1));
            Assert.AreEqual(3.45, distribution.GetXForProbability(0.1), 0.01);

            Console.WriteLine("X value for probability for prop=0.05 : " + distribution.GetXForProbability(0.05));
            Assert.AreEqual(5.05, distribution.GetXForProbability(0.05), 0.01);

            Console.WriteLine("X value for probability for prop=0.025 : " + distribution.GetXForProbability(0.025));
            Assert.AreEqual(7.15, distribution.GetXForProbability(0.025), 0.01);

            Console.WriteLine("X value for probability for prop=0.01 : " + distribution.GetXForProbability(0.01));
            Assert.AreEqual(10.97, distribution.GetXForProbability(0.01), 0.01);

            Console.WriteLine("X value for probability for prop=0.001 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(29.75, distribution.GetXForProbability(0.001), 0.01);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density, df1=1, df2=1", true);

            distribution.SetDF1(1);
            distribution.SetDF2(1);

            Console.WriteLine("x=0.0 : " + distribution.GetPDF(0.0));
            Console.WriteLine("x=0.001 : " + distribution.GetPDF(0.001));
            Console.WriteLine("x=0.1 : " + distribution.GetPDF(0.1));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=7.0 : " + distribution.GetPDF(7.0));
        }
Esempio n. 18
0
        public void TestMethod()
        {
            /* Source 5S2. */

            PIDebug.TitleBig("Weibull distribution (lambda=1, k=1)");

            PIWeibullDistribution distribution = new PIWeibullDistribution();

            /* -- 1) Get probability */

            PIDebug.Title("1) Get probability for X (CDF)");

            /* lambda=1, k=2 */
            PIDebug.Title("..lambda=1; k=2");

            distribution.SetK(2);

            Console.WriteLine("Probability for x=0.0 : " + distribution.GetCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetProbability(0.0), 0.001);

            Console.WriteLine("Probability for x=0.5 : " + distribution.GetCDF(0.5));
            Assert.AreEqual(0.2212, distribution.GetProbability(0.5), 0.001);

            Console.WriteLine("Probability for x=1.0 : " + distribution.GetCDF(1.0));
            Assert.AreEqual(0.6321, distribution.GetProbability(1.0), 0.001);

            Console.WriteLine("Probability for x=2.0 : " + distribution.GetCDF(2.0));
            Assert.AreEqual(0.9817, distribution.GetProbability(2.0), 0.001);

            /* lambda=2, k=3 */
            PIDebug.Title("..lambda=2; k=3", true);

            distribution.SetLambda(2);
            distribution.SetK(3);

            Console.WriteLine("Probability for x=1.0 : " + distribution.GetCDF(1.0));
            Assert.AreEqual(0.1175, distribution.GetProbability(1.0), 0.001);

            /* -- 2) Get T for probability */

            PIDebug.Title("2) Get X for probability (InverseCDF)", true);

            /* lambda=1, k=2 */
            PIDebug.Title("..lambda=1; k=2");

            distribution.SetLambda(1);
            distribution.SetK(2);

            Console.WriteLine("X value for probability for prob=0.0 : " + distribution.GetInverseCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetInverseCDF(0.0), 0.001);

            Console.WriteLine("X value for probability for prob=0.2212 : " + distribution.GetInverseCDF(0.2212));
            Assert.AreEqual(0.5, distribution.GetInverseCDF(0.2212), 0.001);

            Console.WriteLine("X value for probability for prob=0.6321 : " + distribution.GetInverseCDF(0.6321));
            Assert.AreEqual(1.0, distribution.GetInverseCDF(0.6321), 0.001);

            Console.WriteLine("X value for probability for prob=0.9817 : " + distribution.GetInverseCDF(0.9817));
            Assert.AreEqual(2.0, distribution.GetInverseCDF(0.9817), 0.001);

            /* lambda=2, k=3 */
            PIDebug.Title("..lambda=2; k=3", true);

            distribution.SetLambda(2);
            distribution.SetK(3);

            Console.WriteLine("X value for probability for prob=0.1175 : " + distribution.GetInverseCDF(0.1175));
            Assert.AreEqual(1.0, distribution.GetInverseCDF(0.1175), 0.001);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density (PDF)", true);

            PIDebug.Title("..lambda=1, k=1");

            distribution.SetLambda(1);
            distribution.SetK(1);

            Console.WriteLine("x=0.1 : " + distribution.GetPDF(0.1));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=1.0 : " + distribution.GetPDF(1.0));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=5.0 : " + distribution.GetPDF(5.0));
        }
Esempio n. 19
0
        public void TestMethod()
        {
            /* -- Factorial */

            PIDebug.TitleBig("Factorial");

            Console.WriteLine("Factorial(0) = " + PIProbabilityUtils.Factorial(0));
            Assert.AreEqual(1, PIProbabilityUtils.Factorial(0));

            Console.WriteLine("Factorial(1) = " + PIProbabilityUtils.Factorial(1));
            Assert.AreEqual(1, PIProbabilityUtils.Factorial(1));

            Console.WriteLine("Factorial(2) = " + PIProbabilityUtils.Factorial(2));
            Assert.AreEqual(2, PIProbabilityUtils.Factorial(2));

            Console.WriteLine("Factorial(3) = " + PIProbabilityUtils.Factorial(3));
            Assert.AreEqual(6, PIProbabilityUtils.Factorial(3));

            Console.WriteLine("Factorial(7) = " + PIProbabilityUtils.Factorial(7));
            Assert.AreEqual(5040, PIProbabilityUtils.Factorial(7));

            Console.WriteLine("Factorial(10) = " + PIProbabilityUtils.Factorial(10));
            Assert.AreEqual(3628800, PIProbabilityUtils.Factorial(10));

            /* -- Combination */

            PIDebug.TitleBig("Combination", true);

            Console.WriteLine("C(10,3) = " + PIProbabilityUtils.Combination(10, 3));
            Assert.AreEqual(120, PIProbabilityUtils.Combination(10, 3));

            Console.WriteLine("C(14,5) = " + PIProbabilityUtils.Combination(14, 5));
            Assert.AreEqual(2002, PIProbabilityUtils.Combination(14, 5));

            Console.WriteLine("C(7,2) = " + PIProbabilityUtils.Combination(7, 2));
            Assert.AreEqual(21, PIProbabilityUtils.Combination(7, 2));

            Console.WriteLine("C(52,5) = " + PIProbabilityUtils.Combination(52, 5));
            Assert.AreEqual(2598960, PIProbabilityUtils.Combination(52, 5));

            /* -- Catalan number */

            PIDebug.TitleBig("Catalan number", true);

            Console.WriteLine("Catalan number(0) = " + PIProbabilityUtils.CatalanNumber(0));
            Assert.AreEqual(1, PIProbabilityUtils.CatalanNumber(0));

            Console.WriteLine("Catalan number(1) = " + PIProbabilityUtils.CatalanNumber(1));
            Assert.AreEqual(1, PIProbabilityUtils.CatalanNumber(1));

            Console.WriteLine("Catalan number(2) = " + PIProbabilityUtils.CatalanNumber(2));
            Assert.AreEqual(2, PIProbabilityUtils.CatalanNumber(2));

            Console.WriteLine("Catalan number(3) = " + PIProbabilityUtils.CatalanNumber(3));
            Assert.AreEqual(5, PIProbabilityUtils.CatalanNumber(3));

            Console.WriteLine("Catalan number(4) = " + PIProbabilityUtils.CatalanNumber(4));
            Assert.AreEqual(14, PIProbabilityUtils.CatalanNumber(4));

            Console.WriteLine("Catalan number(5) = " + PIProbabilityUtils.CatalanNumber(5));
            Assert.AreEqual(42, PIProbabilityUtils.CatalanNumber(5));

            Console.WriteLine("Catalan number(6) = " + PIProbabilityUtils.CatalanNumber(6));
            Assert.AreEqual(132, PIProbabilityUtils.CatalanNumber(6));

            Console.WriteLine("Catalan number(7) = " + PIProbabilityUtils.CatalanNumber(7));
            Assert.AreEqual(429, PIProbabilityUtils.CatalanNumber(7));

            Console.WriteLine("Catalan number(15) = " + PIProbabilityUtils.CatalanNumber(15));
            Assert.AreEqual(9694845, PIProbabilityUtils.CatalanNumber(15));

            Console.WriteLine("Catalan number(25) = " + PIProbabilityUtils.CatalanNumber(25));
            Assert.AreEqual((ulong)4861946401452, (ulong)PIProbabilityUtils.CatalanNumber(25));

            Console.WriteLine("Catalan number(50) = " + PIProbabilityUtils.CatalanNumber(50));

            Console.WriteLine("Catalan number(150) = " + PIProbabilityUtils.CatalanNumber(150));
        }
Esempio n. 20
0
        public void TestMethod()
        {
            /* Cramers rule (Prachar II/15)
             *
             * x1 + 2x2 - 3x3 = -9
             * 2x1 - 3x2 - 5x3 = -8
             * x1 + x2 + x3 = 4
             *
             * */

            PIDebug.TitleBig("Cramers Rule - (degree=3)");

            PICramersRule cramersRule = new PICramersRule(3);

            Assert.IsNotNull(cramersRule);

            PIDebug.Title("A");

            cramersRule.Get_matrixA().AddValues(new int[] { 1, 2, -3, 2, -3, -5, 1, 1, 1 });
            Console.WriteLine(cramersRule.Get_matrixA().AsString(0));

            PIDebug.Title("B", true);

            cramersRule.Get_matrixB().AddValues(new int[] { -9, -8, 4 });
            Console.WriteLine(cramersRule.Get_matrixB().AsString(0));

            PIDebug.Blank();

            int i = cramersRule.Calc();

            switch (i)
            {
            case -1:
                Console.WriteLine("Some error.");
                Assert.Fail("Some error.");
                break;

            case 0:
                Console.WriteLine("System of linear equitions has no solution.");
                break;

            case 1:
                Console.WriteLine("Result = " + cramersRule.Get_results().AsString(0));

                Assert.AreEqual(2.0, (double)cramersRule.Get_results().GetValue(0));
                Assert.AreEqual(-1.0, (double)cramersRule.Get_results().GetValue(1));
                Assert.AreEqual(3.0, (double)cramersRule.Get_results().GetValue(2));
                break;
            }

            /* Cramers rule - A (1c/16a)
             *
             * x + 4y = 37
             * 2x + 5y = 53
             *
             * */

            PIDebug.TitleBig("Cramers Rule - A - (degree=2)", true);

            PICramersRule cramersRuleA = new PICramersRule(2);

            Assert.IsNotNull(cramersRuleA);

            PIDebug.Title("A");

            cramersRuleA.Get_matrixA().AddValues(new int[] { 1, 4, 2, 5 });
            Console.WriteLine(cramersRuleA.Get_matrixA().AsString(0));

            PIDebug.Title("B", true);

            cramersRuleA.Get_matrixB().AddValues(new int[] { 37, 53 });
            Console.WriteLine(cramersRuleA.Get_matrixB().AsString(0));

            PIDebug.Blank();

            i = cramersRuleA.Calc();

            switch (i)
            {
            case -1:
                Console.WriteLine("Some error.");
                Assert.Fail("Some error.");
                break;

            case 0:
                Console.WriteLine("System of linear equitions has not solution.");
                break;

            case 1:
                Console.WriteLine("Result = " + cramersRuleA.Get_results().AsString(0));

                Assert.AreEqual(9.0, (double)cramersRuleA.Get_results().GetValue(0));
                Assert.AreEqual(7.0, (double)cramersRuleA.Get_results().GetValue(1));
                break;
            }

            /* Cramers rule - B (1c/16b)
             *
             * 3x - 2y = 8
             * -9x + 6y = 5
             *
             * */

            PIDebug.TitleBig("Cramers Rule - B - (degree=2)", true);

            PICramersRule cramersRuleB = new PICramersRule(2);

            Assert.IsNotNull(cramersRuleB);

            PIDebug.Title("A");

            cramersRuleB.Get_matrixA().AddValues(new int[] { 3, -2, -9, 6 });
            Console.WriteLine(cramersRuleB.Get_matrixA().AsString(0));

            PIDebug.Title("B");

            cramersRuleB.Get_matrixB().AddValues(new int[] { 8, 5 });
            Console.WriteLine(cramersRuleB.Get_matrixB().AsString(0));

            PIDebug.Blank();

            i = cramersRuleB.Calc();

            switch (i)
            {
            case -1:
                Console.WriteLine("Some error.");
                Assert.Fail("Some error.");
                break;

            case 0:
                Console.WriteLine("System of linear equitions has not solution.");
                break;

            case 1:
                Console.WriteLine("Result = " + cramersRuleB.Get_results().AsString(0));
                break;
            }

            Assert.AreEqual(cramersRuleB.Get_results().Count(), 0);
        }
        public void TestMethod()
        {
            /* Source 5S2. */

            PIDebug.TitleBig("Rayleigh distribution");

            PIRayleighDistribution distribution = new PIRayleighDistribution();

            /* -- 1) Get probability */

            PIDebug.Title("1) Get probability for X (CDF)");

            /* sigma=1 */
            PIDebug.Title("..sigma=1");

            Console.WriteLine("Probability for x=0.0 : " + distribution.GetCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetProbability(0.0), 0.001);

            Console.WriteLine("Probability for x=1.0 : " + distribution.GetCDF(1.0));
            Assert.AreEqual(0.3933, distribution.GetProbability(1.0), 0.001);

            Console.WriteLine("Probability for x=2.0 : " + distribution.GetCDF(2.0));
            Assert.AreEqual(0.8646, distribution.GetProbability(2.0), 0.001);

            Console.WriteLine("Probability for x=2.5 : " + distribution.GetCDF(2.5));
            Assert.AreEqual(0.9560, distribution.GetProbability(2.5), 0.001);

            /* sigma=3 */
            PIDebug.Title("..sigma=3", true);

            distribution.SetSigma(3);

            Console.WriteLine("Probability for x=1.0 : " + distribution.GetCDF(1.0));
            Assert.AreEqual(0.0540, distribution.GetProbability(1.0), 0.001);

            /* -- 2) Get T for probability */

            PIDebug.Title("2) Get X for probability (InverseCDF)", true);

            /* sigma=1 */
            PIDebug.Title("..sigma=1");

            distribution.SetSigma(1);

            Console.WriteLine("X value for probability for prob=0.0 : " + distribution.GetInverseCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetInverseCDF(0.0), 0.001);

            Console.WriteLine("X value for probability for prob=0.3933 : " + distribution.GetInverseCDF(0.3933));
            Assert.AreEqual(1.0, distribution.GetInverseCDF(0.3933), 0.001);

            Console.WriteLine("X value for probability for prob=0.8646 : " + distribution.GetInverseCDF(0.8646));
            Assert.AreEqual(2.0, distribution.GetInverseCDF(0.8646), 0.001);

            Console.WriteLine("X value for probability for prob=0.9560 : " + distribution.GetInverseCDF(0.9560));
            Assert.AreEqual(2.5, distribution.GetInverseCDF(0.9560), 0.001);

            /* sigma=3 */
            PIDebug.Title("..sigma=3", true);

            distribution.SetSigma(3);

            Console.WriteLine("X value for probability for prob=0.0540 : " + distribution.GetInverseCDF(0.0540));
            Assert.AreEqual(1.0, distribution.GetInverseCDF(0.0540), 0.001);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density (PDF)", true);

            PIDebug.Title("..sigma=1");

            distribution.SetSigma(1);

            Console.WriteLine("x=0.1 : " + distribution.GetPDF(0.1));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=1.0 : " + distribution.GetPDF(1.0));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=5.0 : " + distribution.GetPDF(5.0));
        }
        public void TestMethod()
        {
            /* --------------------------------- */

            PIDebug.TitleBig("Variable");

            /* check variable */

            PIVariable var = new PIVariable();

            Assert.IsNotNull(var);

            /* clear variable */

            var.Clear();
            System.Console.WriteLine("Alter clear()");
            Assert.AreEqual(0, var.Count());

            /* add values */

            var.AddValue((double)10);
            var.AddValue((double)20);
            var.AddValue((double)30);

            /* set value */

            PIDebug.Blank();
            PIDebug.Title("set");
            var.SetValue(1, 25.0);
            Assert.AreEqual(25.0, (double)var.GetValue(1), 0.01);

            Console.WriteLine(var.AsString(0));

            var.SetValue(1, 20.0);

            PIDebug.Blank();

            /* median - odd */

            double median = var.GetMedian();

            Console.WriteLine("median (odd) = " + median);
            Assert.AreEqual(20.0, (double)median, 0.001);

            /* check count */

            Console.WriteLine("count() = " + var.Count());
            Assert.AreEqual(3, var.Count());

            /* check sum */

            Console.WriteLine("sum() = " + var.GetSum());
            Assert.AreEqual(60.0, var.GetSum());

            /* --------------------------------- */

            PIDebug.Blank();
            PIDebug.TitleBig("Variable - another");

            /* add values (source 2a/40) */

            var.Clear();
            var.Set_alwaysRecalc(true);

            var.AddValue(1.90);
            var.AddValue(3.00);
            var.AddValue(2.53);
            var.AddValue(3.71);
            var.AddValue(2.12);
            var.AddValue(1.76);
            var.AddValue(2.71);
            var.AddValue(1.39);
            var.AddValue(4.00);
            var.AddValue(3.33);

            Double sampleMean = var.GetSampleMean();

            Console.WriteLine("sampleMean = " + sampleMean);

            Assert.AreEqual(2.645, (double)sampleMean, 0.0001);

            /* min */

            double min = var.GetMin();

            Console.WriteLine("min = " + min);

            Assert.AreEqual(1.39, min, 0.001);

            /* max */

            double max = var.GetMax();

            Console.WriteLine("max = " + max);

            Assert.AreEqual(4.00, max, 0.001);

            /* asstring */

            Console.WriteLine("Items list");
            Console.WriteLine(var.AsString(2));

            /* sorted list */

            PIVariable sorted = var.GetSorted();

            Console.WriteLine("Sorted items list");
            Console.WriteLine(sorted.AsString(2));

            /* median - even (source 2a/45) */

            median = var.GetMedian();
            Console.WriteLine("median (even) = " + median);
            Assert.AreEqual(2.62, median, 0.001);

            /* sample standard deviation */

            double std = var.GetSampleStandardDeviation();

            Console.WriteLine("sample standard deviation = " + std);
            Assert.AreEqual(0.8674, std, 0.001);

            /* Z score (source 2a/78) */

            double ZScore = var.GetZScore(0);

            Console.WriteLine("Z score = " + ZScore);
            Assert.AreEqual(-0.8589, ZScore, 0.001);

            ZScore = var.GetZScore(1);
            Console.WriteLine("Z score = " + ZScore);
            Assert.AreEqual(0.4093, ZScore, 0.001);

            /* --------------------------------- */

            /* -- source 2d/68 */

            PIDebug.Blank();
            PIDebug.Title("Example with VAR1 and VAR2");

            PIVariable var1 = new PIVariable();
            PIVariable var2 = new PIVariable();

            Assert.IsNotNull(var1);
            Assert.IsNotNull(var2);

            var1.AddMoreValues(4.0, 3);
            var1.AddMoreValues(6.0, 4);
            var1.AddMoreValues(7.0, 2);
            var1.AddMoreValues(9.0, 4);
            var1.AddMoreValues(10.0, 10);
            var1.AddMoreValues(11.0, 5);
            var1.AddMoreValues(11.5, 2);
            var1.AddMoreValues(12.0, 13);
            var1.AddMoreValues(13.0, 4);
            var1.AddMoreValues(14.0, 2);
            var1.AddMoreValues(15.0, 2);
            var1.AddMoreValues(16.0, 4);
            var1.AddMoreValues(17.0, 6);
            var1.AddMoreValues(18.0, 2);
            var1.AddMoreValues(19.0, 2);
            var1.AddMoreValues(20.0, 6);
            var1.AddMoreValues(22.0, 2);

            Console.WriteLine("count = " + var1.Count());
            Assert.AreEqual(73, var1.Count(), 0.001);

            Console.WriteLine("mean = " + var1.GetSampleMean());
            Assert.AreEqual(12.79, var1.GetSampleMean(), 0.01);

            Console.WriteLine("geometric mean = " + var1.GetGeometricMean());
            Assert.AreEqual(11.95, var1.GetGeometricMean(), 0.01);

            Console.WriteLine("mode = " + var1.GetMode());
            Assert.AreEqual(12.00, var1.GetMode(), 0.01);

            Console.WriteLine("median = " + var1.GetMedian());
            Assert.AreEqual(12.00, var1.GetMedian(), 0.01);

            Console.WriteLine("population variance = " + var1.GetPopulationVariance());
            Assert.AreEqual(19.44, var1.GetPopulationVariance(), 0.01);

            Console.WriteLine("population standard deviation = " + var1.GetPopulationStandardDeviation());
            Assert.AreEqual(4.41, var1.GetPopulationStandardDeviation(), 0.01);

            Console.WriteLine("sample variance = " + var1.GetSampleVariance());
            Assert.AreEqual(19.71, var1.GetSampleVariance(), 0.01);

            Console.WriteLine("sample standard deviation = " + var1.GetSampleStandardDeviation());
            Assert.AreEqual(4.44, var1.GetSampleStandardDeviation(), 0.01);

            Console.WriteLine("min = " + var1.GetMin());
            Assert.AreEqual(4.00, var1.GetMin(), 0.01);

            Console.WriteLine("max = " + var1.GetMax());
            Assert.AreEqual(22.00, var1.GetMax(), 0.01);

            Console.WriteLine("range = " + var1.GetRange());
            Assert.AreEqual(18.00, var1.GetRange(), 0.01);

            Console.WriteLine("quartile1 = " + var1.GetQuartile1());
            Assert.AreEqual(10.00, var1.GetQuartile1(), 0.01);

            Console.WriteLine("quartile3 = " + var1.GetQuartile3());
            Assert.AreEqual(16.00, var1.GetQuartile3(), 0.01);

            Console.WriteLine("interquartile range = " + var1.GetInterquartileRange());
            Assert.AreEqual(6.00, var1.GetInterquartileRange(), 0.01);

            Console.WriteLine("skewness = " + var1.GetSkewness());
            Assert.AreEqual(0.16, var1.GetSkewness(), 0.01);

            Console.WriteLine("kurtosis = " + var1.GetKurtosis());

            /* -- 1.0.6. --------------------------------------------- */

            /* -- LAG -- */

            PIDebug.Blank();
            PIDebug.Title("LAG -2");

            PIVariable varLAGSource = new PIVariable();

            varLAGSource.AddMoreValuesRange(1, 10);

            Console.WriteLine("Source = " + varLAGSource.AsString(0));

            /* -2 */
            PIVariable varLAGMinus2 = new PIVariable();

            varLAGMinus2.MakeLag(varLAGSource, -2, false);

            /* LAG -2 = 3;4;5;6;7;8;9;10;<null>;<null> */
            Console.WriteLine("LAG -2 = " + varLAGMinus2.AsString(0));

            Assert.AreEqual(3.0, (double)varLAGMinus2.GetValue(0), 0.1);
            Assert.AreEqual(null, varLAGMinus2.GetValue(8));
            Assert.AreEqual(null, varLAGMinus2.GetValue(9));

            /* +2 */
            PIVariable varLAGPlus2 = new PIVariable();

            varLAGPlus2.MakeLag(varLAGSource, +2, false);

            /* LAG +2 = <null>;<null>;1;2;3;4;5;6;7;8 */
            Console.WriteLine("LAG +2 = " + varLAGPlus2.AsString(0));

            Assert.AreEqual(null, varLAGPlus2.GetValue(0));
            Assert.AreEqual(null, varLAGPlus2.GetValue(1));
            Assert.AreEqual(1.0, (double)varLAGPlus2.GetValue(2), 0.1);

            /* -- 1.0.9. --------------------------------------------- */

            /* -- standardize -- */

            PIDebug.Blank();
            PIDebug.Title("Standardize data (with Z-SCORE method)");

            PIVariable varStandardize = new PIVariable();

            varStandardize.AddValues(new int[] { 10, 20, 25, 17, 13, 16 });

            Console.WriteLine(varStandardize.AsString(0));
            varStandardize.Standardize(StandardizeMethod.Z_SCORE);
            Console.WriteLine(varStandardize.AsString(2));

            PIDebug.Blank();
            PIDebug.Title("Standardize data (with SCALING 0-1 method)");

            PIVariable varStandardize1 = new PIVariable();

            varStandardize1.AddValues(new int[] { 10, 20, 25, 17, 13, 16 });

            Console.WriteLine(varStandardize1.AsString(0));
            varStandardize1.Standardize(StandardizeMethod.SCALING_0_1);
            Console.WriteLine(varStandardize1.AsString(2));

            /* -- 1.2.4 - verifing against Kubanova`s (source 3A,42) skewness - if the result is same as in the book */

            PIDebug.Title("Verifing Kubanova`s skewness", true);

            PIVariable varSkewness = new PIVariable();

            varSkewness.AddMoreValues(1, 21);
            varSkewness.AddMoreValues(2, 43);
            varSkewness.AddMoreValues(3, 37);
            varSkewness.AddMoreValues(4, 9);
            varSkewness.AddMoreValues(5, 2);

            Console.WriteLine("mean = " + varSkewness.GetSampleMean());
            Assert.AreEqual(2.357, (double)varSkewness.GetSampleMean(), 0.001);

            Console.WriteLine("population variance = " + varSkewness.GetPopulationVariance());
            Assert.AreEqual(0.872, (double)varSkewness.GetPopulationVariance(), 0.001);

            Console.WriteLine("population sd = " + varSkewness.GetPopulationStandardDeviation());
            Assert.AreEqual(0.934, (double)varSkewness.GetPopulationStandardDeviation(), 0.001);

            Console.WriteLine("mode = " + varSkewness.GetMode());
            Assert.AreEqual(2.0, (double)varSkewness.GetMode(), 0.001);

            Console.WriteLine("median = " + varSkewness.GetMedian());
            Assert.AreEqual(2.0, (double)varSkewness.GetMedian(), 0.001);

            Console.WriteLine("skewness = " + varSkewness.GetSkewness());
            Assert.AreEqual(0.353, (double)varSkewness.GetSkewness(), 0.001);

            Console.WriteLine("kurtosis = " + varSkewness.GetKurtosis());
            Assert.AreEqual(-0.168, (double)varSkewness.GetKurtosis(), 0.001);

            Console.WriteLine("range = " + varSkewness.GetRange());
            Assert.AreEqual(4.0, (double)varSkewness.GetRange(), 0.001);
        }
Esempio n. 23
0
        public void TestMethod()
        {
            /*
             * Student`s distribution.
             */

            PIDebug.TitleBig("Student`s distribution");

            PIStudentDistribution distribution = new PIStudentDistribution();

            /* -- 1) Get probability for T */

            PIDebug.Title("1) Get probability");

            /* DF=1 */

            PIDebug.Title("..df=1");

            distribution.SetDF(1);

            Console.WriteLine("Probability for x=0.0, df=1 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(0.0), 0.1);
            Console.WriteLine("Probability for x=1, df=1 : " + distribution.GetProbability(1.00));
            Assert.AreEqual(0.5, (double)distribution.GetProbability(1.00), 0.1);
            Console.WriteLine("Probability for x=15.89, df=1 : " + distribution.GetProbability(15.89));
            Assert.AreEqual(0.04, (double)distribution.GetProbability(15.89), 0.1);
            Console.WriteLine("Probability for x=636.6, df=1 : " + distribution.GetProbability(636.6));
            Assert.AreEqual(0.001, (double)distribution.GetProbability(636.6), 0.1);

            PIDebug.Blank();

            distribution.SetDF(2);

            Console.WriteLine("Probability for x=0.0, df=2 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(0.0), 0.1);
            Console.WriteLine("Probability for x=0.816, df=2 : " + distribution.GetProbability(0.816));
            Assert.AreEqual(0.5, (double)distribution.GetProbability(0.816), 0.1);
            Console.WriteLine("Probability for x=4.849, df=2 : " + distribution.GetProbability(4.849));
            Assert.AreEqual(0.04, (double)distribution.GetProbability(4.849), 0.1);
            Console.WriteLine("Probability for x=31.6, df=2 : " + distribution.GetProbability(31.6));
            Assert.AreEqual(0.001, (double)distribution.GetProbability(31.6), 0.1);

            PIDebug.Blank();

            distribution.SetDF(3);

            Console.WriteLine("Probability for x=0.0, df=3 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(0.0), 0.1);
            Console.WriteLine("Probability for x=0.765, df=3 : " + distribution.GetProbability(0.765));
            Assert.AreEqual(0.5, (double)distribution.GetProbability(0.765), 0.1);
            Console.WriteLine("Probability for x=3.482, df=3 : " + distribution.GetProbability(3.482));
            Assert.AreEqual(0.04, (double)distribution.GetProbability(3.482), 0.1);
            Console.WriteLine("Probability for x=12.92, df=3 : " + distribution.GetProbability(12.92));
            Assert.AreEqual(0.001, (double)distribution.GetProbability(12.92), 0.1);

            PIDebug.Blank();

            distribution.SetDF(4);

            Console.WriteLine("Probability for x=0.0, df=4 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(0.0), 0.1);
            Console.WriteLine("Probability for x=0.741, df=4 : " + distribution.GetProbability(0.741));
            Assert.AreEqual(0.5, (double)distribution.GetProbability(0.741), 0.1);
            Console.WriteLine("Probability for x=2.999, df=4 : " + distribution.GetProbability(2.999));
            Assert.AreEqual(0.04, (double)distribution.GetProbability(2.999), 0.1);
            Console.WriteLine("Probability for x=8.610, df=4 : " + distribution.GetProbability(8.610));
            Assert.AreEqual(0.001, (double)distribution.GetProbability(8.610), 0.1);

            PIDebug.Blank();

            distribution.SetDF(5);

            Console.WriteLine("Probability for x=2.757, df=5 : " + distribution.GetProbability(2.757));
            Assert.AreEqual(0.04, (double)distribution.GetProbability(2.757), 0.1);

            distribution.SetDF(10);

            Console.WriteLine("Probability for x=1.372, df=10 : " + distribution.GetProbability(1.372));
            Assert.AreEqual(0.2, (double)distribution.GetProbability(1.372), 0.1);


            /* -- 2) Get T for probability */

            PIDebug.Title("2) Get T for probability", true);

            /* DF=1 */

            PIDebug.Title("..df=1");

            distribution.SetDF(1);

            Console.WriteLine("X value for probability for prob=1.0, df=1 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, (double)distribution.GetXForProbability(1.0), 0.1);
            Console.WriteLine("X value for probability for prob=0.5, df=1 : " + distribution.GetXForProbability(0.5));
            Assert.AreEqual(1.0, (double)distribution.GetXForProbability(0.5), 0.1);
            Console.WriteLine("X value for probability for prob=0.04, df=1 : " + distribution.GetXForProbability(0.04));
            Assert.AreEqual(15.89, (double)distribution.GetXForProbability(0.04), 0.1);
            Console.WriteLine("X value for probability for prob=0.001, df=1 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(636.6, (double)distribution.GetXForProbability(0.001), 0.1);

            PIDebug.Blank();

            distribution.SetDF(2);

            Console.WriteLine("X value for probability for prob=1.0, df=2 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, (double)distribution.GetXForProbability(1.0), 0.1);
            Console.WriteLine("X value for probability for prob=0.5, df=2 : " + distribution.GetXForProbability(0.5));
            Assert.AreEqual(0.816, (double)distribution.GetXForProbability(0.5), 0.1);
            Console.WriteLine("X value for probability for prob=0.04, df=2 : " + distribution.GetXForProbability(0.04));
            Assert.AreEqual(4.849, (double)distribution.GetXForProbability(0.04), 0.1);
            Console.WriteLine("X value for probability for prob=0.001, df=2 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(31.6, (double)distribution.GetXForProbability(0.001), 0.1);

            PIDebug.Blank();

            distribution.SetDF(3);

            Console.WriteLine("X value for probability for prob=1.0, df=3 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, (double)distribution.GetXForProbability(1.0), 0.1);
            Console.WriteLine("X value for probability for prob=0.5, df=3 : " + distribution.GetXForProbability(0.5));
            Assert.AreEqual(0.765, (double)distribution.GetXForProbability(0.5), 0.1);
            Console.WriteLine("X value for probability for prob=0.04, df=3 : " + distribution.GetXForProbability(0.04));
            Assert.AreEqual(3.482, (double)distribution.GetXForProbability(0.04), 0.1);
            Console.WriteLine("X value for probability for prob=0.001, df=3 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(12.92, (double)distribution.GetXForProbability(0.001), 0.1);

            PIDebug.Blank();

            distribution.SetDF(4);

            Console.WriteLine("X value for probability for prob=1.0, df=4 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, (double)distribution.GetXForProbability(1.0), 0.1);
            Console.WriteLine("X value for probability for prob=0.5, df=4 : " + distribution.GetXForProbability(0.5));
            Assert.AreEqual(0.741, (double)distribution.GetXForProbability(0.5), 0.1);
            Console.WriteLine("X value for probability for prob=0.04, df=4 : " + distribution.GetXForProbability(0.04));
            Assert.AreEqual(2.999, (double)distribution.GetXForProbability(0.04), 0.1);
            Console.WriteLine("X value for probability for prob=0.04, df=4 : " + distribution.GetXForProbability(0.001));
            Assert.AreEqual(8.610, (double)distribution.GetXForProbability(0.001), 0.1);

            PIDebug.Blank();

            distribution.SetDF(5);

            Console.WriteLine("X value for probability for prob=0.04, df=5 : " + distribution.GetXForProbability(0.04));
            Assert.AreEqual(2.757, (double)distribution.GetXForProbability(0.04), 0.1);

            distribution.SetDF(10);

            Console.WriteLine("X value for probability for prob=0.2, df=10 : " + distribution.GetXForProbability(0.2));
            Assert.AreEqual(1.372, (double)distribution.GetXForProbability(0.2), 0.1);

            PIDebug.Blank();

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density, df=1", true);

            distribution.SetDF(1);

            Console.WriteLine("x=-7.0 : " + distribution.GetPDF(-7.0));
            Console.WriteLine("x=-2.0 : " + distribution.GetPDF(-2.0));
            Console.WriteLine("x=-0.5 : " + distribution.GetPDF(-0.5));
            Console.WriteLine("x=0.0 : " + distribution.GetPDF(0.0));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=7.0 : " + distribution.GetPDF(7.0));
        }
        public void TestMethod()
        {
            /*
             * SIMPLE EXPONENTIAL SMOOTHING.
             *
             * Source 4H, 60.
             *
             */

            PIDebug.TitleBig("2. - Simple exponential smoothing (Cipra 4h,60) - 1. Part");

            /* - prepare variable for source data */

            PIVariable var1 = new PIVariable();

            Assert.IsNotNull(var1);

            var1.AddValues(new double[] { 29.9, 28.9, 29.9, 28.7, 29.6 });
            var1.AddValues(new double[] { 31.6, 28.0, 29.3, 26.4, 27.9 });
            var1.AddValues(new double[] { 30.1, 28.9, 29.4, 29.6, 27.5 });
            var1.AddValues(new double[] { 30.2, 28.3, 29.2, 28.6, 30.7 });
            var1.AddValues(new double[] { 29.0, 28.1 });

            /* - calc simple exponential smoothing, alpha=0.78 */

            PISimpleExponentialSmoothing smoothing1 = new PISimpleExponentialSmoothing(var1);

            /* use first 6 values for mean...and use it as the first value */
            smoothing1.SetFirstValueCalcType(FirstValueCalcType.MEAN_WINDOWLENGTH);
            smoothing1.SetWindowLength(6);

            smoothing1.SetAlpha(0.78);
            Console.WriteLine(" New ALPHA = " + smoothing1.GetAlpha());

            smoothing1.Calc();

            /* - show results */

            PIDebug.Blank();
            Console.WriteLine("After smoothing = " + smoothing1.GetOutputVariable().AsString(2));
            Assert.AreEqual(29.80, (double)smoothing1.GetOutputVariable().GetValue(0), 0.01);
            Assert.AreEqual(29.6, (double)smoothing1.GetOutputVariable().GetValue(1), 0.01);
            Assert.AreEqual(29.67, (double)smoothing1.GetOutputVariable().GetValue(2), 0.01);

            Console.WriteLine("Errors = " + smoothing1.GetErrors().AsString(2));
            /* ... */

            PIDebug.Blank();
            Console.WriteLine("SSE = " + smoothing1.GetSSE());
            Assert.AreEqual(33.43, (double)smoothing1.GetSSE(), 0.1);

            Console.WriteLine("MSE = " + smoothing1.GetMSE());
            Assert.AreEqual(1.519, (double)smoothing1.GetMSE(), 0.001);
            Console.WriteLine("MSE-1 = " + smoothing1.GetErrors().GetSum2() / (smoothing1.GetSourceVariable().Count() - 1));

            /*
             * SIMPLE EXPONENTIAL SMOOTHING.
             *
             * Source 4H, 60.
             *
             */

            PIDebug.TitleBig("2. - Simple exponential smoothing (Cipra 4h,61) - 2. Part", true);

            /* - calc simple exponential smoothing, alpha=0.9 */

            /* takes mean for first value */
            smoothing1.SetFirstValueCalcType(FirstValueCalcType.MEAN);

            smoothing1.SetAlpha(0.9);
            Console.WriteLine("New ALPHA = " + smoothing1.GetAlpha());

            smoothing1.Calc();

            /* - show results */

            PIDebug.Blank();
            Console.WriteLine("After smoothing = " + smoothing1.GetOutputVariable().AsString(2));
            //Assert.AreEqual(29.80, (double) smoothing1.destVariable.getValue(0), 0.01);
            //Assert.AreEqual(29.6, (double) smoothing1.destVariable.getValue(1), 0.01);
            //Assert.AreEqual(29.67, (double) smoothing1.destVariable.getValue(2), 0.01);

            Console.WriteLine("Errors = " + smoothing1.GetErrors().AsString(2));
            /* ... */

            PIDebug.Blank();
            Console.WriteLine("SSE = " + smoothing1.GetSSE());
            //Assert.AreEqual(33.43, (double) smoothing1.getSSE(), 0.1);

            Console.WriteLine("MSE = " + smoothing1.GetMSE());
            //Assert.AreEqual(1.519, (double) smoothing1.getMSE(), 0.001);
            Console.WriteLine("MSE-1 = " + smoothing1.GetErrors().GetSum2() / (smoothing1.GetSourceVariable().Count() - 1));
        }
Esempio n. 25
0
        public void TestMethod()
        {
            /* Source 6G. */

            PIDebug.TitleBig("Prime");

            //Console.WriteLine( 3 % 100 );

            /* -- Simple */

            PIDebug.Title("Simple method");

            Console.WriteLine("1 : " + PIPrime.IsPrime_Simple(1));
            Assert.AreEqual(false, PIPrime.IsPrime_Simple(1));

            Console.WriteLine("99 : " + PIPrime.IsPrime_Simple(99));
            Assert.AreEqual(false, PIPrime.IsPrime_Simple(99));

            Console.WriteLine("101 : " + PIPrime.IsPrime_Simple(101));
            Assert.AreEqual(true, PIPrime.IsPrime_Simple(101));

            Console.WriteLine("221 : " + PIPrime.IsPrime_Simple(221));
            Assert.AreEqual(false, PIPrime.IsPrime_Simple(221));

            Console.WriteLine("9973 : " + PIPrime.IsPrime_Simple(9973));
            Assert.AreEqual(true, PIPrime.IsPrime_Simple(9973));

            Console.WriteLine("10001261 : " + PIPrime.IsPrime_Simple(10001261));
            Assert.AreEqual(true, PIPrime.IsPrime_Simple(10001261));

            Console.WriteLine("9007199254740880 : " + PIPrime.IsPrime_Simple(9007199254740880));
            Assert.AreEqual(false, PIPrime.IsPrime_Simple(9007199254740880));

            Console.WriteLine("9007199254740881 : " + PIPrime.IsPrime_Simple(9007199254740881));
            Assert.AreEqual(true, PIPrime.IsPrime_Simple(9007199254740881));

            /* -- Fermat */

            PIDebug.Title("Fermat test", true);

            Console.WriteLine("1 : " + PIPrime.IsPrime_Fermat(1, 3));
            Assert.AreEqual(false, PIPrime.IsPrime_Fermat(1, 3));

            Console.WriteLine("99 : " + PIPrime.IsPrime_Fermat(99, 3));
            Assert.AreEqual(false, PIPrime.IsPrime_Fermat(99, 3));

            Console.WriteLine("101 : " + PIPrime.IsPrime_Fermat(101, 3));
            Assert.AreEqual(true, PIPrime.IsPrime_Fermat(101, 3));

            Console.WriteLine("221 : " + PIPrime.IsPrime_Fermat(221, 3));
            Assert.AreEqual(false, PIPrime.IsPrime_Fermat(221, 3));

            Console.WriteLine("9973 : " + PIPrime.IsPrime_Fermat(9973, 3));
            Assert.AreEqual(true, PIPrime.IsPrime_Fermat(9973, 3));

            Console.WriteLine("10001261 : " + PIPrime.IsPrime_Fermat(10001261, 3));
            Assert.AreEqual(true, PIPrime.IsPrime_Fermat(10001261, 3));

            Console.WriteLine("9007199254740880 : " + PIPrime.IsPrime_Fermat(9007199254740880, 3));
            Assert.AreEqual(false, PIPrime.IsPrime_Fermat(9007199254740880, 3));

            //Console.WriteLine( "9007199254740881 : " + PIPrime.IsPrime_Fermat( 9007199254740881 ) );
            //Assert.AreEqual( true, PIPrime.IsPrime_Fermat( 9007199254740881 ) );

            /* -- Miller-Rabin */

            PIDebug.Title("Miller-Rabin test", true);

            Console.WriteLine("221 : " + PIPrime.IsPrime_MillerRabin(221, 5));
            Assert.AreEqual(false, PIPrime.IsPrime_MillerRabin(221, 5));

            Console.WriteLine("5 :" + PIPrime.IsPrime_MillerRabin(5, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(5, 5));

            Console.WriteLine("97 : " + PIPrime.IsPrime_MillerRabin(97, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(97, 5));

            Console.WriteLine("99: " + PIPrime.IsPrime_MillerRabin(99, 5));
            Assert.AreEqual(false, PIPrime.IsPrime_MillerRabin(99, 5));

            Console.WriteLine("101 : " + PIPrime.IsPrime_MillerRabin(101, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(101, 5));

            Console.WriteLine("102 : " + PIPrime.IsPrime_MillerRabin(102, 5));
            Assert.AreEqual(false, PIPrime.IsPrime_MillerRabin(102, 5));

            Console.WriteLine("983 : " + PIPrime.IsPrime_MillerRabin(983, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(983, 5));

            Console.WriteLine("985 : " + PIPrime.IsPrime_MillerRabin(985, 5));
            Assert.AreEqual(false, PIPrime.IsPrime_MillerRabin(985, 5));

            Console.WriteLine("9973 : " + PIPrime.IsPrime_MillerRabin(9973, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(9973, 5));

            Console.WriteLine("10001261 : " + PIPrime.IsPrime_MillerRabin(10001261, 5));
            Assert.AreEqual(true, PIPrime.IsPrime_MillerRabin(10001261, 5));

            Console.WriteLine("9007199254740880 : " + PIPrime.IsPrime_MillerRabin(9007199254740880, 5));
            Assert.AreEqual(false, PIPrime.IsPrime_MillerRabin(9007199254740880, 5));


            //Console.WriteLine( "900719925474000 : " + PIPrime.IsPrime_MillerRabin( 900719925474000, 5 ) );

            //Console.WriteLine( "9007199254740880 : " + PIPrime.IsPrime_MillerRabin(  9007199254740880, 5 ) );
        }
Esempio n. 26
0
        public void TestMethod()
        {
            /*
             *  KUBANOVA example - Source 3i,35. **
             *
             *  Values for partial sums are cutted from START.
             *
             *  */

            PIDebug.TitleBig("KUBANOVA, source 3i,36");

            /* -- 1) PARTIAL_SUMS method */

            PIDebug.Title("Regression 1-A (PARTIAL SUMS method)");

            /* - prepare X data for regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddMoreValuesRange(1, 29);

            /* - prepare Y data for regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new int[] { 3, 5, 7, 9, 14 });
            Y.AddValues(new int[] { 17, 21, 27, 36, 40 });
            Y.AddValues(new int[] { 47, 54, 65, 71, 78 });
            Y.AddValues(new int[] { 84, 96, 102, 108, 113 });
            Y.AddValues(new int[] { 125, 129, 132, 136, 145 });
            Y.AddValues(new int[] { 146, 148, 149, 151 });

            /* - create and compute regression */

            PIGompertzRegression regression = new PIGompertzRegression(X, Y);

            Assert.IsNotNull(regression);

            /* cut partial sums from START */
            regression.SetCutStyleForPartialSum(CutStyleForPartialSum.START);

            regression.Calc();

            Console.WriteLine(regression.GetTextFormula());
            Console.WriteLine(regression.GetTextFormulaFilled());

            Assert.AreEqual((double)188.18, (double)regression.Get_gama(), 0.01);
            Assert.AreEqual((double)0.023, (double)regression.Get_A(), 0.001);
            Assert.AreEqual((double)0.894, (double)regression.Get_B(), 0.001);

            /* - calc prediction for X = 15 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=15 : " + regression.CalcPredictedY(55.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression.GetSSE());
            Console.WriteLine("ME = " + regression.GetME());
            Console.WriteLine("MSE = " + regression.GetMSE());
            Console.WriteLine("MAE = " + regression.GetMAE());
            Console.WriteLine("MAPE = " + regression.GetMAPE());
            Console.WriteLine("MPE = " + regression.GetMPE());

            /* -- 2) PARTLY_AVERAGES method */

            PIDebug.Title("Regression 1-B (PARTLY AVERAGES method)", true);

            regression.SetCalcMethod(CalcMethod.PARTIAL_AVERAGES);
            regression.Calc();

            Console.WriteLine(regression.GetTextFormula());
            Console.WriteLine(regression.GetTextFormulaFilled());

            Assert.AreEqual((double)232.74, (double)regression.Get_gama(), 0.01);
            Assert.AreEqual((double)0.011, (double)regression.Get_A(), 0.001);
            Assert.AreEqual((double)0.91, (double)regression.Get_B(), 0.01);

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression.GetSSE());
            Console.WriteLine("ME = " + regression.GetME());
            Console.WriteLine("MSE = " + regression.GetMSE());
            Console.WriteLine("MAE = " + regression.GetMAE());
            Console.WriteLine("MAPE = " + regression.GetMAPE());
            Console.WriteLine("MPE = " + regression.GetMPE());

            /* -- 3) SELECTED_POINTS method */

            PIDebug.Title("Regression 1-C (SELECTED POINTS method)", true);

            regression.SetCalcMethod(CalcMethod.SELECTED_POINTS);
            regression.Calc();

            //Assert.AreEqual( (double)224.42, (double)regression.get_gama(), 0.01 );
            //Assert.AreEqual( (double)0.021, (double)regression.get_A(), 0.001 );
            //Assert.AreEqual( (double)0.905, (double)regression.get_B(), 0.01 );

            Console.WriteLine(regression.GetTextFormula());
            Console.WriteLine(regression.GetTextFormulaFilled());

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression.GetSSE());
            Console.WriteLine("ME = " + regression.GetME());
            Console.WriteLine("MSE = " + regression.GetMSE());
            Console.WriteLine("MAE = " + regression.GetMAE());
            Console.WriteLine("MAPE = " + regression.GetMAPE());
            Console.WriteLine("MPE = " + regression.GetMPE());

            /*
             *  LINDA example - Source 3j. **
             *
             *  Values for partial sums are cutted from END.
             *
             *  */

            PIDebug.TitleBig("LINDA, source 3j", true);

            /* -- 1) PARTIAL_SUMS method */

            PIDebug.Title("Regression 1-A (PARTIAL SUMS method)");

            /* - prepare X data for regression */

            PIVariable X1 = new PIVariable();

            Assert.IsNotNull(X1);

            X1.AddMoreValuesRange(1, 17);

            /* - prepare Y data for regression */

            PIVariable Y1 = new PIVariable();

            Assert.IsNotNull(Y1);

            Y1.AddValues(new int[] { 28, 66, 105, 236, 348 });
            Y1.AddValues(new int[] { 496, 593, 696, 748, 825 });
            Y1.AddValues(new int[] { 904, 894, 897, 953, 936 });
            Y1.AddValues(new int[] { 1002, 951 });

            /* - create and compute regression */

            PIGompertzRegression regression1 = new PIGompertzRegression(X1, Y1);

            Assert.IsNotNull(regression1);

            /* set cutting from end */
            regression1.SetCutStyleForPartialSum(CutStyleForPartialSum.END);

            regression1.Calc();

            Console.WriteLine(regression1.GetTextFormula());
            Console.WriteLine(regression1.GetTextFormulaFilled());

            //regression.Assert.AreEqual( (double)1.336, (double)regression.get_A(), 0.001 );
            //Assert.AreEqual( (double)0.00097, (double)regression.get_B(), 0.00001 );

            /* - calc prediction for X = 15 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=15 : " + regression1.CalcPredictedY(55.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression1.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression1.GetSSE());
            Console.WriteLine("ME = " + regression1.GetME());
            Console.WriteLine("MSE = " + regression1.GetMSE());
            Console.WriteLine("MAE = " + regression1.GetMAE());
            Console.WriteLine("MAPE = " + regression1.GetMAPE());
            Console.WriteLine("MPE = " + regression1.GetMPE());

            /* -- 2) PARTLY_AVERAGES method */

            PIDebug.Title("Regression 1-B (PARTLY AVERAGES method)", true);

            regression1.SetCalcMethod(CalcMethod.PARTIAL_AVERAGES);
            regression1.Calc();

            Console.WriteLine(regression1.GetTextFormula());
            Console.WriteLine(regression1.GetTextFormulaFilled());

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression1.GetSSE());
            Console.WriteLine("ME = " + regression1.GetME());
            Console.WriteLine("MSE = " + regression1.GetMSE());
            Console.WriteLine("MAE = " + regression1.GetMAE());
            Console.WriteLine("MAPE = " + regression1.GetMAPE());
            Console.WriteLine("MPE = " + regression1.GetMPE());

            /* -- 3) SELECTED_POINTS method */

            PIDebug.Title("Regression 1-C (SELECTED POINTS method)", true);

            regression1.SetCalcMethod(CalcMethod.SELECTED_POINTS);
            regression1.Calc();

            Console.WriteLine(regression1.GetTextFormula());
            Console.WriteLine(regression1.GetTextFormulaFilled());

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(regression1.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("SSE = " + regression1.GetSSE());
            Console.WriteLine("ME = " + regression1.GetME());
            Console.WriteLine("MSE = " + regression1.GetMSE());
            Console.WriteLine("MAE = " + regression1.GetMAE());
            Console.WriteLine("MAPE = " + regression1.GetMAPE());
            Console.WriteLine("MPE = " + regression1.GetMPE());
        }
        public void TestMethod()
        {
            /*
             * CHI-SQUARE distribution.
             */

            PIDebug.TitleBig("Chi-square distribution");

            PICHISquareDistribution distribution = new PICHISquareDistribution();

            /* -- 1) Get probability */

            PIDebug.Title("1) Get probability");

            /* DF=1 */

            PIDebug.Title("..df=1");

            distribution.SetDF(1);

            Console.WriteLine("Probability for x=0.0, df=1 : " + distribution.GetProbability(0.0));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(0.0), 0.1);

            Console.WriteLine("Probability for x=0.001, df=1 : " + distribution.GetProbability(0.001));
            Assert.AreEqual(0.975, (double)distribution.GetProbability(0.001), 0.001);

            Console.WriteLine("Probability for x=2.706, df=1 : " + distribution.GetProbability(2.706));
            Assert.AreEqual(0.100, (double)distribution.GetProbability(2.706), 0.001);

            Console.WriteLine("Probability for x=5.024, df=1 : " + distribution.GetProbability(5.024));
            Assert.AreEqual(0.025, (double)distribution.GetProbability(5.024), 0.001);

            Console.WriteLine("Probability for x=200, df=1 : " + distribution.GetProbability(200));
            Assert.AreEqual(1.0, (double)distribution.GetProbability(200), 0.001);

            /* DF=2 */

            PIDebug.Title("..df=2", true);

            distribution.SetDF(2);

            Console.WriteLine("Probability for x=0.103, df=2 : " + distribution.GetProbability(0.103));
            Assert.AreEqual(0.95, (double)distribution.GetProbability(0.103), 0.001);

            Console.WriteLine("Probability for x=10.597, df=2 : " + distribution.GetProbability(10.597));
            Assert.AreEqual(0.005, (double)distribution.GetProbability(10.597), 0.001);

            /* DF=40 */

            PIDebug.Title("..df=40", true);

            distribution.SetDF(40);

            Console.WriteLine("Probability for x=29.051, df=40 : " + distribution.GetProbability(29.051));
            Assert.AreEqual(0.9, (double)distribution.GetProbability(29.051), 0.001);

            /* -- 2) Get X */

            PIDebug.Title("2) Get X", true);

            /* DF=1 */

            PIDebug.Title("..df=1");

            distribution.SetDF(1);

            Console.WriteLine("X for probability=1.0, df=1 : " + distribution.GetXForProbability(1.0));
            Assert.AreEqual(0.0, (double)distribution.GetXForProbability(1.0), 0.001);

            Console.WriteLine("X for probability=0.975, df=1 : " + distribution.GetXForProbability(0.975));
            Assert.AreEqual(0.001, (double)distribution.GetXForProbability(0.975), 0.001);

            Console.WriteLine("X for probability=0.1, df=1 : " + distribution.GetXForProbability(0.1));
            Assert.AreEqual(2.706, (double)distribution.GetXForProbability(0.1), 0.001);

            Console.WriteLine("X for probability=0.025, df=1 : " + distribution.GetXForProbability(0.025));
            Assert.AreEqual(5.023, (double)distribution.GetXForProbability(0.025), 0.001);

            /* DF=2 */

            PIDebug.Title("..df=2", true);

            distribution.SetDF(2);

            Console.WriteLine("X for probability=0.95, df=2 : " + distribution.GetXForProbability(0.95));
            Assert.AreEqual(0.103, (double)distribution.GetXForProbability(0.95), 0.001);

            Console.WriteLine("X for probability=0.005, df=2 : " + distribution.GetXForProbability(0.005));
            Assert.AreEqual(10.597, (double)distribution.GetXForProbability(0.005), 0.001);

            /* DF=40 */

            PIDebug.Title("..df=40", true);

            distribution.SetDF(40);

            Console.WriteLine("X for probability=0.9, df=40 : " + distribution.GetXForProbability(0.9));
            Assert.AreEqual(29.051, (double)distribution.GetXForProbability(0.9), 0.001);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density, df=1", true);

            distribution.SetDF(1);

            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=0.7 : " + distribution.GetPDF(0.7));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=7.0 : " + distribution.GetPDF(7.0));
        }
        public void TestMethod()
        {
            /* -- source 3b/5 */

            PIDebug.TitleBig("Polynomial regression");

            /* change decimal places count in formulas */
            PIConfiguration.REGRESSION_DECIMAL_PLACES = 6;

            /* - prepare X data for regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddMoreValues(50.0, 3);
            X.AddMoreValues(70.0, 3);
            X.AddMoreValues(80.0, 3);
            X.AddMoreValues(90.0, 3);
            X.AddMoreValues(100.0, 3);

            /* - prepare Y data for regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new Double[] { 3.3, 2.8, 2.9, 2.3, 2.6, 2.1, 2.5, 2.9, 2.4, 3.0, 3.1, 2.8, 3.3, 3.5, 3.0 });

            /* - create and compute regression */

            PIPolynomialRegression polynomialRegression = new PIPolynomialRegression(X, Y, 2);

            Assert.IsNotNull(polynomialRegression);

            /* show degree */
            Console.WriteLine("degree = " + polynomialRegression.Get_degree());
            PIDebug.Blank();

            /* calculate */
            polynomialRegression.Calc();

            /* - show results */

            Console.WriteLine(polynomialRegression.GetTextFormula());
            Console.WriteLine(polynomialRegression.GetTextFormulaFilled());

            PIDebug.Blank();
            Console.WriteLine(polynomialRegression.Get_coefficients().AsString(3));

            Assert.AreEqual((double)7.960, (double)polynomialRegression.Get_coefficients().GetValue(0), 0.001);
            Assert.AreEqual((double)-0.154, (double)polynomialRegression.Get_coefficients().GetValue(1), 0.001);
            Assert.AreEqual((double)0.001, (double)polynomialRegression.Get_coefficients().GetValue(2), 0.001);

            /* - calc prediction for X = 80 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=80 : " + polynomialRegression.CalcPredictedY(80.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(polynomialRegression.GetErrors().AsString(5));
        }
Esempio n. 29
0
        public void TestMethod()
        {
            /* -- source 3a/113 */

            PIDebug.TitleBig("Linear regression");

            /* change decimal places count in formulas */
            PIConfiguration.REGRESSION_DECIMAL_PLACES = 6;

            /* - prepare X data for linear regression */

            PIVariable X = new PIVariable();

            Assert.IsNotNull(X);

            X.AddValues(new Double[] { 0.0, 10.0, 25.0, 33.0, 40.0, 50.0, 60.0, 80.0, 100.00 });

            /* - prepare Y data for linear regression */

            PIVariable Y = new PIVariable();

            Assert.IsNotNull(Y);

            Y.AddValues(new Double[] { 1.3329, 1.3440, 1.3612, 1.3693, 1.3761, 1.3881, 1.3970, 1.4142, 1.4291 });

            /* - create and compute regression */

            PILinearRegression linearRegression = new PILinearRegression(X, Y);

            Assert.IsNotNull(linearRegression);

            linearRegression.Calc();

            Console.WriteLine(linearRegression.GetTextFormula());
            Console.WriteLine(linearRegression.GetTextFormulaFilled());

            Assert.AreEqual((double)1.336, (double)linearRegression.Get_A(), 0.001);
            Assert.AreEqual((double)0.00097, (double)linearRegression.Get_B(), 0.00001);

            /* - calc prediction for X = 55 */

            PIDebug.Blank();

            Console.WriteLine("Prediction for X=55 : " + linearRegression.CalcPredictedY(55.0));

            PIDebug.Blank();
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(linearRegression.GetErrors().AsString(5));

            /* ------------------------------------- */

            /* -- another example, source 2a, 566 */

            PIDebug.TitleBig("Linear regression 1", true);

            /* - prepare X data for linear regression */

            PIVariable X1 = new PIVariable();

            Assert.IsNotNull(X1);

            X1.AddValues(new int[] { 2, 3, 3, 3, 4, 4, 5, 5, 5, 6 });

            /* - prepare Y data for linear regression */

            PIVariable Y1 = new PIVariable();

            Assert.IsNotNull(Y1);

            Y1.AddValues(new double[] { 28.7, 24.8, 26.0, 30.5, 23.8, 24.6, 23.8, 20.4, 21.6, 22.1 });

            /* - create and compute regression */

            PILinearRegression linearRegression1 = new PILinearRegression(X1, Y1);

            Assert.IsNotNull(linearRegression1);

            linearRegression1.Calc();

            Console.WriteLine(linearRegression1.GetTextFormula());
            Console.WriteLine(linearRegression1.GetTextFormulaFilled());

            /* - show predictions + errors */

            PIDebug.Blank();
            Console.WriteLine("Predictions:");
            Console.WriteLine(linearRegression1.GetPredicted().AsString(5));
            Console.WriteLine("Prediction errors:");
            Console.WriteLine(linearRegression1.GetErrors().AsString(5));

            PIDebug.Blank();
            Console.WriteLine("SSE = " + linearRegression1.GetSSE());

            Assert.AreEqual((double)28.946, (double)linearRegression1.GetSSE(), 0.001);


            /* ------------------------------------- */

            /* -- another example, source 3e,4 */

            PIDebug.TitleBig("Linear regression 2", true);

            /* - prepare X data for linear regression */

            PIVariable X2 = new PIVariable();

            Assert.IsNotNull(X2);

            X2.AddValues(new int[] { 4, 4, 7, 7, 8, 9, 10, 10, 10, 11 });
            X2.AddValues(new int[] { 11, 12, 12, 12, 12, 13, 13, 13, 13, 14 });
            X2.AddValues(new int[] { 14, 14, 14, 15, 15, 15, 16, 16, 17, 17 });
            X2.AddValues(new int[] { 17, 18, 18, 18, 18, 19, 19, 19, 20, 20 });
            X2.AddValues(new int[] { 20, 20, 20, 22, 23, 24, 24, 24, 24, 25 });

            /* - prepare Y data for linear regression */

            PIVariable Y2 = new PIVariable();

            Assert.IsNotNull(Y2);

            Y2.AddValues(new int[] { 2, 10, 4, 22, 16, 10, 18, 26, 34, 17 });
            Y2.AddValues(new int[] { 28, 14, 20, 24, 28, 26, 34, 34, 46, 26 });
            Y2.AddValues(new int[] { 36, 60, 80, 20, 26, 54, 32, 40, 32, 40 });
            Y2.AddValues(new int[] { 50, 42, 56, 76, 84, 36, 46, 68, 32, 48 });
            Y2.AddValues(new int[] { 52, 56, 64, 66, 54, 70, 92, 93, 120, 85 });

            /* - create and compute regression */

            PILinearRegression linearRegression2 = new PILinearRegression(X2, Y2);

            Assert.IsNotNull(linearRegression2);

            linearRegression2.Calc();

            Console.WriteLine(linearRegression2.GetTextFormula());
            Console.WriteLine(linearRegression2.GetTextFormulaFilled());

            /* - show predictions + errors */

            PIDebug.Blank();
            Console.WriteLine("Predictions:");
            Console.WriteLine(linearRegression2.GetPredicted().AsString(5));
            PIDebug.Blank();
            Console.WriteLine("Prediction errors (residuals):");
            Console.WriteLine(linearRegression2.GetErrors().AsString(5));

            PIDebug.Blank();

            Console.WriteLine("Residuals min. = " + linearRegression2.GetErrors().GetMin());
            Console.WriteLine("Residuals max. = " + linearRegression2.GetErrors().GetMax());

            Assert.AreEqual((double)-29.069, (double)linearRegression2.GetErrors().GetMin(), 0.001);
            Assert.AreEqual((double)43.201, (double)linearRegression2.GetErrors().GetMax(), 0.001);

            PIDebug.Blank();
            Console.WriteLine("Errors sum = " + linearRegression2.GetErrors().GetSum());
            Console.WriteLine("SSE = " + linearRegression2.GetSSE());

            PIDebug.Blank();
            Console.WriteLine("R2 = " + linearRegression2.GetXYR2());
            Console.WriteLine("R2-adjusted = " + linearRegression2.GetXYR2Adj());

            Assert.AreEqual((double)0.6510, (double)linearRegression2.GetXYR2(), 0.001);
            Assert.AreEqual((double)0.6438, (double)linearRegression2.GetXYR2Adj(), 0.001);
        }
Esempio n. 30
0
        public void TestMethod()
        {
            /* Source 5R4. */

            PIDebug.TitleBig("Erlang distribution (lambda=1, k=1)");

            PIErlangDistribution distribution = new PIErlangDistribution();

            /* -- 1) Get probability */

            PIDebug.Title("1) Get probability for X (CDF)");

            /* lambda=1, k=1 */
            PIDebug.Title("..lambda=1; k=1");

            Console.WriteLine("Probability for x=0.0 : " + distribution.GetCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetProbability(0.0), 0.001);

            Console.WriteLine("Probability for x=0.1111 : " + distribution.GetCDF(0.1111));
            Assert.AreEqual(0.1053, distribution.GetProbability(0.1111), 0.001);

            Console.WriteLine("Probability for x=0.25 : " + distribution.GetCDF(0.25));
            Assert.AreEqual(0.2213, distribution.GetProbability(0.25), 0.001);

            Console.WriteLine("Probability for x=8 : " + distribution.GetCDF(8));
            Assert.AreEqual(0.9998, distribution.GetProbability(8), 0.001);

            /* lambda=1, k=1 */
            PIDebug.Title("..lambda=2; k=3", true);

            distribution.SetLambda(2);
            distribution.SetK(3);

            Console.WriteLine("Probability for x=0.1111 : " + distribution.GetCDF(0.1111));
            Assert.AreEqual(0.0015, distribution.GetProbability(0.1111), 0.001);

            Console.WriteLine("Probability for x=0.25 : " + distribution.GetCDF(0.25));
            Assert.AreEqual(0.0144, distribution.GetProbability(0.25), 0.001);

            Console.WriteLine("Probability for x=8 : " + distribution.GetCDF(8));
            Assert.AreEqual(1.0, distribution.GetProbability(8), 0.001);


            /* -- 2) Get T for probability */

            PIDebug.Title("2) Get X for probability (InverseCDF)", true);

            PIDebug.Title("..lambda=1, k=1");

            distribution.SetLambda(1);
            distribution.SetK(1);

            Console.WriteLine("X value for probability for prob=0.0 : " + distribution.GetInverseCDF(0.0));
            Assert.AreEqual(0.0, distribution.GetInverseCDF(0.0), 0.001);

            Console.WriteLine("X value for probability for prob=0.1053 : " + distribution.GetInverseCDF(0.1053));
            Assert.AreEqual(0.1111, distribution.GetInverseCDF(0.1053), 0.001);

            Console.WriteLine("X value for probability for prob=0.2213 : " + distribution.GetInverseCDF(0.2213));
            Assert.AreEqual(0.25, distribution.GetInverseCDF(0.2213), 0.001);

            PIDebug.Title("..lambda=2; k=3", true);

            distribution.SetLambda(2);
            distribution.SetK(3);

            Console.WriteLine("X value for probability for prob=0.0015 : " + distribution.GetInverseCDF(0.0015));
            Assert.AreEqual(0.1111, distribution.GetInverseCDF(0.0015), 0.01);

            Console.WriteLine("X value for probability for prob=0.0144 : " + distribution.GetInverseCDF(0.0144));
            Assert.AreEqual(0.25, distribution.GetInverseCDF(0.0144), 0.01);

            /* -- 3) Get probability density */

            PIDebug.Title("3) Get probability density (PDF)", true);

            PIDebug.Title("..lambda=1, k=1");

            distribution.SetLambda(1);
            distribution.SetK(1);

            Console.WriteLine("x=0.1 : " + distribution.GetPDF(0.1));
            Console.WriteLine("x=0.5 : " + distribution.GetPDF(0.5));
            Console.WriteLine("x=1.0 : " + distribution.GetPDF(1.0));
            Console.WriteLine("x=2.0 : " + distribution.GetPDF(2.0));
            Console.WriteLine("x=5.0 : " + distribution.GetPDF(5.0));
        }