Пример #1
0
        private EstPoint[] EstBootstrap(double gammaFrom, double gammaTo, int steps, bool minus = false)
        {
            EstPoint[] estPoints = new EstPoint[steps];
            GammaBounds(ref gammaFrom, ref gammaTo);
            double step = (gammaTo - gammaFrom) / (steps - 1);
            var    opts = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 4
            };

            Parallel.For(0, steps, opts, g => {
                double gamma        = gammaFrom + g * step;
                var distr           = new Distribution(Alpha, Beta, gamma, BatchSize);
                Bootstrap bootstrap = new Bootstrap(BatchCount * 50, distr);
                int w = 0;
                for (int batch = 0; batch < BatchCount; batch++)
                {
                    double[] array = bootstrap.Next(BatchSize);
                    double delta   = Hill(distr, array) - distr.AlphaRev;
                    if (delta > distr.Bn * distr.Sigma)
                    {
                        w++;
                    }
                }
                double w0    = (double)w / BatchCount;
                double p1    = Math.Abs(DispSimple(w, BatchCount, gamma, 1) - w0);
                double p2    = Math.Abs(DispSimple(w, BatchCount, gamma, -1) - w0);
                estPoints[g] = new EstPoint(w0, Math.Max(p1, p2), gamma);
            });
            return(estPoints);
        }
Пример #2
0
        private EstPoint[] EstBruteforce(double gammaFrom, double gammaTo, int steps, bool minus = false)
        {
            EstPoint[] estPoints = new EstPoint[steps];
            GammaBounds(ref gammaFrom, ref gammaTo);
            double step = (gammaTo - gammaFrom) / (steps - 1);
            var    opts = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 4
            };

            Parallel.For(0, steps, opts, g => {
                double gamma = gammaFrom + g * step;
                var distr    = MakeDistr(gamma);
                var rnd2     = new ExponentialDistribution(distr.Alpha);
                int w        = 0;
                for (int batch = 0; batch < BatchCount; batch++)
                {
                    double[] array = rnd2.Generate(BatchSize);
                    double delta   = Hill(distr, array) - distr.AlphaRev;
                    if (!minus && delta > distr.Bn || minus && delta < -distr.Bn)
                    {
                        w++;
                    }
                }
                double w0    = (double)w / BatchCount;
                double p0    = 1;             //NormalDistribution.Standard.InverseDistributionFunction(gamma);
                double d     = p0 * Math.Sqrt(w0 * (1 - w0) / BatchCount);
                estPoints[g] = new EstPoint(w0, d, gamma);
            });
            return(estPoints);
        }
Пример #3
0
        private EstPoint[] Est(double gammaFrom, double gammaTo, int steps, bool minus = false)
        {
            EstPoint[] estPoints = new EstPoint[steps];
            GammaBounds(ref gammaFrom, ref gammaTo);
            double step = (gammaTo - gammaFrom) / (steps - 1);
            var    opts = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 4
            };
            double brev = 1.0 / BatchCount;

            Parallel.For(0, steps, opts, g =>
            {
                double gamma = gammaFrom + g * step;
                var distr    = new Distribution(Alpha, Beta, gamma, BatchSize);
                double w     = 0, d = 0;
                for (int batch = 0; batch < BatchCount; batch++)
                {
                    double[] array = minus ? Rnd2(distr, BatchSize) : Rnd(distr, BatchSize);
                    double delta   = Hill(distr, array) - distr.AlphaRev;
                    if ((!minus && delta > distr.Bn) || (minus && delta < -distr.Bn))
                    {
                        int sign  = minus ? -1 : 1;
                        double wp = 1;
                        for (int k = 0; k < BatchSize; k++)
                        {
                            wp *= 1 / (1 + sign * distr.Bn * distr.h(array[k]));
                        }
                        double l = wp * brev;
                        w       += l;
                        d       += wp * l;
                    }
                }
                double p0    = 1;             //NormalDistribution.Standard.InverseDistributionFunction(gamma);
                double sig   = p0 * Math.Sqrt((d - w * w) / BatchCount);
                estPoints[g] = new EstPoint(w, sig, gamma);
            });
            return(estPoints);
        }