Mercurial > hg > octave-avbm
changeset 6617:55da54f6c5c2
[project @ 2007-05-14 16:17:46 by jwe]
author | jwe |
---|---|
date | Mon, 14 May 2007 16:17:46 +0000 |
parents | 66e30383481b |
children | b9bd216661d1 |
files | NEWS scripts/ChangeLog scripts/deprecated/normal_cdf.m scripts/deprecated/normal_inv.m scripts/deprecated/normal_pdf.m scripts/deprecated/normal_rnd.m scripts/statistics/distributions/logninv.m scripts/statistics/distributions/lognpdf.m scripts/statistics/distributions/normcdf.m scripts/statistics/distributions/norminv.m scripts/statistics/distributions/normpdf.m scripts/statistics/distributions/normrnd.m |
diffstat | 12 files changed, 88 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,16 @@ +2007-05-14 Tarmigan Casebolt <tarmigan+list@gmail.com> + + * 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 <dbateman@free.fr> * pkg/pkg.m: Mark loaded packages with "*".
--- 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
--- 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
--- 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
--- 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
--- 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))
--- 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
--- 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");
--- 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 <Kurt.Hornik@wu-wien.ac.at> ## 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
--- 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 <Teresa.Twaroch@ci.tuwien.ac.at> ## 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
--- 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 <Kurt.Hornik@wu-wien.ac.at> ## 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