public void ErrorFunctionComplementarity() { foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 8)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedMath.Erf(x) + AdvancedMath.Erfc(x), 1.0)); } }
public void InverseErfTest() { foreach (double P in TestUtilities.GenerateRealValues(1.0E-8, 1.0, 16)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedMath.Erf(AdvancedMath.InverseErf(P)), P)); Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedMath.Erfc(AdvancedMath.InverseErfc(P)), P)); } }
public void Bug5705() { // large arguments to Erf and Erfc would cause a NonconvergeException because of the way the continued fraction for GammaQ // was evaluated; we added an explicit test before entering the evaluation loop to avoid this Assert.IsTrue(AdvancedMath.Erf(Double.NegativeInfinity) == -1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.NegativeInfinity) == 2.0); Assert.IsTrue(AdvancedMath.Erf(Double.MinValue) == -1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.MinValue) == 2.0); Assert.IsTrue(AdvancedMath.Erf(Double.MaxValue) == 1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.MaxValue) == 0.0); Assert.IsTrue(AdvancedMath.Erf(Double.PositiveInfinity) == 1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.PositiveInfinity) == 0.0); // we should add tests of the behavior of all our advanced functions with large/infinite arguments }
public static double BLAST_SpougeStoE(int y_, Blast_KarlinBlk kbp, Blast_GumbelBlk gbp, int m_, int n_) { // the score and lambda may have been rescaled. We will compute the scaling factor // and use it to scale a, alpha, and Sigma similarly. double scale_factor = kbp.Lambda / gbp.Lambda; // the pair-wise e-value must be scaled back to db-wise e-value double db_scale_factor = (gbp.db_length.HasValue) ? (double)gbp.db_length.Value / (double)n_ : 1.0; double lambda_ = kbp.Lambda; double k_ = kbp.K; double ai_hat_ = gbp.a * scale_factor; double bi_hat_ = gbp.b; double alphai_hat_ = gbp.Alpha * scale_factor; double betai_hat_ = gbp.Beta; double sigma_hat_ = gbp.Sigma * scale_factor; double tau_hat_ = gbp.Tau; /* here we consider symmetric matrix only */ double aj_hat_ = ai_hat_; double bj_hat_ = bi_hat_; double alphaj_hat_ = alphai_hat_; double betaj_hat_ = betai_hat_; /* this is 1/sqrt(2.0*PI) */ double const_val = 0.39894228040143267793994605993438; double m_li_y, vi_y, sqrt_vi_y, m_F, P_m_F; double n_lj_y, vj_y, sqrt_vj_y, n_F, P_n_F; double c_y, p1, p2, area; double e_value; m_li_y = m_ - (ai_hat_ * y_ + bi_hat_); vi_y = Math.Max(2.0 * alphai_hat_ / lambda_, alphai_hat_ * y_ + betai_hat_); sqrt_vi_y = Math.Sqrt(vi_y); m_F = m_li_y / sqrt_vi_y; P_m_F = AdvancedMath.Erfc(-m_F / Math.Sqrt(2.0)) / 2.0; p1 = m_li_y * P_m_F + sqrt_vi_y * const_val * Math.Exp(-0.5 * m_F * m_F); n_lj_y = n_ - (aj_hat_ * y_ + bj_hat_); vj_y = Math.Max(2.0 * alphaj_hat_ / lambda_, alphaj_hat_ * y_ + betaj_hat_); sqrt_vj_y = Math.Sqrt(vj_y); n_F = n_lj_y / sqrt_vj_y; P_n_F = AdvancedMath.Erfc(-n_F / Math.Sqrt(2.0)) / 2.0; p2 = n_lj_y * P_n_F + sqrt_vj_y * const_val * Math.Exp(-0.5 * n_F * n_F); c_y = Math.Max(2.0 * sigma_hat_ / lambda_, sigma_hat_ * y_ + tau_hat_); area = p1 * p2 + c_y * P_m_F * P_n_F; e_value = area * k_ * Math.Exp(-lambda_ * y_) * db_scale_factor; //ASSERT(e_value >= 0.0); return(e_value); }
// standard normal left CDF, usually denoted by capital Phi // this is used by several other distributions, so we expose it here internal static double Phi(double z) { if (z < 0.0) { return(0.5 * AdvancedMath.Erfc(-z / Global.SqrtTwo)); } else { return(0.5 * (1.0 + AdvancedMath.Erf(z / Global.SqrtTwo))); } }
public void ErfcInequality() { foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E4, 16)) { double erfc = AdvancedMath.Erfc(x); double factor = 2.0 / Math.Sqrt(Math.PI) * Math.Exp(-x * x); double lower = factor / (x + Math.Sqrt(x * x + 2.0)); double upper = factor / (x + Math.Sqrt(x * x + 4.0 / Math.PI)); Assert.IsTrue((lower <= erfc) && (erfc <= upper)); } }
public void ErrorFunctionExtremeValues() { Assert.IsTrue(AdvancedMath.Erf(Double.MaxValue) == 1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.MaxValue) == 0.0); Assert.IsTrue(AdvancedMath.Erf(Double.PositiveInfinity) == 1.0); Assert.IsTrue(AdvancedMath.Erfc(Double.PositiveInfinity) == 0.0); Assert.IsTrue(AdvancedMath.Erf(-Double.MaxValue) == -1.0); Assert.IsTrue(AdvancedMath.Erf(Double.NegativeInfinity) == -1.0); Assert.IsTrue(Double.IsNaN(AdvancedMath.Erf(Double.NaN))); Assert.IsTrue(Double.IsNaN(AdvancedMath.Erfc(Double.NaN))); }
private double TailProbability(double x) { return(AdvancedMath.Erfc(x / Global.SqrtTwo) / ED); }
public void ErrorFunctionSpecialCases() { Assert.IsTrue(AdvancedMath.Erf(0.0) == 0.0); Assert.IsTrue(AdvancedMath.Erfc(0.0) == 1.0); }