diff --git a/NEWS.md b/NEWS.md index 0b0d8b13..5500b86e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # Items for next release go here +* Speed improvement from simplifying the normalization when fitting the +generalized Pareto distribution. (#187, @sethaxen) + +* Fixed bug where attribute storing normalizing constant of PSIS weights wasn't +updated when using moment matching. (#167, @fweber144) + * Switch unit tests from Travis to GitHub Actions. (#164) ### Bug fixes diff --git a/R/gpdfit.R b/R/gpdfit.R index 09025565..7cd46ea3 100644 --- a/R/gpdfit.R +++ b/R/gpdfit.R @@ -40,9 +40,7 @@ gpdfit <- function(x, wip = TRUE, min_grid_pts = 30, sort_x = TRUE) { xstar <- x[floor(N / 4 + 0.5)] # first quartile of sample theta <- 1 / x[N] + (1 - sqrt(M / (jj - 0.5))) / prior / xstar l_theta <- N * lx(theta, x) # profile log-lik - w_theta <- 1 / vapply(jj, FUN.VALUE = numeric(1), FUN = function(j) { - sum(exp(l_theta - l_theta[j])) - }) + w_theta <- exp(l_theta - matrixStats::logSumExp(l_theta)) # normalize theta_hat <- sum(theta * w_theta) k <- mean.default(log1p(-theta_hat * x)) sigma <- -k / theta_hat