Beispiel #1
1
Foam::scalar Foam::pdfs::lognormal::sample() const
{

    scalar a = erf((minValue_ - expectation_)/variance_);
    scalar b = erf((maxValue_ - expectation_)/variance_);

    scalar y = rndGen_.scalar01();
    scalar x = erfInv(y*(b - a) + a)*variance_ + expectation_;

    // Note: numerical approximation of the inverse function yields slight
    //       inaccuracies

    x = min(max(exp(x), exp(minValue_)), exp(maxValue_));

    return log(x);
}
Beispiel #2
0
double
vpRobust::simultscale(vpColVector &x)
{
  unsigned int p = 6; //Number of parameters to be estimated.
  unsigned int n = x.getRows();
  double sigma2=0;
  /* long */ double Expectation=0;
  /* long */ double Sum_chi=0;
  /* long */ double chiTmp =0;

  for(unsigned int i=0; i<n; i++)
  {

    chiTmp = simult_chi_huber(x[i]);
    Expectation += chiTmp*(1-erf(chiTmp));
    Sum_chi += chiTmp;

#ifdef VP_DEBUG
#if VP_DEBUG_MODE == 3
    {
      std::cout << "erf = " << 1-erf(chiTmp) << std::endl;
      std::cout << "x[i] = " << x[i] <<std::endl;
      std::cout << "chi = " << chiTmp << std::endl;
      std::cout << "Sum chi = " << chiTmp*vpMath::sqr(sig_prev) << std::endl;
      std::cout << "Expectation = " << chiTmp*(1-erf(chiTmp)) << std::endl;
      //getchar();
    }
#endif
#endif
  }


  sigma2 = Sum_chi*vpMath::sqr(sig_prev)/((n-p)*Expectation);

#ifdef VP_DEBUG
#if VP_DEBUG_MODE == 3
  {
    std::cout << "Expectation = " << Expectation << std::endl;
    std::cout << "Sum chi = " << Sum_chi << std::endl;
    std::cout << "sig_prev" << sig_prev << std::endl;
    std::cout << "sig_out" << sqrt(fabs(sigma2)) << std::endl;
  }
#endif
#endif

  return sqrt(fabs(sigma2));

}
Beispiel #3
0
Foam::scalar Foam::distributionModels::normal::sample() const
{

    scalar a = erf((minValue_ - expectation_)/variance_);
    scalar b = erf((maxValue_ - expectation_)/variance_);

    scalar y = rndGen_.sample01<scalar>();
    scalar x = erfInv(y*(b - a) + a)*variance_ + expectation_;

    // Note: numerical approximation of the inverse function yields slight
    //       inaccuracies

    x = min(max(x, minValue_), maxValue_);

    return x;
}
Beispiel #4
0
static double trans_unif(double x , const arg_pack_type * arg) {
  double y;
  double min   = arg_pack_iget_double(arg , 0);
  double max   = arg_pack_iget_double(arg , 1);
  y = 0.5*(1 + erf(x/sqrt(2.0))); /* 0 - 1 */
  return y * (max - min) + min;
}
Beispiel #5
0
 double function(const double phi, double **data)
 {
   double alfa = (*data[2]);
   double tau = (*data[3]); 
   double X = erf((tau * phi - alfa) / sqrt((1 - tau) * (1 + tau)));
   return X * X * exp(- phi * phi / 2); // / (*data[4]);
 }
Beispiel #6
0
double
Partitioner::CodeCriteria::get_vote(const RegionStats *stats, std::vector<double> *votes) const
{
    if (votes!=NULL)
        votes->resize(dictionary.size(), NAN);

    double sum=0.0, total_wt=0.0;
    for (size_t cc_id=0; cc_id<criteria.size(); ++cc_id) {
        if (criteria[cc_id].weight <= 0.0)
            continue;

        size_t stat_id = stats->find_analysis(get_name(cc_id));
        if (-1==(ssize_t)stat_id)
            continue;

        double stat_val = stats->get_value(stat_id);
        if (!std::isnan(stat_val)) {
            double c = 0.0==criteria[cc_id].variance ?
                       (stat_val==criteria[cc_id].mean ? 1.0 : 0.0) :
                       1 + erf(-fabs(stat_val-criteria[cc_id].mean) / sqrt(2*criteria[cc_id].variance));
            if (votes)
                (*votes)[cc_id] = c;
            if (!std::isnan(c)) {
                sum += c * criteria[cc_id].weight;
                total_wt += criteria[cc_id].weight;
            }
        }
    }
    return total_wt>0.0 ? sum / total_wt : NAN;
}
Beispiel #7
0
//! inverse error function is taken from NIST
double userFunctions::erfinv (double x)
{
    if (x < -1 || x > 1)
        return NAN;
    
    if (x == 0)
        return 0;
    
    int  sign_x;
    if (x > 0) {
        sign_x = 1;
    } else {
        sign_x = -1;
        x = -x;
    }
    
    double r;
    if (x <= 0.686) {
        double x2 = x * x;
        r = x * (((-0.140543331 * x2 + 0.914624893) * x2 + -1.645349621) * x2 + 0.886226899);
        r /= (((0.012229801 * x2 + -0.329097515) * x2 + 1.442710462) * x2 + -2.118377725) * x2 + 1;
    } else {
        double y = sqrt (-log((1 - x) / 2));
        r = (((1.641345311 * y + 3.429567803) * y + -1.62490649) * y + -1.970840454);
        r /= ((1.637067800 * y + 3.543889200) * y + 1);
    }
    
    r *= sign_x;
    x *= sign_x;
    
    r -= (erf(r) - x) / (2 / sqrt (M_PI) * exp(-r*r));
    
    return r;
}
Beispiel #8
0
double ndtr(double a)
{
double x, y, z;

if (isnan(a)) {
  mtherr("ndtr", DOMAIN);
  return (NAN);
}

x = a * SQRTH;
z = fabs(x);

if( z < SQRTH )
	y = 0.5 + 0.5 * erf(x);

else
	{
	y = 0.5 * erfc(z);

	if( x > 0 )
		y = 1.0 - y;
	}

return(y);
}
static double
l_erf(char *nm)
{
    extern double  erf();

    return(erf(argument(1)));
}
Beispiel #10
0
/*c.d.f of Standard Normal*/
double Phi(double x)
{
  double tmp=x/sqrt(2.);
  tmp=1+erf(tmp); 

  return tmp/2;
}
Beispiel #11
0
double
cephes_normal(double x)
{
	double arg, result, sqrt2=1.414213562373095048801688724209698078569672;

	if (x > 0) {
		arg = x/sqrt2;
		result = 0.5 * ( 1 + erf(arg) );
	}
	else {
		arg = -x/sqrt2;
		result = 0.5 * ( 1 - erf(arg) );
	}

	return( result);
}
void Foam::equationReader::evalDimsErfDimCheck
(
    const equationReader * eqnReader,
    const label index,
    const label i,
    const label storageOffset,
    label& storeIndex,
    dimensionSet& xDims,
    dimensionSet sourceDims
) const
{
    if
    (
        !xDims.dimensionless() && dimensionSet::debug
    )
    {
        WarningIn("equationReader::evalDimsErfDimCheck")
            << "Dimension error thrown for operation ["
            << equationOperation::opName
            (
                operator[](index)[i].operation()
            )
            << "] in equation " << operator[](index).name()
            << ", given by:" << token::NL << token::TAB
            << operator[](index).rawText();
    }
    dimensionedScalar ds("temp", xDims, 0.0);
    xDims.reset(erf(ds).dimensions());
    operator[](index)[i].assignOpDimsFunction
    (
        &Foam::equationReader::evalDimsErf
    );
}
Beispiel #13
0
ex evalf( const ex& x )
{
	if( is_a<numeric>(x) )
		return bealab::erf( ex_to<numeric>(x).to_double() );
	else
		return erf(x).hold();
}
Beispiel #14
0
ATF_TC_BODY(erf_inf_pos, tc)
{
	const double x = 1.0L / 0.0L;

	if (erf(x) != 1.0)
		atf_tc_fail_nonfatal("erf(+Inf) != 1.0");
}
Beispiel #15
0
/* ************************************************************************** */
solreal BoysFunction(const int m,solreal x)
{
   static const solreal srpo2=0.88622692545275801365e0; //$\sqrt{\pi}/2$
   solreal srx=sqrt(x);
   solreal F0=srpo2*erf(srx)/srx;
   if (m==0) {return F0;}
   solreal emx=exp(-x);
   solreal oo2x=0.5e0/x;
   if (m==1) {return ((F0-emx)*oo2x);}
   solreal oo2x2=oo2x*oo2x;
   if (m==2) {return (3.0e0*F0*oo2x2-emx*(oo2x+3.0e0*oo2x2));}
   solreal oo2x3=oo2x*oo2x2;
   if (m==3) {return (15.0e0*F0*oo2x3-emx*(oo2x+5.0e0*oo2x2+15.0e0*oo2x3));}
   solreal oo2x4=oo2x2*oo2x2;
   //std::cout << "oo2x4: " << oo2x4 << std::endl;
   if (m==4) {return (105.0e0*F0*oo2x4-emx*(oo2x+7.0e0*oo2x2+35.0e0*oo2x3+105.0e0*oo2x4));}
   solreal oo2x5=oo2x3*oo2x2;
   //std::cout << "oo2x5: " << oo2x5 << std::endl;
   if (m==5) {
      return (945.0e0*F0*oo2x5-emx*(oo2x+9.0e0*oo2x2+63.0e0*oo2x3+315.0e0*oo2x4+945.0e0*oo2x5));
   }
   solreal oo2x6=oo2x3*oo2x3;
   //std::cout << "oo2x6: " << oo2x6 << std::endl;
   if (m==6) {
      return (10395.0e0*F0*oo2x6-emx*(oo2x+11.0e0*oo2x2+99.0e0*oo2x3+693.0e0*oo2x4
                                       +3465.0e0*oo2x5+10395.0e0*oo2x6));
   }
#if DEBUG
   std::cout << "This value of m (" << m << ") is not implemented yet..." << std::endl;
#endif
   return 0.0e0;
}
Beispiel #16
0
 float g1(const Vector& v, const Vector& m) const {
   if(dot(v, m) * Bsdf::cos_theta(v) <= 0.f) {
     return 0.f;
   }
   float a = Bsdf::cos_theta(v) / (this->alpha_b * Bsdf::sin_theta(v));
   return 2.f / (1.f + erf(a) + exp(-square(a)) / (a * SQRT_PI));
 }
int main() {
    double x = 1.0;
    double y = 1.0;
    int i = 1;
    acosh(x);
    asinh(x);
    atanh(x);
    cbrt(x);
    expm1(x);
    erf(x);
    erfc(x);
    isnan(x);
    j0(x);
    j1(x);
    jn(i,x);
    ilogb(x);
    logb(x);
    log1p(x);
    rint(x);
    y0(x);
    y1(x);
    yn(i,x);
#   ifdef _THREAD_SAFE
    gamma_r(x,&i);
    lgamma_r(x,&i);
#   else
    gamma(x);
    lgamma(x);
#   endif
    hypot(x,y);
    nextafter(x,y);
    remainder(x,y);
    scalb(x,y);
    return 0;
}
Beispiel #18
0
int main(void)
{
	#pragma STDC FENV_ACCESS ON
	double y;
	float d;
	int e, i, err = 0;
	struct d_d *p;

	for (i = 0; i < sizeof t/sizeof *t; i++) {
		p = t + i;

		if (p->r < 0)
			continue;
		fesetround(p->r);
		feclearexcept(FE_ALL_EXCEPT);
		y = erf(p->x);
		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);

		if (!checkexcept(e, p->e, p->r)) {
			printf("%s:%d: bad fp exception: %s erf(%a)=%a, want %s",
				p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
			printf(" got %s\n", estr(e));
			err++;
		}
		d = ulperr(y, p->y, p->dy);
		if (!checkulp(d, p->r)) {
			printf("%s:%d: %s erf(%a) want %a got %a ulperr %.3f = %a + %a\n",
				p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
			err++;
		}
	}
	return !!err;
}
Beispiel #19
0
double Novosibirsk::Normalisation(PhaseSpaceBoundary * boundary)
{
	(void) boundary;
	
	// Get the physics parameters
	width = allParameters.GetPhysicsParameter( widthName )->GetValue();
	peak  = allParameters.GetPhysicsParameter( peakName )->GetValue();
	tail  = allParameters.GetPhysicsParameter( tailName )->GetValue();

	double tailLog4 = tail * sqrt(log(4.));
	double widthLog4 = width * sqrt(log(4.));
	double _sinh = sinh(tailLog4);
	double _csch = 1./sinh(tailLog4);
	
	double val(0.);

	double xhigh = 0.12;
	double xlow = 0.;
	
	//cout << - width*tail*sqrt(TMath::Pi()*log(2.))*_csch*erf( ( tail*tail - log( (xhigh - peak)*_sinh/widthLog4 + 1. ) ) / (sqrt(2.)*tail) ) << endl;
	//cout << + width*tail*sqrt(TMath::Pi()*log(2.))*_csch*erf( ( tail*tail - log( (xlow  - peak)*_sinh/widthLog4 + 1. ) ) / (sqrt(2.)*tail) ) << endl;

	val = - width*tail*sqrt(TMath::Pi()*log(2.))*_csch*erf( ( tail*tail - log( (xhigh - peak)*_sinh/widthLog4 + 1. ) ) / (sqrt(2.)*tail) );
	      //+ width*tail*sqrt(TMath::Pi()*log(2.))*_csch*erf( ( tail*tail - log( (xlow  - peak)*_sinh/widthLog4 + 1. ) ) / (sqrt(2.)*tail) );

	return 2.*val;
}
Beispiel #20
0
/* Implementation of complementary Error function */
double
erfc(double x)
{
  static const double one_sqrtpi=  0.564189583547756287;
  double a = 1;
  double b = x;
  double c = x;
  double d = x*x+0.5;
  double q1;
  double q2 = b/d;
  double n = 1.0;
  double t;
  if (fabs(x) < 2.2) {
    return 1.0 - erf(x);
  }
  if (x < 0.0) { /*signbit(x)*/
    return 2.0 - erfc(-x);
  }
  do {
    t  = a*n+b*x;
    a  = b;
    b  = t;
    t  = c*n+d*x;
    c  = d;
    d  = t;
    n += 0.5;
    q1 = q2;
    q2 = b/d;
  } while (fabs(q1-q2)/q2 > MATH_TOLERANCE);
  return one_sqrtpi*exp(-x*x)*q2;
}
Beispiel #21
0
ATF_TC_BODY(erf_inf_neg, tc)
{
	const double x = -1.0L / 0.0L;

	if (erf(x) != -1.0)
		atf_tc_fail_nonfatal("erf(-Inf) != -1.0");
}
Beispiel #22
0
/*************************************************************************
Normal distribution function

Returns the area under the Gaussian probability density
function, integrated from minus infinity to x:

                           x
                            -
                  1        | |          2
   ndtr(x)  = ---------    |    exp( - t /2 ) dt
              sqrt(2pi)  | |
                          -
                         -inf.

            =  ( 1 + erf(z) ) / 2
            =  erfc(z) / 2

where z = x/sqrt(2). Computation is via the functions
erf and erfc.


ACCURACY:

                     Relative error:
arithmetic   domain     # trials      peak         rms
   IEEE     -13,0        30000       3.4e-14     6.7e-15

Cephes Math Library Release 2.8:  June, 2000
Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
*************************************************************************/
double normaldistribution(double x)
{
    double result;

    result = 0.5*(erf(x/1.41421356237309504880)+1);
    return result;
}
// Combines p-values using Z-score.
double Zscore_combined_pvalue(std::vector<double> &pvals) {

  unsigned long i;
  double z, zcomb, pcomb;

  zcomb = 0.;
  for (i=0; i < pvals.size(); i++) {

    // If some p-value is 0, the score will be 0.
    if (pvals[i] <= 0) {
      return 0;
    }

    // If some p-value is 1, the score will be 1.
    if (pvals[i] >= 1) {
      return 1;
    }

    z = sqrt(2)*boost::math::erf_inv(2*(1-pvals[i]) - 1);       // Sure ???
    zcomb = zcomb + z;
  }
  zcomb = zcomb / sqrt((double) pvals.size());
  pcomb = 1 - 0.5*(1+erf(zcomb/sqrt(2)));
  return pcomb;
}
Beispiel #24
0
int main() {
    printf(
        "The integral of a Normal(0, 1) distribution between -1.96 and 1.96 "
        "is: %g\n", erf(1.96 * sqrt(1/2))
    );
    return 0;
}
Beispiel #25
0
/* cumalative distribution function of a-truncated N(mean, u) */
double ighmm_rand_normal_right_cdf (double x, double mean, double u, double a)
{
# define CUR_PROC "ighmm_rand_normal_right_cdf"

  if (x <= a)
    return (0.0);
  if (u <= a) {
    GHMM_LOG(LCONVERTED, "u <= a not allowed\n");
    goto STOP;
  }
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  /*
     Function: int erfc (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 + (erf ((x - mean) / sqrt (u * 2)) -
                1.0) / erfc ((a - mean) / sqrt (u * 2));
#else
  return 1.0 + (ighmm_erf ((x - mean) / sqrt (u * 2)) -
                1.0) / ighmm_erfc ((a - mean) / sqrt (u * 2));
#endif /* Check for ISO C99 */
STOP:
  return (-1.0);
# undef CUR_PROC
}                               /* double ighmm_rand_normal_cdf */
Beispiel #26
0
 function erf_x_over_x ()
     {
     if ($1 == 0)
         return mu;
     else
         return erf($1)/$1;
     }
Beispiel #27
0
int main(int argc, char **argv) {
    try {
        std::vector<Common::UString> args;
        Common::Platform::getParameters(argc, argv, args);

        Aurora::GameID game = Aurora::kGameIDUnknown;

        int returnValue = 1;
        Command command = kCommandNone;
        Common::UString archive;
        std::set<Common::UString> files;
        std::vector<byte> password;

        if (!parseCommandLine(args, returnValue, command, archive, files, game, password))
            return returnValue;

        Aurora::ERFFile erf(new Common::ReadFile(archive), password);

        if      (command == kCommandInfo)
            displayInfo(erf);
        else if (command == kCommandList)
            listFiles(erf, game);
        else if (command == kCommandListVerbose)
            listVerboseFiles(erf, game);
        else if (command == kCommandExtract)
            extractFiles(erf, game, files, kExtractModeStrip);
        else if (command == kCommandExtractSub)
            extractFiles(erf, game, files, kExtractModeSubstitute);

    } catch (...) {
        Common::exceptionDispatcherError();
    }

    return 0;
}
Beispiel #28
0
/// Derivatives of the histogram.
/// @param jacobian :: The output Jacobian.
/// @param left :: The left-most bin boundary.
/// @param right :: A pointer to an array of successive right bin boundaries
/// (size = nBins).
/// @param nBins :: Number of bins.
void Gaussian::histogramDerivative1D(Jacobian *jacobian, double left,
                                     const double *right,
                                     const size_t nBins) const {
  const double h = getParameter("Height");
  const double c = getParameter("PeakCentre");
  const double s = getParameter("Sigma");
  const double w = pow(1 / s, 2);
  const double sw = sqrt(w);

  auto cumulFun = [sw, c](double x) {
    return sqrt(M_PI / 2) / sw * erf(sw / sqrt(2.0) * (x - c));
  };
  auto fun = [w, c](double x) { return exp(-w / 2 * pow(x - c, 2)); };

  double xl = left;
  double fLeft = fun(left);
  double cLeft = cumulFun(left);
  const double h_over_2w = h / (2 * w);
  for (size_t i = 0; i < nBins; ++i) {
    double xr = right[i];
    double fRight = fun(xr);
    double cRight = cumulFun(xr);
    jacobian->set(i, 0, cRight - cLeft);        // height
    jacobian->set(i, 1, -h * (fRight - fLeft)); // centre
    jacobian->set(i, 2, h_over_2w * ((xr - c) * fRight - (xl - c) * fLeft +
                                     cLeft - cRight)); // weight
    fLeft = fRight;
    cLeft = cRight;
    xl = xr;
  }
}
Beispiel #29
0
double complex secondPart(const int l, const double gamma, const double Lamda, const double qSqur, int * const rstatus)
{
  int s1 = 0, s2 = 0;
  double complex secondPartInt = 0+0*I;
  if(l != 0){
    secondPartInt = 0.0;
  }
  else{
    //Integration method.
    /*
      secondPartInt = spheHarm(0, 0, 0, 0, &s1) * gamma * pow(M_PI,3.0/2.0) 
      * ( 2 * qSqur * sndInteFunc(Lamda, qSqur, &s2)
      -2 * exp(Lamda * qSqur)/sqrt(Lamda));
    */
    //Arithmetic method.
    double inteCore = 0.0;
    if(qSqur > 0){
      //Dawson function for qSqur>0
      inteCore = 4 * sqrt(qSqur) * exp(Lamda * qSqur) * gsl_sf_dawson(sqrt(Lamda * qSqur)); 
    }
    else if(fabs(qSqur) < DBL_EPSILON) {
      inteCore = 0;
    }
    else if(qSqur < 0){
      //Error function for qSqur<0
      inteCore = -2 * sqrt(M_PI) * sqrt( - qSqur) * erf( sqrt( - Lamda * qSqur) );
    }
    
    secondPartInt = spheHarm(0, 0, 0, 0, &s1) * gamma * pow(M_PI,3.0/2.0)
      * ( inteCore 	-  2 * exp(Lamda * qSqur)/sqrt(Lamda));
  }
  *rstatus = s1 + s2;
  //printf("Lamda=%lf,qSqur = %.4f\nsecondPartInt = %.24f \n", Lamda, qSqur, secondPartInt);
  return secondPartInt;
}
Beispiel #30
0
void _sep_3D_ewald_short_bond(sepatom *ptr, double kappa, double cf, sep3D *sys){
  double Ucol, rv[3], r2, r, ft, f, erfckr=0, erfkr, zizj, krsq;
  int i1, i2, n, k;
  const double A = 2*kappa/sqrt(SEP_PI), cf2 = cf*cf;


  Ucol = 0.0;
  for (i1 = 0; i1 < sys->npart; i1++){
    n = 0;
    while (1){
      i2 = ptr[i1].neighb[n];
      if (i2 == -1) break;

      r2 = 0.0;
      for (k=0; k<3; k++){
	rv[k] = ptr[i1].x[k] - ptr[i2].x[k];
	if (sys->bound[k] == 'p'){
	  sep_Wrap( rv[k], sys->length[k] );
	}	
	r2 += rv[k]*rv[k];
      }

      r = sqrt(r2);
      krsq = kappa*kappa*r2;
      zizj = ptr[i1].z*ptr[i2].z;
       
      // Not same molecule - short ranged real space contribution
      if ( (ptr[i1].molindex == -1 && r2<cf2) || 
	   (ptr[i1].molindex != ptr[i2].molindex && r2<cf2) ){ 
	erfckr = erfc(kappa*r)/r;
	ft = zizj*(erfckr + A*exp(-krsq))/r2;
	for ( k=0; k<3; k++ ){
	  f = ft*rv[k];
	  ptr[i1].a[k] += f/ptr[i1].m;
	  ptr[i2].a[k] -= f/ptr[i2].m;
	}
	
	Ucol += zizj*erfckr;
      }
      // Same molecule no real space contribution, but remove 
      // the self part from the Fourier part
      else if ( ptr[i1].molindex == ptr[i2].molindex ){
	erfkr = erf(kappa*r)/r;
      	ft = -zizj*(erfkr - A*exp(-krsq))/r2;
	for ( k=0; k<3; k++ ){
	  f = ft*rv[k];
	  ptr[i1].a[k] += f/ptr[i1].m;
	  ptr[i2].a[k] -= f/ptr[i2].m;
	}
	
	Ucol -= zizj*erfckr;
      }

      n++;
    }
  }

  sys->retval[0] = Ucol;
}