public void DocumentationTest1() { #region doc_ctor // Create a new trapezoidal distribution with linear growth between // 0 and 2, stability between 2 and 8, and decrease between 8 and 10. // // // +-----------+ // /| |\ // / | | \ // / | | \ // -------+---+-----------+---+------- // ... 0 2 4 6 8 10 ... // var trapz = new TrapezoidalDistribution(a: 0, b: 2, c: 8, d: 10, n1: 1, n3: 1); double mean = trapz.Mean; // 2.25 double median = trapz.Median; // 5.0 double mode = trapz.Mode; // 4.7706917621394611 double var = trapz.Variance; // 17.986666666666665 double cdf = trapz.DistributionFunction(x: 1.4); // 0.13999999999999999 double pdf = trapz.ProbabilityDensityFunction(x: 1.4); // 0.10000000000000001 double lpdf = trapz.LogProbabilityDensityFunction(x: 1.4); // -2.3025850929940455 double ccdf = trapz.ComplementaryDistributionFunction(x: 1.4); // 0.85999999999999999 double icdf = trapz.InverseDistributionFunction(p: cdf); // 1.3999999999999997 double hf = trapz.HazardFunction(x: 1.4); // 0.11627906976744187 double chf = trapz.CumulativeHazardFunction(x: 1.4); // 0.15082288973458366 string str = trapz.ToString(CultureInfo.InvariantCulture); // Trapezoidal(x; a=0, b=2, c=8, d=10, n1=1, n3=1, α = 1) #endregion Assert.AreEqual(2.25, mean); Assert.AreEqual(5.0, median); Assert.AreEqual(4.7706917621394611, mode); Assert.AreEqual(17.986666666666665, var); Assert.AreEqual(0.15082288973458366, chf); Assert.AreEqual(0.13999999999999999, cdf); Assert.AreEqual(0.10000000000000001, pdf); Assert.AreEqual(-2.3025850929940455, lpdf); Assert.AreEqual(0.11627906976744187, hf); Assert.AreEqual(0.85999999999999999, ccdf); Assert.AreEqual(1.3999999999999997, icdf); Assert.AreEqual("Trapezoidal(x; a = 0, b = 2, c = 8, d = 10, n1 = 1, n3 = 1, α = 1)", str); var range1 = trapz.GetRange(0.95); var range2 = trapz.GetRange(0.99); var range3 = trapz.GetRange(0.01); Assert.AreEqual(0.50000000000000044, range1.Min); Assert.AreEqual(9.5, range1.Max); Assert.AreEqual(0.10000000000000009, range2.Min); Assert.AreEqual(9.9, range2.Max); Assert.AreEqual(0.10000000000000001, range3.Min); Assert.AreEqual(9.9, range3.Max); }
public void icdf() { var dist = new TrapezoidalDistribution(0, 1, 2, 3, 1, 1); double[] percentiles = Vector.Range(0.0, 1.0, stepSize: 0.1); for (int i = 0; i < percentiles.Length; i++) { double x = percentiles[i]; double icdf = dist.InverseDistributionFunction(x); double cdf = dist.DistributionFunction(icdf); Assert.AreEqual(x, cdf, 1e-5); } }