include/vinecopulib/bicop/implementation/gumbel.ipp
// This is copy&paste from the VineCopula package
This is copy&paste from the VineCopula package
This is copy&paste from the VineCopula package
inline double
qcondgum(double* q, double* u, double* de)
{
  double a, p, z1, z2, con, de1, dif;
  double mxdif;
  int iter;
  p = 1 - *q;
  z1 = -log(*u);
  con = log(1. - p) - z1 + (1. - *de) * log(z1);
  de1 = *de - 1.;
  a = pow(2. * pow(z1, *de), 1. / (*de));
  mxdif = 1;
  iter = 0;
  dif = .1; 
  while ((mxdif > 1.e-6) && (iter < 20)) {
    double g = a + de1 * log(a) + con;
    double gp = 1. + de1 / a;
    if ((boost::math::isnan)(g) || (boost::math::isnan)(gp) ||
        (boost::math::isnan)(g / gp)) {
      dif /= -2.;
    } else {
      dif = g / gp;
    }
    a -= dif;
    iter++;
    int it = 0;
    while ((a <= z1) && (it < 20)) {
      dif /= 2.;
      a += dif;
      ++it;
    }
    mxdif = fabs(dif);
  }
  z2 = pow(pow(a, *de) - pow(z1, *de), 1. / (*de));
  return (exp(-z2));
}
inline double qcondgum ( double * q , double * u , double * de ) { double a , p , z1 , z2 , con , de1 , dif ; double mxdif ; int iter ; p = 1 - * q ; z1 = - log ( * u ) ; con = log ( 1. - p ) - z1 + ( 1. - * de ) * log ( z1 ) ; de1 = * de - 1. ; a = pow ( 2. * pow ( z1 , * de ) , 1. / ( * de ) ) ; mxdif = 1 ; iter = 0 ; dif = .1 ; while ( ( mxdif > 1.e-6 ) && ( iter < 20 ) ) { double g = a + de1 * log ( a ) + con ; double gp = 1. + de1 / a ; if ( ( boost :: math :: isnan ) ( g ) || ( boost :: math :: isnan ) ( gp ) || ( boost :: math :: isnan ) ( g / gp ) ) { dif /= -2. ; } else { dif = g / gp ; } a -= dif ; iter ++ ; int it = 0 ; while ( ( a <= z1 ) && ( it < 20 ) ) { dif /= 2. ; a += dif ; ++ it ; } mxdif = fabs ( dif ) ; } z2 = pow ( pow ( a , * de ) - pow ( z1 , * de ) , 1. / ( * de ) ) ; return ( exp ( - z2 ) ) ; }
This is copy&paste from the VineCopula package
This is copy&paste from the VineCopula package
// needed in case first step leads to NaN // added for de>50