File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments