public void fit_example()
        {
            #region doc_fit
            // Let's say we have a UnivariateContinuousDistribution that we have
            // built somehow, either using a constructor for a common distribution
            // or that we have received as the output of a method we have called:
            UnivariateContinuousDistribution dist = new NormalDistribution();

            // Let's say we have a set of observations, and some optional weights:
            double[] observations = { 0.12, 2, 0.52 };

            // Note: the weights are optional. You do not need to have different weights
            // for the different observations you would like to fit, but we will use them
            // as an example to show that it is also possible to specify them if we would
            // like to, but we could also set them to null in case we do not need them:
            double[] weights = { 0.25, 0.25, 0.50 }; // could also be null

            // Now, we can finally fit the distribution to the observations that we have:
            dist.Fit(observations, weights); // changes 'dist' to become the dist we need

            // Now we can verify that the distribution has been updated:
            double mean   = dist.Mean;              // should be 0.79
            double var    = dist.Variance;          // should be 0.82352
            double stdDev = dist.StandardDeviation; // should be 0.90748002732842559
            #endregion

            Assert.AreEqual(0.79, mean);
            Assert.AreEqual(0.82352, var);
            Assert.AreEqual(0.90748002732842559, stdDev);
        }
Exemplo n.º 2
0
        public void FitTest2()
        {
            NormalDistribution target;

            target = new NormalDistribution();
            double[] observations = { 1, 1, 1, 1 };

            bool thrown = false;

            try { target.Fit(observations); }
            catch (ArgumentException) { thrown = true; }

            Assert.IsTrue(thrown);
        }
Exemplo n.º 3
0
        public NormalDistributionInfo GetPeakNormalDistribution(double peak, int index, int numOfPoints)
        {
            NormalDistributionInfo   Info = new NormalDistributionInfo();
            List <double>            ls   = new List <double>();
            Dictionary <double, int> dict = CalculateTimesEachX(index);

            double[] keyArr = dict.Keys.ToArray();
            int      i      = 0;

            for (i = 0; i < keyArr.Length; i++)
            {
                if (keyArr[i] == peak)
                {
                    break;
                }
            }
            for (int j = i - numOfPoints; j < i; j++)
            {
                if (j < 0)
                {
                    j = 0;
                }
                int value = dict[keyArr[j]];
                for (int k = 0; k < value; k++)
                {
                    ls.Add(keyArr[j]);
                }
            }

            for (int j = i; j < i + numOfPoints + 1; j++)
            {
                if (j >= keyArr.Length)
                {
                    break;
                }
                int value = dict[keyArr[j]];
                for (int k = 0; k < value; k++)
                {
                    ls.Add(keyArr[j]);
                }
            }

            NormalDistribution ND = new NormalDistribution();

            ND.Fit(ls.ToArray());
            Info.mean = ND.Mean;
            Info.SD   = ND.StandardDeviation;
            return(Info);
        }
Exemplo n.º 4
0
 public FuncionNormal(double[] eventos) : base(eventos)
 {
     try
     {
         DistribucionContinua = new NormalDistribution();
         DistribucionContinua.Fit(eventos);
         media     = ((NormalDistribution)DistribucionContinua).Mean.ToString("0.0000");
         sigma     = ((NormalDistribution)DistribucionContinua).StandardDeviation.ToString("0.0000");
         Resultado = new ResultadoAjuste(StringFDP, StringInversa, DistribucionContinua.StandardDeviation, DistribucionContinua.Mean, DistribucionContinua.Variance, this);
     }
     catch (Exception)
     {
         Resultado = null;
     }
 }
Exemplo n.º 5
0
        public void FitExtensionTest()
        {
            NormalDistribution target = new NormalDistribution();

            double[] observations = { 0.10, 0.40, 2.00, 2.00 };
            target.Fit(observations);
            NormalDistribution same = observations.Fit <NormalDistribution>();

            Assert.AreNotSame(same, target);
            Assert.AreEqual(same.ToString(), target.ToString());

            NormalDistribution copy = target.FitNew(observations);

            Assert.AreNotSame(copy, target);
            Assert.AreEqual(copy.ToString(), target.ToString());
        }
Exemplo n.º 6
0
        public NormalDistributionInfo GetNormalDistributionFitWithNumOfSamePoints(int index)
        {
            NormalDistributionInfo Info = new NormalDistributionInfo();
            int length = MD.Length;

            double[] arr = new double[length];
            for (int i = 0; i < length; i++)
            {
                arr[i] = MD[i].GetParameters()[index];
            }
            NormalDistribution ND = new NormalDistribution();

            ND.Fit(arr);
            Info.mean = ND.Mean;
            Info.SD   = ND.StandardDeviation;
            return(Info);
        }
Exemplo n.º 7
0
        public void FitTest()
        {
            double expectedMean  = 1.125;
            double expectedSigma = 1.01775897605147;

            NormalDistribution target;

            target = new NormalDistribution();
            double[] observations = { 0.10, 0.40, 2.00, 2.00 };
            double[] weights      = { 0.25, 0.25, 0.25, 0.25 };
            target.Fit(observations, weights);

            Assert.AreEqual(expectedMean, target.Mean);
            Assert.AreEqual(expectedSigma, target.StandardDeviation, 1e-6);


            target = new NormalDistribution();
            double[] observations2 = { 0.10, 0.10, 0.40, 2.00 };
            double[] weights2      = { 0.125, 0.125, 0.25, 0.50 };
            target.Fit(observations2, weights2);

            Assert.AreEqual(expectedMean, target.Mean);
        }
Exemplo n.º 8
0
        public void FitExtensionTest_options()
        {
            NormalDistribution target = new NormalDistribution();

            double[] observations = { 0.10, 0.40, 2.00, 2.00 };
            double[] weights      = { 0.25, 0.25, 0.25, 0.25 };
            target.Fit(observations, weights);
            NormalDistribution same = observations.Fit <NormalDistribution, NormalOptions>(new NormalOptions()
            {
                Regularization = 10
            }, weights);

            Assert.AreNotSame(same, target);
            Assert.AreEqual(same.ToString(), target.ToString());

            NormalDistribution copy = target.FitNew(observations, new NormalOptions()
            {
                Regularization = 10
            }, weights);

            Assert.AreNotSame(copy, target);
            Assert.AreEqual(copy.ToString(), target.ToString());
        }
Exemplo n.º 9
0
        public void FitTest()
        {
            double expectedMean = 1.125;
            double expectedSigma = 1.01775897605147;

            NormalDistribution target;

            target = new NormalDistribution();
            double[] observations = { 0.10, 0.40, 2.00, 2.00 };
            double[] weights = { 0.25, 0.25, 0.25, 0.25 };
            target.Fit(observations, weights);

            Assert.AreEqual(expectedMean, target.Mean);
            Assert.AreEqual(expectedSigma, target.StandardDeviation, 1e-6);


            target = new NormalDistribution();
            double[] observations2 = { 0.10, 0.10, 0.40, 2.00 };
            double[] weights2 = { 0.125, 0.125, 0.25, 0.50 };
            target.Fit(observations2, weights2);

            Assert.AreEqual(expectedMean, target.Mean);
        }
Exemplo n.º 10
0
        public void FitTest2()
        {
            NormalDistribution target;

            target = new NormalDistribution();
            double[] observations = { 1, 1, 1, 1 };

            bool thrown = false;
            try { target.Fit(observations); }
            catch (ArgumentException) { thrown = true; }

            Assert.IsTrue(thrown);
        }