Example #1
0
            public override double[] GenerateSequence(int n = N)
            {
                var norm = new NormalDG().GenerateSequence();

                double[] res = new double[n].Select((x, i) => U * Math.Exp(U * (Math.Log(U) + Math.Sqrt(S) * norm[i]))).ToArray();

                return(res);
            }
Example #2
0
        static void Main(string[] args)
        {
            var NormalDG      = new NormalDG();
            var ExponentialDG = new ExponentialDG();
            var LogisticDG    = new LogisticDG();
            var CauchyDG      = new CauchyDG();
            var StudentsDG    = new StudentsDG();

            string Format(double val)
            {
                return(string.Format("{0:0.###}", val));
            }

            double[] PrintDGMainInfo(DistributionGenerator dg, string dg_name)
            {
                var arr = dg.GenerateSequence();

                if (dg.GetType() != typeof(CauchyDG))
                {
                    DistributionGenerator.GetRealExpectedValueAndDispersion(arr, out double expval, out double disp);

                    Console.WriteLine($"[{dg_name}]         \n" +
                                      $"Expected value: {Format(dg.ExpectedValue)}     Real: {Format(expval)}\n" +
                                      $"Dispersion:     {Format(dg.Dispersion)}     Real: {Format(disp)}\n\n");
                }
                else
                {
                    CauchyDG cauchyDG = (CauchyDG)dg;

                    Console.WriteLine($"[{dg_name}]         \n" +
                                      $"Selective median: {Format(CauchyDG.SMV)}   Real: {Format(cauchyDG.CalculateSMV(arr))}\n\n");
                }

                return(arr);
            }

            Console.WriteLine("[==================[Main task]==================]");
            PrintDGMainInfo(NormalDG, "NormalDG");
            PrintDGMainInfo(ExponentialDG, "ExponentialDG");
            PrintDGMainInfo(LogisticDG, "LogisticDG");
            PrintDGMainInfo(CauchyDG, "CauchyDG");
            PrintDGMainInfo(StudentsDG, "StudentsDG");

            var MixedExponentialLogisticDG = new MixedExponentialLogisticDG();
            var BoxMullerDG            = new BoxMullerDG();
            var TruncatedExponentialDG = new TruncatedExponentialDG(1.9, 2.1);

            BoxMullerDG.GenerateSequence(out double corr);

            Console.WriteLine("[==================[Additional tasks]==================]");

            PrintDGMainInfo(MixedExponentialLogisticDG, "MixedExponentialLogisticDG");
            PrintDGMainInfo(TruncatedExponentialDG, "TruncatedExponentialDistribution(a = 1.9, b = 2.1)");

            Console.WriteLine($"[BoxMullerDistribution]    \nEven/odd correlation: {Format(corr)}");

            Console.Read();
        }
Example #3
0
            public override double[] GenerateSequence(int n = N)
            {
                double[] norm = new NormalDG().GenerateSequence();
                double[] res  = new double[n]
                                .Select(_ => norm[Random.Next(0, n)] * Math.Sqrt(Enumerable.Repeat(0, M)
                                                                                 .Select(y => Math.Pow(norm[Random.Next(0, n)], 2)).Sum() / M))
                                .ToArray();

                return(res);
            }