Exemplo n.º 1
0
        public void MergeIntensities(double alpha)
        {
            for (int i = 0; i < intensities.Length - 1; i++)
            {
                double v = intensities[i + 1] - intensities[i];
                v /= Math.Sqrt((masY[i] - 1) * intensities[i + 1] * intensities[i + 1] +
                               (masY[i + 1] - 1) * intensities[i] * intensities[i]);

                double nu = masY[i] + masY[i + 1] - 2;

                v *= Math.Sqrt((masY[i] * masY[i + 1] * nu) / (masY[i] + masY[i + 1]));

                if (Math.Abs(v) > Kvantili.Student(alpha, nu))
                {
                    continue;
                }

                //merging  block

                double tau1 = masX[i + 1] - masX[i];
                double tau2 = 0;

                if (i + 2 <= intensities.Length - 1)
                {
                    tau2 = masX[i + 2] - masX[i + 1];
                }
                else
                {
                    tau2 = Max - masX[i + 1];
                }

                double lyambdaMerged = (masY[i] + masY[i + 1]) / ((d.Length - masY.Take(i + 2).Sum()) * (tau1 + tau2));

                if (double.IsPositiveInfinity(lyambdaMerged))
                {
                    //lyambdaMerged = 0;
                    lyambdaMerged = intensities[i + 1] * 1.3;
                }

                masY[i] += masY[i + 1];
                masY     = masY.Where((el, index) => index != i + 1).ToArray(); //remove i+1 element

                intensities[i] = lyambdaMerged;
                intensities    = intensities.Where((el, index) => index != i + 1).ToArray();

                masX = masX.Where((el, index) => index != i + 1).ToArray();

                i--;
            }
        }
        public static string KZPirsona(STAT stat, double alpha = 0.05)
        {
            double min = 0;
            double max = 0;
            double sum = 0;

            for (int i = 0; i < stat.M; i++)
            {
                min = stat.Min + stat.h * i;
                max = min + stat.h;

                double n0 = stat._ReproductDistribution.F(max) - stat._ReproductDistribution.F(min);

                n0 *= stat.d.Length;
                double ni = stat.masY[i];

                sum += Math.Pow((ni - n0), 2) / n0;
            }

            string result = "";
            double kv     = Kvantili.Hi2(alpha, stat.M - 1);

            Action <string>       add2log = v => result += v + Environment.NewLine;
            Func <double, double> r       = v => Math.Round(v);

            add2log("");
            add2log("Критерій Пірсона:");
            add2log("kv = " + r(kv));
            add2log("sum = " + r(sum));
            if (sum < kv)
            {
                add2log("sum < kv");
                add2log("Пройдено");
            }
            else
            {
                add2log("sum >= kv");
                add2log("Не пройдено");
            }

            return(result);
        }