public void ConstructorTest1() { var trig = new TriangularDistribution(a: 1, b: 6, c: 3); double mean = trig.Mean; // 3.3333333333333335 double median = trig.Median; // 3.2613872124741694 double mode = trig.Mode; // 3.0 double var = trig.Variance; // 1.0555555555555556 double cdf = trig.DistributionFunction(x: 2); // 0.10000000000000001 double pdf = trig.ProbabilityDensityFunction(x: 2); // 0.20000000000000001 double lpdf = trig.LogProbabilityDensityFunction(x: 2); // -1.6094379124341003 double ccdf = trig.ComplementaryDistributionFunction(x: 2); // 0.90000000000000002 double icdf = trig.InverseDistributionFunction(p: cdf); // 2.0000000655718773 double hf = trig.HazardFunction(x: 2); // 0.22222222222222224 double chf = trig.CumulativeHazardFunction(x: 2); // 0.10536051565782628 string str = trig.ToString(CultureInfo.InvariantCulture); // Triangular(x; a = 1, b = 6, c = 3) Assert.AreEqual(3.3333333333333335, mean); Assert.AreEqual(3.2613872124741694, median); Assert.AreEqual(1.0555555555555556, var); Assert.AreEqual(0.10536051565782628, chf); Assert.AreEqual(0.10000000000000001, cdf); Assert.AreEqual(0.20000000000000001, pdf); Assert.AreEqual(-1.6094379124341003, lpdf); Assert.AreEqual(0.22222222222222224, hf); Assert.AreEqual(0.90000000000000002, ccdf); Assert.AreEqual(2.0000000655718773, icdf); Assert.AreEqual("Triangular(x; a = 1, b = 6, c = 3)", str); }
//End of ui.cs file Contents //------------------------------------------------------------------------- //Begin of Random.cs file contents /// <summary> /// Initializes the random-number generator with a specific seed. /// </summary> public void Initialize(uint seed) { RandomNumberGenerator = new MT19937Generator(seed); betaDist = new BetaDistribution(RandomNumberGenerator); betaPrimeDist = new BetaPrimeDistribution(RandomNumberGenerator); cauchyDist = new CauchyDistribution(RandomNumberGenerator); chiDist = new ChiDistribution(RandomNumberGenerator); chiSquareDist = new ChiSquareDistribution(RandomNumberGenerator); continuousUniformDist = new ContinuousUniformDistribution(RandomNumberGenerator); erlangDist = new ErlangDistribution(RandomNumberGenerator); exponentialDist = new ExponentialDistribution(RandomNumberGenerator); fisherSnedecorDist = new FisherSnedecorDistribution(RandomNumberGenerator); fisherTippettDist = new FisherTippettDistribution(RandomNumberGenerator); gammaDist = new GammaDistribution(RandomNumberGenerator); laplaceDist = new LaplaceDistribution(RandomNumberGenerator); lognormalDist = new LognormalDistribution(RandomNumberGenerator); normalDist = new NormalDistribution(RandomNumberGenerator); paretoDist = new ParetoDistribution(RandomNumberGenerator); powerDist = new PowerDistribution(RandomNumberGenerator); rayleighDist = new RayleighDistribution(RandomNumberGenerator); studentsTDist = new StudentsTDistribution(RandomNumberGenerator); triangularDist = new TriangularDistribution(RandomNumberGenerator); weibullDist = new WeibullDistribution(RandomNumberGenerator); poissonDist = new PoissonDistribution(RandomNumberGenerator); // generator.randomGenerator = new MT19937Generator(seed); }
private IServer CreateProcessStep(string name, double min, double mean, double max) { IDoubleDistribution triangle = new TriangularDistribution(m_model, name + "_distribution", Guid.NewGuid(), min, mean, max); IPeriodicity svcPeriod = new Periodicity(triangle, Periodicity.Units.Minutes); return(new BufferedServer(m_model, name, Guid.NewGuid(), svcPeriod, null, true, false)); }
public void ConstructorTest1() { var trig = new TriangularDistribution(a: 1, b: 6, c: 3); double mean = trig.Mean; // 3.3333333333333335 double median = trig.Median; // 3.2613872124741694 double mode = trig.Mode; // 3.0 double var = trig.Variance; // 1.0555555555555556 double cdf = trig.DistributionFunction(x: 2); // 0.10000000000000001 double pdf = trig.ProbabilityDensityFunction(x: 2); // 0.20000000000000001 double lpdf = trig.LogProbabilityDensityFunction(x: 2); // -1.6094379124341003 double ccdf = trig.ComplementaryDistributionFunction(x: 2); // 0.90000000000000002 double icdf = trig.InverseDistributionFunction(p: cdf); // 2.0000000655718773 double hf = trig.HazardFunction(x: 2); // 0.22222222222222224 double chf = trig.CumulativeHazardFunction(x: 2); // 0.10536051565782628 string str = trig.ToString(CultureInfo.InvariantCulture); // Triangular(x; a = 1, b = 6, c = 3) Assert.AreEqual(3.3333333333333335, mean); Assert.AreEqual(3.2613872124741694, median); Assert.AreEqual(1.0555555555555556, var); Assert.AreEqual(0.10536051565782628, chf); Assert.AreEqual(0.10000000000000001, cdf); Assert.AreEqual(0.20000000000000001, pdf); Assert.AreEqual(-1.6094379124341003, lpdf); Assert.AreEqual(0.22222222222222224, hf); Assert.AreEqual(0.90000000000000002, ccdf); Assert.AreEqual(2.0000000655718773, icdf); Assert.AreEqual("Triangular(x; a = 1, b = 6, c = 3)", str); }
public override double getIncome() { double pos = 0.01 * Math.Pow(popularity + members.Count, 2); TriangularDistribution t = new TriangularDistribution(-0.5, 3, 1); pos *= t.Sample(rand); return(pos * 2.5); }
public void TriangularDistributionGeneratorTest(double begin, double end, double distributionEpsilon, double statEpsilon, int totalValues, int totalIntervals) { var dist = new TriangularDistribution(begin, end); var generator = new TriangularDistributionGenerator(dist); CheckAssert( generator, dist, distributionEpsilon, statEpsilon, totalValues, totalIntervals); }
public int MineralConcentration(int highConcBias = 0) { var lowChance = 30 - (highConcBias * 5); if (this.Next(100) < lowChance) { return(this.Next(1, 31)); } return((int)TriangularDistribution.Sample(this.rng, 31, 75, 120)); }
public void DistributionBase() { // test that implementations on base Distribution classes function and agree with overridden implementations ContinuousDistribution d = new TestDistribution(); ContinuousDistribution t = new TriangularDistribution(0.0, 1.0, 1.0); Assert.IsTrue(TestUtilities.IsNearlyEqual(d.Mean, t.Mean)); Assert.IsTrue(TestUtilities.IsNearlyEqual(d.StandardDeviation, t.StandardDeviation)); Assert.IsTrue(TestUtilities.IsNearlyEqual(d.Skewness, t.Skewness)); Assert.IsTrue(TestUtilities.IsNearlyEqual(d.Median, t.Median)); }
public void ConstructorTest1() { var tri = new TriangularDistribution(min: 1, max: 6, mode: 3); double mean = tri.Mean; // 3.3333333333333335 double median = tri.Median; // 3.2613872124741694 double mode = tri.Mode; // 3.0 double var = tri.Variance; // 1.0555555555555556 double cdf = tri.DistributionFunction(x: 2); // 0.10000000000000001 double pdf = tri.ProbabilityDensityFunction(x: 2); // 0.20000000000000001 double lpdf = tri.LogProbabilityDensityFunction(x: 2); // -1.6094379124341003 double ccdf = tri.ComplementaryDistributionFunction(x: 2); // 0.90000000000000002 double icdf = tri.InverseDistributionFunction(p: cdf); // 2.0000000655718773 double hf = tri.HazardFunction(x: 2); // 0.22222222222222224 double chf = tri.CumulativeHazardFunction(x: 2); // 0.10536051565782628 string str = tri.ToString(CultureInfo.InvariantCulture); // Triangular(x; a = 1, b = 6, c = 3) Assert.AreEqual(3.3333333333333335, mean); Assert.AreEqual(3.0, mode); Assert.AreEqual(3.2613872124741694, median); Assert.AreEqual(1.0555555555555556, var); Assert.AreEqual(0.10536051565782628, chf); Assert.AreEqual(0.10000000000000001, cdf); Assert.AreEqual(0.20000000000000001, pdf); Assert.AreEqual(-1.6094379124341003, lpdf); Assert.AreEqual(0.22222222222222224, hf); Assert.AreEqual(0.90000000000000002, ccdf); Assert.AreEqual(2.0000000655718773, icdf); Assert.AreEqual("Triangular(x; a = 1, b = 6, c = 3)", str); var range1 = tri.GetRange(0.95); var range2 = tri.GetRange(0.99); var range3 = tri.GetRange(0.01); Assert.AreEqual(1.7071067704914942, range1.Min); Assert.AreEqual(5.1339745973005186, range1.Max); Assert.AreEqual(1.3162277235820534, range2.Min); Assert.AreEqual(5.6127016687540774, range2.Max); Assert.AreEqual(1.3162277235820532, range3.Min); Assert.AreEqual(5.6127016687540774, range3.Max); Assert.AreEqual(1, tri.Support.Min); Assert.AreEqual(6, tri.Support.Max); Assert.AreEqual(tri.InverseDistributionFunction(0), tri.Support.Min); Assert.AreEqual(tri.InverseDistributionFunction(1), tri.Support.Max); }
/// <summary> /// Calculates the income of this company, updates popularity based on astroturfs, and removes sold stock /// </summary> /// <returns>the amount of money the company earned in this turn</returns> public double getIncome() { TriangularDistribution t = new TriangularDistribution(0.5, 2, 1.2); double sellRate = popularityToModifier(popularity * t.Sample()); double output = 0; foreach (string key in productStock.Keys.ToList()) { int sold = (int)(productStock[key] * sellRate); productStock[key] -= sold; output += products[key] * sold; } //Dividends output -= getDividendCost(output, true); //Update popularity if (astroturfs < 1) { astroturfs = 1; } popularity *= (1 + (astroturfs)) / (2 + (astroturfs)); if (astroturfs > 1) { astroturfs--; } //Update stock history stock_history.Add(stock_price); foreach (string p in automation) { if (productStock.ContainsKey(p)) { productStock[p]++; } else { //Remove discontinued/errored products //automation.Remove(p); //Never mind, it doesn't like when you delete stuff in its own foreach loop } } //Update owner updateOwner(); return(output); }
public void TestTriangularDistribution() { double[][] para = { new double[] {} }; for (int i = 0; i < para.Length; i++) { var tester = new ContDistTester(para[i], delegate(double a, double b) { var ret = new TriangularDistribution(a, 0.5 * (a + b), b); return(ret); } ); tester.Test(1E-14); } }
public Form1() { InitializeComponent(); //-- mTranslations = new Dictionary <string, Translations>(); mPlainListWords = new PlainWords(); //-- mBinominalDistr = new BinomialDistribution(); mTriangleDistr = new TriangularDistribution(); mUniformDistr = new DiscreteUniformDistribution(); mContUniformDist = new ContinuousUniformDistribution(); mRnd = new Random(); mStopTimer = false; }
public void ConstructorTest1() { var tri = new TriangularDistribution(min: 1, max: 6, mode: 3); double mean = tri.Mean; // 3.3333333333333335 double median = tri.Median; // 3.2613872124741694 double mode = tri.Mode; // 3.0 double var = tri.Variance; // 1.0555555555555556 double cdf = tri.DistributionFunction(x: 2); // 0.10000000000000001 double pdf = tri.ProbabilityDensityFunction(x: 2); // 0.20000000000000001 double lpdf = tri.LogProbabilityDensityFunction(x: 2); // -1.6094379124341003 double ccdf = tri.ComplementaryDistributionFunction(x: 2); // 0.90000000000000002 double icdf = tri.InverseDistributionFunction(p: cdf); // 2.0000000655718773 double hf = tri.HazardFunction(x: 2); // 0.22222222222222224 double chf = tri.CumulativeHazardFunction(x: 2); // 0.10536051565782628 string str = tri.ToString(CultureInfo.InvariantCulture); // Triangular(x; a = 1, b = 6, c = 3) Assert.AreEqual(3.3333333333333335, mean); Assert.AreEqual(3.0, mode); Assert.AreEqual(3.2613872124741694, median); Assert.AreEqual(1.0555555555555556, var); Assert.AreEqual(0.10536051565782628, chf); Assert.AreEqual(0.10000000000000001, cdf); Assert.AreEqual(0.20000000000000001, pdf); Assert.AreEqual(-1.6094379124341003, lpdf); Assert.AreEqual(0.22222222222222224, hf); Assert.AreEqual(0.90000000000000002, ccdf); Assert.AreEqual(2.0000000655718773, icdf); Assert.AreEqual("Triangular(x; a = 1, b = 6, c = 3)", str); var range1 = tri.GetRange(0.95); var range2 = tri.GetRange(0.99); var range3 = tri.GetRange(0.01); Assert.AreEqual(1.7071067704914942, range1.Min); Assert.AreEqual(5.1339745973005186, range1.Max); Assert.AreEqual(1.3162277235820534, range2.Min); Assert.AreEqual(5.6127016687540774, range2.Max); Assert.AreEqual(1.3162277235820532, range3.Min); Assert.AreEqual(5.6127016687540774, range3.Max); }
public void TestDistributionTriangular() { IDoubleDistribution dist = new TriangularDistribution(m_model, "TriangularDistribution", Guid.NewGuid(), 2.0, 5.0, 9.0); Assert.IsTrue(dist.GetValueWithCumulativeProbability(0.50) == 5.2583426132260591); dist.SetCDFInterval(0.5, 0.5); Assert.IsTrue(dist.GetNext() == 5.2583426132260591); dist.SetCDFInterval(0.0, 1.0); System.IO.StreamWriter tw = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("TEMP") + "\\DistributionTriangular.csv"); Debug.WriteLine("Generating raw data."); int DATASETSIZE = 1500000; double[] rawData = new double[DATASETSIZE]; for (int x = 0; x < DATASETSIZE; x++) { rawData[x] = dist.GetNext(); //tw.WriteLine(rawData[x]); } Debug.WriteLine("Performing histogram analysis."); Histogram1D_Double hist = new Histogram1D_Double(rawData, 1.0, 10.0, 450, "distribution"); hist.LabelProvider = new LabelProvider(((Histogram1D_Double)hist).DefaultLabelProvider); hist.Recalculate(); Debug.WriteLine("Writing data dump file."); int[] bins = (int[])hist.Bins; for (int i = 0; i < bins.Length; i++) { //Debug.WriteLine(hist.GetLabel(new int[]{i}) + ", " + bins[i]); tw.WriteLine(hist.GetLabel(new int[] { i }) + ", " + bins[i]); } tw.Flush(); tw.Close(); if (m_visuallyVerify) { System.Diagnostics.Process.Start("excel.exe", Environment.GetEnvironmentVariable("TEMP") + "\\DistributionTriangular.csv"); } }
public void GenerateTest2() { Accord.Math.Tools.SetupGenerator(0); var target = new TriangularDistribution(-4.2, 7, 1); double[] samples = target.Generate(10000000); for (int i = 0; i < samples.Length; i++) { samples[i] = System.Math.Round(samples[i], 2); } double min = samples.Min(); double max = samples.Max(); double mode = samples.Mode(); Assert.AreEqual(min, target.Min, 1e-2); Assert.AreEqual(max, target.Max, 1e-2); Assert.AreEqual(mode, target.Mode, 0.035); }
/// <summary> /// Shows a new chart in a default form. /// </summary> /// <param name="dist">The distribution.</param> /// <param name="function">The distribution function to plot.</param> /// <param name="numInterpolatedValues">The number of interpolated values.</param> /// <remarks> /// Equivalent to: /// <code> /// NMathStatsChart.Show( ToChart( dist, function, numInterpolatedValues ) ); /// </code> /// </remarks> public static void Show( TriangularDistribution dist, DistributionFunction function = DistributionFunction.PDF, int numInterpolatedValues = 100 ) { Show( ToChart( dist, function, numInterpolatedValues ) ); }
public void GenerateTest2() { Accord.Math.Tools.SetupGenerator(0); var target = new TriangularDistribution(-4.2, 7, 1); double[] samples = target.Generate(10000000); for (int i = 0; i < samples.Length; i++) samples[i] = System.Math.Round(samples[i], 2); double min = samples.Min(); double max = samples.Max(); double mode = samples.Mode(); Assert.AreEqual(min, target.Min, 1e-2); Assert.AreEqual(max, target.Max, 1e-2); Assert.AreEqual(mode, target.Mode, 0.035); }
private void btnGenerate_Click(object sender, EventArgs e) { string error; if (!ValidateInput(out error)) { MessageBox.Show(error); return; } Distribution distribution = null; var generator = new Generator(); switch (distributionType) { case DistributionType.Uniform: var a = double.Parse(textBoxA.Text); var b = double.Parse(textBoxB.Text); distribution = new UniformDistribution(generator, a, b); break; case DistributionType.Gaussian: var mean = double.Parse(textBoxMParameter.Text); var standartDeviation = double.Parse(textBoxQParameter.Text); distribution = new GaussianDistribution(generator, mean, standartDeviation); break; case DistributionType.Exponential: var lambda = double.Parse(textBoxLambda.Text); distribution = new ExponentialDistribution(generator, lambda); break; case DistributionType.Gamma: var eta = Convert.ToInt32(numericUpDownEta.Text); var lambdaG = double.Parse(textBoxLambdaG.Text); distribution = new GammaDistribution(generator, eta, lambdaG); break; case DistributionType.Triangular: var aT = double.Parse(textBoxAT.Text); var bT = double.Parse(textBoxBT.Text); var isFirstVariant = radioBtnVariant1.Checked; distribution = new TriangularDistribution(generator, aT, bT, isFirstVariant); break; case DistributionType.Simpsons: var aS = double.Parse(textBoxAS.Text); var bS = double.Parse(textBoxBS.Text); distribution = new SimpsonsDistribution(generator, aS, bS); break; default: distribution = null; break; } if (ReferenceEquals(distribution, null)) { MessageBox.Show("Error: distribution is undefined"); return; } var n = Convert.ToInt32(numericUpDownLength.Text); generatedValues = new List <double>(); listBoxGeneratedValues.Items.Clear(); for (int i = 0; i < n; i++) { var value = distribution.GetNext(); generatedValues.Add(value); listBoxGeneratedValues.Items.Add(value); } DrawChart(); var m = CalcM(generatedValues); var d = CalcD(generatedValues, m); var q = Math.Sqrt(d); textBoxMActual.Text = m.ToString(CultureInfo.InvariantCulture); textBoxDActual.Text = d.ToString(CultureInfo.InvariantCulture); textBoxQActual.Text = q.ToString(CultureInfo.InvariantCulture); }
/// <summary> /// Sets the distribution for operations using the current genrator /// </summary> /// <param name="distx">Distx.</param> public void setDistribution(distributions distx, Dictionary <string, double> args) { //TODO check arguments to ensure they are making a change to the distribution //otherwise throw an exception see laplace as a example of implementing this switch (distx) { case distributions.Bernoili: BernoulliDistribution x0 = new BernoulliDistribution(gen); if (args.ContainsKey("alpha")) { x0.Alpha = args["alpha"]; } else { throw new System.Exception("for Bernoili distribution you must provide an alpha"); } dist = x0; break; case distributions.Beta: BetaDistribution x1 = new BetaDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x1.Alpha = args["alpha"]; x1.Beta = args["beta"]; } else { throw new System.Exception(" for beta distribution you must provide alpha and beta"); } dist = x1; break; case distributions.BetaPrime: BetaPrimeDistribution x2 = new BetaPrimeDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x2.Alpha = args["alpha"]; x2.Beta = args["beta"]; } else { throw new System.Exception(" for betaPrime distribution you must provide alpha and beta"); } dist = x2; break; case distributions.Cauchy: CauchyDistribution x3 = new CauchyDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("gamma")) { x3.Alpha = args["alpha"]; x3.Gamma = args["gamma"]; } else { throw new System.Exception("for cauchy dist you must provide alpha and gamma"); } dist = x3; break; case distributions.Chi: ChiDistribution x4 = new ChiDistribution(gen); if (args.ContainsKey("alpha")) { x4.Alpha = (int)args["alpha"]; } else { throw new System.Exception("for chi you must provide alpha"); } dist = x4; break; case distributions.ChiSquared: ChiSquareDistribution x5 = new ChiSquareDistribution(gen); if (args.ContainsKey("alpha")) { x5.Alpha = (int)args["alpha"]; } else { throw new System.Exception("for chiSquared you must provide alpha"); } dist = x5; break; case distributions.ContinuousUniform: ContinuousUniformDistribution x6 = new ContinuousUniformDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x6.Alpha = args["alpha"]; x6.Beta = args["beta"]; } else { throw new System.Exception("for ContinuousUniform you must provide alpha and beta"); } dist = x6; break; case distributions.DiscreteUniform: DiscreteUniformDistribution x7 = new DiscreteUniformDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x7.Alpha = (int)args["alpha"]; x7.Beta = (int)args["beta"]; } else { throw new System.Exception("for discrete uniform distribution you must provide alpha and beta"); } dist = x7; break; case distributions.Erlang: ErlangDistribution x8 = new ErlangDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("lambda")) { x8.Alpha = (int)args["alpha"]; x8.Lambda = (int)args["lambda"]; } else { throw new System.Exception("for Erlang dist you must provide alpha and lambda"); } dist = x8; break; case distributions.Exponential: ExponentialDistribution x9 = new ExponentialDistribution(gen); if (args.ContainsKey("lambda")) { x9.Lambda = args["lambda"]; } else { throw new System.Exception("for exponential dist you must provide lambda"); } dist = x9; break; case distributions.FisherSnedecor: FisherSnedecorDistribution x10 = new FisherSnedecorDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x10.Alpha = (int)args["alpha"]; x10.Beta = (int)args["beta"]; } else { throw new System.Exception("for FisherSnedecor you must provide alpha and beta"); } dist = x10; break; case distributions.FisherTippett: FisherTippettDistribution x11 = new FisherTippettDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("mu")) { x11.Alpha = args["alpha"]; x11.Mu = args["mu"]; } else { throw new System.Exception("for FisherTippets you must provide alpha and mu"); } dist = x11; break; case distributions.Gamma: GammaDistribution x12 = new GammaDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("theta")) { x12.Alpha = args["alpha"]; x12.Theta = args["theta"]; } else { throw new System.Exception("for Gamma dist you must provide alpha and theta"); } dist = x12; break; case distributions.Geometric: GeometricDistribution x13 = new GeometricDistribution(gen); if (args.ContainsKey("alpha")) { x13.Alpha = args["alpha"]; } else { throw new System.Exception("Geometric distribution requires alpha value"); } dist = x13; break; case distributions.Binomial: BinomialDistribution x14 = new BinomialDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x14.Alpha = args["alpha"]; x14.Beta = (int)args["beta"]; } else { throw new System.Exception("binomial distribution requires alpha and beta"); } dist = x14; break; case distributions.None: break; case distributions.Laplace: LaplaceDistribution x15 = new LaplaceDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("mu")) { if (x15.IsValidAlpha(args["alpha"]) && x15.IsValidMu(args["mu"])) { x15.Alpha = args["alpha"]; x15.Mu = args["mu"]; } else { throw new ArgumentException("alpha must be greater than zero"); } } else { throw new System.Exception("Laplace dist requires alpha and mu"); } dist = x15; break; case distributions.LogNormal: LognormalDistribution x16 = new LognormalDistribution(gen); if (args.ContainsKey("mu") && args.ContainsKey("sigma")) { x16.Mu = args["mu"]; x16.Sigma = args["sigma"]; } else { throw new System.Exception("lognormal distribution requires mu and sigma"); } dist = x16; break; case distributions.Normal: NormalDistribution x17 = new NormalDistribution(gen); if (args.ContainsKey("mu") && args.ContainsKey("sigma")) { x17.Mu = args["mu"]; x17.Sigma = args["sigma"]; } else { throw new System.Exception("normal distribution requires mu and sigma"); } dist = x17; break; case distributions.Pareto: ParetoDistribution x18 = new ParetoDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x18.Alpha = args["alpha"]; x18.Beta = args["beta"]; } else { throw new System.Exception("pareto distribution requires alpha and beta"); } dist = x18; break; case distributions.Poisson: PoissonDistribution x19 = new PoissonDistribution(gen); if (args.ContainsKey("lambda")) { x19.Lambda = args["lambda"]; } else { throw new System.Exception("Poisson distribution requires lambda"); } dist = x19; break; case distributions.Power: PowerDistribution x20 = new PowerDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta")) { x20.Alpha = args["alpha"]; x20.Beta = args["beta"]; } else { throw new System.Exception("Power dist requires alpha and beta"); } dist = x20; break; case distributions.RayLeigh: RayleighDistribution x21 = new RayleighDistribution(gen); if (args.ContainsKey("sigma")) { x21.Sigma = args["sigma"]; } else { throw new System.Exception("Rayleigh dist requires sigma"); } dist = x21; break; case distributions.StudentsT: StudentsTDistribution x22 = new StudentsTDistribution(gen); if (args.ContainsKey("nu")) { x22.Nu = (int)args["nu"]; } else { throw new System.Exception("StudentsT dist requirres nu"); } dist = x22; break; case distributions.Triangular: TriangularDistribution x23 = new TriangularDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("beta") && args.ContainsKey("gamma")) { x23.Alpha = args["alpha"]; x23.Beta = args["beta"]; x23.Gamma = args["gamma"]; } else { throw new System.Exception("Triangular distribution requires alpha, beta and gamma"); } dist = x23; break; case distributions.WeiBull: WeibullDistribution x24 = new WeibullDistribution(gen); if (args.ContainsKey("alpha") && args.ContainsKey("lambda")) { x24.Alpha = args["alpha"]; x24.Lambda = args["lambda"]; } else { throw new System.Exception("WeiBull dist requires alpha and lambda"); } dist = x24; break; default: throw new NotImplementedException("the distribution you want has not yet been implemented " + "you could help everyone out by going and implementing it"); } }
/// <summary> /// Updates the given chart with the specified distribution. /// </summary> /// <param name="chart">A chart.</param> /// <param name="dist">The distribution.</param> /// <param name="function">The distribution function to plot.</param> /// <param name="numInterpolatedValues">The number of interpolated values.</param> /// <returns>A new chart.</returns> /// <remarks> /// Plots the specified function of the given distribution for 0.0001 <= p <= 0.9999. /// <br/> /// Titles are added only if chart does not currently contain any titles. /// <br/> /// chart.Series[0] is replaced, or added if necessary. /// </remarks> public static void Update( ref ChartControl chart, TriangularDistribution dist, DistributionFunction function = DistributionFunction.PDF, int numInterpolatedValues = 100 ) { List<string> titles = new List<string>() { "TriangularDistribution", String.Format("lower={0}, upper={1}, mode={2}", dist.LowerLimit, dist.UpperLimit, dist.Mode) }; UpdateContinuousDistribution( ref chart, dist, titles, function, numInterpolatedValues ); }
/// <summary> /// Returns a new line chart plotting the specified function of the given distribution for 0.0001 <= p <= 0.9999. /// </summary> /// <param name="dist">The distribution.</param> /// <param name="function">The distribution function to plot.</param> /// <param name="numInterpolatedValues">The number of interpolated values.</param> /// <returns>A new chart.</returns> public static ChartControl ToChart( TriangularDistribution dist, DistributionFunction function = DistributionFunction.PDF, int numInterpolatedValues = 100 ) { ChartControl chart = GetDefaultChart(); Update( ref chart, dist, function, numInterpolatedValues ); return chart; }