/// <summary> /// Gets the inverse of the cumulative distribution function (icdf) for /// this distribution evaluated at probability <c>p</c>. This function /// is also known as the Quantile function. /// </summary> /// /// <param name="p">A probability value between 0 and 1.</param> /// /// <returns> /// A sample which could original the given probability /// value when applied in the <see cref="DistributionFunction"/>. /// </returns> /// public override double InverseDistributionFunction(double p) { if (this.exact) { return(base.InverseDistributionFunction(p)); } return(approximation.InverseDistributionFunction(p)); }
/// <summary> /// Gets the inverse of the cumulative distribution function (icdf) for /// this distribution evaluated at probability <c>p</c>. This function /// is also known as the Quantile function. /// </summary> /// /// <param name="p">A probability value between 0 and 1.</param> /// /// <returns> /// A sample which could original the given probability /// value when applied in the <see cref="UnivariateContinuousDistribution.DistributionFunction(double)"/>. /// </returns> /// protected internal override double InnerInverseDistributionFunction(double p) { if (this.exact) { return(base.InnerInverseDistributionFunction(p)); } return(approximation.InverseDistributionFunction(p)); }
/// <summary> /// Gets the inverse of the cumulative distribution function (icdf) for /// this distribution evaluated at probability <c>p</c>. This function /// is also known as the Quantile function. /// </summary> /// /// <param name="p">A probability value between 0 and 1.</param> /// /// <returns> /// A sample which could original the given probability /// value when applied in the <see cref="UnivariateContinuousDistribution.DistributionFunction(double)"/>. /// </returns> /// protected internal override double InnerInverseDistributionFunction(double p) { if (this.exact) { if (n1 > n2) { Trace.TraceWarning("Warning: Using a MannWhitneyDistribution where the first sample is larger than the second."); double lower = 0; double upper = 0; double f = DistributionFunction(0); if (f > p) { while (f > p && !double.IsInfinity(lower)) { lower = upper; upper = 2 * upper + 1; f = DistributionFunction(upper); } } else if (f < p) { while (f < p && !double.IsInfinity(upper)) { upper = lower; lower = 2 * lower - 1; f = DistributionFunction(lower); } } else { return(0); } if (double.IsNegativeInfinity(lower)) { lower = double.MinValue; } if (double.IsPositiveInfinity(upper)) { upper = double.MaxValue; } double value = BrentSearch.Find(DistributionFunction, p, lower, upper); return(value); } return(base.InnerInverseDistributionFunction(p)); } return(approximation.InverseDistributionFunction(p)); }
public void InverseDistributionFunctionTest() { double[] expected = { Double.NegativeInfinity, -4.38252, -2.53481, -1.20248, -0.0640578, 1.0, 2.06406, 3.20248, 4.53481, 6.38252, Double.PositiveInfinity }; NormalDistribution target = new NormalDistribution(1.0, 4.2); for (int i = 0; i < expected.Length; i++) { double x = i / 10.0; double actual = target.InverseDistributionFunction(x); Assert.AreEqual(expected[i], actual, 1e-5); Assert.IsFalse(Double.IsNaN(actual)); } }