Skip to content

Commit f0520a2

Browse files
committed
Gaunt approximation DOES work as long as Mu*Nu > 1.5 and Mu > 1.5
1 parent dea8c3e commit f0520a2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

stan/asymp_approx.stan

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/*Asymptotic approximation using four terms using Theorem 1 of Gaunt et al. 2019 */
2-
real log_Z_COMP_Asymp(real log_mu, real nu) {
2+
real log_Z_COMP_Asymp_new(real log_mu, real nu) {
33
// Asymptotic expansion of Z(mu, nu) with four terms.
44
// Based on equations (4) and (31) of doi:10.1007/s10463-017-0629-6
55
real nu2 = nu^2;
6-
real log_resids[4];
6+
real log_common = log(nu) + log_mu/nu;
7+
real resids[4];
78
real ans;
89
real lcte = (nu * exp(log_mu/nu)) - ( (nu-1)/(2*nu)* log_mu + (nu-1)/2*log(2*pi()) + 0.5 *log(nu));
910
real c_1 = (nu2-1)/24;
1011
real c_2 = (nu2-1)/1152*(nu2 + 23);
1112
real c_3 = (nu2-1)/414720* (5*square(nu2) - 298*nu2 + 11237);
12-
if(nu < 1){//TODO: check this makes sense. Could do away with.
13-
print("Approximation doesn't work great when nu < 1, returning without residuals");
14-
return(lcte);
15-
}
16-
log_resids[1] = 0;
17-
log_resids[2] = log(c_1) - 1 * (log(nu) + log_mu/nu);
18-
log_resids[3] = log(c_2) - 2 * (log(nu) + log_mu/nu);
19-
log_resids[4] = log(c_3) - 3 * (log(nu) + log_mu/nu);
20-
ans = lcte + log_sum_exp(log_resids);
13+
resids[1] = 1;
14+
resids[2] = c_1 * exp(-1 * log_common) ;
15+
resids[3] = c_2 * exp(-2 * log_common);
16+
resids[4] = c_3 * exp(-3 * log_common);
17+
ans = lcte + log(sum(resids));
2118
return ans;
2219
}
2320

0 commit comments

Comments
 (0)