public void CanSampleSequence() { var n = new Chi(1.0); var ied = n.Samples(); GC.KeepAlive(ied.Take(5).ToArray()); }
public void ValidateDensityLn(double dof, double x, double expected) { var chi = new Chi(dof); Assert.That(chi.DensityLn(x), Is.EqualTo(expected).Within(13)); Assert.That(Chi.PDFLn(dof, x), Is.EqualTo(expected).Within(13)); }
public void ValidateToString() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var n = new Chi(1.0); Assert.AreEqual("Chi(k = 1)", n.ToString()); }
public void SetDofFailsWithNonPositiveDoF(double dof) { { var n = new Chi(1.0); n.DegreesOfFreedom = dof; } }
public void ValidateCumulativeDistribution(double dof, double x) { var n = new Chi(dof); double expected = SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x * x / 2.0) / SpecialFunctions.Gamma(dof / 2.0); Assert.AreEqual(expected, n.CumulativeDistribution(x)); Assert.AreEqual(expected, Chi.CDF(dof, x)); }
public void ValidateDensityLn(double dof, double x) { var n = new Chi(dof); double expected = ((1.0 - (dof / 2.0)) * Math.Log(2.0)) + ((dof - 1.0) * Math.Log(x)) - (x * (x / 2.0)) - SpecialFunctions.GammaLn(dof / 2.0); Assert.AreEqual(expected, n.DensityLn(x)); Assert.AreEqual(expected, Chi.PDFLn(dof, x)); }
public void ValidateDensity(double dof, double x) { var n = new Chi(dof); double expected = (Math.Pow(2.0, 1.0 - (dof / 2.0)) * Math.Pow(x, dof - 1.0) * Math.Exp(-x * (x / 2.0))) / SpecialFunctions.Gamma(dof / 2.0); Assert.AreEqual(expected, n.Density(x)); Assert.AreEqual(expected, Chi.PDF(dof, x)); }
public void ValidateCumulativeDistribution( [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, [Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x) { var n = new Chi(dof); Assert.AreEqual(SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x * x / 2.0) / SpecialFunctions.Gamma(dof / 2.0), n.CumulativeDistribution(x)); }
public void ValidateDensityLn( [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, [Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x) { var n = new Chi(dof); Assert.AreEqual(((1.0 - (dof / 2.0)) * Math.Log(2.0)) + ((dof - 1.0) * Math.Log(x)) - (x * (x / 2.0)) - SpecialFunctions.GammaLn(dof / 2.0), n.DensityLn(x)); }
public void ValidateDensity( [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, [Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x) { var n = new Chi(dof); Assert.AreEqual((Math.Pow(2.0, 1.0 - (dof / 2.0)) * Math.Pow(x, dof - 1.0) * Math.Exp(-x * (x / 2.0))) / SpecialFunctions.Gamma(dof / 2.0), n.Density(x)); }
public void ValidateMode(double dof) { var n = new Chi(dof); if (dof >= 1) { Assert.AreEqual(Math.Sqrt(dof - 1), n.Mode); } }
public void ValidateMode([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof) { var n = new Chi(dof); if (dof >= 1) { Assert.AreEqual(Math.Sqrt(dof - 1), n.Mode); } }
public void ValidateCumulativeDistribution(double dof, double x, double expected) { var chi = new Chi(dof); Assert.That(chi.CumulativeDistribution(x), Is.EqualTo(expected).Within(13)); Assert.That(Chi.CDF(dof, x), Is.EqualTo(expected).Within(13)); //double expected = SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x * x / 2.0) / SpecialFunctions.Gamma(dof / 2.0); //Assert.AreEqual(expected, n.CumulativeDistribution(x)); //Assert.AreEqual(expected, Chi.CDF(dof, x)); }
public void chi() { var rand = new Random(Seed); var r = 10; var chi = new Chi(r, rand); Assert.True(Math.Abs(0.05 - chi.GetCdf(3.94)) < 0.001); Assert.True(Math.Abs(0.999 - chi.GetCdf(29.59)) < 0.001); }
public void inverse_chi() { var rand = new Random(Seed); var n = 1000; var r = 10; var chi = new Chi(r, rand); var samples = chi.GenerateSample(n); Assert.True(Math.Abs(r - samples.Mean()) < 0.5); Assert.True(Math.Abs(2 * r - samples.Variance()) < 1.5); }
public static void chi_square_noncentral_cdf_values_test() //****************************************************************************80 // // Purpose: // // CHI_SQUARE_NONCENTRAL_CDF_VALUES_TEST tests CHI_SQUARE_NONCENTRAL_CDF_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 February 2007 // // Author: // // John Burkardt // { int df = 0; double fx = 0; double lambda = 0; double x = 0; Console.WriteLine(""); Console.WriteLine("CHI_SQUARE_NONCENTRAL_CDF_VALUES_TEST:"); Console.WriteLine(" CHI_SQUARE_NONCENTRAL_CDF_VALUES returns values of"); Console.WriteLine(" the noncentral Chi-Squared Cumulative Density Function."); Console.WriteLine(""); Console.WriteLine(" X LAMBDA DF CDF"); Console.WriteLine(""); int n_data = 0; for (;;) { Chi.chi_square_noncentral_cdf_values(ref n_data, ref df, ref lambda, ref x, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + x.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + lambda.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + df.ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + ""); } }
public static void scaled_inverse_chi_square_pdf_values_test( ) //****************************************************************************80 // // Purpose: // // SCALED_INVERSE_CHI_SQUARE_PDF_VALUES_TEST tests SCALED_INVERSE_CHI_SQUARE_PDF_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 05 August 2015 // // Author: // // John Burkardt // { double df = 0; double fx = 0; double x = 0; double xi = 0; Console.WriteLine(""); Console.WriteLine("SCALED_INVERSE_CHI_SQUARE_PDF_VALUES_TEST:"); Console.WriteLine(" SCALED_INVERSE_CHI_SQUARE_PDF_VALUES returns values of "); Console.WriteLine(" the scaled inverse Chi-Square Probability Density Function."); Console.WriteLine(""); Console.WriteLine(" DF XI X PDF"); Console.WriteLine(""); int n_data = 0; for ( ; ;) { Chi.scaled_inverse_chi_square_pdf_values(ref n_data, ref df, ref xi, ref x, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + df.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + xi.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + x.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + ""); } }
public static void chi_values_test() //****************************************************************************80 // // Purpose: // // CHI_VALUES_TEST tests CHI_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 June 2007 // // Author: // // John Burkardt // { double fx = 0; double x = 0; Console.WriteLine(""); Console.WriteLine("CHI_VALUES_TEST:"); Console.WriteLine(" CHI_VALUES stores values of"); Console.WriteLine(" the Hyperbolic Cosine Integral function CHI(X)."); Console.WriteLine(""); Console.WriteLine(" X CHI(X)"); Console.WriteLine(""); int n_data = 0; for (;;) { Chi.chi_values(ref n_data, ref x, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + " " + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + ""); } }
public static double maxwell_sample(double a, ref int seed) //****************************************************************************80 // // Purpose: // // MAXWELL_SAMPLE samples the Maxwell PDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 October 2004 // // Author: // // John Burkardt // // Parameters: // // Input, double A, the parameter of the PDF. // 0 < A. // // Input/output, int &SEED, a seed for the random number generator. // // Output, double MAXWELL_SAMPLE, a sample of the PDF. // { const double a2 = 3.0; double x = Chi.chi_square_sample(a2, ref seed); x = a * Math.Sqrt(x); return(x); }
public void ValidateCumulativeDistribution(double dof, double x) { var n = new Chi(dof); Assert.AreEqual<double>(SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x * x / 2.0) / SpecialFunctions.Gamma(dof / 2.0), n.CumulativeDistribution(x)); }
public void ValidateMode(double dof) { var n = new Chi(dof); if (dof >= 1) { Assert.AreEqual<double>(Math.Sqrt(dof - 1), n.Mode); } }
public void ValidateVariance(double dof) { var n = new Chi(dof); Assert.AreEqual(dof - (n.Mean * n.Mean), n.Variance); }
public void ValidateDensityLn(double dof, double x) { var n = new Chi(dof); Assert.AreEqual<double>((1.0 - dof / 2.0) * Math.Log(2.0) + (dof - 1.0) * Math.Log(x) - x * x / 2.0 - SpecialFunctions.GammaLn(dof / 2.0), n.DensityLn(x)); }
public void ValidateToString() { var n = new Chi(1.0); Assert.AreEqual("Chi(DoF = 1)", n.ToString()); }
public void CanSample() { var n = new Chi(1.0); n.Sample(); }
public IActionResult Status() { Chi myChi = new Chi(); return(View("Status", myChi)); }
public void ChiCreateFailsWithBadParameters(double dof) { var n = new Chi(dof); }
public void CanSetDoF(double dof) { var n = new Chi(1.0); n.DegreesOfFreedom = dof; }
public void CanCreateChi(double dof) { var n = new Chi(dof); Assert.AreEqual<double>(dof, n.DegreesOfFreedom); }
public void ValidateVariance(double dof) { var n = new Chi(dof); Assert.AreEqual<double>(dof - n.Mean * n.Mean, n.Variance); }
public void ValidateStdDev(double dof) { var n = new Chi(dof); Assert.AreEqual<double>(Math.Sqrt(n.Variance), n.StdDev); }
public void CanCreateChi(double dof) { var n = new Chi(dof); Assert.AreEqual(dof, n.DegreesOfFreedom); }
public void CanSampleSequence() { var n = new Chi(1.0); var ied = n.Samples(); ied.Take(5).ToArray(); }
public void ValidateMean(double dof) { var n = new Chi(dof); Assert.AreEqual(Constants.Sqrt2 * (SpecialFunctions.Gamma((dof + 1.0) / 2.0) / SpecialFunctions.Gamma(dof / 2.0)), n.Mean); }
public void CanCreateChi([Values(1.0, 3.0, Double.PositiveInfinity)] double dof) { var n = new Chi(dof); Assert.AreEqual(dof, n.DegreesOfFreedom); }
public void ValidateMean(double dof) { var n = new Chi(dof); Assert.AreEqual<double>(Math.Sqrt(2) * (SpecialFunctions.Gamma((dof + 1.0) / 2.0) / SpecialFunctions.Gamma(dof / 2.0)), n.Mean); }
public void SetDofFailsWithNonPositiveDoF([Values(-1.0, -0.0, 0.0)] double dof) { var n = new Chi(1.0); Assert.Throws<ArgumentOutOfRangeException>(() => n.DegreesOfFreedom = dof); }
public void ValidateMinimum() { var n = new Chi(1.0); Assert.AreEqual(0.0, n.Minimum); }
public void ValidateDensity(double dof, double x) { var n = new Chi(dof); Assert.AreEqual<double>((Math.Pow(2.0, 1.0 - dof / 2.0) * Math.Pow(x, dof - 1.0) * Math.Exp(-x * x / 2.0)) / SpecialFunctions.Gamma(dof / 2.0), n.Density(x)); }
public void ValidateDensityLn(double dof, double x) { var n = new Chi(dof); Assert.AreEqual(((1.0 - (dof / 2.0)) * Math.Log(2.0)) + ((dof - 1.0) * Math.Log(x)) - (x * (x / 2.0)) - SpecialFunctions.GammaLn(dof / 2.0), n.DensityLn(x)); }
public void ValidateStdDev(double dof) { var n = new Chi(dof); Assert.AreEqual(Math.Sqrt(n.Variance), n.StdDev); }
public void ValidateMedian() { var n = new Chi(1.0); var median = n.Median; }
public void ValidateMedianThrowsNotSupportedException() { var n = new Chi(1.0); Assert.Throws <NotSupportedException>(() => { var median = n.Median; }); }
public void ValidateMaximum() { var n = new Chi(1.0); Assert.AreEqual(Double.PositiveInfinity, n.Maximum); }
public void ValidateMedianThrowsNotSupportedException() { var n = new Chi(1.0); Assert.Throws<NotSupportedException>(() => { var median = n.Median; }); }
public void ValidateMean([Values(1.0, 2.0, 2.5, 5.0, Double.PositiveInfinity)] double dof) { var n = new Chi(dof); Assert.AreEqual(Math.Sqrt(2) * (SpecialFunctions.Gamma((dof + 1.0) / 2.0) / SpecialFunctions.Gamma(dof / 2.0)), n.Mean); }
public void ValidateToString() { var n = new Chi(1.0); Assert.AreEqual("Chi(k = 1)", n.ToString()); }
public void ValidateVariance([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof) { var n = new Chi(dof); Assert.AreEqual(dof - (n.Mean * n.Mean), n.Variance); }
/// <summary> /// Run example /// </summary> /// <a href="http://en.wikipedia.org/wiki/Chi_distribution">Chi distribution</a> public void Run() { // 1. Initialize the new instance of the Chi distribution class with parameter dof = 1. var chi = new Chi(1); Console.WriteLine(@"1. Initialize the new instance of the Chi distribution class with parameter DegreesOfFreedom = {0}", chi.DegreesOfFreedom); Console.WriteLine(); // 2. Distributuion properties: Console.WriteLine(@"2. {0} distributuion properties:", chi); // Cumulative distribution function Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", chi.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000")); // Probability density Console.WriteLine(@"{0} - Probability density at location '0.3'", chi.Density(0.3).ToString(" #0.00000;-#0.00000")); // Log probability density Console.WriteLine(@"{0} - Log probability density at location '0.3'", chi.DensityLn(0.3).ToString(" #0.00000;-#0.00000")); // Entropy Console.WriteLine(@"{0} - Entropy", chi.Entropy.ToString(" #0.00000;-#0.00000")); // Largest element in the domain Console.WriteLine(@"{0} - Largest element in the domain", chi.Maximum.ToString(" #0.00000;-#0.00000")); // Smallest element in the domain Console.WriteLine(@"{0} - Smallest element in the domain", chi.Minimum.ToString(" #0.00000;-#0.00000")); // Mean Console.WriteLine(@"{0} - Mean", chi.Mean.ToString(" #0.00000;-#0.00000")); // Mode Console.WriteLine(@"{0} - Mode", chi.Mode.ToString(" #0.00000;-#0.00000")); // Variance Console.WriteLine(@"{0} - Variance", chi.Variance.ToString(" #0.00000;-#0.00000")); // Standard deviation Console.WriteLine(@"{0} - Standard deviation", chi.StdDev.ToString(" #0.00000;-#0.00000")); // Skewness Console.WriteLine(@"{0} - Skewness", chi.Skewness.ToString(" #0.00000;-#0.00000")); Console.WriteLine(); // 3. Generate 10 samples of the Chi distribution Console.WriteLine(@"3. Generate 10 samples of the Chi distribution"); for (var i = 0; i < 10; i++) { Console.Write(chi.Sample().ToString("N05") + @" "); } Console.WriteLine(); Console.WriteLine(); // 4. Generate 100000 samples of the Chi(1) distribution and display histogram Console.WriteLine(@"4. Generate 100000 samples of the Chi(1) distribution and display histogram"); var data = new double[100000]; for (var i = 0; i < data.Length; i++) { data[i] = chi.Sample(); } ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 5. Generate 100000 samples of the Chi(2) distribution and display histogram Console.WriteLine(@"5. Generate 100000 samples of the Chi(2) distribution and display histogram"); chi.DegreesOfFreedom = 2; for (var i = 0; i < data.Length; i++) { data[i] = chi.Sample(); } ConsoleHelper.DisplayHistogram(data); Console.WriteLine(); // 6. Generate 100000 samples of the Chi(5) distribution and display histogram Console.WriteLine(@"6. Generate 100000 samples of the Chi(5) distribution and display histogram"); chi.DegreesOfFreedom = 5; for (var i = 0; i < data.Length; i++) { data[i] = chi.Sample(); } ConsoleHelper.DisplayHistogram(data); }
public void ValidateStdDev([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof) { var n = new Chi(dof); Assert.AreEqual(Math.Sqrt(n.Variance), n.StdDev); }