Esempio n. 1
0
        public void MomentMathConsistency()
        {
            // We can't be too demanding here, since there can be strong cancelations.
            // We take a low number of simple integer cumulants and try to verify consistency.

            double[] K0 = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
            double   mu = K0[1];

            double[] C1fromK0 = MomentMath.CumulantToCentral(K0);
            Assert.IsTrue(C1fromK0[0] == 1.0);
            Assert.IsTrue(C1fromK0[1] == 0.0);
            Assert.IsTrue(C1fromK0[2] == K0[2]);

            double[] M1fromK0 = MomentMath.CumulantToRaw(K0);
            Assert.IsTrue(M1fromK0[0] == 1.0);
            Assert.IsTrue(M1fromK0[1] == K0[1]);

            double[] K2fromC1 = MomentMath.CentralToCumulant(mu, C1fromK0);
            Assert.IsTrue(TestUtilities.IsNearlyEqual(K2fromC1, K0));

            double[] M2fromC1 = MomentMath.CentralToRaw(mu, C1fromK0);
            Assert.IsTrue(TestUtilities.IsNearlyEqual(M2fromC1, M1fromK0));

            double[] K2fromM1 = MomentMath.RawToCumulant(M1fromK0);
            Assert.IsTrue(TestUtilities.IsNearlyEqual(K2fromM1, K0));

            double[] C2fromM1 = MomentMath.RawToCentral(M1fromK0);
            Assert.IsTrue(TestUtilities.IsNearlyEqual(C2fromM1, C1fromK0));
        }
Esempio n. 2
0
        public void MomentMathOrderOne()
        {
            double mu = 2.0;

            double[] M = new double[] { 1.0, mu };
            double[] C = MomentMath.RawToCentral(M);
            Assert.IsTrue(C[0] == 1.0);
            Assert.IsTrue(C[1] == 0.0);
            double[] K = MomentMath.RawToCumulant(M);
            Assert.IsTrue(K[1] == mu);

            M = MomentMath.CentralToRaw(mu, C);
            Assert.IsTrue(M[0] == 1.0);
            Assert.IsTrue(M[1] == mu);
            K = MomentMath.CentralToCumulant(mu, C);
            Assert.IsTrue(K[1] == mu);

            M = MomentMath.CumulantToRaw(K);
            Assert.IsTrue(M[0] == 1.0);
            Assert.IsTrue(M[1] == mu);
            C = MomentMath.CumulantToCentral(K);
            Assert.IsTrue(C[0] == 1.0);
            Assert.IsTrue(C[1] == 0.0);
        }
Esempio n. 3
0
        public void CumulantToCentralAndRaw()
        {
            int n = 8;

            foreach (UnivariateDistribution d in Distributions)
            {
                Console.WriteLine(d.GetType().Name);

                // Problems with NaN/Infinity
                if (d is CauchyDistribution)
                {
                    continue;
                }
                if (d is StudentDistribution)
                {
                    continue;
                }
                if (d is FisherDistribution)
                {
                    continue;
                }
                if (d is ParetoDistribution)
                {
                    continue;
                }

                // Real problems
                if (d is KolmogorovDistribution)
                {
                    continue;
                }
                if (d is KuiperDistribution)
                {
                    continue;
                }

                // From cumulants to central and raw moments

                double[] inK = new double[n];
                for (int r = 0; r < n; r++)
                {
                    inK[r] = d.Cumulant(r);
                }

                double[] outC = MomentMath.CumulantToCentral(inK);
                for (int r = 0; r < n; r++)
                {
                    Console.WriteLine("r={0} K={1} -> C={2} v C={3}", r, inK[r], outC[r], d.CentralMoment(r));
                }
                for (int r = 0; r < n; r++)
                {
                    Assert.IsTrue(TestUtilities.IsNearlyEqual(outC[r], d.CentralMoment(r)));
                }

                double[] outM = MomentMath.CumulantToRaw(inK);
                for (int r = 0; r < n; r++)
                {
                    Console.WriteLine("r={0} K={1} -> M={2} v M={3}", r, inK[r], outM[r], d.RawMoment(r));
                }
                for (int r = 0; r < n; r++)
                {
                    Assert.IsTrue(TestUtilities.IsNearlyEqual(outM[r], d.RawMoment(r)));
                }
            }
        }