# HG changeset patch # User jwe # Date 1179159466 0 # Node ID 55da54f6c5c2b076cac6906b1760f4f2067ee0a5 # Parent 66e30383481bf8d73215e8729ded9450dc224558 [project @ 2007-05-14 16:17:46 by jwe] diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -143,7 +143,8 @@ [status, output] = system (cmd); - ** For compatibility with Matlab, the third argument to normcdf is - now the standard deviation instead of the variance. + ** For compatibility with Matlab, normcdf, norminv, normpdf, and + normrnd have been modified to compute distributions using the + standard deviation instead of the variance. See NEWS.2 for old news. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,16 @@ +2007-05-14 Tarmigan Casebolt + + * statistics/distributions/norminv.m, + statistics/distributions/norminv.m, + statistics/distributions/normpdf.m, + statistics/distributions/normrnd.m: + Use standard deviation, not variance. + * statistics/distributions/lognpdf.m: Adapt to change in norminv. + * statistics/distributions/logninv.m: Refer to norminv, not normal_inv. + * deprecated/normal_cdf.m, deprecated/normal_inv.m, + deprecated/normal_pdf.m, deprecated/normal_rnd.m: Preserve + backward compatibility. + 2007-05-14 David Bateman * pkg/pkg.m: Mark loaded packages with "*". diff --git a/scripts/deprecated/normal_cdf.m b/scripts/deprecated/normal_cdf.m --- a/scripts/deprecated/normal_cdf.m +++ b/scripts/deprecated/normal_cdf.m @@ -31,6 +31,10 @@ function cdf = normal_cdf (varargin) + if (nargin > 2) + varargin{3} = sqrt (varargin{3}); + endif + cdf = normcdf (varargin{:}); endfunction diff --git a/scripts/deprecated/normal_inv.m b/scripts/deprecated/normal_inv.m --- a/scripts/deprecated/normal_inv.m +++ b/scripts/deprecated/normal_inv.m @@ -31,6 +31,10 @@ function inv = normal_inv (varargin) + if (nargin > 2) + varargin{3} = sqrt (varargin{3}); + endif + inv = norminv (varargin{:}); endfunction diff --git a/scripts/deprecated/normal_pdf.m b/scripts/deprecated/normal_pdf.m --- a/scripts/deprecated/normal_pdf.m +++ b/scripts/deprecated/normal_pdf.m @@ -31,6 +31,10 @@ function pdf = normal_pdf (varargin) - pdf = normpdf (varargin{:}); + if (nargin > 2) + varargin{3} = sqrt (varargin{3}); + endif + pdf = normpdf (varargin{:}); + endfunction diff --git a/scripts/deprecated/normal_rnd.m b/scripts/deprecated/normal_rnd.m --- a/scripts/deprecated/normal_rnd.m +++ b/scripts/deprecated/normal_rnd.m @@ -34,6 +34,10 @@ function rnd = normal_rnd (varargin) + if (nargin > 1) + varargin{2} = sqrt (varargin{2}); + endif + rnd = normrnd (varargin{:}); endfunction diff --git a/scripts/statistics/distributions/logninv.m b/scripts/statistics/distributions/logninv.m --- a/scripts/statistics/distributions/logninv.m +++ b/scripts/statistics/distributions/logninv.m @@ -44,7 +44,7 @@ ## The following "straightforward" implementation unfortunately does ## not work (because exp (Inf) -> NaN): - ## inv = exp (normal_inv (x, mu, sigma)); + ## inv = exp (norminv (x, mu, sigma)); ## Hence ... if (!isscalar (mu) || !isscalar (sigma)) diff --git a/scripts/statistics/distributions/lognpdf.m b/scripts/statistics/distributions/lognpdf.m --- a/scripts/statistics/distributions/lognpdf.m +++ b/scripts/statistics/distributions/lognpdf.m @@ -44,7 +44,7 @@ ## The following "straightforward" implementation unfortunately does ## not work for the special cases (Inf, ...) - ## pdf = (x > 0) ./ x .* normal_pdf (log (x), mu, sigma); + ## pdf = (x > 0) ./ x .* normpdf (log (x), mu, sigma); ## Hence ... if (!isscalar (mu) || !isscalar (sigma)) @@ -64,9 +64,9 @@ k = find ((x > 0) & (x < Inf) & (sigma > 0) & (sigma < Inf)); if (any (k)) if (isscalar (mu) && isscalar (sigma)) - pdf(k) = normpdf (log (x(k)), mu, sigma.^2) ./ x(k); + pdf(k) = normpdf (log (x(k)), mu, sigma) ./ x(k); else - pdf(k) = normpdf (log (x(k)), mu(k), sigma(k).^2) ./ x(k); + pdf(k) = normpdf (log (x(k)), mu(k), sigma(k)) ./ x(k); endif endif diff --git a/scripts/statistics/distributions/normcdf.m b/scripts/statistics/distributions/normcdf.m --- a/scripts/statistics/distributions/normcdf.m +++ b/scripts/statistics/distributions/normcdf.m @@ -40,7 +40,7 @@ s = 1; endif - if (!isscalar (m) || !isscalar(s)) + if (!isscalar (m) || !isscalar (s)) [retval, x, m, s] = common_size (x, m, s); if (retval > 0) error ("normcdf: x, m and s must be of common size or scalar"); diff --git a/scripts/statistics/distributions/norminv.m b/scripts/statistics/distributions/norminv.m --- a/scripts/statistics/distributions/norminv.m +++ b/scripts/statistics/distributions/norminv.m @@ -18,18 +18,18 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} norminv (@var{x}, @var{m}, @var{v}) +## @deftypefn {Function File} {} norminv (@var{x}, @var{m}, @var{s}) ## For each element of @var{x}, compute the quantile (the inverse of the ## CDF) at @var{x} of the normal distribution with mean @var{m} and -## variance @var{v}. +## standard deviation @var{s}. ## -## Default values are @var{m} = 0, @var{v} = 1. +## Default values are @var{m} = 0, @var{s} = 1. ## @end deftypefn ## Author: KH ## Description: Quantile function of the normal distribution -function inv = norminv (x, m, v) +function inv = norminv (x, m, s) if (nargin != 1 && nargin != 3) print_usage (); @@ -37,43 +37,43 @@ if (nargin == 1) m = 0; - v = 1; + s = 1; endif - if (!isscalar (m) || !isscalar(v)) - [retval, x, m, v] = common_size (x, m, v); + if (!isscalar (m) || !isscalar (s)) + [retval, x, m, s] = common_size (x, m, s); if (retval > 0) - error ("norminv: x, m and v must be of common size or scalars"); + error ("norminv: x, m and s must be of common size or scalars"); endif endif sz = size (x); inv = zeros (sz); - if (isscalar (m) && isscalar(v)) - if (find (isinf (m) | isnan (m) | !(v > 0) | !(v < Inf))) + if (isscalar (m) && isscalar (s)) + if (find (isinf (m) | isnan (m) | !(s > 0) | !(s < Inf))) inv = NaN * ones (sz); else - inv = m + sqrt (v) .* stdnormal_inv (x); + inv = m + s .* stdnormal_inv (x); endif else - k = find (isinf (m) | isnan (m) | !(v > 0) | !(v < Inf)); + k = find (isinf (m) | isnan (m) | !(s > 0) | !(s < Inf)); if (any (k)) inv(k) = NaN; endif - k = find (!isinf (m) & !isnan (m) & (v > 0) & (v < Inf)); + k = find (!isinf (m) & !isnan (m) & (s > 0) & (s < Inf)); if (any (k)) - inv(k) = m(k) + sqrt (v(k)) .* stdnormal_inv (x(k)); + inv(k) = m(k) + s(k) .* stdnormal_inv (x(k)); endif endif - k = find ((v == 0) & (x > 0) & (x < 1)); + k = find ((s == 0) & (x > 0) & (x < 1)); if (any (k)) inv(k) = m(k); endif - inv((v == 0) & (x == 0)) = -Inf; - inv((v == 0) & (x == 1)) = Inf; + inv((s == 0) & (x == 0)) = -Inf; + inv((s == 0) & (x == 1)) = Inf; endfunction diff --git a/scripts/statistics/distributions/normpdf.m b/scripts/statistics/distributions/normpdf.m --- a/scripts/statistics/distributions/normpdf.m +++ b/scripts/statistics/distributions/normpdf.m @@ -18,18 +18,18 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} normpdf (@var{x}, @var{m}, @var{v}) +## @deftypefn {Function File} {} normpdf (@var{x}, @var{m}, @var{s}) ## For each element of @var{x}, compute the probability density function ## (PDF) at @var{x} of the normal distribution with mean @var{m} and -## variance @var{v}. +## standard deviation @var{s}. ## -## Default values are @var{m} = 0, @var{v} = 1. +## Default values are @var{m} = 0, @var{s} = 1. ## @end deftypefn ## Author: TT ## Description: PDF of the normal distribution -function pdf = normpdf (x, m, v) +function pdf = normpdf (x, m, s) if (nargin != 1 && nargin != 3) print_usage (); @@ -37,38 +37,38 @@ if (nargin == 1) m = 0; - v = 1; + s = 1; endif - if (!isscalar (m) || !isscalar(v)) - [retval, x, m, v] = common_size (x, m, v); + if (!isscalar (m) || !isscalar (s)) + [retval, x, m, s] = common_size (x, m, s); if (retval > 0) - error ("normpdf: x, m and v must be of common size or scalars"); + error ("normpdf: x, m and s must be of common size or scalars"); endif endif sz = size (x); pdf = zeros (sz); - if (isscalar (m) && isscalar(v)) - if (find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf))) + if (isscalar (m) && isscalar (s)) + if (find (isinf (m) | isnan (m) | !(s >= 0) | !(s < Inf))) pdf = NaN * ones (sz); else - pdf = stdnormal_pdf ((x - m) ./ sqrt (v)) ./ sqrt (v); + pdf = stdnormal_pdf ((x - m) ./ s) ./ s; endif else - k = find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf)); + k = find (isinf (m) | isnan (m) | !(s >= 0) | !(s < Inf)); if (any (k)) pdf(k) = NaN; endif - k = find (!isinf (m) & !isnan (m) & (v >= 0) & (v < Inf)); + k = find (!isinf (m) & !isnan (m) & (s >= 0) & (s < Inf)); if (any (k)) - pdf(k) = stdnormal_pdf ((x(k) - m(k)) ./ sqrt (v(k))) ./ sqrt (v(k)); + pdf(k) = stdnormal_pdf ((x(k) - m(k)) ./ s(k)) ./ s(k); endif endif - pdf((v == 0) & (x == m)) = Inf; - pdf((v == 0) & ((x < m) | (x > m))) = 0; + pdf((s == 0) & (x == m)) = Inf; + pdf((s == 0) & ((x < m) | (x > m))) = 0; endfunction diff --git a/scripts/statistics/distributions/normrnd.m b/scripts/statistics/distributions/normrnd.m --- a/scripts/statistics/distributions/normrnd.m +++ b/scripts/statistics/distributions/normrnd.m @@ -18,27 +18,27 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} normrnd (@var{m}, @var{v}, @var{r}, @var{c}) -## @deftypefnx {Function File} {} normrnd (@var{m}, @var{v}, @var{sz}) +## @deftypefn {Function File} {} normrnd (@var{m}, @var{s}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} normrnd (@var{m}, @var{s}, @var{sz}) ## Return an @var{r} by @var{c} or @code{size (@var{sz})} matrix of -## random samples from the normal distribution with parameters @var{m} -## and @var{v}. Both @var{m} and @var{v} must be scalar or of size -## @var{r} by @var{c}. +## random samples from the normal distribution with parameters mean @var{m} +## and standard deviation @var{s}. Both @var{m} and @var{s} must be scalar +## or of size @var{r} by @var{c}. ## ## If @var{r} and @var{c} are omitted, the size of the result matrix is -## the common size of @var{m} and @var{v}. +## the common size of @var{m} and @var{s}. ## @end deftypefn ## Author: KH ## Description: Random deviates from the normal distribution -function rnd = normrnd (m, v, r, c) +function rnd = normrnd (m, s, r, c) if (nargin > 1) - if (!isscalar(m) || !isscalar(v)) - [retval, m, v] = common_size (m, v); + if (!isscalar (m) || !isscalar (s)) + [retval, m, s] = common_size (m, s); if (retval > 0) - error ("normrnd: m and v must be of common size or scalar"); + error ("normrnd: m and s must be of common size or scalar"); endif endif endif @@ -54,7 +54,7 @@ if (any (size (m) != 1) && (length (size (m)) != length (sz) || any (size (m) != sz))) - error ("normrnd: m and v must be scalar or of size [r, c]"); + error ("normrnd: m and s must be scalar or of size [r, c]"); endif elseif (nargin == 3) if (isscalar (r) && (r > 0)) @@ -67,7 +67,7 @@ if (any (size (m) != 1) && (length (size (m)) != length (sz) || any (size (m) != sz))) - error ("normrnd: m and v must be scalar or of size sz"); + error ("normrnd: m and s must be scalar or of size sz"); endif elseif (nargin == 2) sz = size(m); @@ -75,15 +75,15 @@ print_usage (); endif - if (isscalar (m) && isscalar (v)) - if (find (isnan (m) | isinf (m) | !(v > 0) | !(v < Inf))) + if (isscalar (m) && isscalar (s)) + if (find (isnan (m) | isinf (m) | !(s > 0) | !(s < Inf))) rnd = NaN * ones (sz); else - rnd = m + sqrt (v) .* randn (sz); + rnd = m + s .* randn (sz); endif else - rnd = m + sqrt (v) .* randn (sz); - k = find (isnan (m) | isinf (m) | !(v > 0) | !(v < Inf)); + rnd = m + s .* randn (sz); + k = find (isnan (m) | isinf (m) | !(s > 0) | !(s < Inf)); if (any (k)) rnd(k) = NaN; endif