Mercurial > hg > octave-lyh
changeset 6777:4775fc1aa728
[project @ 2007-07-18 16:32:51 by dbateman]
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -147,4 +147,9 @@ normrnd have been modified to compute distributions using the standard deviation instead of the variance. + ** For compatibility with Matlab, gamcdf, gaminv, gampdf, gamrnd, + expcdf, expinv, exppdf and exprnd have been modified to compute + the distributions using the standard scale factor rather than + one over the scale factor. + See NEWS.2 for old news.
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,18 @@ +2007-07-18 David Bateman <dbateman@free.fr> + + * statistics/distributions/gamcdf.m, statistics/distributions/gaminv.m, + statistics/distributions/gampdf.m, statistics/distributions/gamrnd.m, + statistics/distributions/expcdf.m, statistics/distributions/expinv.m, + statistics/distributions/exppdf.m, statistics/distributions/exprnd.m: + Use standard scale factor rather than one on the scale factor for + compatibility. + + * deprecated/gamma_cdf.m, deprecated/gamma_inv.m, + deprecated/gamma_pdf.m, deprecated/gamma_rnd.m, + deprecated/exponential_cdf.m, deprecated/exponential_inv.m, + deprecated/exponential_pdf.m, deprecated/exponential_rnd.m: + Preserve backward compatibility. + 2007-07-17 Michael Goffioul <michael.goffioul@gmail.com> * pkg/pkg.m (pkg:installed_packages): Use findstr rather than regexp
--- a/scripts/deprecated/exponential_cdf.m +++ b/scripts/deprecated/exponential_cdf.m @@ -31,6 +31,10 @@ function cdf = exponential_cdf (varargin) + if (nargin > 1) + varargin{2} = 1 ./ varargin{2}; + endif + cdf = expcdf (varargin{:}); endfunction
--- a/scripts/deprecated/exponential_inv.m +++ b/scripts/deprecated/exponential_inv.m @@ -29,6 +29,10 @@ function inv = exponential_inv (varargin) + if (nargin > 1) + varargin{2} = 1 ./ varargin{2}; + endif + inv = expinv (varargin{:}); endfunction
--- a/scripts/deprecated/exponential_pdf.m +++ b/scripts/deprecated/exponential_pdf.m @@ -28,6 +28,10 @@ function pdf = exponential_pdf (varargin) + if (nargin > 1) + varargin{2} = 1 ./ varargin{2}; + endif + pdf = exppdf (varargin{:}); endfunction
--- a/scripts/deprecated/exponential_rnd.m +++ b/scripts/deprecated/exponential_rnd.m @@ -34,6 +34,10 @@ function rnd = exponential_rnd (varargin) + if (nargin > 0) + varargin{1} = 1 ./ varargin{1}; + endif + rnd = exprnd (varargin{:}); endfunction
--- a/scripts/deprecated/gamma_cdf.m +++ b/scripts/deprecated/gamma_cdf.m @@ -29,6 +29,10 @@ function cdf = gamma_cdf (varargin) + if (nargin > 2) + varargin{3} = 1 ./ varargin{3}; + endif + cdf = gamcdf (varargin{:}); endfunction
--- a/scripts/deprecated/gamma_inv.m +++ b/scripts/deprecated/gamma_inv.m @@ -29,6 +29,10 @@ function inv = gamma_inv (varargin) + if (nargin > 2) + varargin{3} = 1 ./ varargin{3}; + endif + inv = gaminv (varargin{:}); endfunction
--- a/scripts/deprecated/gamma_pdf.m +++ b/scripts/deprecated/gamma_pdf.m @@ -29,6 +29,10 @@ function pdf = gamma_pdf (varargin) + if (nargin > 2) + varargin{3} = 1 ./ varargin{3}; + endif + pdf = gampdf (varargin{:}); endfunction
--- a/scripts/deprecated/gamma_rnd.m +++ b/scripts/deprecated/gamma_rnd.m @@ -34,6 +34,10 @@ function rnd = gamma_rnd (varargin) + if (nargin > 1) + varargin{2} = 1 ./ varargin{2}; + endif + rnd = gamrnd (varargin{:}); endfunction
--- a/scripts/statistics/distributions/expcdf.m +++ b/scripts/statistics/distributions/expcdf.m @@ -63,11 +63,11 @@ k = find ((x > 0) & (x < Inf) & (l > 0)); if (any (k)) if isscalar (l) - cdf (k) = 1 - exp (- l .* x(k)); + cdf (k) = 1 - exp (- x(k) ./ l); elseif isscalar (x) - cdf (k) = 1 - exp (- l(k) .* x); + cdf (k) = 1 - exp (- x ./ l(k)); else - cdf (k) = 1 - exp (- l(k) .* x(k)); + cdf (k) = 1 - exp (- x(k) ./ l(k)); endif endif
--- a/scripts/statistics/distributions/expinv.m +++ b/scripts/statistics/distributions/expinv.m @@ -61,11 +61,11 @@ k = find ((x > 0) & (x < 1) & (l > 0)); if (any (k)) if isscalar (l) - inv(k) = - log (1 - x(k)) ./ l; + inv(k) = - l .* log (1 - x(k)); elseif isscalar (x) - inv(k) = - log (1 - x) ./ l(k); + inv(k) = - l(k) .* log (1 - x); else - inv(k) = - log (1 - x(k)) ./ l(k); + inv(k) = - l(k) .* log (1 - x(k)); endif endif
--- a/scripts/statistics/distributions/exppdf.m +++ b/scripts/statistics/distributions/exppdf.m @@ -54,11 +54,11 @@ k = find ((x > 0) & (x < Inf) & (l > 0)); if (any (k)) if isscalar (l) - pdf(k) = l .* exp (- l .* x(k)); + pdf(k) = exp (- x(k) ./ l) ./ l; elseif isscalar (x) - pdf(k) = l(k) .* exp (- l(k) .* x); + pdf(k) = exp (- x ./ l(k)) ./ l(k); else - pdf(k) = l(k) .* exp (- l(k) .* x(k)); + pdf(k) = exp (- x(k) ./ l(k)) ./ l(k); endif endif
--- a/scripts/statistics/distributions/exprnd.m +++ b/scripts/statistics/distributions/exprnd.m @@ -69,7 +69,7 @@ if (isscalar (l)) if ((l > 0) && (l < Inf)) - rnd = rande(sz) / l; + rnd = rande(sz) * l; else rnd = NaN * ones (sz); endif @@ -81,7 +81,7 @@ endif k = find ((l > 0) & (l < Inf)); if (any (k)) - rnd(k) = rande(size(k)) / l(k); + rnd(k) = rande(size(k)) .* l(k); endif endif
--- a/scripts/statistics/distributions/gamcdf.m +++ b/scripts/statistics/distributions/gamcdf.m @@ -52,9 +52,9 @@ k = find ((x > 0) & (a > 0) & (b > 0)); if (any (k)) if (isscalar (a) && isscalar(b)) - cdf (k) = gammainc (b * x(k), a); + cdf (k) = gammainc (x(k) ./ b, a); else - cdf (k) = gammainc (b(k) .* x(k), a(k)); + cdf (k) = gammainc (x(k) ./ b(k), a(k)); endif endif
--- a/scripts/statistics/distributions/gaminv.m +++ b/scripts/statistics/distributions/gaminv.m @@ -59,9 +59,9 @@ if (!isscalar(a) || !isscalar(b)) a = a (k); b = b (k); - y = a ./ b; + y = a .* b; else - y = a / b * ones (size (k)); + y = a * b * ones (size (k)); endif x = x (k); l = find (x < eps);
--- a/scripts/statistics/distributions/gampdf.m +++ b/scripts/statistics/distributions/gampdf.m @@ -52,22 +52,22 @@ k = find ((x > 0) & (a > 0) & (a <= 1) & (b > 0)); if (any (k)) if (isscalar(a) && isscalar(b)) - pdf(k) = ((b .^ a) .* (x(k) .^ (a - 1)) - .* exp(-b .* x(k)) ./ gamma (a)); + pdf(k) = (x(k) .^ (a - 1)) ... + .* exp(- x(k) ./ b) ./ gamma (a) ./ (b .^ a); else - pdf(k) = ((b(k) .^ a(k)) .* (x(k) .^ (a(k) - 1)) - .* exp(-b(k) .* x(k)) ./ gamma (a(k))); + pdf(k) = (x(k) .^ (a(k) - 1)) ... + .* exp(- x(k) ./ b(k)) ./ gamma (a(k)) ./ (b(k) .^ a(k)); endif endif k = find ((x > 0) & (a > 1) & (b > 0)); if (any (k)) if (isscalar(a) && isscalar(b)) - pdf(k) = exp (a .* log (b) + (a-1) .* log (x(k)) - - b .* x(k) - gammaln (a)); + pdf(k) = exp (- a .* log (b) + (a-1) .* log (x(k)) + - x(k) ./ b - gammaln (a)); else - pdf(k) = exp (a(k) .* log (b(k)) + (a(k)-1) .* log (x(k)) - - b(k) .* x(k) - gammaln (a(k))); + pdf(k) = exp (- a(k) .* log (b(k)) + (a(k)-1) .* log (x(k)) + - x(k) ./ b(k) - gammaln (a(k))); endif endif
--- a/scripts/statistics/distributions/gamrnd.m +++ b/scripts/statistics/distributions/gamrnd.m @@ -82,7 +82,7 @@ if (find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf))) rnd = NaN * ones (sz); else - rnd = randg(a,sz)/b; + rnd = b .* randg(a, sz); endif else k = find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf)); @@ -91,7 +91,7 @@ endif k = find ((a > 0) & (a < Inf) & (b > 0) & (b < Inf)); if (any (k)) - rnd(k) = randg(a(k),size(k))/b(k); + rnd(k) = b(k) .* randg(a(k), size(k)); endif endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2007-07-18 David Bateman <dbateman@free.fr> + + * zfstream.cc (int_type gzfilebuf::pbackfail (int_type)): New + method to putback a character when the putback position in the + internal buffer doesn't exist. + * zfstream.h (int_type pbackfail (int_type)): Declaration it. + 2007-07-14 Michael Goffioul <michael.goffioul@swing.be> * src/ov-bool-sparse.cc (octave_sparse_bool_matrix:load_hdf5):
--- a/src/zfstream.cc +++ b/src/zfstream.cc @@ -207,6 +207,47 @@ return 0; } +// Puts back a character to the stream in two cases. Firstly, when there +// is no putback position available, and secondly when the character putback +// differs from the one in the file. We can only support the first case +// with gzipped files. +gzfilebuf::int_type +gzfilebuf::pbackfail (gzfilebuf::int_type c) +{ + if (this->is_open()) + { + if (gzseek (file, this->gptr() - this->egptr() - 1, SEEK_CUR) < 0) + return traits_type::eof(); + + // Invalidates contents of the buffer + enable_buffer (); + + // Attempt to fill internal buffer from gzipped file + // (buffer must be guaranteed to exist...) + int bytes_read = gzread(file, buffer, buffer_size); + // Indicates error or EOF + if (bytes_read <= 0) + { + // Reset get area + this->setg(buffer, buffer, buffer); + return traits_type::eof(); + } + + // Make all bytes read from file available as get area + this->setg(buffer, buffer, buffer + bytes_read); + + // If next character in get area differs from putback character + // flag a failure + gzfilebuf::int_type ret = traits_type::to_int_type(*(this->gptr())); + if (ret != c) + return traits_type::eof(); + else + return ret; + } + else + return traits_type::eof(); +} + // Fill get area from gzipped file gzfilebuf::int_type gzfilebuf::underflow()