Example #1
0
File: kstest.cpp Project: th5th/cea
double ks_test::ks_cdf(double z)
{
    // CDF of the Kolmogorov-Smirnov distribution.
    using std::exp; using std::pow; using std::sqrt;
    if(z < 0.0)
    {
        throw("z must be non-negative in ks_cdf in ks_test.");
    }
    else if(z == 0.0)
    {
        return 0.0;
    }
    else if(z < 1.18)
    {
        double x = 1.23370055013616983/square(z);
        double y = exp(-x);
        return 2.25675833419102515*sqrt(x)*
            (y + pow(y,9) + pow(y,25) + pow(y,49));
    }
    else
    {
        double y = exp(-2.0*square(z));
        return 1.0 - 2.0*(y - pow(y,4) + pow(y,9));
    }
}
shared_vec osc_operation( shared_vec q , shared_vec q_l , shared_vec q_r , shared_vec dpdt )
{
    using std::pow;
    using std::abs;
    using boost::math::sign;

    const size_t M = q->size();

    double coupling = pow( abs((*q_l)[q_l->size()-1]-(*q)[0]) , LAMBDA-1 ) * sign((*q_l)[q_l->size()-1]-(*q)[0]);

    // (*dpdt)[0] = -pow( abs((*q)[0]) , KAPPA-1 ) * sign( (*q)[0] )
    //     - pow( abs((*q)[0]-(*q)[1]) , LAMBDA-1 ) * sign( (*q)[0]-(*q)[1] )
    //     - pow( abs((*q)[0]-(*q_l)[q_l->size()-1]) , LAMBDA-1 ) * sign((*q)[0]-(*q_l)[q_l->size()-1]);

    for( size_t i=0 ; i<M-1 ; ++i )
    {
        (*dpdt)[i] = -pow( abs((*q)[i]) , KAPPA-1 ) * sign((*q)[i])
            + coupling;
        coupling = pow( abs((*q)[i]-(*q)[i+1]) , LAMBDA-1 ) * sign((*q)[i]-(*q)[i+1]);
        (*dpdt)[i] -= coupling;
    }

    (*dpdt)[M-1] = -pow( abs((*q)[M-1]) , KAPPA-1 ) * sign((*q)[M-1]) 
        - pow( abs((*q)[M-1] - (*q_r)[0]) , LAMBDA-1 ) * sign((*q)[M-1]-(*q_r)[0])
        + coupling;

    return dpdt;
}
Example #3
0
//! Compute local-to-static pressure ratio.
double computeLocalToStaticPressureRatio( double machNumber,
                                          double ratioOfSpecificHeats )
{
    // Return local-to-static pressure ratio.
    return pow( 2.0 / ( 2.0 + ( ratioOfSpecificHeats - 1.0 ) * pow( machNumber, 2.0 ) ),
                ratioOfSpecificHeats / ( ratioOfSpecificHeats - 1.0 ) );
}
Example #4
0
void Stippler::redistributeStipples() {
	using std::pow;
	using std::sqrt;
	using std::pair;
	using std::make_pair;
	using std::vector;

	vector< pair< Point< float >, EdgeList > > vectorized;
	for ( EdgeMap::iterator key_iter = edges.begin(); key_iter != edges.end(); ++key_iter ) {
		vectorized.push_back(make_pair(key_iter->first, key_iter->second));
	}

	float local_displacement = 0.0f;

	#pragma omp parallel for reduction(+:local_displacement)
	for (int i = 0; i < (int)vectorized.size(); i++) {
		pair< Point< float >, EdgeList > item = vectorized[i];
		pair< Point<float>, float > centroid = calculateCellCentroid( item.first, item.second );	// first : point, second: edge list

		radii[i] = centroid.second;
		vertsX[i] = centroid.first.x;
		vertsY[i] = centroid.first.y;

		local_displacement += sqrt( pow( item.first.x - centroid.first.x, 2.0f ) + pow( item.first.y - centroid.first.y, 2.0f ) );
	}

	displacement = local_displacement / vectorized.size(); // average out the displacement
}
Example #5
0
//! Compute pressure coefficient using the ACM empirical method.
double computeAcmEmpiricalPressureCoefficient(
    double inclinationAngle, double machNumber )
{
    // Declare local variables.
    double pressureCoefficient_;
    double minimumPressureCoefficient_;
    double preliminaryPressureCoefficient_;

    // Set minimum pressure coefficient.
    minimumPressureCoefficient_ = -1.0 / pow( machNumber, 2.0 );

    // Calculate preliminary pressure coefficient.
    preliminaryPressureCoefficient_ = 180.0 / PI * inclinationAngle
            / ( 16.0 * pow( machNumber, 2.0 ) );

    // If necessary, correct preliminary pressure coefficient.
    if ( minimumPressureCoefficient_ > preliminaryPressureCoefficient_ )
    {
        pressureCoefficient_ = minimumPressureCoefficient_;
    }

    else
    {
        pressureCoefficient_ = preliminaryPressureCoefficient_;
    }

    // Return pressure coefficient.
    return pressureCoefficient_;
}
 double evaluate ( double radius ) const
 {
   if (radius >= _r) return 0.0;
   double p = radius / _r;
   using std::pow;
   return pow(1.0-p,8.0) * (32.0*pow(p,3.0) + 25.0*pow(p,2.0) + 8.0*p + 1.0);
 }
Example #7
0
//! Compute pressure coefficient using the Smyth delta wing method.
double computeSmythDeltaWingPressureCoefficient(
    double inclinationAngle, double machNumber )
{
    // Declare local variables.
    double machNumberSine_;
    double correctedInclinationAngle_;

    // Calculate inclination angle for use in calculations ( angles lower than
    // 1 degree not allowed ).
    if ( inclinationAngle < PI / 180.0 )
    {
        correctedInclinationAngle_ = PI / 180.0;
    }

    else
    {
        correctedInclinationAngle_ = inclinationAngle;
    }

    // Pre-compute for efficiency.
    machNumberSine_ = machNumber * sin( correctedInclinationAngle_ );

    // Employ empirical correlation to calculate pressure coefficient.
    // Return pressure coefficient.
    return 1.66667 * ( pow( 1.09 * machNumberSine_ + exp( -0.49 * machNumberSine_ ), 2.0 ) - 1.0 )
            / pow( machNumber, 2.0 );
}
Example #8
0
//! Compute pressure coefficient using the Hankey flat surface method.
double computeHankeyFlatSurfacePressureCoefficient(
    double inclinationAngle, double machNumber )
{
    // Declare local variables.
    double stagnationPressureCoefficient_;

    // Calculate 'effective' stagnation pressure coefficient for low
    // inclination angle.
    if( inclinationAngle < PI / 18.0 )
    {
        stagnationPressureCoefficient_ = ( 0.195 + 0.222594 / pow( machNumber, 0.3 ) - 0.4 )
                * inclinationAngle * 180.0 / PI + 4.0;
    }
    // Calculate 'effective' stagnation pressure coefficient for other
    // inclination angle.
    else
    {
        stagnationPressureCoefficient_ = 1.95 + 0.3925 / ( pow( machNumber, 0.3 )
                                                           * tan( inclinationAngle ) );
    }

    // Return pressure coefficient using 'effective' stagnation pressure
    // coefficient.
    return computeModifiedNewtonianPressureCoefficient(
                inclinationAngle, stagnationPressureCoefficient_ );
}
Example #9
0
    typename return_type<T_prob>::type
    binomial_cdf_log(const T_n& n, const T_N& N, const T_prob& theta) {
      static const char* function("binomial_cdf_log");
      typedef typename stan::partials_return_type<T_n, T_N, T_prob>::type
        T_partials_return;

      if (!(stan::length(n) && stan::length(N) && stan::length(theta)))
        return 0.0;

      T_partials_return P(0.0);

      check_nonnegative(function, "Population size parameter", N);
      check_finite(function, "Probability parameter", theta);
      check_bounded(function, "Probability parameter", theta, 0.0, 1.0);
      check_consistent_sizes(function,
                             "Successes variable", n,
                             "Population size parameter", N,
                             "Probability parameter", theta);

      VectorView<const T_n> n_vec(n);
      VectorView<const T_N> N_vec(N);
      VectorView<const T_prob> theta_vec(theta);
      size_t size = max_size(n, N, theta);

      using std::exp;
      using std::pow;
      using std::log;
      using std::exp;

      OperandsAndPartials<T_prob> operands_and_partials(theta);

      // Explicit return for extreme values
      // The gradients are technically ill-defined,
      // but treated as negative infinity
      for (size_t i = 0; i < stan::length(n); i++) {
        if (value_of(n_vec[i]) < 0)
          return operands_and_partials.value(negative_infinity());
      }

      for (size_t i = 0; i < size; i++) {
        // Explicit results for extreme values
        // The gradients are technically ill-defined, but treated as zero
        if (value_of(n_vec[i]) >= value_of(N_vec[i])) {
          continue;
        }
        const T_partials_return n_dbl = value_of(n_vec[i]);
        const T_partials_return N_dbl = value_of(N_vec[i]);
        const T_partials_return theta_dbl = value_of(theta_vec[i]);
        const T_partials_return betafunc = exp(lbeta(N_dbl-n_dbl, n_dbl+1));
        const T_partials_return Pi = inc_beta(N_dbl - n_dbl, n_dbl + 1,
                                              1 - theta_dbl);

        P += log(Pi);

        if (!is_constant_struct<T_prob>::value)
          operands_and_partials.d_x1[i] -= pow(theta_dbl, n_dbl)
            * pow(1-theta_dbl, N_dbl-n_dbl-1) / betafunc / Pi;
      }
      return operands_and_partials.value(P);
    }
Example #10
0
TEST(AgradFvar, pow) {
  using stan::agrad::fvar;
  using std::pow;
  using std::log;
  using std::isnan;

  fvar<double> x(0.5);
  x.d_ = 1.0;
  double y = 5.0;

  fvar<double> a = pow(x, y);
  EXPECT_FLOAT_EQ(pow(0.5, 5.0), a.val_);
  EXPECT_FLOAT_EQ(5.0 * pow(0.5, 5.0 - 1.0), a.d_);

  fvar<double> b = pow(y, x);
  EXPECT_FLOAT_EQ(pow(5.0, 0.5), b.val_);
  EXPECT_FLOAT_EQ(log(5.0) * pow(5.0, 0.5), b.d_);

  fvar<double> z(1.2);
  z.d_ = 2.0;
  fvar<double> c = pow(x, z);
  EXPECT_FLOAT_EQ(pow(0.5, 1.2), c.val_);
  EXPECT_FLOAT_EQ((2.0 * log(0.5) + 1.2 * 1.0 / 0.5) * pow(0.5, 1.2), c.d_);

  fvar<double> w(-0.4);
  w.d_ = 1.0;
  fvar<double> d = pow(w, x);
  isnan(d.val_);
  isnan(d.d_);
}
Example #11
0
Scalar MASA::cp_normal<Scalar>::eval_post_var()
{
  using std::pow;

  Scalar var;
  var =1/((1/pow(sigma,2)) + (Scalar(vec_data.size())/pow(sigma_d,2)));
  return var;
}
Example #12
0
// this is the factor which makes a unnormalized primitive spherical
// gauss orbital, i.e.   S_lm(r)*exp(-zeta r^2),'s self overlap one.
// note that the angular normalization factors are already absorbed in the S_lm
// (S_00 = 1). This function accounts for the radial part only. See purple
// book sec 6.6.4.
double GaussNormalizationSpher( double Zeta, int l )
{
   // purple book (6.6.14). (last 4*pi/(2*l+1) is for factor between
   // Ylm and Slm)
   using std::pow; using std::sqrt;
   return 2.0 * pow( 2.0 * Zeta, 0.75 ) / pow(M_PI,0.25) *
      sqrt( (1 << l) / static_cast<double>( DoubleFact(2*l+1) ) ) *
      intpow( sqrt( 2.0 * Zeta ), l ) / sqrt(4*M_PI/(2*l+1));
}
float cpp_rosenbrock(double* vals, long sz){
  //The rosenbrock function! It does things!
  double tot = 0.0, adjusted_val, adjusted_next = vals[0] * 0.004;
  for(long i = 0; i < (sz - 1); ++i){
    adjusted_val = adjusted_next;
    adjusted_next = vals[i + 1] * 0.004;
    tot += (100.0 * pow(adjusted_next - (pow(adjusted_val, 2)), 2) + pow(adjusted_val - 1, 2));
  }
  return tot;
}
Example #14
0
double PolyaGamma::jj_m1(double b, double z) 
{
    z = fabs(z);
    double m1 = 0.0;
    if (z > 1e-12)
	m1 = b * tanh(z) / z;
    else
	m1 = b * (1 - (1.0/3) * pow(z,2) + (2.0/15) * pow(z,4) - (17.0/315) * pow(z,6));
    return m1;
}
Example #15
0
Scalar MASA::cp_normal<Scalar>::eval_post_mean()
{
  using std::sqrt;
  using std::pow;

  Scalar mean;
  Scalar sigmap = sqrt(1/((1/pow(sigma,2)) + (Scalar(vec_data.size())/pow(sigma_d,2))));
  mean     = pow(sigmap,2) * (m/pow(sigma,2) + (Scalar(vec_data.size())*x_bar/pow(sigma_d,2)));  
  return mean;
}
Example #16
0
Scalar MASA::cp_normal<Scalar>::eval_prior(Scalar x)
{
  using std::sqrt;
  using std::exp;
  using std::pow;

  Scalar prior;
  prior = sqrt(2*pi*pow(sigma,2)) * exp(-(1/(2*pow(sigma,2)))*pow((x-m),2));
  return prior;
}
float cpp_schafferf7(double* vals, long sz){
  //The schafferf7 function! It does other things!
  double tot = 0.0, norm = 1.0/sz, si, adjusted_val, adjusted_next = vals[0] / 512.0 * 100.0;
  for(long i = 0; i < (sz - 1); ++i){
    adjusted_val = adjusted_next;
    adjusted_next = vals[i + 1] / 512.0 * 100.0;
    si = sqrt(pow(adjusted_val, 2) + pow(adjusted_next, 2));
    tot += pow(norm * sqrt(si) * (sin(50 * pow(si, 0.20)) + 1), 2);
  }
  return tot;
}
Example #18
0
float
example_state_view::
pointer_radius(int index, bool old) const
noexcept
{
	using std::sqrt;
	using std::pow;
	return float(sqrt(
		pow(ndc_pointer_x(index, old), 2)+
		pow(ndc_pointer_y(index, old), 2)
	));
}
Example #19
0
std::tuple<T, T>
phi54(const T& a, const T& b1, const T& b2)
{
    using std::pow;
    T t1 = sqrt(pow(b1, 2) + 1) - b1;
    T t2 = sqrt(pow(b2, 2) + 1) - b2;
    T k1 = sqrt(pow(1 - a, 2) + b2 * b2);
    T k2 = sqrt(pow(a, 2) + pow(b1, 2));
    T f = t1 * k1 + t2 * k2;
    T g = -t1 * (1 - a) / k1 + t2 * a / k2;
    return std::make_tuple(f, g);
}
Example #20
0
//! Compute pressure coefficient using empirical tangent wedge method.
double computeEmpiricalTangentWedgePressureCoefficient(
    double inclinationAngle, double machNumber )
{
    // Declare local variable.
    double machNumberSine_;

    // Set local variable.
    machNumberSine_ = machNumber * sin( inclinationAngle );

    // Return pressure coefficient approximation.
    return ( pow( 1.2 * machNumberSine_ + exp( -0.6 * machNumberSine_ ), 2.0 )
             - 1.0 ) / ( 0.6 * pow( machNumber, 2.0 ) );
}
inline double pdf_dweibull(double x, double q, double beta,
                           bool& throw_warning) {
#ifdef IEEE_754
  if (ISNAN(x) || ISNAN(q) || ISNAN(beta))
    return x+q+beta;
#endif
  if (q <= 0.0 || q >= 1.0 || beta <= 0.0) {
    throw_warning = true;
    return NAN;
  }
  if (!isInteger(x) || x < 0.0)
    return 0.0;
  return pow(q, pow(x, beta)) - pow(q, pow(x+1.0, beta));
}
//uses some trigonometry magic to update the position of the current point based on a limited speed given by SPEED_OF_MOVEMENT
Point speedGovernor(Point current, Point destination, double dist) {
    double x_dist = destination.x - current.x;
    double y_dist = destination.y - current.y;
    double distance = sqrt(pow((x_dist), 2) + pow((y_dist), 2));
    double angle = atan2(y_dist, x_dist);
    if (distance > dist) {
        distance = dist;
        x_dist = distance*(cos(angle));
        y_dist = distance*(sin(angle));
    }
    current.x = current.x + x_dist;
    current.y = current.y + y_dist;
    return current;
}
Point2D VKDrone::futurePosition(const GameObject *obj, double laserSpeed) {
    // Distance to obj.
    double dist = sqrt(pow(obj->posx - myShip->posx, 2) +
                       pow(obj->posy - myShip->posy, 2));

    // Time needed to a laser beam travel all dist.
    double dt = dist / laserSpeed;

    Point2D nextPos;
    nextPos.x = obj->posx + obj->velx * dt;
    nextPos.y = obj->posy + obj->vely * dt;

    return nextPos;
}
Example #24
0
Scalar MASA::cp_normal<Scalar>::eval_posterior(Scalar x)
{
  using std::sqrt;
  using std::exp;
  using std::pow;

  Scalar av = 0;
  Scalar post;
  Scalar sigmap;
  Scalar mp;

  for(int it = 0;it<int(vec_data.size());it++)
    {
      av +=vec_data[it];
    }
  av = av / (Scalar)vec_data.size();

  //set x_bar to average of data vector
  this->set_var("x_bar",av);
  
  sigmap = sqrt(1/((1/pow(sigma,2)) + (Scalar(vec_data.size())/pow(sigma_d,2))));
  mp     = pow(sigmap,2) * (m/pow(sigma,2) + (Scalar(vec_data.size())*x_bar/pow(sigma_d,2)));
  post   = sqrt(2*pi*pow(sigmap,2)) * exp(-(1/(2*pow(sigmap,2)))*pow((x-mp),2));

  return post;
}
Example #25
0
/**
 * The evaluation of the coresersic profile at coresersic coordinates (x,y).
 *
 * The coresersic profile has this form:
 *
 *    (1+(r/rb)^(-a))^(b/a)*
 *        exp(-bn*(((r^a+rb^a)/re^a))^(1/(nser*a)))
 *
 * with::
 *
 *           r = (x^{2+B} + y^{2+B})^{1/(2+B)}
 *           B = box parameter
 */
double CoreSersicProfile::evaluate_at(double x, double y) const {

	using std::abs;
	using std::exp;
	using std::pow;

	double box = this->box + 2.;
	double r = pow( pow(abs(x), box) + pow(abs(y), box), 1./box);
	return pow(1 + pow(r/rb,-a), b/a) *
	       exp(-_bn * pow((pow(r, a) + pow(rb, a))/pow(re,a), 1/(nser*a)));
}
Example #26
0
//! Compute shock deflection angle.
double computeShockDeflectionAngle( double shockAngle, double machNumber,
                                    double ratioOfSpecificHeats )
{
    // Declare local variables.
    double tangentOfDeflectionAngle_;

    // Calculate tangent of deflection angle.
    tangentOfDeflectionAngle_ = 2.0 * ( pow( machNumber * sin( shockAngle ), 2.0 ) - 1.0 )
            / ( tan( shockAngle ) * ( pow( machNumber, 2.0 )
                                      * ( ratioOfSpecificHeats
                                          + cos( 2.0 * shockAngle ) ) + 2.0 ) );

    // Return deflection angle.
    return atan( tangentOfDeflectionAngle_ );
}
Example #27
0
TEST(AgradFwdPow, Double_FvarVar_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::log;
  using std::pow;

  double x(0.5);
  fvar<var> z(1.2,1.0);
  fvar<var> a = pow(x,z);

  AVEC y = createAVEC(z.val_);
  VEC g;
  a.d_.grad(y,g);
  EXPECT_FLOAT_EQ(pow(0.5,1.2) * log(0.5) * log(0.5), g[0]);
}
Example #28
0
TEST(AgradFwdPow, FvarVar_Double_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::log;
  using std::pow;

  fvar<var> x(0.5,1.0);
  double z(1.2);
  fvar<var> a = pow(x,z);

  AVEC y = createAVEC(x.val_);
  VEC g;
  a.d_.grad(y,g);
  EXPECT_FLOAT_EQ((1.2 - 1.0) * 1.2 * pow(0.5,1.2 - 2.0), g[0]);
}
Example #29
0
Track_Scholz2000::Track_Scholz2000(const Particle &particle,
                                   const double density,
                                   double t)
{
    particleType = particle.type;

    const double AMU2MEV = 931.494027;  //MeV/amu
    particleEnergy = particle.e_c / particle.restEnergy * AMU2MEV;
    r_max = GAMMA * pow(particle.e_c / particle.restEnergy * AMU2MEV, DELTA);  //um

    if( r_max < R_MIN )
        r_max = R_MIN;

    let = particle.let;
    e_c = particle.e_c;

    const double CONV = 160.2177;  //(J*um^3)/(MeV*dm^3) : Constant of conversion (MeV*dm^3)/(Kg*um^3) -> Gy
    lambda = CONV / (2 * M_PI * density * (0.5 + log(r_max/R_MIN))); //Gy * um^3/MeV

    x_track = particle.x;  // mm
    y_track = particle.y;  // mm
    weight = particle.weight;
    
    time = t;
}
Example #30
0
 typename stan::return_type<T_y, T_shape, T_scale>::type 
 cdf_log_function(const T_y& y, const T_shape& alpha, const T_scale& sigma,
                  const T3&, const T4&, const T5&) {
   using std::log;
   using std::pow;
   return log(1.0 - exp(-pow(y / sigma, alpha)));
 }