public static double logpdf(double x,double mu,double sigma,double k){
  if (x == Double.POSITIVE_INFINITY || x == Double.NEGATIVE_INFINITY) {
    return Double.NEGATIVE_INFINITY;
  }
  x=(x - mu) / sigma;
  if (k > 0 || k < 0) {
    if (k * x > 1) {
      return Double.NEGATIVE_INFINITY;
    }
    double t=Math.log(1 - k * x);
    return t == Double.NEGATIVE_INFINITY ? -Math.log(sigma) : t == Double.POSITIVE_INFINITY ? Double.NEGATIVE_INFINITY : (1 - k) * t / k - Math.exp(t / k) - Math.log(sigma);
  }
 else {
    return -x - Math.exp(-x) - Math.log(sigma);
  }
}

public static double logpdf ( double x , double mu , double sigma , double k ) { if ( x == Double . POSITIVE_INFINITY || x == Double . NEGATIVE_INFINITY ) { return Double . NEGATIVE_INFINITY ; } x = ( x - mu ) / sigma ; if ( k > 0 || k < 0 ) { if ( k * x > 1 ) { return Double . NEGATIVE_INFINITY ; } double t = Math . log ( 1 - k * x ) ; return t == Double . NEGATIVE_INFINITY ? - Math . log ( sigma ) : t == Double . POSITIVE_INFINITY ? Double . NEGATIVE_INFINITY : ( 1 - k ) * t / k - Math . exp ( t / k ) - Math . log ( sigma ) ; } else { return - x - Math . exp ( - x ) - Math . log ( sigma ) ; } }
log pdf of gev distribution
