/*============================================================================*/ double randvar_get_PHI (double x) { # define CUR_PROC "randvar_get_PHI" #ifdef DO_WITH_GSL return (gsl_sf_erf (x * M_SQRT1_2) + 1.0) / 2.0; #else int i; double phi_x; if (randvar_init_PHI () == -1) { mes_proc (); goto STOP; } /* Linear interpolation (Alternative: Round off with i=m_int(fabs(x)*X_FAKT)) */ i = (int) (fabs (x) * X_FAKT_PHI); if (i >= PHI_len - 1) { i = PHI_len - 1; phi_x = PHI[i]; } else phi_x = PHI[i] + (fabs (x) - i * X_STEP_PHI) * (PHI[i + 1] - PHI[i]) / X_STEP_PHI; /* NOTA BENE: PHI is tabulated for negative values! */ if (x > 0.0) return (1.0 - phi_x); else return (phi_x); #endif /* DO_WITH_GSL */ STOP: return (-1.0); # undef CUR_PROC } /* randvar_get_PHI */
/* cumalative distribution function of -EPS_NDT-truncated N(mean, u) */ double randvar_normal_pos_cdf (double x, double mean, double u) { # define CUR_PROC "randvar_normal_pos_cdf" #ifndef DO_WITH_GSL double Fx, c; #endif if (x <= 0.0) return (0.0); if (u <= 0.0) { mes_prot ("u <= 0.0 not allowed\n"); goto STOP; } #ifdef DO_WITH_GSL /* Function: int gsl_sf_erfc_e (double x, gsl_sf_result * result) These routines compute the complementary error function erfc(x) = 1 - erf(x) = 2/\sqrt(\pi) \int_x^\infty \exp(-t^2). */ return 1.0 + (gsl_sf_erf ((x - mean) / sqrt (u * 2)) - 1.0) / gsl_sf_erfc ((-mean) / sqrt (u * 2)); #else /*The denominator is possibly < EPS??? Check that ? */ Fx = randvar_get_PHI ((x - mean) / sqrt (u)); c = randvar_get_1overa (-EPS_NDT, mean, u); return (c * (Fx - 1) + 1); #endif /* DO_WITH_GSL */ STOP: return (-1.0); # undef CUR_PROC } /* double randvar_normal_cdf */
/* ------------------------------------------------------ */ gsl_complex gsl_complex_erf (gsl_complex a) { gsl_complex z; GSL_SET_COMPLEX (&z, gsl_sf_erf(GSL_REAL(a)), 0); return z; }
/* the GSL headers specify double x, not const double x */ double FC_FUNC_(oct_erf, OCT_ERF) (const double *x) { /* avoid floating invalids in the asymptotic limit */ if(*x > 20.0) return 1.0; if(*x < -20.0) return -1.0; /* otherwise call gsl */ return gsl_sf_erf(*x); }
double normalized_erf( Doblst a, double t ) { return 0.5 * a[0] * (1 + gsl_sf_erf( sqrt(a[1]) * (t - a[2]) ) ) ; // Yi = p(t).(r0+r1.t+r2.t^2) + (1-p(t)).(l0+l1.t+l2.t^2) + // + sum( ai.exp(-ki.(t-ci)^2), i=0..nPk-1 ) // where // p(t) = sum(ai/sum(a)*(1/2).[1+erf(sqrt(ki).(t-ci))], i=0..nPk-1 // ki are constant parameters received from gsl // }
double kolmogorov_gauss(double* values) { double m = 0, cv=0, ce=0; gsl_sort(values, 1, N); int i; for (i = 0; i < N; ++i) { m = fmax( m, fabs( i*1.0/N - 0.5 - 0.5*gsl_sf_erf(values[i] / sqrt(2.0)) ) ); } return m * sqrt(N); }
void CroppedGaussianProfile::setPrecision(double eps) { this->GaussianProfile::setPrecision(eps); double eps1 = this->getPrecision(); mscale = 1.0; if (eps1 < 1) { double area = gsl_sf_erf(sqrt(-log(eps1))); mscale = 1.0 / area; } }
scalar sasfit_peak_ExponentiallyModifiedGaussianArea(scalar x, sasfit_param * param) { scalar y, bckgr, area, center, width, distortion; SASFIT_ASSERT_PTR( param ); sasfit_get_param(param, 5, &area, ¢er, &width, &distortion, &bckgr); SASFIT_CHECK_COND1((width <= 0), param, "width(%lg) <= 0 ",width); SASFIT_CHECK_COND1((distortion == 0), param, "distortion(%lg) == 0 ",distortion); y = bckgr+area/(2*distortion) * exp(pow(width/distortion,2)/2.+(center-x)/distortion) * (gsl_sf_erf((x-center)/(sqrt(2)*width)-width/(sqrt(2)*distortion))+distortion/fabs(distortion)); return y; }
/* cumalative distribution function of N(mean, u) */ double randvar_normal_cdf (double x, double mean, double u) { # define CUR_PROC "randvar_normal_cdf" if (u <= 0.0) { mes_prot ("u <= 0.0 not allowed\n"); goto STOP; } #ifdef DO_WITH_GSL /* PHI(x)=erf(x/sqrt(2))/2+0.5 */ return (gsl_sf_erf ((x - mean) / sqrt (u * 2.0)) + 1.0) / 2.0; #else /* The denominator is possibly < EPS??? Check that ? */ return (randvar_get_PHI ((x - mean) / sqrt (u))); #endif /* DO_WITH_GSL */ STOP: return (-1.0); # undef CUR_PROC } /* double randvar_normal_cdf */
scalar sasfit_ff_beaucage_exppowlaw_2(scalar q, sasfit_param * param) { SASFIT_ASSERT_PTR(param); // assert pointer param is valid SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((G < 0.0), param, "G(%lg) < 0",G); // modify condition to your needs SASFIT_CHECK_COND1((B < 0.0), param, "B(%lg) < 0",B); // modify condition to your needs SASFIT_CHECK_COND1((R_I < 0.0), param, "R_i(%lg) < 0",R_I); // modify condition to your needs SASFIT_CHECK_COND1((R_Ip1 < 0.0), param, "R_i+1(%lg) < 0",R_Ip1); // modify condition to your needs SASFIT_CHECK_COND1((K < 0.0), param, "k(%lg) < 0",K); // modify condition to your needs SASFIT_CHECK_COND1((P < 0.0), param, "P(%lg) < 0",P); // modify condition to your needs // insert your code here scalar x, xs, tmp; x = q*R_I; xs = q*R_Ip1; tmp = gsl_pow_3( gsl_sf_erf(x *K /sqrt(6.)) ) / q; return G*exp(-x*x/3.0) + B*exp(-xs*xs/3.)*pow(tmp,P); }
int main() { typedef double T; #define SC_(x) static_cast<double>(x) # include "erf_small_data.ipp" # include "erf_data.ipp" # include "erf_large_data.ipp" add_data(erf_small_data); add_data(erf_data); add_data(erf_large_data); unsigned data_total = data.size(); screen_data([](const std::vector<double>& v){ return boost::math::erf(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return ::erf(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return std::tr1::erf(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) screen_data([](const std::vector<double>& v){ return gsl_sf_erf(v[0]); }, [](const std::vector<double>& v){ return v[1]; }); #endif unsigned data_used = data.size(); std::string function = "erf[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "erf"; double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::erf(v[0]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); // // Boost again, but with promotion to long double turned off: // #if !defined(COMPILER_COMPARISON_TABLES) if(sizeof(long double) != sizeof(double)) { double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::erf(v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX)) report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); #endif report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>"); } #endif #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return ::erf(v[0]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "math.h"); #endif #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::erf(v[0]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath"); #endif #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_erf(v[0]); }); std::cout << time << std::endl; report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); #endif return 0; }
double erf_i (Doblst a, double t) // a[0] is NOT used, it´s Ok. { return 0.5 * (1 + gsl_sf_erf( sqrt(a[1]) * (t - a[2]) ) ); }
double call(double x){ return gsl_sf_erf (x); }
static VALUE Error_erf(VALUE self, VALUE x) { return rb_float_new(gsl_sf_erf(NUM2DBL(x))); }
void geterf_(double *xanderfx) { xanderfx[1] = gsl_sf_erf(xanderfx[0]); }
void Potential::generate_local_potential() { PROFILE_WITH_TIMER("sirius::Potential::generate_local_potential"); mdarray<double, 2> vloc_radial_integrals(unit_cell_.num_atom_types(), ctx_.gvec().num_shells()); /* split G-shells between MPI ranks */ splindex<block> spl_gshells(ctx_.gvec().num_shells(), comm_.size(), comm_.rank()); #pragma omp parallel { /* splines for all atom types */ std::vector< Spline<double> > sa(unit_cell_.num_atom_types()); for (int iat = 0; iat < unit_cell_.num_atom_types(); iat++) sa[iat] = Spline<double>(unit_cell_.atom_type(iat).radial_grid()); #pragma omp for for (int igsloc = 0; igsloc < spl_gshells.local_size(); igsloc++) { int igs = spl_gshells[igsloc]; for (int iat = 0; iat < unit_cell_.num_atom_types(); iat++) { auto& atom_type = unit_cell_.atom_type(iat); if (igs == 0) { for (int ir = 0; ir < atom_type.num_mt_points(); ir++) { double x = atom_type.radial_grid(ir); sa[iat][ir] = (x * atom_type.uspp().vloc[ir] + atom_type.zn()) * x; } vloc_radial_integrals(iat, igs) = sa[iat].interpolate().integrate(0); } else { double g = ctx_.gvec().shell_len(igs); double g2 = std::pow(g, 2); for (int ir = 0; ir < atom_type.num_mt_points(); ir++) { double x = atom_type.radial_grid(ir); sa[iat][ir] = (x * atom_type.uspp().vloc[ir] + atom_type.zn() * gsl_sf_erf(x)) * std::sin(g * x); } vloc_radial_integrals(iat, igs) = (sa[iat].interpolate().integrate(0) / g - atom_type.zn() * std::exp(-g2 / 4) / g2); } } } } int ld = unit_cell_.num_atom_types(); comm_.allgather(vloc_radial_integrals.at<CPU>(), ld * spl_gshells.global_offset(), ld * spl_gshells.local_size()); auto v = unit_cell_.make_periodic_function(vloc_radial_integrals, ctx_.gvec()); ctx_.fft().prepare(ctx_.gvec().partition()); ctx_.fft().transform<1>(ctx_.gvec().partition(), &v[ctx_.gvec().partition().gvec_offset_fft()]); ctx_.fft().output(&local_potential_->f_rg(0)); ctx_.fft().dismiss(); }
// ../src/tools/tools__error_function.cpp =================================================== // // // Catalyst Lib is free software: you can redistribute it and/or modifyit under the terms of // the GNU General Public License as published bythe Free Software Foundation, either version // 3 of the License, or(at your option) any later version. // // Catalyst Lib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with Catalyst Lib. // If not, see <http://www.gnu.org/licenses/>. // // ========================================================================================== // // // // /// @param [in] a A real number. // /// @brief Calls the GSL library to calculate the error function. // /// @return @f$ erf(a) @f$. // /// @cite gsl // inline double error_function(const double &a) { return gsl_sf_erf(a); };
scalar sasfit_erf_pure(scalar x) { // float gammp(); // return x < 0.0 ? -gammp(interp,0.5,x*x,error) : gammp(interp,0.5,x*x,error); return gsl_sf_erf(x); }