public void TestMethod1() { Distribution n0 = new TransformedDistribution(new NormalDistribution(), -2.0, 3.0); Distribution n1 = new NormalDistribution(-2.0, 3.0); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.Mean, n1.Mean)); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.Variance, n1.Variance)); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.StandardDeviation, n1.StandardDeviation)); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.Skewness, n1.Skewness)); for (int k = 0; k < 8; k++) { Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.Moment(k), n1.Moment(k))); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.MomentAboutMean(k), n1.MomentAboutMean(k))); } foreach (double x in TestUtilities.GenerateUniformRealValues(-8.0, 8.0, 8)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.ProbabilityDensity(x), n1.ProbabilityDensity(x))); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.LeftProbability(x), n1.LeftProbability(x))); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.RightProbability(x), n1.RightProbability(x))); } foreach (double P in TestUtilities.GenerateRealValues(1.0E-4, 1.0, 4)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.InverseLeftProbability(P), n1.InverseLeftProbability(P))); Assert.IsTrue(TestUtilities.IsNearlyEqual(n0.InverseRightProbability(P), n1.InverseRightProbability(P))); } }
/* * x: mide el tiempo * y: mide la cantidad que ingresa en el anden * m: es el máximo de la campana de gauss * r1, r2: son números aleatorios */ public static int Normal(int minValue, int maxValue) { double r1, r2, m, x, y, mu, sigma, fx; if ((minValue >= maxValue) || (minValue < 0) || (maxValue < 0)) { throw new System.ArgumentException("Valores incorrectos"); } mu = calcularMedia(minValue, maxValue); sigma = calcularDesvio(minValue, maxValue); NormalDistribution f = new NormalDistribution(mu, sigma); m = 1 / (sigma * Math.Sqrt(2 * Math.PI)); do { r1 = Rand(); r2 = Rand(); x = minValue + (maxValue - minValue) * r1; y = m * r2; fx = f.ProbabilityDensity((x - mu) / sigma); } while (y <= fx); return Convert.ToInt32(x); }