Mercurial > octave-antonio
changeset 5693:446b28529300
[project @ 2006-03-17 18:16:03 by jwe]
author | jwe |
---|---|
date | Fri, 17 Mar 2006 18:16:03 +0000 |
parents | fe226f54d259 |
children | 95d90f781ca8 |
files | scripts/ChangeLog scripts/deprecated/weibcdf.m scripts/deprecated/weibinv.m scripts/deprecated/weibpdf.m scripts/deprecated/weibrnd.m scripts/deprecated/weibull_cdf.m scripts/deprecated/weibull_inv.m scripts/deprecated/weibull_pdf.m scripts/deprecated/weibull_rnd.m scripts/statistics/distributions/wblcdf.m scripts/statistics/distributions/wblinv.m scripts/statistics/distributions/wblpdf.m scripts/statistics/distributions/wblrnd.m scripts/statistics/distributions/weibcdf.m scripts/statistics/distributions/weibinv.m scripts/statistics/distributions/weibpdf.m scripts/statistics/distributions/weibrnd.m |
diffstat | 17 files changed, 546 insertions(+), 343 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog Fri Mar 17 17:02:32 2006 +0000 +++ b/scripts/ChangeLog Fri Mar 17 18:16:03 2006 +0000 @@ -1,9 +1,25 @@ 2006-03-17 John W. Eaton <jwe@octave.org> + * deprecated/weibcdf.m, deprecated/weibinv.m, + deprecated/weibpdf.m, deprecated/weibrnd.m: New functions. + + * deprecated/weibull_cdf.m, deprecated/weibull_inv.m, + deprecated/weibull_pdf.m, deprecated/weibull_rnd.m: + Call new wbl functions to do the real work. + Swap args and provide default values as necessary to preserve + compatibility with old version of Octave. + + * statistics/distributions/wblcdf.m: Rename from weibcdf.m. + statistics/distributions/wblinv.m: Rename from weibinv.m. + statistics/distributions/wblpdf.m: Rename from weibpdf.m. + statistics/distributions/wblrnd.m: Rename from weibrnd.m. + Swap scale and shape args for compatibility. + * 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,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/weibcdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,38 @@ +## Copyright (C) 2006 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} weibcdf (@var{x}, @var{scale}, @var{shape}) +## Compute the cumulative distribution function (CDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}, which is +## +## @example +## 1 - exp(-(x/shape)^scale) +## @end example +## +## @noindent +## for @var{x} >= 0. +## @end deftypefn + +function cdf = weibcdf (varargin) + + cdf = wblcdf (varargin{:}); + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/weibinv.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,31 @@ +## Copyright (C) 2006 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} weibinv (@var{x}, @var{scale}, @var{shape}) +## Compute the quantile (the inverse of the CDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}. +## @end deftypefn + +function inv = weibinv (varargin) + + inv = wblinv (varargin{:}); + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/weibpdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,38 @@ +## Copyright (C) 2006 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} weibpdf (@var{x}, @var{scale}, @var{shape}) +## Compute the probability density function (PDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape} which is given by +## +## @example +## scale * shape^(-scale) * x^(scale-1) * exp(-(x/shape)^scale) +## @end example +## +## @noindent +## for @var{x} > 0. +## @end deftypefn + +function pdf = weibpdf (varargin) + + pdf = wblpdf (varargin{:}); + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/weibrnd.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,37 @@ +## Copyright (C) 2006 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} weibrnd (@var{scale}, @var{shape}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} weibrnd (@var{scale}, @var{shape}, @var{sz}) +## Return an @var{r} by @var{c} matrix of random samples from the +## Weibull distribution with parameters @var{scale} and @var{shape} +## which must be scalar or of size @var{r} by @var{c}. Or if @var{sz} +## is a vector return 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{alpha} and @var{sigma}. +## @end deftypefn + +function rnd = weibrnd (varargin) + + rnd = wblrnd (varargin{:}); + +endfunction +
--- a/scripts/deprecated/weibull_cdf.m Fri Mar 17 17:02:32 2006 +0000 +++ b/scripts/deprecated/weibull_cdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## Copyright (C) 2006 John W. Eaton ## ## This file is part of Octave. ## @@ -18,24 +18,30 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} weibull_cdf (@var{x}, @var{alpha}, @var{sigma}) +## @deftypefn {Function File} {} weibull_cdf (@var{x}, @var{shape}, @var{scale}) ## Compute the cumulative distribution function (CDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma}, which is +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}, which is ## ## @example -## 1 - exp(-(x/sigma)^alpha) +## 1 - exp(-(x/shape)^scale) ## @end example ## ## @noindent ## for @var{x} >= 0. ## @end deftypefn -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: CDF of the Weibull distribution - function cdf = weibull_cdf (varargin) - cdf = weibcdf (varargin{:}); + if (nargin == 2) + varargin{3} = varargin{2}; + varargin{2} = 1; + elseif (nargin > 2) + tmp = varargin{3}; + varargin{3} = varargin{2}; + varargin{2} = tmp; + endif + + cdf = wblcdf (varargin{:}); endfunction
--- a/scripts/deprecated/weibull_inv.m Fri Mar 17 17:02:32 2006 +0000 +++ b/scripts/deprecated/weibull_inv.m Fri Mar 17 18:16:03 2006 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## Copyright (C) 2006 John W. Eaton ## ## This file is part of Octave. ## @@ -18,17 +18,23 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} weibull_inv (@var{x}, @var{lambda}, @var{alpha}) +## @deftypefn {Function File} {} weibull_inv (@var{x}, @var{shape}, @var{scale}) ## Compute the quantile (the inverse of the CDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma}. +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}. ## @end deftypefn -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: Quantile function of the Weibull distribution - function inv = weibull_inv (varargin) - inv = weibinv (varargin{:}); + if (nargin == 2) + varargin{3} = varargin{2}; + varargin{2} = 1; + elseif (nargin > 2) + tmp = varargin{3}; + varargin{3} = varargin{2}; + varargin{2} = tmp; + endif + + inv = wblinv (varargin{:}); endfunction
--- a/scripts/deprecated/weibull_pdf.m Fri Mar 17 17:02:32 2006 +0000 +++ b/scripts/deprecated/weibull_pdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## Copyright (C) 2006 John W. Eaton ## ## This file is part of Octave. ## @@ -18,24 +18,30 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} weibull_pdf (@var{x}, @var{alpha}, @var{sigma}) +## @deftypefn {Function File} {} weibull_pdf (@var{x}, @var{shape}, @var{scale}) ## Compute the probability density function (PDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma} which is given by +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape} which is given by ## ## @example -## alpha * sigma^(-alpha) * x^(alpha-1) * exp(-(x/sigma)^alpha) +## scale * shape^(-scale) * x^(scale-1) * exp(-(x/shape)^scale) ## @end example ## ## @noindent ## for @var{x} > 0. ## @end deftypefn -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: PDF of the Weibull distribution - function pdf = weibull_pdf (varargin) - pdf = weibpdf (varargin{:}); + if (nargin == 2) + varargin{3} = varargin{2}; + varargin{2} = 1; + elseif (nargin > 2) + tmp = varargin{3}; + varargin{3} = varargin{2}; + varargin{2} = tmp; + endif + + pdf = wblpdf (varargin{:}); endfunction
--- a/scripts/deprecated/weibull_rnd.m Fri Mar 17 17:02:32 2006 +0000 +++ b/scripts/deprecated/weibull_rnd.m Fri Mar 17 18:16:03 2006 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## Copyright (C) 2006 John W. Eaton ## ## This file is part of Octave. ## @@ -18,13 +18,10 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} weibull_rnd (@var{alpha}, @var{sigma}, @var{r}, @var{c}) -## @deftypefnx {Function File} {} weibull_rnd (@var{alpha}, @var{sigma}, @var{sz}) -## -## This function has been deprecated. Use weibrnd instead. -## +## @deftypefn {Function File} {} weibull_rnd (@var{shape}, @var{scale}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} weibull_rnd (@var{shape}, @var{scale}, @var{sz}) ## Return an @var{r} by @var{c} matrix of random samples from the -## Weibull distribution with parameters @var{alpha} and @var{sigma} +## Weibull distribution with parameters @var{scale} and @var{shape} ## which must be scalar or of size @var{r} by @var{c}. Or if @var{sz} ## is a vector return a matrix of size @var{sz}. ## @@ -32,11 +29,15 @@ ## the common size of @var{alpha} and @var{sigma}. ## @end deftypefn -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: Random deviates from the Weibull distribution - function rnd = weibull_rnd (varargin) - rnd = weibrnd(varargin{:}); + if (nargin > 1) + tmp = varargin{2}; + varargin{2} = varargin{1}; + varargin{1} = tmp; + endif + + rnd = wblrnd (varargin{:}); endfunction +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/statistics/distributions/wblcdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,81 @@ +## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} wblcdf (@var{x}, @var{scale}, @var{shape}) +## Compute the cumulative distribution function (CDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}, which is +## +## @example +## 1 - exp(-(x/shape)^scale) +## @end example +## +## @noindent +## for @var{x} >= 0. +## @end deftypefn + +## Author: KH <Kurt.Hornik@wu-wien.ac.at> +## Description: CDF of the Weibull distribution + +function cdf = wblcdf (x, scale, shape) + + if (nargin < 1 || nargin > 3) + usage ("wblcdf (x, scale, shape)"); + endif + + if (nargin < 3) + shape = 1; + endif + + if (nargin < 2) + scale = 1; + endif + + if (!isscalar (shape) || !isscalar (scale)) + [retval, x, shape, scale] = common_size (x, shape, scale); + if (retval > 0) + error ("wblcdf: x, scale and shape must be of common size or scalar"); + endif + endif + + cdf = NaN * ones (size (x)); + + ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); + + k = find ((x <= 0) & ok); + if (any (k)) + cdf(k) = 0; + endif + + k = find ((x > 0) & (x < Inf) & ok); + if (any (k)) + if (isscalar (shape) && isscalar (scale)) + cdf(k) = 1 - exp (- (x(k) / scale) .^ shape); + else + cdf(k) = 1 - exp (- (x(k) ./ scale(k)) .^ shape(k)); + endif + endif + + k = find ((x == Inf) & ok); + if (any (k)) + cdf(k) = 1; + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/statistics/distributions/wblinv.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,74 @@ +## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} wblinv (@var{x}, @var{scale}, @var{shape}) +## Compute the quantile (the inverse of the CDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape}. +## @end deftypefn + +## Author: KH <Kurt.Hornik@wu-wien.ac.at> +## Description: Quantile function of the Weibull distribution + +function inv = wblinv (x, scale, shape) + + if (nargin < 1 || nargin > 3) + usage ("wblinv (x, scale, shape)"); + endif + + if (nargin < 3) + shape = 1; + endif + + if (nargin < 2) + scale = 1; + endif + + if (!isscalar (shape) || !isscalar (scale)) + [retval, x, shape, scale] = common_size (x, shape, scale); + if (retval > 0) + error ("wblinv: x, scale and shape must be of common size or scalar"); + endif + endif + + inv = NaN * ones (size (x)); + + ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); + + k = find ((x == 0) & ok); + if (any (k)) + inv(k) = -Inf; + endif + + k = find ((x > 0) & (x < 1) & ok); + if (any (k)) + if (isscalar (shape) && isscalar (scale)) + inv(k) = scale * (- log (1 - x(k))) .^ (1 / shape); + else + inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); + endif + endif + + k = find ((x == 1) & ok); + if (any (k)) + inv(k) = Inf; + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/statistics/distributions/wblpdf.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,79 @@ +## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} wblpdf (@var{x}, @var{scale}, @var{shape}) +## Compute the probability density function (PDF) at @var{x} of the +## Weibull distribution with shape parameter @var{scale} and scale +## parameter @var{shape} which is given by +## +## @example +## scale * shape^(-scale) * x^(scale-1) * exp(-(x/shape)^scale) +## @end example +## +## @noindent +## for @var{x} > 0. +## @end deftypefn + +## Author: KH <Kurt.Hornik@wu-wien.ac.at> +## Description: PDF of the Weibull distribution + +function pdf = wblpdf (x, scale, shape) + + if (nargin < 1 || nargin > 3) + usage ("wblpdf (x, scale, shape)"); + endif + + if (nargin < 3) + shape = 1; + endif + + if (nargin < 2) + scale = 1; + endif + + if (!isscalar (shape) || !isscalar (scale)) + [retval, x, shape, scale] = common_size (x, shape, scale); + if (retval > 0) + error ("wblpdf: x, scale and shape must be of common size or scalar"); + endif + endif + + pdf = NaN * ones (size (x)); + ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); + + k = find ((x > -Inf) & (x <= 0) & ok); + if (any (k)) + pdf(k) = 0; + endif + + k = find ((x > 0) & (x < Inf) & ok); + if (any (k)) + if (isscalar (shape) && isscalar (scale)) + pdf(k) = (shape .* (scale .^ -shape) + .* (x(k) .^ (shape - 1)) + .* exp(- (x(k) / scale) .^ shape)); + else + pdf(k) = (shape(k) .* (scale(k) .^ -shape(k)) + .* (x(k) .^ (shape(k) - 1)) + .* exp(- (x(k) ./ scale(k)) .^ shape(k))); + endif + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/statistics/distributions/wblrnd.m Fri Mar 17 18:16:03 2006 +0000 @@ -0,0 +1,96 @@ +## Copyright (C) 1995, 1996, 1997 Kurt Hornik +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} wblrnd (@var{scale}, @var{shape}, @var{r}, @var{c}) +## @deftypefnx {Function File} {} wblrnd (@var{scale}, @var{shape}, @var{sz}) +## Return an @var{r} by @var{c} matrix of random samples from the +## Weibull distribution with parameters @var{scale} and @var{shape} +## which must be scalar or of size @var{r} by @var{c}. Or if @var{sz} +## is a vector return 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{alpha} and @var{sigma}. +## @end deftypefn + +## Author: KH <Kurt.Hornik@wu-wien.ac.at> +## Description: Random deviates from the Weibull distribution + +function rnd = wblrnd (scale, shape, r, c) + + if (nargin > 1) + if (!isscalar(shape) || !isscalar(scale)) + [retval, shape, scale] = common_size (shape, scale); + if (retval > 0) + error ("wblrnd: shape and scale must be of common size or scalar"); + endif + endif + endif + + if (nargin == 4) + if (! (isscalar (r) && (r > 0) && (r == round (r)))) + error ("wblrnd: r must be a positive integer"); + endif + if (! (isscalar (c) && (c > 0) && (c == round (c)))) + error ("wblrnd: c must be a positive integer"); + endif + sz = [r, c]; + + if (any (size (scale) != 1) && + ((length (size (scale)) != length (sz)) || + any (size (scale) != sz))) + error ("wblrnd: shape and scale must be scalar or of size [r, c]"); + endif + elseif (nargin == 3) + if (isscalar (r) && (r > 0)) + sz = [r, r]; + elseif (isvector(r) && all (r > 0)) + sz = r(:)'; + else + error ("wblrnd: r must be a postive integer or vector"); + endif + + if (any (size (scale) != 1) && + ((length (size (scale)) != length (sz)) || + any (size (scale) != sz))) + error ("wblrnd: shape and scale must be scalar or of size sz"); + endif + elseif (nargin == 2) + sz = size(shape); + else + usage ("wblrnd (alpha, sigma, r, c)"); + endif + + if (isscalar (shape) && isscalar (scale)) + if ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)) + rnd = (scale * (- log (1 - rand (sz))) .^ (1 / shape)); + else + rnd = NaN * ones (sz); + endif + else + rnd = NaN * ones (sz); + k = find ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); + if (any (k)) + rnd(k) = (scale(k) + .* (- log (1 - rand (size (k)))) .^ (1 ./ shape(k))); + endif + endif + +endfunction +
--- a/scripts/statistics/distributions/weibcdf.m Fri Mar 17 17:02:32 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} weibcdf (@var{x}, @var{alpha}, @var{sigma}) -## Compute the cumulative distribution function (CDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma}, which is -## -## @example -## 1 - exp(-(x/sigma)^alpha) -## @end example -## -## @noindent -## for @var{x} >= 0. -## @end deftypefn - -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: CDF of the Weibull distribution - -function cdf = weibcdf (x, shape, scale) - - if (nargin != 3) - usage ("weibcdf (x, alpha, sigma)"); - endif - - if (!isscalar (shape) || !isscalar (scale)) - [retval, x, shape, scale] = common_size (x, shape, scale); - if (retval > 0) - error ("weibcdf: x, alpha and sigma must be of common size or scalar"); - endif - endif - - cdf = NaN * ones (size (x)); - - ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); - - k = find ((x <= 0) & ok); - if (any (k)) - cdf(k) = 0; - endif - - k = find ((x > 0) & (x < Inf) & ok); - if (any (k)) - if (isscalar (shape) && isscalar (scale)) - cdf(k) = 1 - exp (- (x(k) / scale) .^ shape); - else - cdf(k) = 1 - exp (- (x(k) ./ scale(k)) .^ shape(k)); - endif - endif - - k = find ((x == Inf) & ok); - if (any (k)) - cdf(k) = 1; - endif - -endfunction
--- a/scripts/statistics/distributions/weibinv.m Fri Mar 17 17:02:32 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} weibinv (@var{x}, @var{lambda}, @var{alpha}) -## Compute the quantile (the inverse of the CDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma}. -## @end deftypefn - -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: Quantile function of the Weibull distribution - -function inv = weibinv (x, shape, scale) - - if (nargin != 3) - usage ("weibinv (x, alpha, sigma)"); - endif - - if (!isscalar (shape) || !isscalar (scale)) - [retval, x, shape, scale] = common_size (x, shape, scale); - if (retval > 0) - error ("weibinv: x, alpha and sigma must be of common size or scalar"); - endif - endif - - inv = NaN * ones (size (x)); - - ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); - - k = find ((x == 0) & ok); - if (any (k)) - inv(k) = -Inf; - endif - - k = find ((x > 0) & (x < 1) & ok); - if (any (k)) - if (isscalar (shape) && isscalar (scale)) - inv(k) = scale * (- log (1 - x(k))) .^ (1 / shape); - else - inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); - endif - endif - - k = find ((x == 1) & ok); - if (any (k)) - inv(k) = Inf; - endif - -endfunction
--- a/scripts/statistics/distributions/weibpdf.m Fri Mar 17 17:02:32 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} weibpdf (@var{x}, @var{alpha}, @var{sigma}) -## Compute the probability density function (PDF) at @var{x} of the -## Weibull distribution with shape parameter @var{alpha} and scale -## parameter @var{sigma} which is given by -## -## @example -## alpha * sigma^(-alpha) * x^(alpha-1) * exp(-(x/sigma)^alpha) -## @end example -## -## @noindent -## for @var{x} > 0. -## @end deftypefn - -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: PDF of the Weibull distribution - -function pdf = weibpdf (x, shape, scale) - - if (nargin != 3) - usage ("weibpdf (x, alpha, sigma)"); - endif - - if (!isscalar (shape) || !isscalar (scale)) - [retval, x, shape, scale] = common_size (x, shape, scale); - if (retval > 0) - error ("weibpdf: x, alpha and sigma must be of common size or scalar"); - endif - endif - - pdf = NaN * ones (size (x)); - ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); - - k = find ((x > -Inf) & (x <= 0) & ok); - if (any (k)) - pdf(k) = 0; - endif - - k = find ((x > 0) & (x < Inf) & ok); - if (any (k)) - if (isscalar (shape) && isscalar (scale)) - pdf(k) = (shape .* (scale .^ -shape) - .* (x(k) .^ (shape - 1)) - .* exp(- (x(k) / scale) .^ shape)); - else - pdf(k) = (shape(k) .* (scale(k) .^ -shape(k)) - .* (x(k) .^ (shape(k) - 1)) - .* exp(- (x(k) ./ scale(k)) .^ shape(k))); - endif - endif - -endfunction
--- a/scripts/statistics/distributions/weibrnd.m Fri Mar 17 17:02:32 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -## Copyright (C) 1995, 1996, 1997 Kurt Hornik -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {} weibrnd (@var{alpha}, @var{sigma}, @var{r}, @var{c}) -## @deftypefnx {Function File} {} weibrnd (@var{alpha}, @var{sigma}, @var{sz}) -## Return an @var{r} by @var{c} matrix of random samples from the -## Weibull distribution with parameters @var{alpha} and @var{sigma} -## which must be scalar or of size @var{r} by @var{c}. Or if @var{sz} -## is a vector return 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{alpha} and @var{sigma}. -## @end deftypefn - -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: Random deviates from the Weibull distribution - -function rnd = weibrnd (shape, scale, r, c) - - if (nargin > 1) - if (!isscalar(shape) || !isscalar(scale)) - [retval, shape, scale] = common_size (shape, scale); - if (retval > 0) - error ("weibrnd: shape and scale must be of common size or scalar"); - endif - endif - endif - - if (nargin == 4) - if (! (isscalar (r) && (r > 0) && (r == round (r)))) - error ("weibrnd: r must be a positive integer"); - endif - if (! (isscalar (c) && (c > 0) && (c == round (c)))) - error ("weibrnd: c must be a positive integer"); - endif - sz = [r, c]; - - if (any (size (scale) != 1) && - ((length (size (scale)) != length (sz)) || - any (size (scale) != sz))) - error ("weibrnd: shape and scale must be scalar or of size [r, c]"); - endif - elseif (nargin == 3) - if (isscalar (r) && (r > 0)) - sz = [r, r]; - elseif (isvector(r) && all (r > 0)) - sz = r(:)'; - else - error ("weibrnd: r must be a postive integer or vector"); - endif - - if (any (size (scale) != 1) && - ((length (size (scale)) != length (sz)) || - any (size (scale) != sz))) - error ("weibrnd: shape and scale must be scalar or of size sz"); - endif - elseif (nargin == 2) - sz = size(shape); - else - usage ("weibrnd (alpha, sigma, r, c)"); - endif - - if (isscalar (shape) && isscalar (scale)) - if ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)) - rnd = (scale * (- log (1 - rand (sz))) .^ (1 / shape)); - else - rnd = NaN * ones (sz); - endif - else - rnd = NaN * ones (sz); - k = find ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); - if (any (k)) - rnd(k) = (scale(k) - .* (- log (1 - rand (size (k)))) .^ (1 ./ shape(k))); - endif - endif - -endfunction -