public void GammaDistributionConstructorTest2() { var gamma = new GammaDistribution(theta: 4, k: 2); double mean = gamma.Mean; // 8.0 double median = gamma.Median; // 6.7133878418421506 double var = gamma.Variance; // 32.0 double cdf = gamma.DistributionFunction(x: 0.27); // 0.002178158242390601 double pdf = gamma.ProbabilityDensityFunction(x: 0.27); // 0.015773530285395465 double lpdf = gamma.LogProbabilityDensityFunction(x: 0.27); // -4.1494220422235433 double ccdf = gamma.ComplementaryDistributionFunction(x: 0.27); // 0.99782184175760935 double icdf = gamma.InverseDistributionFunction(p: cdf); // 0.26999998689819171 double hf = gamma.HazardFunction(x: 0.27); // 0.015807962529274005 double chf = gamma.CumulativeHazardFunction(x: 0.27); // 0.0021805338793574793 string str = gamma.ToString(CultureInfo.InvariantCulture); // "Γ(x; k = 2, θ = 4)" Assert.AreEqual(8.0, mean); Assert.AreEqual(6.7133878418421506, median, 1e-6); Assert.AreEqual(32.0, var); Assert.AreEqual(0.0021805338793574793, chf); Assert.AreEqual(0.002178158242390601, cdf); Assert.AreEqual(0.015773530285395465, pdf); Assert.AreEqual(-4.1494220422235433, lpdf); Assert.AreEqual(0.015807962529274005, hf); Assert.AreEqual(0.99782184175760935, ccdf); Assert.AreEqual(0.26999998689819171, icdf, 1e-6); Assert.AreEqual("Γ(x; k = 2, θ = 4)", str); double p05 = gamma.DistributionFunction(median); Assert.AreEqual(0.5, p05, 1e-6); }
public void GammaDistributionConstructorTest2() { #region doc_ctor // Create a Γ-distribution with k = 2 and θ = 4 var gamma = new GammaDistribution(theta: 4, k: 2); // Common measures double mean = gamma.Mean; // 8.0 double median = gamma.Median; // 6.7133878418421506 double var = gamma.Variance; // 32.0 double mode = gamma.Mode; // 4.0 // Cumulative distribution functions double cdf = gamma.DistributionFunction(x: 0.27); // 0.002178158242390601 double ccdf = gamma.ComplementaryDistributionFunction(x: 0.27); // 0.99782184175760935 double icdf = gamma.InverseDistributionFunction(p: cdf); // 0.26999998689819171 // Probability density functions double pdf = gamma.ProbabilityDensityFunction(x: 0.27); // 0.015773530285395465 double lpdf = gamma.LogProbabilityDensityFunction(x: 0.27); // -4.1494220422235433 // Hazard (failure rate) functions double hf = gamma.HazardFunction(x: 0.27); // 0.015807962529274005 double chf = gamma.CumulativeHazardFunction(x: 0.27); // 0.0021805338793574793 // String representation string str = gamma.ToString(CultureInfo.InvariantCulture); // "Γ(x; k = 2, θ = 4)" #endregion Assert.AreEqual(8.0, mean); Assert.AreEqual(6.7133878418421506, median, 1e-6); Assert.AreEqual(32.0, var); Assert.AreEqual(4.0, mode); Assert.AreEqual(0.0021805338793574793, chf, 1e-10); Assert.AreEqual(0.002178158242390601, cdf, 1e-10); Assert.AreEqual(0.015773530285395465, pdf, 1e-10); Assert.AreEqual(-4.1494220422235433, lpdf, 1e-10); Assert.AreEqual(0.015807962529274005, hf, 1e-10); Assert.AreEqual(0.99782184175760935, ccdf, 1e-10); Assert.AreEqual(0.26999998689819171, icdf, 1e-6); Assert.AreEqual("Γ(x; k = 2, θ = 4)", str); double p05 = gamma.DistributionFunction(median); Assert.AreEqual(0.5, p05, 1e-6); var range1 = gamma.GetRange(0.95); var range2 = gamma.GetRange(0.99); var range3 = gamma.GetRange(0.01); Assert.AreEqual(1.4214460427946485, range1.Min, 1e-10); Assert.AreEqual(18.975458073562308, range1.Max, 1e-10); Assert.AreEqual(0.59421896101306348, range2.Min, 1e-10); Assert.AreEqual(26.553408271975243, range2.Max, 1e-10); Assert.AreEqual(0.59421896101306348, range3.Min, 1e-10); Assert.AreEqual(26.553408271975243, range3.Max, 1e-10); }
public void GammaDistributionConstructorTest2() { var gamma = new GammaDistribution(theta: 4, k: 2); double mean = gamma.Mean; // 8.0 double median = gamma.Median; // 6.7133878418421506 double var = gamma.Variance; // 32.0 double mode = gamma.Mode; // 4.0 double cdf = gamma.DistributionFunction(x: 0.27); // 0.002178158242390601 double pdf = gamma.ProbabilityDensityFunction(x: 0.27); // 0.015773530285395465 double lpdf = gamma.LogProbabilityDensityFunction(x: 0.27); // -4.1494220422235433 double ccdf = gamma.ComplementaryDistributionFunction(x: 0.27); // 0.99782184175760935 double icdf = gamma.InverseDistributionFunction(p: cdf); // 0.26999998689819171 double hf = gamma.HazardFunction(x: 0.27); // 0.015807962529274005 double chf = gamma.CumulativeHazardFunction(x: 0.27); // 0.0021805338793574793 string str = gamma.ToString(CultureInfo.InvariantCulture); // "Γ(x; k = 2, θ = 4)" Assert.AreEqual(8.0, mean); Assert.AreEqual(6.7133878418421506, median, 1e-6); Assert.AreEqual(32.0, var); Assert.AreEqual(4.0, mode); Assert.AreEqual(0.0021805338793574793, chf); Assert.AreEqual(0.002178158242390601, cdf); Assert.AreEqual(0.015773530285395465, pdf); Assert.AreEqual(-4.1494220422235433, lpdf); Assert.AreEqual(0.015807962529274005, hf); Assert.AreEqual(0.99782184175760935, ccdf); Assert.AreEqual(0.26999998689819171, icdf, 1e-6); Assert.AreEqual("Γ(x; k = 2, θ = 4)", str); double p05 = gamma.DistributionFunction(median); Assert.AreEqual(0.5, p05, 1e-6); var range1 = gamma.GetRange(0.95); var range2 = gamma.GetRange(0.99); var range3 = gamma.GetRange(0.01); Assert.AreEqual(1.4214460427946485, range1.Min); Assert.AreEqual(18.975458073562308, range1.Max); Assert.AreEqual(0.59421896101306348, range2.Min); Assert.AreEqual(26.553408271975243, range2.Max); Assert.AreEqual(0.59421896101306348, range3.Min); Assert.AreEqual(26.553408271975243, range3.Max); }