示例#1
0
        public void ConstructorTest()
        {
            var vonMises = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            double mean   = vonMises.Mean;                                    // 0.42
            double median = vonMises.Median;                                  // 0.42
            double var    = vonMises.Variance;                                // 0.48721760532782921

            double cdf  = vonMises.DistributionFunction(x: 1.4);              // 0.81326928491589345
            double pdf  = vonMises.ProbabilityDensityFunction(x: 1.4);        // 0.2228112141141676
            double lpdf = vonMises.LogProbabilityDensityFunction(x: 1.4);     // -1.5014304395467863

            double ccdf = vonMises.ComplementaryDistributionFunction(x: 1.4); // 0.18673071508410655
            double icdf = vonMises.InverseDistributionFunction(p: cdf);       // 1.3999999637927665

            double hf  = vonMises.HazardFunction(x: 1.4);                     // 1.1932220899695576
            double chf = vonMises.CumulativeHazardFunction(x: 1.4);           // 1.6780877262500649

            string str = vonMises.ToString(CultureInfo.InvariantCulture);     // VonMises(x; μ = 0.42, κ = 1.2)

            double imedian = vonMises.InverseDistributionFunction(p: 0.5);

            Assert.AreEqual(0.42, mean);
            Assert.AreEqual(0.42, median);
            Assert.AreEqual(0.42000000260613551, imedian, 1e-8);
            Assert.AreEqual(0.48721760532782921, var);
            Assert.AreEqual(1.6780877262500649, chf);
            Assert.AreEqual(0.81326928491589345, cdf);
            Assert.AreEqual(0.2228112141141676, pdf);
            Assert.AreEqual(-1.5014304395467863, lpdf);
            Assert.AreEqual(1.1932220899695576, hf);
            Assert.AreEqual(0.18673071508410655, ccdf);
            Assert.AreEqual(1.39999999999, icdf, 1e-8);
            Assert.AreEqual("VonMises(x; μ = 0.42, κ = 1.2)", str);
        }
        public void ProbabilityDensityFunctionTest()
        {
            VonMisesDistribution dist = new VonMisesDistribution(2.249981, 2.411822);

            double actual   = dist.ProbabilityDensityFunction(2.14);
            double expected = 0.5686769438969197;

            Assert.AreEqual(expected, actual, 1e-10);
        }
示例#3
0
        public void ConstructorTest16()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            var vonMises = GeneralContinuousDistribution.FromDensityFunction(
                original.Support, original.ProbabilityDensityFunction);

            testVonMises(vonMises, 100);
        }
示例#4
0
        public void ConstructorTest17()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            var vonMises = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            testVonMises(vonMises);
        }
        public void LogProbabilityDensityFunctionTest()
        {
            VonMisesDistribution dist = new VonMisesDistribution(2.249981, 2.411822);
            double x = 2.14;

            double actual   = dist.LogProbabilityDensityFunction(x);
            double expected = System.Math.Log(dist.ProbabilityDensityFunction(x));

            Assert.AreEqual(expected, actual, 1e-10);
        }
        public void ConstructorTest()
        {
            var vonMises = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            double mean   = vonMises.Mean;                                    // 0.42
            double median = vonMises.Median;                                  // 0.42
            double var    = vonMises.Variance;                                // 0.48721760532782921
            double mode   = vonMises.Mode;                                    // 0.42

            double cdf  = vonMises.DistributionFunction(x: 1.4);              // 0.81326928491589345
            double pdf  = vonMises.ProbabilityDensityFunction(x: 1.4);        // 0.2228112141141676
            double lpdf = vonMises.LogProbabilityDensityFunction(x: 1.4);     // -1.5014304395467863

            double ccdf = vonMises.ComplementaryDistributionFunction(x: 1.4); // 0.18673071508410655
            double icdf = vonMises.InverseDistributionFunction(p: cdf);       // 1.3999999637927665

            double hf  = vonMises.HazardFunction(x: 1.4);                     // 1.1932220899695576
            double chf = vonMises.CumulativeHazardFunction(x: 1.4);           // 1.6780877262500649

            string str = vonMises.ToString(CultureInfo.InvariantCulture);     // VonMises(x; μ = 0.42, κ = 1.2)

            double imedian = vonMises.InverseDistributionFunction(p: 0.5);

            Assert.AreEqual(0.42, mean);
            Assert.AreEqual(0.42, median);
            Assert.AreEqual(0.42, mode);
            Assert.AreEqual(0.42000000260613551, imedian, 1e-8);
            Assert.AreEqual(0.48721760532782921, var);
            Assert.AreEqual(1.6780877262500649, chf);
            Assert.AreEqual(0.81326928491589345, cdf);
            Assert.AreEqual(0.2228112141141676, pdf);
            Assert.AreEqual(-1.5014304395467863, lpdf);
            Assert.AreEqual(1.1932220899695576, hf);
            Assert.AreEqual(0.18673071508410655, ccdf);
            Assert.AreEqual(1.39999999999, icdf, 1e-8);
            Assert.AreEqual("VonMises(x; μ = 0.42, κ = 1.2)", str);

            var range1 = vonMises.GetRange(0.95);
            var range2 = vonMises.GetRange(0.99);
            var range3 = vonMises.GetRange(0.01);

            Assert.AreEqual(-1.5990672124935188, range1.Min, 1e-14);
            Assert.AreEqual(2.4390672124935207, range1.Max, 1e-14);
            Assert.AreEqual(-2.4355782410688764, range2.Min, 1e-14);
            Assert.AreEqual(3.2755782410688861, range2.Max, 1e-14);
            Assert.AreEqual(-2.4355782410688764, range3.Min, 1e-14);
            Assert.AreEqual(3.2755782410688861, range3.Max, 1e-14);

            Assert.AreEqual(-2.7215926535897932, vonMises.Support.Min, 1e-10);
            Assert.AreEqual(3.561592653589793, vonMises.Support.Max, 1e-10);

            Assert.AreEqual(vonMises.InverseDistributionFunction(0), vonMises.Support.Min);
            Assert.AreEqual(vonMises.InverseDistributionFunction(1), vonMises.Support.Max);
        }
示例#7
0
        public void generate_test()
        {
            double kappa  = 35;
            var    vm     = new VonMisesDistribution(0, kappa);
            var    target = new VonMisesFisherDistribution(new double[] { -1, 0, 0 }, kappa);

            double[][] actual = target.Generate(100);

            var sphere = new UniformSphereDistribution(3);

            for (int i = 0; i < actual.Length; i++)
            {
                double p = sphere.ProbabilityDensityFunction(actual[i]);
                Assert.AreEqual(0.025330295910584444, p, 1e-8);
            }
        }
        public void FitTest()
        {
            double[] angles =
            {
                2.537498, 0.780449, 3.246623, 1.835845, 1.525273,
                2.821987, 1.783134, 1.165753, 3.298262, 2.941366,
                2.485515, 2.090029, 2.460631, 2.804243, 1.626327,
            };


            var distribution = VonMisesDistribution.Estimate(angles);

            Assert.AreEqual(2.411822, distribution.Concentration, 1e-6);
            Assert.AreEqual(2.249981, distribution.Mean, 1e-6);

            Assert.AreEqual(0.2441525, distribution.Variance, 1e-3);
        }
示例#9
0
        public void ConstructorTest17()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

            var vonMises = GeneralContinuousDistribution.FromDistributionFunction(
                original.Support, original.DistributionFunction);

            for (double i = -10; i < +10; i += 0.1)
            {
                double expected = original.ProbabilityDensityFunction(i);
                double actual   = vonMises.ProbabilityDensityFunction(i);

                Assert.IsTrue(expected.IsRelativelyEqual(actual, 1e-4));
            }

            testVonMises(vonMises, 1);
        }
示例#10
0
        public void ConstructorTest1()
        {
            // If p=2 the distribution reduces to the von Mises distribution on the circle.

            double kappa  = 4.2;
            var    vm     = new VonMisesDistribution(0, kappa);
            var    target = new VonMisesFisherDistribution(new double[] { -1, 0 }, kappa);

            double s = Math.Sqrt(2) / 2;

            double[] mean = target.Mean;

            double a000 = target.ProbabilityDensityFunction(new double[] { +1, +0 });
            double a045 = target.ProbabilityDensityFunction(new double[] { +s, +s });
            double a090 = target.ProbabilityDensityFunction(new double[] { +0, +1 });
            double a135 = target.ProbabilityDensityFunction(new double[] { -s, +s });
            double a180 = target.ProbabilityDensityFunction(new double[] { -1, +0 });
            double a225 = target.ProbabilityDensityFunction(new double[] { -s, -s });
            double a270 = target.ProbabilityDensityFunction(new double[] { +0, -1 });
            double a315 = target.ProbabilityDensityFunction(new double[] { +s, -s });
            double a360 = target.ProbabilityDensityFunction(new double[] { +1, +0 });

            double offset = -Math.PI;
            double e000   = vm.ProbabilityDensityFunction(offset + 0);
            double e045   = vm.ProbabilityDensityFunction(offset + Math.PI / 4);
            double e090   = vm.ProbabilityDensityFunction(offset + Math.PI / 2);
            double e135   = vm.ProbabilityDensityFunction(offset + Math.PI * (3 / 4.0));
            double e180   = vm.ProbabilityDensityFunction(offset + Math.PI);
            double e225   = vm.ProbabilityDensityFunction(offset + Math.PI * (5 / 4.0));
            double e270   = vm.ProbabilityDensityFunction(offset + Math.PI * (3 / 2.0));
            double e315   = vm.ProbabilityDensityFunction(offset + Math.PI * (7 / 4.0));
            double e360   = vm.ProbabilityDensityFunction(offset + Math.PI * 2);


            Assert.AreEqual(e000, a000, 1e-8);
            Assert.AreEqual(e045, a045, 1e-8);
            Assert.AreEqual(e090, a090, 1e-8);
            Assert.AreEqual(e135, a135, 1e-8);
            Assert.AreEqual(e180, a180, 1e-8);
            Assert.AreEqual(e225, a225, 1e-8);
            Assert.AreEqual(e270, a270, 1e-8);
            Assert.AreEqual(e315, a315, 1e-8);
            Assert.AreEqual(e360, a360, 1e-8);
        }
        public void MedianTest()
        {
            VonMisesDistribution target = new VonMisesDistribution(1.621, 4.52);

            Assert.AreEqual(target.Median, target.InverseDistributionFunction(0.5), 1e-6);
        }