public void CauchyDistributionConstructorTest2() { double location = 0.42; double scale = 1.57; CauchyDistribution cauchy = new CauchyDistribution(location, scale); double mean = cauchy.Mean; // NaN - Cauchy's mean is undefined. double var = cauchy.Variance; // NaN - Cauchy's variance is undefined. double median = cauchy.Median; // 0.42 double cdf = cauchy.DistributionFunction(x: 0.27); // 0.46968025841608563 double pdf = cauchy.ProbabilityDensityFunction(x: 0.27); // 0.2009112009763413 double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27); // -1.6048922547266871 double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27); // 0.53031974158391437 double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991); // 1.5130304686978195 double hf = cauchy.HazardFunction(x: 0.27); // 0.3788491832800277 double chf = cauchy.CumulativeHazardFunction(x: 0.27); // 0.63427516833243092 string str = cauchy.ToString(System.Globalization.CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57) Assert.IsTrue(Double.IsNaN(mean)); Assert.IsTrue(Double.IsNaN(var)); Assert.AreEqual(0.42, median); Assert.AreEqual(0.63427516833243092, chf); Assert.AreEqual(0.46968025841608563, cdf); Assert.AreEqual(0.2009112009763413, pdf); Assert.AreEqual(-1.6048922547266871, lpdf); Assert.AreEqual(0.3788491832800277, hf); Assert.AreEqual(0.53031974158391437, ccdf); Assert.AreEqual(1.5130304686978195, icdf); Assert.AreEqual("Cauchy(x; x0 = 0.42, γ = 1.57)", str); }
public void CauchyDistributionConstructorTest2() { double location = 0.42; double scale = 1.57; CauchyDistribution cauchy = new CauchyDistribution(location, scale); double mean = cauchy.Mean; // NaN - Cauchy's mean is undefined. double var = cauchy.Variance; // NaN - Cauchy's variance is undefined. double median = cauchy.Median; // 0.42 double mode = cauchy.Mode; // 0.42 double cdf = cauchy.DistributionFunction(x: 0.27); // 0.46968025841608563 double pdf = cauchy.ProbabilityDensityFunction(x: 0.27); // 0.2009112009763413 double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27); // -1.6048922547266871 double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27); // 0.53031974158391437 double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991); // 1.5130304686978195 double hf = cauchy.HazardFunction(x: 0.27); // 0.3788491832800277 double chf = cauchy.CumulativeHazardFunction(x: 0.27); // 0.63427516833243092 string str = cauchy.ToString(System.Globalization.CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57) Assert.IsTrue(Double.IsNaN(mean)); Assert.IsTrue(Double.IsNaN(var)); Assert.AreEqual(0.42, median); Assert.AreEqual(0.42, mode, 1e-6); Assert.AreEqual(0.63427516833243092, chf); Assert.AreEqual(0.46968025841608563, cdf); Assert.AreEqual(0.2009112009763413, pdf); Assert.AreEqual(-1.6048922547266871, lpdf); Assert.AreEqual(0.3788491832800277, hf); Assert.AreEqual(0.53031974158391437, ccdf); Assert.AreEqual(1.5130304686978195, icdf); Assert.AreEqual("Cauchy(x; x0 = 0.42, γ = 1.57)", str); var range1 = cauchy.GetRange(0.95); var range2 = cauchy.GetRange(0.99); var range3 = cauchy.GetRange(0.01); Assert.AreEqual(-9.4925897567183526, range1.Min, 1e-10); Assert.AreEqual(10.332589895085842, range1.Max, 1e-10); Assert.AreEqual(-49.538210069999685, range2.Min, 1e-10); Assert.AreEqual(50.378210075966564, range2.Max, 1e-10); Assert.AreEqual(-49.538210069999892, range3.Min, 1e-10); Assert.AreEqual(50.378210075966564, range3.Max, 1e-10); Assert.AreEqual(Double.NegativeInfinity, cauchy.Support.Min); Assert.AreEqual(Double.PositiveInfinity, cauchy.Support.Max); Assert.AreEqual(cauchy.InverseDistributionFunction(0), cauchy.Support.Min); Assert.AreEqual(cauchy.InverseDistributionFunction(1), cauchy.Support.Max); }
public void ProbabilityDensityFunctionTest() { double[] expected = { 0.03183099, 0.03314002, 0.03452385, 0.03598755, 0.03753654, 0.03917660, 0.04091387, 0.04275485, 0.04470644, 0.04677588, 0.04897075, 0.05129893 }; CauchyDistribution target = new CauchyDistribution(location: 4, scale: 2); for (int i = 0; i < expected.Length; i++) { double actual = target.ProbabilityDensityFunction(i / 10.0); Assert.AreEqual(expected[i], actual, 1e-7); Assert.IsFalse(Double.IsNaN(actual)); } }
private void GeneratePlot() { DataContext = null; if (!double.TryParse(RangeFromBox.Text, out from) || !double.TryParse(RangeToBox.Text, out to) || !double.TryParse(LocationBox.Text, out location) || !double.TryParse(ScaleBox.Text, out scale)) { MessageBox.Show("Nieprawidłowy format ciągu wejściowego"); return; } double step = (Math.Abs(from) + Math.Abs(to)) / 100; Pdf = new ChartValues <ObservablePoint>(); CauchyDistribution myCauchy = new CauchyDistribution(Double.Parse(LocationBox.Text), Double.Parse(ScaleBox.Text)); for (double i = from; i <= to; i += step) { Pdf.Add(new ObservablePoint(i, myCauchy.ProbabilityDensityFunction(i))); } DataContext = this; }