Skip to content

Commit

Permalink
change parameter name from 'nu' to 's' in Rician distribution functio…
Browse files Browse the repository at this point in the history
…ns for MATLAB compatibilbity
  • Loading branch information
pr0m1th3as committed Feb 28, 2024
1 parent d0138dc commit d4f8e0d
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 160 deletions.
32 changes: 16 additions & 16 deletions inst/dist_fit/ricefit.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
## @code{@var{paramhat} = ricefit (@var{x})} returns the maximum likelihood
## estimates of the parameters of the Rician distribution given the data in
## @var{x}. @qcode{@var{paramhat}(1)} is the non-centrality (distance)
## parameter, @math{nu}, and @qcode{@var{paramhat}(2)} is the scale parameter,
## parameter, @math{s}, and @qcode{@var{paramhat}(2)} is the scale parameter,
## @math{sigma}.
##
## @code{[@var{paramhat}, @var{paramci}] = ricefit (@var{x})} returns the 95%
Expand Down Expand Up @@ -217,28 +217,28 @@
%! hold on
%!
%! ## Estimate their α and β parameters
%! nu_sigmaA = ricefit (r(:,1));
%! nu_sigmaB = ricefit (r(:,2));
%! nu_sigmaC = ricefit (r(:,3));
%! s_sigmaA = ricefit (r(:,1));
%! s_sigmaB = ricefit (r(:,2));
%! s_sigmaC = ricefit (r(:,3));
%!
%! ## Plot their estimated PDFs
%! x = [0.01,0.1:0.2:18];
%! y = ricepdf (x, nu_sigmaA(1), nu_sigmaA(2));
%! y = ricepdf (x, s_sigmaA(1), s_sigmaA(2));
%! plot (x, y, "-pr");
%! y = ricepdf (x, nu_sigmaB(1), nu_sigmaB(2));
%! y = ricepdf (x, s_sigmaB(1), s_sigmaB(2));
%! plot (x, y, "-sg");
%! y = ricepdf (x, nu_sigmaC(1), nu_sigmaC(2));
%! y = ricepdf (x, s_sigmaC(1), s_sigmaC(2));
%! plot (x, y, "-^c");
%! hold off
%! legend ({"Normalized HIST of sample 1 with ν=1 and σ=2", ...
%! "Normalized HIST of sample 2 with ν=2 and σ=4", ...
%! "Normalized HIST of sample 3 with ν=7.5 and σ=1", ...
%! sprintf("PDF for sample 1 with estimated ν=%0.2f and σ=%0.2f", ...
%! nu_sigmaA(1), nu_sigmaA(2)), ...
%! sprintf("PDF for sample 2 with estimated ν=%0.2f and σ=%0.2f", ...
%! nu_sigmaB(1), nu_sigmaB(2)), ...
%! sprintf("PDF for sample 3 with estimated ν=%0.2f and σ=%0.2f", ...
%! nu_sigmaC(1), nu_sigmaC(2))})
%! legend ({"Normalized HIST of sample 1 with s=1 and σ=2", ...
%! "Normalized HIST of sample 2 with s=2 and σ=4", ...
%! "Normalized HIST of sample 3 with s=7.5 and σ=1", ...
%! sprintf("PDF for sample 1 with estimated s=%0.2f and σ=%0.2f", ...
%! s_sigmaA(1), s_sigmaA(2)), ...
%! sprintf("PDF for sample 2 with estimated s=%0.2f and σ=%0.2f", ...
%! s_sigmaB(1), s_sigmaB(2)), ...
%! sprintf("PDF for sample 3 with estimated s=%0.2f and σ=%0.2f", ...
%! s_sigmaC(1), s_sigmaC(2))})
%! title ("Three population samples from different Rician distibutions")
%! hold off

Expand Down
2 changes: 1 addition & 1 deletion inst/dist_fit/ricelike.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
##
## @code{@var{nlogL} = ricelike (@var{params}, @var{x})} returns the negative
## log likelihood of the data in @var{x} corresponding to the Rician
## distribution with (1) non-centrality (distance) parameter @math{nu} and (2)
## distribution with (1) non-centrality (distance) parameter @math{s} and (2)
## scale parameter @math{sigma} given in the two-element vector @var{params}.
##
## @code{[@var{nlogL}, @var{acov}] = ricelike (@var{params}, @var{x})} also
Expand Down
58 changes: 29 additions & 29 deletions inst/dist_fun/ricecdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {statistics} {@var{p} =} ricecdf (@var{x}, @var{nu}, @var{sigma})
## @deftypefnx {statistics} {@var{p} =} ricecdf (@var{x}, @var{nu}, @var{sigma}, @qcode{"upper"})
## @deftypefn {statistics} {@var{p} =} ricecdf (@var{x}, @var{s}, @var{sigma})
## @deftypefnx {statistics} {@var{p} =} ricecdf (@var{x}, @var{s}, @var{sigma}, @qcode{"upper"})
##
## Rician cumulative distribution function (CDF).
##
## For each element of @var{x}, compute the cumulative distribution function
## (CDF) of the Rician distribution with non-centrality (distance) parameter
## @var{nu} and scale parameter @var{sigma}. The size of @var{p} is the common
## size of @var{x}, @var{nu}, and @var{sigma}. A scalar input functions as a
## @var{s} and scale parameter @var{sigma}. The size of @var{p} is the common
## size of @var{x}, @var{s}, and @var{sigma}. A scalar input functions as a
## constant matrix of the same size as the other inputs.
##
## @code{@var{p} = ricecdf (@var{x}, @var{nu}, @var{sigma}, "upper")} computes
## @code{@var{p} = ricecdf (@var{x}, @var{s}, @var{sigma}, "upper")} computes
## the upper tail probability of the Rician distribution with parameters
## @var{nu} and @var{sigma}, at the values in @var{x}.
## @var{s} and @var{sigma}, at the values in @var{x}.
##
## Further information about the Rician distribution can be found at
## @url{https://en.wikipedia.org/wiki/Rice_distribution}
##
## @seealso{riceinv, ricepdf, ricernd, ricefit, ricelike, ricestat}
## @end deftypefn

function p = ricecdf (x, nu, sigma, uflag)
function p = ricecdf (x, s, sigma, uflag)

## Check for valid number of input arguments
if (nargin < 3)
Expand All @@ -53,39 +53,39 @@
uflag = false;
endif

## Check for common size of X and SIGMA
if (! isscalar (x) || ! isscalar (nu) || ! isscalar (sigma))
[retval, x, nu, sigma] = common_size (x, nu, sigma);
## Check for common size of X, S, and SIGMA
if (! isscalar (x) || ! isscalar (s) || ! isscalar (sigma))
[retval, x, s, sigma] = common_size (x, s, sigma);
if (retval > 0)
error ("ricecdf: X, NU, and SIGMA must be of common size or scalars.");
error ("ricecdf: X, S, and SIGMA must be of common size or scalars.");
endif
endif

## Check for X and SIGMA being reals
if (iscomplex (x) || iscomplex (nu) || iscomplex (sigma))
error ("ricecdf: X, NU, and SIGMA must not be complex.");
## Check for X, S, and SIGMA being reals
if (iscomplex (x) || iscomplex (s) || iscomplex (sigma))
error ("ricecdf: X, S, and SIGMA must not be complex.");
endif

## Check for class type
if (isa (x, "single") || isa (nu, "single") || isa (sigma, "single"));
if (isa (x, "single") || isa (s, "single") || isa (sigma, "single"));
p = zeros (size (x), "single");
else
p = zeros (size (x));
endif

## Force 1 for upper flag and X <= 0
k0 = nu >= 0 & sigma > 0 & x < 0;
k0 = s >= 0 & sigma > 0 & x < 0;
if (uflag && any (k0(:)))
p(k0) = 1;
end

## Calculate Rayleigh CDF for valid parameter and data range
k = nu >= 0 & sigma > 0 & x >= 0;
k = s >= 0 & sigma > 0 & x >= 0;
if (any (k(:)))
if (uflag)
p(k) = marcumQ1 (nu(k) ./ sigma(k), x(k) ./ sigma(k));
p(k) = marcumQ1 (s(k) ./ sigma(k), x(k) ./ sigma(k));
else
p(k) = 1 - marcumQ1 (nu(k) ./ sigma(k), x(k) ./ sigma(k));
p(k) = 1 - marcumQ1 (s(k) ./ sigma(k), x(k) ./ sigma(k));
endif
endif

Expand Down Expand Up @@ -150,8 +150,8 @@
%! grid on
%! ylim ([0, 1])
%! xlim ([0, 8])
%! legend ({"ν = 0, σ = 1", "ν = 0.5, σ = 1", "ν = 1, σ = 1", ...
%! "ν = 2, σ = 1", "ν = 4, σ = 1"}, "location", "southeast")
%! legend ({"s = 0, σ = 1", "s = 0.5, σ = 1", "s = 1, σ = 1", ...
%! "s = 2, σ = 1", "s = 4, σ = 1"}, "location", "southeast")
%! title ("Rician CDF")
%! xlabel ("values in x")
%! ylabel ("probability")
Expand All @@ -177,8 +177,8 @@
## Test output
%!test
%! x = 0:0.5:2.5;
%! nu = 1:6;
%! p = ricecdf (x, nu, 1);
%! s = 1:6;
%! p = ricecdf (x, s, 1);
%! expected_p = [0.0000, 0.0179, 0.0108, 0.0034, 0.0008, 0.0001];
%! assert (p, expected_p, 0.001);
%!test
Expand Down Expand Up @@ -209,12 +209,12 @@
%!error<ricecdf: function called with too few input arguments.> ricecdf (1, 2)
%!error<ricecdf: invalid argument for upper tail.> ricecdf (1, 2, 3, "uper")
%!error<ricecdf: invalid argument for upper tail.> ricecdf (1, 2, 3, 4)
%!error<ricecdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricecdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricecdf (ones (3), ones (2), ones (2))
%!error<ricecdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricecdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricecdf (ones (2), ones (3), ones (2))
%!error<ricecdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricecdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricecdf (ones (2), ones (2), ones (3))
%!error<ricecdf: X, NU, and SIGMA must not be complex.> ricecdf (i, 2, 3)
%!error<ricecdf: X, NU, and SIGMA must not be complex.> ricecdf (2, i, 3)
%!error<ricecdf: X, NU, and SIGMA must not be complex.> ricecdf (2, 2, i)
%!error<ricecdf: X, S, and SIGMA must not be complex.> ricecdf (i, 2, 3)
%!error<ricecdf: X, S, and SIGMA must not be complex.> ricecdf (2, i, 3)
%!error<ricecdf: X, S, and SIGMA must not be complex.> ricecdf (2, 2, i)
46 changes: 23 additions & 23 deletions inst/dist_fun/riceinv.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {statistics} {@var{x} =} riceinv (@var{p}, @var{nu}, @var{sigma})
## @deftypefn {statistics} {@var{x} =} riceinv (@var{p}, @var{s}, @var{sigma})
##
## Inverse of the Rician distribution (iCDF).
##
## For each element of @var{p}, compute the quantile (the inverse of the CDF)
## of the Rician distribution with non-centrality (distance) parameter @var{nu}
## of the Rician distribution with non-centrality (distance) parameter @var{s}
## and scale parameter @var{sigma}. The size of @var{x} is the common size of
## @var{x}, @var{nu}, and @var{sigma}. A scalar input functions as a constant
## @var{x}, @var{s}, and @var{sigma}. A scalar input functions as a constant
## matrix of the same size as the other inputs.
##
## Further information about the Rician distribution can be found at
Expand All @@ -32,39 +32,39 @@
## @seealso{ricecdf, ricepdf, ricernd, ricefit, ricelike, ricestat}
## @end deftypefn

function x = riceinv (p, nu, sigma)
function x = riceinv (p, s, sigma)

## Check for valid number of input arguments
if (nargin < 3)
error ("riceinv: function called with too few input arguments.");
endif

## Check for common size of P, NU, and B
if (! isscalar (p) || ! isscalar (nu) || ! isscalar (sigma))
[retval, p, nu, sigma] = common_size (p, nu, sigma);
## Check for common size of P, S, and B
if (! isscalar (p) || ! isscalar (s) || ! isscalar (sigma))
[retval, p, s, sigma] = common_size (p, s, sigma);
if (retval > 0)
error ("riceinv: P, NU, and B must be of common size or scalars.");
error ("riceinv: P, S, and B must be of common size or scalars.");
endif
endif

## Check for P, NU, and B being reals
if (iscomplex (p) || iscomplex (nu) || iscomplex (sigma))
error ("riceinv: P, NU, and B must not be complex.");
## Check for P, S, and B being reals
if (iscomplex (p) || iscomplex (s) || iscomplex (sigma))
error ("riceinv: P, S, and B must not be complex.");
endif

## Check for class type
if (isa (p, "single") || isa (nu, "single") || isa (sigma, "single"))
if (isa (p, "single") || isa (s, "single") || isa (sigma, "single"))
x = zeros (size (p), "single");
else
x = zeros (size (p));
endif

k = nu < 0 | sigma <= 0 | p < 0 | p > 1 | ...
isnan (p) | isnan (nu) | isnan (sigma);
k = s < 0 | sigma <= 0 | p < 0 | p > 1 | ...
isnan (p) | isnan (s) | isnan (sigma);
x(k) = NaN;

k = ! k;
x(k) = sigma(k) .* sqrt (ncx2inv (p(k), 2, (nu(k) ./ sigma(k)) .^ 2));
x(k) = sigma(k) .* sqrt (ncx2inv (p(k), 2, (s(k) ./ sigma(k)) .^ 2));

endfunction

Expand All @@ -78,8 +78,8 @@
%! x5 = riceinv (p, 4, 1);
%! plot (p, x1, "-b", p, x2, "-g", p, x3, "-r", p, x4, "-m", p, x5, "-k")
%! grid on
%! legend ({"ν = 0, σ = 1", "ν = 0.5, σ = 1", "ν = 1, σ = 1", ...
%! "ν = 2, σ = 1", "ν = 4, σ = 1"}, "location", "northwest")
%! legend ({"s = 0, σ = 1", "s = 0.5, σ = 1", "s = 1, σ = 1", ...
%! "s = 2, σ = 1", "s = 4, σ = 1"}, "location", "northwest")
%! title ("Rician iCDF")
%! xlabel ("probability")
%! ylabel ("values in x")
Expand Down Expand Up @@ -108,12 +108,12 @@
%!error<riceinv: function called with too few input arguments.> riceinv (1)
%!error<riceinv: function called with too few input arguments.> riceinv (1,2)
%!error<riceinv: function called with too many inputs> riceinv (1,2,3,4)
%!error<riceinv: P, NU, and B must be of common size or scalars.> ...
%!error<riceinv: P, S, and B must be of common size or scalars.> ...
%! riceinv (ones (3), ones (2), ones (2))
%!error<riceinv: P, NU, and B must be of common size or scalars.> ...
%!error<riceinv: P, S, and B must be of common size or scalars.> ...
%! riceinv (ones (2), ones (3), ones (2))
%!error<riceinv: P, NU, and B must be of common size or scalars.> ...
%!error<riceinv: P, S, and B must be of common size or scalars.> ...
%! riceinv (ones (2), ones (2), ones (3))
%!error<riceinv: P, NU, and B must not be complex.> riceinv (i, 2, 2)
%!error<riceinv: P, NU, and B must not be complex.> riceinv (2, i, 2)
%!error<riceinv: P, NU, and B must not be complex.> riceinv (2, 2, i)
%!error<riceinv: P, S, and B must not be complex.> riceinv (i, 2, 2)
%!error<riceinv: P, S, and B must not be complex.> riceinv (2, i, 2)
%!error<riceinv: P, S, and B must not be complex.> riceinv (2, 2, i)
44 changes: 22 additions & 22 deletions inst/dist_fun/ricepdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {statistics} {@var{y} =} ricepdf (@var{x}, @var{nu}, @var{sigma})
## @deftypefn {statistics} {@var{y} =} ricepdf (@var{x}, @var{s}, @var{sigma})
##
## Rician probability density function (PDF).
##
## For each element of @var{x}, compute the probability density function (PDF)
## of the Rician distribution with non-centrality (distance) parameter @var{nu}
## of the Rician distribution with non-centrality (distance) parameter @var{s}
## and scale parameter @var{sigma}. The size of @var{y} is the common size of
## @var{x}, @var{nu}, and @var{sigma}. A scalar input functions as a constant
## @var{x}, @var{s}, and @var{sigma}. A scalar input functions as a constant
## matrix of the same size as the other inputs.
##
## Further information about the Rician distribution can be found at
Expand All @@ -32,40 +32,40 @@
## @seealso{ricecdf, riceinv, ricernd, ricefit, ricelike, ricestat}
## @end deftypefn

function y = ricepdf (x, nu, sigma)
function y = ricepdf (x, s, sigma)

## Check for valid number of input arguments
if (nargin < 3)
error ("ricepdf: function called with too few input arguments.");
endif

## Check for common size of X, NU, and SIGMA
if (! isscalar (x) || ! isscalar (nu) || ! isscalar (sigma))
[retval, x, nu, sigma] = common_size (x, nu, sigma);
## Check for common size of X, S, and SIGMA
if (! isscalar (x) || ! isscalar (s) || ! isscalar (sigma))
[retval, x, s, sigma] = common_size (x, s, sigma);
if (retval > 0)
error ("ricepdf: X, NU, and SIGMA must be of common size or scalars.");
error ("ricepdf: X, S, and SIGMA must be of common size or scalars.");
endif
endif

## Check for X, NU, and SIGMA being reals
if (iscomplex (x) || iscomplex (nu) || iscomplex (sigma))
error ("ricepdf: X, NU, and SIGMA must not be complex.");
## Check for X, S, and SIGMA being reals
if (iscomplex (x) || iscomplex (s) || iscomplex (sigma))
error ("ricepdf: X, S, and SIGMA must not be complex.");
endif

## Check for class type
if (isa (x, "single") || isa (nu, "single") || isa (sigma, "single"));
if (isa (x, "single") || isa (s, "single") || isa (sigma, "single"));
y = zeros (size (x), "single");
else
y = zeros (size (x));
endif

k = nu < 0 | sigma <= 0 | x < 0 | isnan (x) | isnan (nu) | isnan (sigma);
k = s < 0 | sigma <= 0 | x < 0 | isnan (x) | isnan (s) | isnan (sigma);
y(k) = NaN;

k = ! k;
## Do the math
x_k = x(k);
n_k = nu(k);
n_k = s(k);
s_sq = sigma(k) .^ 2;
x_s2 = x_k ./ s_sq;
xnsq = (x_k .^ 2 + n_k .^ 2) ./ (2 .* s_sq);
Expand Down Expand Up @@ -93,8 +93,8 @@
%! grid on
%! ylim ([0, 0.65])
%! xlim ([0, 8])
%! legend ({"ν = 0, σ = 1", "ν = 0.5, σ = 1", "ν = 1, σ = 1", ...
%! "ν = 2, σ = 1", "ν = 4, σ = 1"}, "location", "northeast")
%! legend ({"s = 0, σ = 1", "s = 0.5, σ = 1", "s = 1, σ = 1", ...
%! "s = 2, σ = 1", "s = 4, σ = 1"}, "location", "northeast")
%! title ("Rician PDF")
%! xlabel ("values in x")
%! ylabel ("density")
Expand All @@ -120,12 +120,12 @@
%!error<ricepdf: function called with too few input arguments.> ricepdf (1)
%!error<ricepdf: function called with too few input arguments.> ricepdf (1,2)
%!error<ricepdf: function called with too many inputs> ricepdf (1,2,3,4)
%!error<ricepdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricepdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricepdf (ones (3), ones (2), ones (2))
%!error<ricepdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricepdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricepdf (ones (2), ones (3), ones (2))
%!error<ricepdf: X, NU, and SIGMA must be of common size or scalars.> ...
%!error<ricepdf: X, S, and SIGMA must be of common size or scalars.> ...
%! ricepdf (ones (2), ones (2), ones (3))
%!error<ricepdf: X, NU, and SIGMA must not be complex.> ricepdf (i, 2, 2)
%!error<ricepdf: X, NU, and SIGMA must not be complex.> ricepdf (2, i, 2)
%!error<ricepdf: X, NU, and SIGMA must not be complex.> ricepdf (2, 2, i)
%!error<ricepdf: X, S, and SIGMA must not be complex.> ricepdf (i, 2, 2)
%!error<ricepdf: X, S, and SIGMA must not be complex.> ricepdf (2, i, 2)
%!error<ricepdf: X, S, and SIGMA must not be complex.> ricepdf (2, 2, i)
Loading

0 comments on commit d4f8e0d

Please sign in to comment.