예제 #1
0
        public void GetRandom(out double[] rdIR, out double[] rdEQ)
        {
            var normalD = new MathNet.Numerics.Distributions.Normal();

            rdIR = new double[EndMth];
            rdEQ = new double[EndMth];

            for (int i = 0; i < EndMth; i++)
            {
                rdIR[i] = normalD.InverseCumulativeDistribution(RD.NextDouble());
                rdEQ[i] = normalD.InverseCumulativeDistribution(RD.NextDouble());
            }
        }
예제 #2
0
 private void BtnPromedios_Click(object sender, EventArgs e)
 {
     try
     {
         double acumulador = 0;
         double promedio = 0, Alfa = 100, Z, LimI, LimS;
         Alfa                 = (Alfa - Convert.ToDouble(txtConfianza.Text)) / 100;
         txtAlfa.Text         = Alfa.ToString();
         Z                    = 1 - (Alfa / 2);
         txtZ.Text            = Z.ToString();
         Distribucion         = Math.Round(Math.Abs(dnormal.InverseCumulativeDistribution(Z)), 2);
         txtDistribucion.Text = Distribucion.ToString();
         LimI                 = 0.5 - (Distribucion * (1 / Math.Sqrt(12 * Convert.ToDouble(txtCantidad.Text))));
         LimS                 = 0.5 + (Distribucion * (1 / Math.Sqrt(12 * Convert.ToDouble(txtCantidad.Text))));
         txtLI.Text           = LimI.ToString();
         txtLS.Text           = LimS.ToString();
         foreach (DataGridViewRow i in dgvPseudoaleatorio.Rows)
         {
             acumulador += Convert.ToDouble(i.Cells["Crn"].Value);
         }
         promedio         = acumulador / dgvPseudoaleatorio.RowCount;
         txtPromedio.Text = promedio.ToString();
         if (promedio >= LimI && promedio <= LimS)
         {
             lblr.Text = "Los números estan\n distribuidos uniformemente";
         }
         else
         {
             lblr.Text = "Los números no están\n distribuidos uniformemente";
         }
     }catch (Exception ex)
     {
         MessageBox.Show("El formato de entrada no es el correcto.\nIntente de nuevo\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
예제 #3
0
        // 1000개 랜덤
        public List <double> GetRandomOfNormal()
        {
            List <double> rdSet = new List <double>();

            var normalD = new MathNet.Numerics.Distributions.Normal();

            double pValue = 0.0;

            int testCnt = 0;

            while (pValue < 0.9)
            {
                rdSet.Clear();

                for (int i = 0; i < ScenCnt; i++)
                {
                    rdSet.Add(normalD.InverseCumulativeDistribution(RD.NextDouble()));
                }

                // Create a new Shapiro-Wilk test:
                var sw = new Accord.Statistics.Testing.ShapiroWilkTest(rdSet.ToArray());
                pValue = sw.PValue;
                testCnt++;
            }

            return(rdSet);
        }
예제 #4
0
        public String get_z()
        {
            double z;

            MathNet.Numerics.Distributions.Normal result = new MathNet.Numerics.Distributions.Normal();
            z = result.InverseCumulativeDistribution(probabilidad_cumplir);
            return(Convert.ToString(z));
        }
예제 #5
0
        public void CurtainsLeadTime()
        {
            var mean = 17.54F;
            var std  = 15.16F;

            var dist = new MathNet.Numerics.Distributions.Normal(mean, std);

            List <double> results = new List <double>();

            for (double d = 0; d <= 1.0; d += 0.05)
            {
                results.Add(dist.InverseCumulativeDistribution(d));
            }
        }
예제 #6
0
        public static void TestRandom()
        {
            var rd = new MathNet.Numerics.Random.MersenneTwister();

            var           normalD = new MathNet.Numerics.Distributions.Normal();
            List <double> vals    = new List <double>();

            for (int i = 0; i < 100000; i++)
            {
                vals.Add(normalD.InverseCumulativeDistribution(rd.NextDouble()));
            }

            // Create a new Shapiro-Wilk test:
            var sw = new Accord.Statistics.Testing.ShapiroWilkTest(vals.ToArray());
        }
예제 #7
0
        // 50년 누적값이 몇개의 난수셋을 거치면서 안정되는지 확인
        public static void TestRandom2()
        {
            var rd = new MathNet.Numerics.Random.MersenneTwister();

            var normalD = new MathNet.Numerics.Distributions.Normal();

            double        val    = 0.0;
            double        avg    = 0.0;
            List <double> avgVal = new List <double>();

            for (int i = 1; i <= 1000000; i++)
            {
                double cumVal = 1.0;
                for (int j = 0; j < 50; j++)
                {
                    val     = normalD.InverseCumulativeDistribution(rd.NextDouble());
                    cumVal *= 1.0 + (val / 10.0);
                }

                if (i == 1)
                {
                    avg = cumVal;
                }
                else
                {
                    avg = avg * (Convert.ToDouble(i - 1) / Convert.ToDouble(i))
                          + cumVal * (1 / Convert.ToDouble(i));
                }

                // 1000개마다 평균값을 저장
                if (i % 1000 == 0)
                {
                    avgVal.Add(avg);
                }
            }
        }
예제 #8
0
        //TODO: Add discounts

        public MissionResult(HumanPlayer player, double progression, Mission.Mission lastMission, List <Armour> loot, string closeButtonText)
        {
            InitializeComponent();
            this.player      = player;
            nextMission.Text = closeButtonText;

            //Enable level up
            levelUpButton.Enabled = player.storedLevelUps != 0;
            levelUpButton.Text    = $"Level up x{player.storedLevelUps}";

            //Generate reward
            Reward _reward = lastMission.Reward();

            if (_reward.jewelryReward != null)
            {
                if (_reward.jewelryReward.jewelries != null)
                {
                    reward.AddRange(_reward.jewelryReward.jewelries);
                }

                while (_reward.jewelryReward.number != 0)
                {
                    //Determine the quality
                    MathNet.Numerics.Distributions.Normal normal = new MathNet.Numerics.Distributions.Normal();
                    int offset = (int)normal.InverseCumulativeDistribution(World.random.NextDouble());
                    int num    = E.GetQualityPos(_reward.jewelryReward.quality) + offset;
                    num = Math.Min(Math.Max(num, 0), Enum.GetNames(typeof(Quality)).Length); //Bound the value
                    Quality quality = E.GetQuality(num);
                    reward.Add(Jewelry.GenerateJewelry(quality));
                    _reward.jewelryReward.number--;
                }
            }
            if (!(_reward.weaponReward is null))
            {
                reward.Add(Campaign.CalculateWeaponReward(_reward.weaponReward, (int)(progression * 10), 10));
            }
            if (!(_reward.spellReward is null))
            {
                Spell spell = _reward.spellReward.spell;
                if (spell != null && !player.spells.Exists(s => spell.name == s.name))
                {
                    reward.Add(spell);
                }
            }
            if (_reward.Money != 0)
            {
                reward.Add(new Coin(_reward.Money));
            }
            if (_reward.itemReward != null)
            {
                reward.Add(_reward.itemReward.reward);
            }
            reward.AddRange(loot);

            //Populate reward list
            foreach (var item in reward)
            {
                lootList.Items.Add(item);
            }

            playerView.Activate(player, null, false);

            Render();
        }
예제 #9
0
        public void TestMethod2()
        {
            List <double> inputs  = new List <double>();
            List <double> outputs = new List <double>();

            var data = new double[] { 1, 3.1, 4.2478, 5.7856, 6.234, 7.76, 8.45, 9.37, 12, 13, 14, 3.865, 3.542, 5.54, 76, 2.354, 4.745, 6, 56, 5.4, 45, 4.235, 34, 6.43, 7.74, 4.32 };

            //var data = new double[] { 1,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5 };

            //data = data.OrderBy(d => d).ToArray();

            //ParetoShaped Data
            //var data = new double[] { 10, 6.6, 5, 4, 3.3, 2.8, 2.5, 2.3, 2, 1.85 };

            var mean  = MathNet.Numerics.Statistics.ArrayStatistics.Mean(data);
            var stDev = MathNet.Numerics.Statistics.ArrayStatistics.StandardDeviation(data);

            //var distribution = new MathNet.Numerics.Distributions.Normal(mean, stDev);

            var distribution = new MathNet.Numerics.Distributions.Normal(mean, stDev);


            List <double> errorBefore = new List <double>();

            for (int i = 0; i < data.Length; i++)
            {
                double cumulativeDistribution = (double)(i + 1) / (double)data.Length;

                inputs.Add(cumulativeDistribution);

                var actual = distribution.CumulativeDistribution(data[i]);

                outputs.Add(actual);

                var error = cumulativeDistribution / actual;
                errorBefore.Add(error);
            }

            double averageErrorBefore = errorBefore.Average();

            double baseLineAddition = MathNet.Numerics.Statistics.ArrayStatistics.Minimum(outputs.ToArray()) -
                                      MathNet.Numerics.Statistics.ArrayStatistics.Minimum(inputs.ToArray());
            double baseLineMultiple = 1 / (MathNet.Numerics.Statistics.ArrayStatistics.Maximum(outputs.ToArray()) - baseLineAddition);

            double sigmoidAlphaValue = 1;

            ActivationNetwork network = new ActivationNetwork(new SigmoidFunction(1), 1, 4, 4, 1);
            //new BipolarSigmoidFunction(sigmoidAlphaValue),
            //1, 3, 1);

            BackPropagationLearning teacher = new BackPropagationLearning(network);

            teacher.LearningRate = 0.478587;
            teacher.Momentum     = 0.0;

            double[][] nnInputs  = inputs.Select(s => new double[] { s }).ToArray();
            double[][] nnOutputs = outputs.Select(s => new double[] { (s - baseLineAddition) * baseLineMultiple }).ToArray();


            for (int i = 0; i < 50000; i++)
            {
                // run epoch of learning procedure
                double error = teacher.RunEpoch(
                    nnInputs,
                    nnOutputs
                    ) / inputs.Count;
            }

            List <double> errors = new List <double>();

            for (int i = 0; i < nnInputs.Length; i++)
            {
                double actual   = network.Compute(nnInputs[i])[0];
                double expected = nnOutputs[i][0];
                errors.Add(Math.Abs(1 - (expected / actual)));
            }

            double nnAverageError = errors.Average();

            errors = new List <double>();
            List <double[]> actuals = new List <double[]>();

            for (int i = 0; i < data.Length; i++)
            {
                double cumulativeDistribution = (double)(i + 1) / (double)data.Length;

                double aiCumulativeDistribution = network.Compute(new double[] { cumulativeDistribution })[0];

                aiCumulativeDistribution = (aiCumulativeDistribution / baseLineMultiple) + baseLineAddition;


                var actual = distribution.InverseCumulativeDistribution(aiCumulativeDistribution);

                errors.Add(Math.Abs(1 - (data[i] / actual)));
                actuals.Add(new double[] { actual, data[i] });
            }

            double averageError = errors.Average();
        }
예제 #10
0
        internal static double inverse(double probability, double mean, double stdev)
        {
            var normalDistribution = new MathNet.Numerics.Distributions.Normal(mean, stdev);

            return(normalDistribution.InverseCumulativeDistribution(probability));
        }