From 276f82642481cd11b513ec01daf850585503b52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Laboissi=C3=A8re?= Date: Fri, 22 Mar 2024 07:33:12 -0300 Subject: d/p/binomial-dist-median.patch: Update with upstream commit --- debian/patches/binomial-dist-median.patch | 74 ++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/debian/patches/binomial-dist-median.patch b/debian/patches/binomial-dist-median.patch index 89477be..4636e64 100644 --- a/debian/patches/binomial-dist-median.patch +++ b/debian/patches/binomial-dist-median.patch @@ -1,22 +1,66 @@ -Description: Drop test for median value of the binomial distribution - One of the BISTs in file BinomialDistribution.m hit a corner case. - Indeed, the median value of a binomial distribution for n = 5 and p = - 0.5 is not unique and the BIST produces different values on i386 and - amd64 architectures (2 and 3, respectively). Hence, the package FTBFS - on i386 without this patch. -Author: Rafael Laboissière -Bug: https://github.com/gnu-octave/statistics/issues/140 -Forwarded: not-needed -Last-Update: 2024-03-10 - ---- octave-statistics-1.6.5.orig/inst/dist_obj/BinomialDistribution.m -+++ octave-statistics-1.6.5/inst/dist_obj/BinomialDistribution.m -@@ -662,7 +662,7 @@ endfunction +Description: Fix median method of BinomialDistribution +Author: Rafael Laboissière +Origin: upstream, https://github.com/gnu-octave/statistics/issues/142 +Last-Update: 2024-03-21 + +From 8fdd588eb46a25e9ed9c3ab42286e44276632bf1 Mon Sep 17 00:00:00 2001 +From: Rafael Laboissière +Date: Tue, 19 Mar 2024 11:57:34 +0100 +Subject: [PATCH] Correct median value of binomial distribution when p = 0.5 + and N is odd + +For a thorough discussion on this issue, see: + +Nowakowski S (2021) Uniqueness of a median of a binomial distribution with +rational probability. Advances in Mathematics: Scientific Journal +10(4):1951-1958. (http://dx.doi.org/10.37418/amsj.10.4.9) + +Essentially, when p = 0.5 and N is odd, there would be two "median +values" (both integer values around N/2). In this case, the median value +should be the fully trimmed mid-range, which happens to be equal to the +mean value. + +Notice that these changes only cope with the untruncated case. For the +general truncated case, the solution seems not to be straightforward. +In particular, the code below: + +``` +pd = BinomialDistribution (5, 0.5); +t = truncate (pd, 0, 5) +t.median () +``` + +will produce value `3`, which is wrong (it should be `2.5`). + +At any rate, this change is bug-compatible with Matlab, thanks to the +use of `__traditional_()`. +--- + inst/dist_obj/BinomialDistribution.m | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/inst/dist_obj/BinomialDistribution.m b/inst/dist_obj/BinomialDistribution.m +index c87e606b..3a1c5641 100644 +--- a/inst/dist_obj/BinomialDistribution.m ++++ b/inst/dist_obj/BinomialDistribution.m +@@ -284,7 +284,11 @@ function disp (this) + Fa_b = binocdf ([lx, ux], this.N, this.p); + m = binoinv (sum (Fa_b) / 2, this.N, this.p); + else +- m = binoinv (0.5, this.N, this.p); ++ if (! __traditional__() & this.p == 0.5 & rem (this.N, 2) == 1) ++ m = this.mean (); ++ else ++ m = binoinv (0.5, this.N, this.p); ++ endif + endif + endfunction + +@@ -662,7 +666,7 @@ function checkparams (N, p) #%!assert (iqr (t), 1); %!assert (mean (pd), 2.5, 1e-10); #%!assert (mean (t), 2.8, 1e-10); -%!assert (median (pd), 3); -+#%!assert (median (pd), 3); ++%!assert (median (pd), 2.5); #%!assert (median (t), 3); %!assert (pdf (pd, [0:5]), [0.0312, 0.1562, 0.3125, 0.3125, 0.1562, 0.0312], 1e-4); #%!assert (pdf (t, [0:5]), [0, 0, 0.4, 0.4, 0.2, 0], 1e-4); -- cgit v1.2.3