source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/normcdfln.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.1 KB
Line 
1function e = normcdfln(x)
2% NORMCDFLN   log of normal cumulative density function.
3% More accurate than log(normcdf(x)) when x is small.
4% The following is a quick and dirty approximation to normcdfln:
5% normcdfln(x) =approx -(log(1+exp(0.88-x))/1.5)^2
6
7% Written by Tom Minka
8% (c) Microsoft Corporation. All rights reserved.
9
10% make e the same shape as x, and inherit any NaNs.
11e = x;
12t = -6.5;
13i = find(x >= t);
14if ~isempty(i)
15  e(i) = log(normcdf(x(i)));
16end
17i = find(x < t);
18if ~isempty(i)
19  x = x(i);
20  z = x.^(-2);
21  if 0
22    % log of asymptotic series for cdf
23    % subs(x=-x,asympt(sqrt(2*Pi)*gauss_cdf(-x),x));
24    c = [-1 3 -15 105 -945 10395 -135135 2027025 -34459425 654729075];
25    y = 0;
26    for i = length(c):-1:1
27      y = z.*(y + c(i));
28    end
29    %y = z.*(c(1)+z.*(c(2)+z.*(c(3)+z.*(c(4)+z.*(c(5)+z.*(c(6)+z.*c(7)))))));
30    y = log(1+y);
31  else
32    % asymptotic series for logcdf
33    % subs(x=-x,asympt(log(gauss_cdf(-x)),x));
34    c = [-1 5/2 -37/3 353/4 -4081/5 55205/6 -854197/7];
35    y = z.*(c(1)+z.*(c(2)+z.*(c(3)+z.*(c(4)+z.*(c(5)+z.*(c(6)+z.*c(7)))))));
36  end
37  e(i) = y -0.5*log(2*pi) -0.5*x.^2 - log(-x);
38end
Note: See TracBrowser for help on using the repository browser.