Skip to content

Commit 865e178

Browse files
author
Matthias Koeppe
committed
src/sage/probability/probability_distribution.pyx: Docstring/doctest cosmetics
1 parent 60e906e commit 865e178

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

src/sage/probability/probability_distribution.pyx

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
r"""
22
Probability Distributions
33
44
This module provides three types of probability distributions:
@@ -63,13 +63,13 @@ cdef enum:
6363
beta
6464

6565
cdef class ProbabilityDistribution:
66-
"""
66+
r"""
6767
Concrete probability distributions should be derived from this
6868
abstract class.
6969
"""
7070

7171
def __init__(self):
72-
"""
72+
r"""
7373
To be implemented by a derived class::
7474
7575
sage: P = sage.probability.probability_distribution.ProbabilityDistribution()
@@ -78,7 +78,7 @@ cdef class ProbabilityDistribution:
7878
pass
7979

8080
def get_random_element(self):
81-
"""
81+
r"""
8282
To be implemented by a derived class::
8383
8484
sage: P = sage.probability.probability_distribution.ProbabilityDistribution()
@@ -91,15 +91,15 @@ cdef class ProbabilityDistribution:
9191
raise NotImplementedError("implement in derived class")
9292

9393
def generate_histogram_data(self, num_samples=1000, bins=50):
94-
"""
94+
r"""
9595
Compute a histogram of the probability distribution.
9696
9797
INPUT:
9898
99-
- ``num_samples`` - (optional) number of times to sample from
99+
- ``num_samples`` -- (optional) number of times to sample from
100100
the probability distribution
101101
102-
- ``bins`` - (optional) number of bins to divide the samples
102+
- ``bins`` -- (optional) number of bins to divide the samples
103103
into.
104104
105105
OUTPUT:
@@ -144,8 +144,8 @@ cdef class ProbabilityDistribution:
144144
S = pylab.hist(ell, bins, density=True)
145145
return [list(S[0]), list(S[1])]
146146

147-
def generate_histogram_plot(self, name, num_samples = 1000, bins = 50):
148-
"""
147+
def generate_histogram_plot(self, name, num_samples=1000, bins=50):
148+
r"""
149149
Save the histogram from :func:`generate_histogram_data() <sage.libs.gsl.ProbabilityDistribution.generate_histogram_data>`
150150
to a file.
151151
@@ -177,7 +177,7 @@ cdef class ProbabilityDistribution:
177177

178178

179179
cdef class SphericalDistribution(ProbabilityDistribution):
180-
"""
180+
r"""
181181
This class is capable of producing random points uniformly distributed
182182
on the surface of an `(n-1)`-sphere in `n`-dimensional euclidean space. The
183183
dimension `n` is selected via the keyword ``dimension``. The random
@@ -252,19 +252,19 @@ cdef class SphericalDistribution(ProbabilityDistribution):
252252
self.vec = <double *>sig_malloc(self.dimension*(sizeof(double)))
253253

254254
def set_seed(self, seed):
255-
"""
255+
r"""
256256
Set the seed for the underlying random number generator.
257257
258258
EXAMPLES::
259259
260-
sage: T = SphericalDistribution(seed = 0)
260+
sage: T = SphericalDistribution(seed=0)
261261
sage: T.set_seed(100)
262262
"""
263263
gsl_rng_set(self.r, seed)
264264
self.seed = seed
265265

266266
def set_random_number_generator(self, rng='default'):
267-
"""
267+
r"""
268268
Set the gsl random number generator to be one of ``default``,
269269
``luxury``, or ``taus``.
270270
@@ -295,12 +295,12 @@ cdef class SphericalDistribution(ProbabilityDistribution):
295295
sig_free(self.vec)
296296

297297
def get_random_element(self):
298-
"""
298+
r"""
299299
Get a random sample from the probability distribution.
300300
301301
EXAMPLES::
302302
303-
sage: T = SphericalDistribution(seed = 0)
303+
sage: T = SphericalDistribution(seed=0)
304304
sage: T.get_random_element() # rel tol 4e-16
305305
(0.07961564104639995, -0.05237671627581255, 0.9954486572862178)
306306
"""
@@ -312,12 +312,12 @@ cdef class SphericalDistribution(ProbabilityDistribution):
312312
return vector(sage.rings.real_double.RDF, v) # This could be made more efficient by directly constructing the vector, TODO.
313313

314314
def reset_distribution(self):
315-
"""
315+
r"""
316316
This method resets the distribution.
317317
318318
EXAMPLES::
319319
320-
sage: T = SphericalDistribution(seed = 0)
320+
sage: T = SphericalDistribution(seed=0)
321321
sage: [T.get_random_element() for _ in range(4)] # rel tol 4e-16
322322
[(0.07961564104639995, -0.05237671627581255, 0.9954486572862178),
323323
(0.4123599490593727, 0.5606817859360097, -0.7180495855658982),
@@ -337,7 +337,7 @@ cdef class SphericalDistribution(ProbabilityDistribution):
337337
# gsl_rng_env_setup()
338338

339339
cdef class RealDistribution(ProbabilityDistribution):
340-
"""
340+
r"""
341341
The :class:`RealDistribution` class provides a number of routines for sampling
342342
from and analyzing and visualizing probability distributions.
343343
For precise definitions of the distributions and their parameters
@@ -523,10 +523,10 @@ cdef class RealDistribution(ProbabilityDistribution):
523523
twister. Also available are the RANDLXS algorithm and the
524524
Tausworthe generator (see the gsl reference manual for more
525525
details). These are all supposed to be simulation quality
526-
generators. For RANDLXS use ``rng = 'luxury'`` and for
527-
tausworth use ``rng = 'taus'``::
526+
generators. For RANDLXS use ``rng='luxury'`` and for
527+
tausworth use ``rng='taus'``::
528528
529-
sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)
529+
sage: T = RealDistribution('gaussian', 1, rng='luxury', seed=10)
530530
531531
To change the seed at a later time use ``set_seed``::
532532
@@ -557,7 +557,7 @@ cdef class RealDistribution(ProbabilityDistribution):
557557
r"""
558558
EXAMPLES::
559559
560-
sage: T = RealDistribution('gaussian', 1, seed = 0)
560+
sage: T = RealDistribution('gaussian', 1, seed=0)
561561
sage: T.get_random_element() # rel tol 4e-16
562562
0.13391860811867587
563563
@@ -589,20 +589,20 @@ cdef class RealDistribution(ProbabilityDistribution):
589589
self.set_distribution(type, parameters)
590590

591591
def set_seed(self, seed):
592-
"""
592+
r"""
593593
Set the seed for the underlying random number generator.
594594
595595
EXAMPLES::
596596
597-
sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)
597+
sage: T = RealDistribution('gaussian', 1, rng='luxury', seed=10)
598598
sage: T.set_seed(100)
599599
"""
600600

601601
gsl_rng_set(self.r, seed)
602602
self.seed = seed
603603

604-
def set_random_number_generator(self, rng = 'default'):
605-
"""
604+
def set_random_number_generator(self, rng='default'):
605+
r"""
606606
Set the gsl random number generator to be one of ``'default'``,
607607
``'luxury'``, or ``'taus'``.
608608
@@ -633,7 +633,7 @@ cdef class RealDistribution(ProbabilityDistribution):
633633
sig_free(self.parameters)
634634

635635
def __str__(self):
636-
"""
636+
r"""
637637
Return the name of the current distribution.
638638
639639
EXAMPLES::
@@ -648,12 +648,12 @@ cdef class RealDistribution(ProbabilityDistribution):
648648
return self.name
649649

650650
def get_random_element(self):
651-
"""
651+
r"""
652652
Get a random sample from the probability distribution.
653653
654654
EXAMPLES::
655655
656-
sage: T = RealDistribution('gaussian', 1, seed = 0)
656+
sage: T = RealDistribution('gaussian', 1, seed=0)
657657
sage: T.get_random_element() # rel tol 4e-16
658658
0.13391860811867587
659659
@@ -688,7 +688,7 @@ cdef class RealDistribution(ProbabilityDistribution):
688688
return sage.rings.real_double.RDF(result)
689689

690690
def set_distribution(self, name='uniform', parameters=None):
691-
"""
691+
r"""
692692
This method can be called to change the current probability distribution.
693693
694694
EXAMPLES::
@@ -821,12 +821,12 @@ cdef class RealDistribution(ProbabilityDistribution):
821821
# def _get_random_element_c():
822822

823823
def reset_distribution(self):
824-
"""
825-
This method resets the distribution.
824+
r"""
825+
Reset the distribution.
826826
827827
EXAMPLES::
828828
829-
sage: T = RealDistribution('gaussian', 1, seed = 10)
829+
sage: T = RealDistribution('gaussian', 1, seed=10)
830830
sage: [T.get_random_element() for _ in range(10)] # rel tol 4e-16
831831
[-0.7460999595745819, -0.004644606626413462, -0.8720538317207641, 0.6916259921666037, 2.67668674666043, 0.6325002813661014, -0.7974263521959355, -0.5284976893366636, 1.1353119849528792, 0.9912505673230749]
832832
sage: T.reset_distribution()
@@ -840,7 +840,7 @@ cdef class RealDistribution(ProbabilityDistribution):
840840
# gsl_rng_env_setup()
841841

842842
def distribution_function(self, x):
843-
"""
843+
r"""
844844
Evaluate the distribution function of the
845845
probability distribution at ``x``.
846846
@@ -882,7 +882,7 @@ cdef class RealDistribution(ProbabilityDistribution):
882882
raise TypeError("Not a supported probability distribution")
883883

884884
def cum_distribution_function(self, x):
885-
"""
885+
r"""
886886
Evaluate the cumulative distribution function of
887887
the probability distribution at ``x``.
888888
@@ -918,7 +918,7 @@ cdef class RealDistribution(ProbabilityDistribution):
918918
raise TypeError("Not a supported probability distribution")
919919

920920
def cum_distribution_function_inv(self, x):
921-
"""
921+
r"""
922922
Evaluate the inverse of the cumulative distribution
923923
distribution function of the probability distribution at ``x``.
924924
@@ -955,7 +955,7 @@ cdef class RealDistribution(ProbabilityDistribution):
955955
raise TypeError("Not a supported probability distribution")
956956

957957
def plot(self, *args, **kwds):
958-
"""
958+
r"""
959959
Plot the distribution function for the probability
960960
distribution. Parameters to :func:`sage.plot.plot.plot` can be
961961
passed through ``*args`` and ``**kwds``.
@@ -970,18 +970,18 @@ cdef class RealDistribution(ProbabilityDistribution):
970970

971971

972972
cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
973-
"""
973+
r"""
974974
Create a discrete probability distribution.
975975
976976
INPUT:
977977
978-
- ``P`` - list of probabilities. The list will automatically be
978+
- ``P`` -- list of probabilities. The list will automatically be
979979
normalised if ``sum(P)`` is not equal to 1.
980980
981-
- ``rng`` - (optional) random number generator to use. May be
981+
- ``rng`` -- (optional) random number generator to use. May be
982982
one of ``'default'``, ``'luxury'``, or ``'taus'``.
983983
984-
- ``seed`` - (optional) seed to use with the random number
984+
- ``seed`` -- (optional) seed to use with the random number
985985
generator.
986986
987987
OUTPUT:
@@ -991,7 +991,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
991991
992992
EXAMPLES:
993993
994-
Constructs a ``GeneralDiscreteDistribution`` with the probability
994+
Construct a ``GeneralDiscreteDistribution`` with the probability
995995
distribution `P` where `P(0) = 0.3`, `P(1) = 0.4`, `P(2) = 0.3`::
996996
997997
sage: P = [0.3, 0.4, 0.3]
@@ -1013,7 +1013,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
10131013
The distribution probabilities will automatically be normalised::
10141014
10151015
sage: P = [0.1, 0.3]
1016-
sage: X = GeneralDiscreteDistribution(P, seed = 0)
1016+
sage: X = GeneralDiscreteDistribution(P, seed=0)
10171017
sage: counts = [0, 0]
10181018
sage: for _ in range(10000):
10191019
....: counts[X.get_random_element()] += 1
@@ -1042,7 +1042,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
10421042
cdef gsl_ran_discrete_t *dist
10431043
cdef long seed
10441044

1045-
def __init__(self, P, rng = 'default', seed = None):
1045+
def __init__(self, P, rng='default', seed=None):
10461046
r"""
10471047
Given a list of probabilities P construct an instance of a gsl
10481048
discrete random variable generator.
@@ -1108,7 +1108,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
11081108
sig_free(P_vec)
11091109

11101110
def set_seed(self, seed):
1111-
"""
1111+
r"""
11121112
Set the seed to be used by the random number generator.
11131113
11141114
EXAMPLES::
@@ -1121,8 +1121,8 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
11211121
gsl_rng_set(self.r, seed)
11221122
self.seed = seed
11231123

1124-
def set_random_number_generator(self, rng = 'default'):
1125-
"""
1124+
def set_random_number_generator(self, rng='default'):
1125+
r"""
11261126
Set the random number generator to be used by gsl.
11271127
11281128
EXAMPLES::
@@ -1147,7 +1147,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
11471147
gsl_ran_discrete_free(self.dist)
11481148

11491149
def get_random_element(self):
1150-
"""
1150+
r"""
11511151
Get a random sample from the probability distribution.
11521152
11531153
EXAMPLES::
@@ -1162,7 +1162,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
11621162
return sage.rings.integer.Integer(gsl_ran_discrete(self.r, self.dist))
11631163

11641164
def reset_distribution(self):
1165-
"""
1165+
r"""
11661166
This method resets the distribution.
11671167
11681168
EXAMPLES::

0 commit comments

Comments
 (0)