Esempio n. 1
0
        public void FitTest6()
        {
            UnivariateDiscreteDistribution target = CreateUnivariateDiscreteDistribution();

            double[] observations = { 0, 1, 1, 1, 1 };
            target.Fit(observations);

            double mean = Accord.Statistics.Tools.Mean(observations);

            Assert.AreEqual(mean, target.Mean);
        }
Esempio n. 2
0
        public void FitTest7()
        {
            UnivariateDiscreteDistribution target = CreateUnivariateDiscreteDistribution();

            double[] observations = { 0, 1, 1, 1, 1 };
            double[] weights      = { 0.125, 0.125, 0.25, 0.25, 0.25 };
            target.Fit(observations, weights);

            double mean = Accord.Statistics.Tools.WeightedMean(observations, weights);

            Assert.AreEqual(mean, target.Mean);
        }
        public void FitTest4()
        {
            UnivariateDiscreteDistribution target = CreateUnivariateDiscreteDistribution();

            double[]        observations = { 0, 1, 1, 1, 1 };
            IFittingOptions options      = null;

            target.Fit(observations, options);

            double mean = Measures.Mean(observations);

            Assert.AreEqual(mean, target.Mean);
        }
Esempio n. 4
0
        public void ProbabilityMassFunctionTest()
        {
            UnivariateDiscreteDistribution target = CreateUnivariateDiscreteDistribution();

            double p = 0.42;
            double q = 1 - p;

            Assert.AreEqual(q, target.ProbabilityMassFunction(0));
            Assert.AreEqual(p, target.ProbabilityMassFunction(1));

            double[] observations = { 0, 1, 0, 0, 1, 0 };

            target.Fit(observations);

            p = target.Mean;
            q = 1 - p;

            Assert.AreEqual(q, target.ProbabilityMassFunction(0));
            Assert.AreEqual(p, target.ProbabilityMassFunction(1));
        }
Esempio n. 5
0
        public void EntropyTest()
        {
            UnivariateDiscreteDistribution target = CreateUnivariateDiscreteDistribution();

            double q = 0.42;
            double p = 1 - q;

            double actual   = target.Entropy;
            double expected = -q *System.Math.Log(q) - p * System.Math.Log(p);

            Assert.AreEqual(expected, actual);


            target.Fit(new double[] { 0, 1, 0, 0, 1, 0 });

            q = target.Mean;
            p = 1 - q;

            actual   = target.Entropy;
            expected = -q *System.Math.Log(q) - p * System.Math.Log(p);

            Assert.AreEqual(expected, actual);
        }