[37] | 1 | x = linspace(-20,2,100); |
---|
| 2 | w = exp(-0.5*x.^2 -0.5*log(2*pi)); |
---|
| 3 | f = exp(-normcdfln(x)); |
---|
| 4 | g = 1./normcdf(x); |
---|
| 5 | %g = exp((log(1+exp(0.88+x))./1.5).^2); |
---|
| 6 | %g = exp(0.5*log(2*pi) +0.5*x.^2 + log(x)); |
---|
| 7 | plot(x, f.*w, x, g.*w) |
---|
| 8 | legend('exp(-normcdfln)','1/normcdf'); |
---|
| 9 | |
---|
| 10 | if 0 |
---|
| 11 | true = -27.3843074988; |
---|
| 12 | [abs(log(normcdf(-7))-true) abs(normcdfln(-7)-true)] |
---|
| 13 | end |
---|
| 14 | |
---|
| 15 | if 0 |
---|
| 16 | %matnet |
---|
| 17 | %imports('c:/Documents and Settings/minka/Depots/Infer/Core/bin/Debug/Core.dll') |
---|
| 18 | h = g; |
---|
| 19 | for i = 1:length(x) |
---|
| 20 | h(i) = 1./cl.MMath.NormalCdf(x(i)); |
---|
| 21 | end |
---|
| 22 | %h = 0.5*(-x + sqrt(x.*x + 8/pi)); |
---|
| 23 | plot(x, f.*w, x, g.*w, x, h.*w) |
---|
| 24 | legend('exp(-normcdfln)','1/normcdf', '1/normcdf2'); |
---|
| 25 | |
---|
| 26 | plot(x, f.*w - h.*w) |
---|
| 27 | end |
---|
| 28 | |
---|
| 29 | % evalf(subs(t=1e-4,subs(x=2*(1-t)/t,erfc(x)*exp(x*x))),100); |
---|
| 30 | |
---|
| 31 | if 0 |
---|
| 32 | % test approximations |
---|
| 33 | a = exp(sqrt(2/pi)); |
---|
| 34 | b = 1/log(2/pi*a); |
---|
| 35 | g = log(a-1 + exp(x.*exp(1./(x.^2 + b)))); |
---|
| 36 | g = log(a-1 + exp(x)); |
---|
| 37 | plot(x, f, x, g) |
---|
| 38 | plot(x, log(exp(f)+1-a)./x) |
---|
| 39 | plot(x, 1./log(log(exp(f)+1-a)./x)) |
---|
| 40 | end |
---|
| 41 | |
---|
| 42 | % read `/u/tpminka/src/maple/gauss_cdf`; |
---|
| 43 | % f := 1/sqrt(2*Pi)*exp(-1/2*x^2)/gauss_cdf(-x); |
---|
| 44 | % g := exp(sqrt(2/Pi))-1+exp(x); |
---|
| 45 | % plot(f, x=0..50); |
---|
| 46 | % h := log(exp(f*sqrt(Pi/2)-1)+1); |
---|
| 47 | % h := log(exp(f - sqrt(2/Pi))+1); |
---|
| 48 | % h := 1/log(log(exp(f) +1-exp(sqrt(2/Pi)))/x); |
---|
| 49 | % asympt(h,x); |
---|