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);
        }
Esempio n. 2
0
        /// <summary>
        ///   Estimates a new von-Mises distribution from a given set of angles.
        /// </summary>
        ///
        public static VonMisesDistribution Estimate(double[] angles, double[] weights, VonMisesOptions options)
        {
            VonMisesDistribution vonMises = new VonMisesDistribution();

            vonMises.Fit(angles, weights, options);
            return(vonMises);
        }
        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);
        }
        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 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);
        }
        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);
        }
        public void ConstructorTest16()
        {
            var original = new VonMisesDistribution(mean: 0.42, concentration: 1.2);

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

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

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

            testVonMises(vonMises);
        }
 /// <summary>
 ///   Estimates a new von-Mises distribution from a given set of angles.
 /// </summary>
 /// 
 public static VonMisesDistribution Estimate(double[] angles, double[] weights, VonMisesOptions options)
 {
     VonMisesDistribution vonMises = new VonMisesDistribution();
     vonMises.Fit(angles, weights, options);
     return vonMises;
 }