private void button_Click(object sender, RoutedEventArgs e) { double theta_param = double.Parse(param1tb.Text); double k = double.Parse(param2tb.Text); int count = int.Parse(counttb.Text); Accord.Statistics.Distributions.Univariate.GammaDistribution gd1 = new Accord.Statistics.Distributions.Univariate.GammaDistribution(theta_param, k); double[] dd1 = gd1.Generate(count); currGammaArray = dd1; DistributionInstance dis = new DistributionInstance(currGammaArray); dis.DParams.Add("theta", theta_param); dis.DParams.Add("k", k); currentDis = dis; UpdateList(currentDis); }
/// <summary> /// Returns WGEN generated daily precipitation (inches) data for numDays number of days /// </summary> /// <param name="rndSeed">Random number generator seed</param> /// <param name="PWW">One dimensional array(Month) of probabilities of a wet day following a wet day. Month: Month of the year.</param> /// <param name="PWD">One dimensional array(Month) of probabilities of a wet day following a dry day. Month: Month of the year.</param> /// <param name="alpha">One dimensional arry(Month) of Gamma Distribution Shape parameter. Month: Month of the year.</param> /// <param name="beta">One dimensional arry(Month) of Gamma Distribution Scale parameter. Month: Month of the year</param> /// <param name="numDays">Number of days for which precipitation is to be generated</param> /// <param name="precip">One dimensional array[Day] of daily precipitation in inches</param> /// <param name="errorMsg"></param> private void GeneratePrecip(int rndSeed, double[] PWW, double[] PWD, double[] alpha, double[] beta, int numDays, out double[] precip, out string errorMsg) { errorMsg = ""; precip = new double[numDays]; int[] month = { 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 }; Random rnd = new Random(rndSeed); int mon = 0; Accord.Statistics.Distributions.Univariate.GammaDistribution gamma = new Accord.Statistics.Distributions.Univariate.GammaDistribution(alpha[0], beta[0]); Accord.Math.Random.Generator.Seed = rndSeed; bool previousDayWet = false; //Randomly decide if the first day is dry or wet double rnd1 = rnd.NextDouble(); if (rnd1 > 0.5) { previousDayWet = true; } else { previousDayWet = false; } //If previous day is wet then assign it the precipitation amount by generating a random variate from Gamma Distribution if (previousDayWet == true) { precip[0] = gamma.Generate(); } int year = 0; //Start the loop from 2nd day because the first day has already been decided for (int i = 1; i < numDays; i++) { if ((i - year * 365) > month[mon]) //Check if month has changed { mon = mon + 1; if (mon > 11) { mon = 1; year = year + 1; } gamma = new Accord.Statistics.Distributions.Univariate.GammaDistribution(alpha[mon], beta[mon]); //Instantiate Gamma Distribution for the month } //Check if it is a wet or dry day rnd1 = rnd.NextDouble(); if (previousDayWet == true) { if (rnd1 <= PWW[mon]) //wet day followed by a wet day { previousDayWet = true; //set for the next iteration precip[i] = gamma.Generate(); } else //wet day followed by a dry day { previousDayWet = false; //set for the next iteration precip[i] = 0; } } else //Previous day is dry { if (rnd1 <= PWD[mon]) //dry day follwoed by a wet day { previousDayWet = true; //set for the next iteration precip[i] = gamma.Generate(); } else //dry day followed by a dry day { previousDayWet = false; precip[i] = 0; //set for the next iteration } } } return; }