Example #1
0
        /*
        * minValue: es el minimo de personas que llegan al andén
        * maxValue: es el máximo de personas que llegan al andén
        * personasPorMinuto: cantida de personas que llegan por minuto
        * cantidadEnHoras: tiempo en horas de la muestra de personas
        */
        public static int Poisson(int minValue, int maxValue, int personasPorMinuto, int cantidadEnHoras)
        {
            double r1, r2, m, y, fx;
            int k, lambda, x;

            if ((personasPorMinuto <= 0) || (cantidadEnHoras <= 0))
            {
                throw new System.ArgumentException("Valores incorrectos");
            }

            k = personasPorMinuto;

            lambda = cantidadEnHoras;

            PoissonDistribution f = new PoissonDistribution(lambda);

            m = Math.Pow(k, k) / (Math.Exp(k) * AdvancedIntegerMath.Factorial(k));

            do
            {
                r1 = Rand();

                r2 = Rand();

                x = Convert.ToInt32(minValue + (maxValue - minValue) * r1);

                y = m * r2;

                fx = f.ProbabilityMass(Convert.ToInt32(k * r1));

            } while (y < fx);

            return x;
        }
Example #2
0
        public void ChiSquareDistribution()
        {
            int B = 8;
            Random rng = new Random(0);
            //BinomialDistribution d = new BinomialDistribution(0.25, 6);
            //DiscreteUniformDistribution d = new DiscreteUniformDistribution(0, 4);
            //BernoulliDistribution d = new BernoulliDistribution(0.25);
            DiscreteDistribution d = new PoissonDistribution(2.0);

            Sample s = new Sample();
            ChiSquaredDistribution nullDistribution = null;
            for (int i = 0; i < 512; i++) {

                Histogram h = new Histogram(B);
                for (int j = 0; j < 1024; j++) {
                    int k = d.GetRandomValue(rng);
                    h.Add(k);
                    //if (k < h.Count) h[k].Increment();
                    //h[d.GetRandomValue(rng)].Increment();
                }
                TestResult cr = h.ChiSquaredTest(d);
                nullDistribution = (ChiSquaredDistribution) cr.Distribution;
                //Console.WriteLine(((ChiSquaredDistribution) cr.Distribution).DegreesOfFreedom);
                s.Add(cr.Statistic);

            }

            Console.WriteLine(nullDistribution.DegreesOfFreedom);
            TestResult kr = s.KuiperTest(nullDistribution);
            Console.WriteLine(kr.LeftProbability);
        }
 public void PoissonBug()
 {
     PoissonDistribution pd = new PoissonDistribution(0.5);
     double x = pd.InverseLeftProbability(0.7716);
     Console.WriteLine(x);
 }