eenticott / gamstackr

Tools for stacking probabilistic densities.
GNU General Public License v3.0
0 stars 0 forks source link

eta_to_alpha #1

Closed capezza closed 1 year ago

capezza commented 1 year ago

https://github.com/eenticott/gamstackr/blob/0b4e4d35a64624fe3b957c8fbf216f8f984e0b61/R/conversions.R#L5-L6

Maybe it is more stable to do:

  nu <- matrix(unlist(list_of_eta), ncol = length(list_of_eta))
  nu1 <- cbind(0, nu)
  # nuCen <- nu1 - matrixStats::rowMaxs(nu1)
  nuCen <- nu1 - apply(nu1, 1, max)
  exp_nuCen <- exp(nuCen)
  a <- exp_nuCen / rowSums(exp_nuCen)
  return(a)
eenticott commented 1 year ago

Thanks, I have implemented this!