sagemath/sage

Make numerical and probability doctests ready for random seeds

Closed this issue · 15 comments

kliem commented

This ticket makes

sage -t --long --random-seed=n src/sage/numerical/
sage -t --long --random-seed=n src/sage/probabilty/

pass for different values n than just 0.

Depends on #29962

Component: doctest framework

Author: Jonathan Kliem

Branch/Commit: b6bef4b

Reviewer: Markus Wageringel

Issue created by migration from https://trac.sagemath.org/ticket/29975

kliem commented
comment:1
sage -t --long --random-seed=151058820726654196682836430928254760259 src/sage/numerical/optimize.py  # 2 doctests failed
sage -t --long --random-seed=151058820726654196682836430928254760259 src/sage/probability/probability_distribution.pyx  # 18 doctests failed
kliem commented

Branch: public/29975

kliem commented

Commit: 4f65860

kliem commented

Author: Jonathan Kliem

kliem commented

New commits:

4453f7amake numerical ready for random seeds
4f65860make probability ready for random seeds
comment:4

Although this is unlikely to fail, the test should agree with the documentation, so please apply this change for the uniform distribution:

     Uniform distribution on the interval ``[a, b]``::
 
         sage: a = 0
         sage: b = 2
         sage: T = RealDistribution('uniform', [a, b])
-        sage: a <= T.get_random_element() < b
+        sage: a <= T.get_random_element() <= b
         True

For the Pareto distribution, you could also add a test that s >= b. Similarly, the Rayleigh, Lognormal, F, Chisquared and Weibull distributions are ≥ 0, and the Beta distribution lives on [0,1].

Finally, I think this test should document the expected outcome, for clarity:

         sage: [1.0*x/nr_samples for x in counts]  # abs tol 1e-1
-        [0.304200000000000, 0.397300000000000, 0.298500000000000]
+        [0.3, 0.4, 0.3]

I hope it is sufficiently unlikely that this test fails, but it is not impossible.

Reviewer: Markus Wageringel

Changed commit from 4f65860 to c79005a

Branch pushed to git repo; I updated commit sha1. New commits:

c79005amore precices doctests
kliem commented
comment:6

Thanks for improving the doctests.

Replying to @mwageringel:

Finally, I think this test should document the expected outcome, for clarity:

         sage: [1.0*x/nr_samples for x in counts]  # abs tol 1e-1
-        [0.304200000000000, 0.397300000000000, 0.298500000000000]
+        [0.3, 0.4, 0.3]

I hope it is sufficiently unlikely that this test fails, but it is not impossible.

I even modified it down to 3e-2. I tested it and the maximal difference is 0.0192 in 10 000 runs. So I guess it is much less likely than 1 in 10 000 that this test will fail.

Changed commit from c79005a to b6bef4b

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

505d502more precices doctests
b6bef4b29975: more fixes
comment:9

Thanks for the updates. The change to multigraphics seems unintentional – I have removed it from your commit. I have also fixed another doctest:

sage -t --long --warn-long 55.4 --random-seed=2001 src/sage/numerical/optimize.py
**********************************************************************
File "src/sage/numerical/optimize.py", line 264, in sage.numerical.optimize.find_local_minimum
Failed example:
    plot(f, (x,-2.5, 2)).ymin()
Expected:
    -2.1827...
Got:
    -2.182677572710766

You can set this to positive if you agree with my changes.

kliem commented
comment:10

Thank you. Yes, agreed.

Changed branch from public/29975 to b6bef4b