Mercurial > hg > octave-nkf
changeset 5692:fe226f54d259
[project @ 2006-03-17 17:02:32 by jwe]
author | jwe |
---|---|
date | Fri, 17 Mar 2006 17:02:32 +0000 |
parents | 9be68956e450 |
children | 446b28529300 |
files | scripts/ChangeLog scripts/deprecated/lognormal_cdf.m scripts/deprecated/lognormal_inv.m scripts/deprecated/lognormal_pdf.m scripts/deprecated/lognormal_rnd.m scripts/statistics/distributions/logncdf.m scripts/statistics/distributions/logninv.m scripts/statistics/distributions/lognpdf.m scripts/statistics/distributions/lognrnd.m |
diffstat | 9 files changed, 160 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,15 @@ 2006-03-17 John W. Eaton <jwe@octave.org> + * deprecated/lognormal_cdf.m, deprecated/lognormal_inv.m, + deprecated/lognormal_pdf.m, deprecated/lognormal_rnd.m: + Preserve compatibility with old versions of Octave given new + definitions of logncdf, logninv, lognpdf, and lognrnd. + * statistics/distributions/logncdf.m, + statistics/distributions/logninv.m, + statistics/distributions/lognpdf.m, + statistics/distributions/lognrnd.m: Compatibility fixes. + From Ben Barrowes <barrowes@alum.mit.edu> + * deprecated/hypergeometric_rnd.m: Update interface to match current 2.1.x version.
--- a/scripts/deprecated/lognormal_cdf.m +++ b/scripts/deprecated/lognormal_cdf.m @@ -33,6 +33,22 @@ function cdf = lognormal_cdf (varargin) - cdf = logncdf (varargin{:}); + if (nargin > 1) + a = varargin{2}; + idx = a >= 0; + a(idx) = log (a(idx)); + a(!idx) = NaN; + varargin{2} = a; + endif + + if (nargin > 2) + v = varargin{3}; + idx = v >= 0; + v(idx) = sqrt (v(idx)); + v(!idx) = NaN; + varargin{3} = v; + endif + + cdf = logncdf (varargin{:}); endfunction
--- a/scripts/deprecated/lognormal_inv.m +++ b/scripts/deprecated/lognormal_inv.m @@ -33,6 +33,22 @@ function inv = lognormal_inv (varargin) - inv = logninv (varargin{:}); + if (nargin > 1) + a = varargin{2}; + idx = a >= 0; + a(idx) = log (a(idx)); + a(!idx) = NaN; + varargin{2} = a; + endif + + if (nargin > 2) + v = varargin{3}; + idx = v >= 0; + v(idx) = sqrt (v(idx)); + v(!idx) = NaN; + varargin{3} = v; + endif + + inv = logninv (varargin{:}); endfunction
--- a/scripts/deprecated/lognormal_pdf.m +++ b/scripts/deprecated/lognormal_pdf.m @@ -33,6 +33,22 @@ function pdf = lognormal_pdf (varargin) - pdf = lognpdf (varargin{:}); + if (nargin > 1) + a = varargin{2}; + idx = a >= 0; + a(idx) = log (a(idx)); + a(!idx) = NaN; + varargin{2} = a; + endif + + if (nargin > 2) + v = varargin{3}; + idx = v >= 0; + v(idx) = sqrt (v(idx)); + v(!idx) = NaN; + varargin{3} = v; + endif + + pdf = lognpdf (varargin{:}); endfunction
--- a/scripts/deprecated/lognormal_rnd.m +++ b/scripts/deprecated/lognormal_rnd.m @@ -34,6 +34,22 @@ function rnd = lognormal_rnd (varargin) - rnd = lognrnd (varargin{:}); + if (nargin > 1) + a = varargin{2}; + idx = a >= 0; + a(idx) = log (a(idx)); + a(!idx) = NaN; + varargin{2} = a; + endif + + if (nargin > 2) + v = varargin{3}; + idx = v >= 0; + v(idx) = sqrt (v(idx)); + v(!idx) = NaN; + varargin{3} = v; + endif + + rnd = lognrnd (varargin{:}); endfunction
--- a/scripts/statistics/distributions/logncdf.m +++ b/scripts/statistics/distributions/logncdf.m @@ -18,60 +18,60 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} logncdf (@var{x}, @var{a}, @var{v}) +## @deftypefn {Function File} {} logncdf (@var{x}, @var{mu}, @var{sigma}) ## For each element of @var{x}, compute the cumulative distribution ## function (CDF) at @var{x} of the lognormal distribution with -## parameters @var{a} and @var{v}. If a random variable follows this +## parameters @var{mu} and @var{sigma}. If a random variable follows this ## distribution, its logarithm is normally distributed with mean -## @code{log (@var{a})} and variance @var{v}. +## @var{mu} and standard deviation @var{sigma}. ## -## Default values are @var{a} = 1, @var{v} = 1. +## Default values are @var{mu} = 1, @var{sigma} = 1. ## @end deftypefn ## Author: KH <Kurt.Hornik@wu-wien.ac.at> ## Description: CDF of the log normal distribution -function cdf = logncdf (x, a, v) +function cdf = logncdf (x, mu, sigma) if (! ((nargin == 1) || (nargin == 3))) - usage ("logncdf (x, a, v)"); + usage ("logncdf (x, mu, sigma)"); endif if (nargin == 1) - a = 1; - v = 1; + mu = 0; + sigma = 1; endif ## The following "straightforward" implementation unfortunately does ## not work (because exp (Inf) -> NaN etc): - ## cdf = normal_cdf (log (x), log (a), v); + ## cdf = normal_cdf (log (x), log (mu), sigma); ## Hence ... - if (!isscalar (a) || !isscalar (v)) - [retval, x, a, v] = common_size (x, a, v); + if (!isscalar (mu) || !isscalar (sigma)) + [retval, x, mu, sigma] = common_size (x, mu, sigma); if (retval > 0) - error ("logncdf: x, a and v must be of common size or scalars"); + error ("logncdf: x, mu and sigma must be of common size or scalars"); endif endif cdf = zeros (size (x)); - k = find (isnan (x) | !(a > 0) | !(a < Inf) | !(v > 0) | !(v < Inf)); + k = find (isnan (x) | !(sigma > 0) | !(sigma < Inf)); if (any (k)) cdf(k) = NaN; endif - k = find ((x == Inf) & (a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((x == Inf) & (sigma > 0) & (sigma < Inf)); if (any (k)) cdf(k) = 1; endif - k = find ((x > 0) & (x < Inf) & (a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((x > 0) & (x < Inf) & (sigma > 0) & (sigma < Inf)); if (any (k)) - if (isscalar (a) && isscalar (v)) - cdf(k) = stdnormal_cdf ((log (x(k)) - log (a)) / sqrt (v)); + if (isscalar (mu) && isscalar (sigma)) + cdf(k) = stdnormal_cdf ((log (x(k)) - mu) / sigma); else - cdf(k) = stdnormal_cdf ((log (x(k)) - log (a(k))) ./ sqrt (v(k))); + cdf(k) = stdnormal_cdf ((log (x(k)) - mu(k)) ./ sigma(k)); endif endif
--- a/scripts/statistics/distributions/logninv.m +++ b/scripts/statistics/distributions/logninv.m @@ -18,61 +18,60 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} logninv (@var{x}, @var{a}, @var{v}) +## @deftypefn {Function File} {} logninv (@var{x}, @var{mu}, @var{sigma}) ## For each element of @var{x}, compute the quantile (the inverse of the -## CDF) at @var{x} of the lognormal distribution with parameters @var{a} -## and @var{v}. If a random variable follows this distribution, its -## logarithm is normally distributed with mean @code{log (@var{a})} and -## variance @var{v}. +## CDF) at @var{x} of the lognormal distribution with parameters @var{mu} +## and @var{sigma}. If a random variable follows this distribution, its +## logarithm is normally distributed with mean @code{log (@var{mu})} and +## variance @var{sigma}. ## -## Default values are @var{a} = 1, @var{v} = 1. +## Default values are @var{mu} = 1, @var{sigma} = 1. ## @end deftypefn ## Author: KH <Kurt.Hornik@wu-wien.ac.at> ## Description: Quantile function of the log normal distribution -function inv = logninv (x, a, v) +function inv = logninv (x, mu, sigma) if (! ((nargin == 1) || (nargin == 3))) - usage ("logninv (x, a, v)"); + usage ("logninv (x, mu, sigma)"); endif if (nargin == 1) - a = 1; - v = 1; + mu = 0; + sigma = 1; endif ## The following "straightforward" implementation unfortunately does ## not work (because exp (Inf) -> NaN): - ## inv = exp (normal_inv (x, log (a), v)); + ## inv = exp (normal_inv (x, mu, sigma)); ## Hence ... - if (!isscalar (a) || !isscalar (v)) - [retval, x, a, v] = common_size (x, a, v); + if (!isscalar (mu) || !isscalar (sigma)) + [retval, x, mu, sigma] = common_size (x, mu, sigma); if (retval > 0) - error ("logninv: x, a and v must be of common size or scalars"); + error ("logninv: x, mu and sigma must be of common size or scalars"); endif endif inv = zeros (size (x)); - k = find (!(x >= 0) | !(x <= 1) | !(a > 0) | !(a < Inf) - | !(v > 0) | !(v < Inf)); + k = find (!(x >= 0) | !(x <= 1) | !(sigma > 0) | !(sigma < Inf)); if (any (k)) inv(k) = NaN; endif - k = find ((x == 1) & (a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((x == 1) & (sigma > 0) & (sigma < Inf)); if (any (k)) inv(k) = Inf; endif - k = find ((x > 0) & (x < 1) & (a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((x > 0) & (x < 1) & (sigma > 0) & (sigma < Inf)); if (any (k)) - if (isscalar (a) && isscalar (v)) - inv(k) = a .* exp (sqrt (v) .* stdnormal_inv (x(k))); + if (isscalar (mu) && isscalar (sigma)) + inv(k) = exp (mu) .* exp (sigma .* stdnormal_inv (x(k))); else - inv(k) = a(k) .* exp (sqrt (v(k)) .* stdnormal_inv (x(k))); + inv(k) = exp (mu(k)) .* exp (sigma(k) .* stdnormal_inv (x(k))); endif endif
--- a/scripts/statistics/distributions/lognpdf.m +++ b/scripts/statistics/distributions/lognpdf.m @@ -18,56 +18,56 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} lognpdf (@var{x}, @var{a}, @var{v}) +## @deftypefn {Function File} {} lognpdf (@var{x}, @var{mu}, @var{sigma}) ## For each element of @var{x}, compute the probability density function ## (PDF) at @var{x} of the lognormal distribution with parameters -## @var{a} and @var{v}. If a random variable follows this distribution, -## its logarithm is normally distributed with mean @code{log (@var{a})} -## and variance @var{v}. +## @var{mu} and @var{sigma}. If a random variable follows this distribution, +## its logarithm is normally distributed with mean @var{mu} +## and standard deviation @var{sigma}. ## -## Default values are @var{a} = 1, @var{v} = 1. +## Default values are @var{mu} = 1, @var{sigma} = 1. ## @end deftypefn ## Author: KH <Kurt.Hornik@wu-wien.ac.at> ## Description: PDF of the log normal distribution -function pdf = lognpdf (x, a, v) +function pdf = lognpdf (x, mu, sigma) if (! ((nargin == 1) || (nargin == 3))) - usage ("lognpdf (x, a, v)"); + usage ("lognpdf (x, mu, sigma)"); endif if (nargin == 1) - a = 1; - v = 1; + mu = 0; + sigma = 1; endif ## The following "straightforward" implementation unfortunately does ## not work for the special cases (Inf, ...) - ## pdf = (x > 0) ./ x .* normal_pdf (log (x), log (a), v); + ## pdf = (x > 0) ./ x .* normal_pdf (log (x), mu, sigma); ## Hence ... - if (!isscalar (a) || !isscalar (v)) - [retval, x, a, v] = common_size (x, a, v); + if (!isscalar (mu) || !isscalar (sigma)) + [retval, x, mu, sigma] = common_size (x, mu, sigma); if (retval > 0) - error ("lognpdf: x, a and v must be of common size or scalars"); + error ("lognpdf: x, mu and sigma must be of common size or scalars"); endif endif pdf = zeros (size (x)); - k = find (isnan (x) | !(a > 0) | !(a < Inf) | !(v > 0) | !(v < Inf)); + k = find (isnan (x) | !(sigma > 0) | !(sigma < Inf)); if (any (k)) pdf(k) = NaN; endif - k = find ((x > 0) & (x < Inf) & (a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((x > 0) & (x < Inf) & (sigma > 0) & (sigma < Inf)); if (any (k)) - if (isscalar (a) && isscalar (v)) - pdf(k) = normpdf (log (x(k)), log (a), v) ./ x(k); + if (isscalar (mu) && isscalar (sigma)) + pdf(k) = normpdf (log (x(k)), mu, sigma.^2) ./ x(k); else - pdf(k) = normpdf (log (x(k)), log (a(k)), v(k)) ./ x(k); - endif + pdf(k) = normpdf (log (x(k)), mu(k), sigma(k).^2) ./ x(k); + endif endif endfunction
--- a/scripts/statistics/distributions/lognrnd.m +++ b/scripts/statistics/distributions/lognrnd.m @@ -1,3 +1,4 @@ + ## Copyright (C) 1995, 1996, 1997 Kurt Hornik ## ## This file is part of Octave. @@ -18,27 +19,27 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} lognrnd (@var{a}, @var{v}, @var{r}, @var{c}) -## @deftypefnx {Function File} {} lognrnd (@var{a}, @var{v}, @var{sz}) +## @deftypefn {Function File} {} lognrnd (@var{mu}, @var{sigma}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} lognrnd (@var{mu}, @var{sigma}, @var{sz}) ## Return an @var{r} by @var{c} matrix of random samples from the -## lognormal distribution with parameters @var{a} and @var{v}. Both -## @var{a} and @var{v} must be scalar or of size @var{r} by @var{c}. +## lognormal distribution with parameters @var{mu} and @var{sigma}. Both +## @var{mu} and @var{sigma} must be scalar or of size @var{r} by @var{c}. ## Or if @var{sz} is a vector, create a matrix of size @var{sz}. ## ## If @var{r} and @var{c} are omitted, the size of the result matrix is -## the common size of @var{a} and @var{v}. +## the common size of @var{mu} and @var{sigma}. ## @end deftypefn ## Author: KH <Kurt.Hornik@wu-wien.ac.at> ## Description: Random deviates from the log normal distribution -function rnd = lognrnd (a, v, r, c) +function rnd = lognrnd (mu, sigma, r, c) if (nargin > 1) - if (!isscalar(a) || !isscalar(v)) - [retval, a, v] = common_size (a, v); + if (!isscalar(mu) || !isscalar(sigma)) + [retval, mu, sigma] = common_size (mu, sigma); if (retval > 0) - error ("lognrnd: a and v must be of common size or scalar"); + error ("lognrnd: mu and sigma must be of common size or scalar"); endif endif endif @@ -52,9 +53,9 @@ endif sz = [r, c]; - if (any (size (a) != 1) && - ((length (size (a)) != length (sz)) || any (size (a) != sz))) - error ("lognrnd: a and b must be scalar or of size [r, c]"); + if (any (size (mu) != 1) && + ((length (size (mu)) != length (sz)) || any (size (mu) != sz))) + error ("lognrnd: mu and sigma must be scalar or of size [r, c]"); endif elseif (nargin == 3) @@ -66,34 +67,34 @@ error ("lognrnd: r must be a postive integer or vector"); endif - if (any (size (a) != 1) && - ((length (size (a)) != length (sz)) || any (size (a) != sz))) - error ("lognrnd: a and b must be scalar or of size sz"); + if (any (size (mu) != 1) && + ((length (size (mu)) != length (sz)) || any (size (mu) != sz))) + error ("lognrnd: mu and sigma must be scalar or of size sz"); endif elseif (nargin == 2) - sz = size(a); + sz = size(mu); else - usage ("lognrnd (a, v, r, c)"); + usage ("lognrnd (mu, sigma, r, c)"); endif - if (isscalar (a) && isscalar (v)) - if (!(a > 0) | !(a < Inf) | !(v > 0) | !(v < Inf)) + if (isscalar (mu) && isscalar (sigma)) + if (!(mu > 0) | !(mu < Inf) | !(sigma > 0) | !(sigma < Inf)) rnd = NaN * ones (sz); - elseif find ((a > 0) & (a < Inf) & (v > 0) & (v < Inf)); - rnd = a * exp (sqrt (v) .* randn (sz)); + elseif find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf)); + rnd = exp (mu) * exp (sigma .* randn (sz)); else rnd = zeros (sz); endif else rnd = zeros (sz); - k = find (!(a > 0) | !(a < Inf) | !(v > 0) | !(v < Inf)); + k = find (!(mu > 0) | !(mu < Inf) | !(sigma > 0) | !(sigma < Inf)); if (any (k)) rnd(k) = NaN * ones (1, length (k)); endif - k = find ((a > 0) & (a < Inf) & (v > 0) & (v < Inf)); + k = find ((mu > 0) & (mu < Inf) & (sigma > 0) & (sigma < Inf)); if (any (k)) - rnd(k) = a(k) .* exp (sqrt (v(k)) .* randn (1, length (k))); + rnd(k) = exp (mu(k)) .* exp (sigma(k) .* randn (1, length (k))); endif endif