Example #1
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);
        }
Example #2
0
        static void Main(string[] args)
        {
            const int maxItemsInQueue = 6;

            int ia = 30, ib = 10;

            var s = new Schema(maxItemsInQueue, 2);

            const int totalWorkingTime = 10000;

            var fr  = new ExponentialDistribution(7, 5, 3, uint.MaxValue, totalWorkingTime, ia);
            var frl = fr.Generate();

            var dr  = new ExponentialDistribution(7, 5, 3, uint.MaxValue, totalWorkingTime, ib);
            var drl = dr.Generate();

            int sumOch       = 0;
            int wokingWorker = 0;

            for (int i = 0; i < totalWorkingTime; i++)
            {
                if (!s.HasGeneratedItem(i))
                {
                    s.GenerateItem(i + (int)(frl.Skip(r.Next(totalWorkingTime)).First() * ia));
                }

                if (s.IsGenerated(i))
                {
                    s.AddToQueue();
                }

                for (int j = 0; j < s.CountInQueue; j++)
                {
                    if (!s.AllChanelsInWorkingState(i))
                    {
                        var endTime = i + (int)(drl.Skip(r.Next(totalWorkingTime)).First() * ib);

                        if (endTime < totalWorkingTime)
                        {
                            s.AddToWork(i, endTime);
                            s.RemoveFromQueue();
                        }
                    }
                }

                wokingWorker += s.CountWorkingWorkers(i);

                sumOch += s.CountInQueue;
            }

            Console.WriteLine("Абсолютная пропускная способность = " + 1 / (double)ia * (1 - s.CountDroped / (double)totalWorkingTime));
            Console.WriteLine("Среднее число занятых рабочих = " + wokingWorker / (double)totalWorkingTime);
            Console.WriteLine("Среднее число неисправных станков = " + sumOch / (double)totalWorkingTime);
            Console.ReadKey();
        }
        public void GenerateTest()
        {
            ExponentialDistribution target = new ExponentialDistribution(2.5);

            double[] samples = target.Generate(1000000);

            var actual = ExponentialDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(2.5, actual.Rate, 0.01);
        }
        public void GenerateTest2()
        {
            ExponentialDistribution target = new ExponentialDistribution(2.5);

            double[] samples = new double[1000000];
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = target.Generate();
            }

            var actual = ExponentialDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(2.5, actual.Rate, 0.01);
        }
Example #5
0
        private void radButton3_Click(object sender, EventArgs e)
        {
            // чистим данные
            Id.Clear();
            X.Clear();

            // чистим графики
            scatterplotView1.Graph.GraphPane.CurveList.Clear();
            radChartView1.Series[0].DataPoints.Clear();
            radChartView2.Series[0].DataPoints.Clear();

            // параметиры для генерации выборки
            int    N    = this.labeledIntValue3.Value;
            double rate = this.labeledDoubleValye3.Value;

            // генерируем индекс (можно быстрее, но так нагляднее)
            for (int i = 0; i < N; i++)
            {
                Id.Add(i);
            }

            // генератор
            ExponentialDistribution exp = new ExponentialDistribution(rate);

            // создание выборки объемом N
            X.AddRange(exp.Generate(N));

            // визуализация - скаттерплот
            scatterplotView1.DataSource = X.ToArray();

            // визуализация - гистограмма
            Histogram histogram = new Histogram();

            histogram.Compute(X.ToArray());
            histogramView1.DataSource = histogram;

            for (int i = 0; i < N; i++)
            {
                radChartView1.Series[0].DataPoints.Add(new ScatterDataPoint(Id[i], X[i]));
            }

            foreach (HistogramBin bin in histogram.Bins)
            {
                string b = $"{bin.Range.Min}-{bin.Range.Max}";
                radChartView2.Series[0].DataPoints.Add(new CategoricalDataPoint(bin.Value, b));
            }
        }
        public void GenerateTest2()
        {
            ExponentialDistribution target = new ExponentialDistribution(2.5);

            double[] samples = new double[1000000];
            for (int i = 0; i < samples.Length; i++)
                samples[i] = target.Generate();

            var actual = ExponentialDistribution.Estimate(samples);
            actual.Fit(samples);

            Assert.AreEqual(2.5, actual.Rate, 0.01);
        }
        public void GenerateTest()
        {
            ExponentialDistribution target = new ExponentialDistribution(2.5);

            double[] samples = target.Generate(1000000);

            var actual = ExponentialDistribution.Estimate(samples);
            actual.Fit(samples);

            Assert.AreEqual(2.5, actual.Rate, 0.01);
        }
Example #8
0
 public double Generate()
 {
     return(_expDis.Generate(_n).Sum());
 }