1
- """
1
+ r """
2
2
Probability Distributions
3
3
4
4
This module provides three types of probability distributions:
@@ -63,13 +63,13 @@ cdef enum:
63
63
beta
64
64
65
65
cdef class ProbabilityDistribution:
66
- """
66
+ r """
67
67
Concrete probability distributions should be derived from this
68
68
abstract class.
69
69
"""
70
70
71
71
def __init__ (self ):
72
- """
72
+ r """
73
73
To be implemented by a derived class::
74
74
75
75
sage: P = sage. probability. probability_distribution. ProbabilityDistribution( )
@@ -78,7 +78,7 @@ cdef class ProbabilityDistribution:
78
78
pass
79
79
80
80
def get_random_element (self ):
81
- """
81
+ r """
82
82
To be implemented by a derived class::
83
83
84
84
sage: P = sage. probability. probability_distribution. ProbabilityDistribution( )
@@ -91,15 +91,15 @@ cdef class ProbabilityDistribution:
91
91
raise NotImplementedError (" implement in derived class" )
92
92
93
93
def generate_histogram_data (self , num_samples = 1000 , bins = 50 ):
94
- """
94
+ r """
95
95
Compute a histogram of the probability distribution.
96
96
97
97
INPUT:
98
98
99
- - ``num_samples`` - (optional) number of times to sample from
99
+ - ``num_samples`` -- ( optional) number of times to sample from
100
100
the probability distribution
101
101
102
- - ``bins`` - (optional) number of bins to divide the samples
102
+ - ``bins`` -- ( optional) number of bins to divide the samples
103
103
into.
104
104
105
105
OUTPUT:
@@ -144,8 +144,8 @@ cdef class ProbabilityDistribution:
144
144
S = pylab.hist(ell, bins, density = True )
145
145
return [list (S[0 ]), list (S[1 ])]
146
146
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 """
149
149
Save the histogram from :func:`generate_histogram_data( ) <sage. libs. gsl. ProbabilityDistribution. generate_histogram_data>`
150
150
to a file.
151
151
@@ -177,7 +177,7 @@ cdef class ProbabilityDistribution:
177
177
178
178
179
179
cdef class SphericalDistribution(ProbabilityDistribution):
180
- """
180
+ r """
181
181
This class is capable of producing random points uniformly distributed
182
182
on the surface of an `( n-1) `-sphere in `n`-dimensional euclidean space. The
183
183
dimension `n` is selected via the keyword ``dimension``. The random
@@ -252,19 +252,19 @@ cdef class SphericalDistribution(ProbabilityDistribution):
252
252
self .vec = < double * > sig_malloc(self .dimension* (sizeof(double )))
253
253
254
254
def set_seed (self , seed ):
255
- """
255
+ r """
256
256
Set the seed for the underlying random number generator.
257
257
258
258
EXAMPLES::
259
259
260
- sage: T = SphericalDistribution(seed = 0)
260
+ sage: T = SphericalDistribution( seed= 0)
261
261
sage: T. set_seed( 100)
262
262
"""
263
263
gsl_rng_set(self .r, seed)
264
264
self .seed = seed
265
265
266
266
def set_random_number_generator (self , rng = ' default' ):
267
- """
267
+ r """
268
268
Set the gsl random number generator to be one of ``default``,
269
269
``luxury``, or ``taus``.
270
270
@@ -295,12 +295,12 @@ cdef class SphericalDistribution(ProbabilityDistribution):
295
295
sig_free(self .vec)
296
296
297
297
def get_random_element (self ):
298
- """
298
+ r """
299
299
Get a random sample from the probability distribution.
300
300
301
301
EXAMPLES::
302
302
303
- sage: T = SphericalDistribution(seed = 0)
303
+ sage: T = SphericalDistribution( seed= 0)
304
304
sage: T. get_random_element( ) # rel tol 4e-16
305
305
( 0. 07961564104639995, -0. 05237671627581255, 0. 9954486572862178)
306
306
"""
@@ -312,12 +312,12 @@ cdef class SphericalDistribution(ProbabilityDistribution):
312
312
return vector(sage.rings.real_double.RDF, v) # This could be made more efficient by directly constructing the vector, TODO.
313
313
314
314
def reset_distribution (self ):
315
- """
315
+ r """
316
316
This method resets the distribution.
317
317
318
318
EXAMPLES::
319
319
320
- sage: T = SphericalDistribution(seed = 0)
320
+ sage: T = SphericalDistribution( seed= 0)
321
321
sage: [T.get_random_element() for _ in range(4) ] # rel tol 4e-16
322
322
[(0.07961564104639995, -0.05237671627581255, 0.9954486572862178),
323
323
(0.4123599490593727, 0.5606817859360097, -0.7180495855658982),
@@ -337,7 +337,7 @@ cdef class SphericalDistribution(ProbabilityDistribution):
337
337
# gsl_rng_env_setup()
338
338
339
339
cdef class RealDistribution(ProbabilityDistribution):
340
- """
340
+ r """
341
341
The :class:`RealDistribution` class provides a number of routines for sampling
342
342
from and analyzing and visualizing probability distributions.
343
343
For precise definitions of the distributions and their parameters
@@ -523,10 +523,10 @@ cdef class RealDistribution(ProbabilityDistribution):
523
523
twister. Also available are the RANDLXS algorithm and the
524
524
Tausworthe generator ( see the gsl reference manual for more
525
525
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'``::
528
528
529
- sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)
529
+ sage: T = RealDistribution( 'gaussian', 1, rng= 'luxury', seed= 10)
530
530
531
531
To change the seed at a later time use ``set_seed``::
532
532
@@ -557,7 +557,7 @@ cdef class RealDistribution(ProbabilityDistribution):
557
557
r """
558
558
EXAMPLES::
559
559
560
- sage: T = RealDistribution( 'gaussian', 1, seed = 0)
560
+ sage: T = RealDistribution( 'gaussian', 1, seed= 0)
561
561
sage: T. get_random_element( ) # rel tol 4e-16
562
562
0. 13391860811867587
563
563
@@ -589,20 +589,20 @@ cdef class RealDistribution(ProbabilityDistribution):
589
589
self .set_distribution(type , parameters)
590
590
591
591
def set_seed (self , seed ):
592
- """
592
+ r """
593
593
Set the seed for the underlying random number generator.
594
594
595
595
EXAMPLES::
596
596
597
- sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)
597
+ sage: T = RealDistribution( 'gaussian', 1, rng= 'luxury', seed= 10)
598
598
sage: T. set_seed( 100)
599
599
"""
600
600
601
601
gsl_rng_set(self .r, seed)
602
602
self .seed = seed
603
603
604
- def set_random_number_generator (self , rng = ' default' ):
605
- """
604
+ def set_random_number_generator (self , rng = ' default' ):
605
+ r """
606
606
Set the gsl random number generator to be one of ``'default'``,
607
607
``'luxury'``, or ``'taus'``.
608
608
@@ -633,7 +633,7 @@ cdef class RealDistribution(ProbabilityDistribution):
633
633
sig_free(self .parameters)
634
634
635
635
def __str__ (self ):
636
- """
636
+ r """
637
637
Return the name of the current distribution.
638
638
639
639
EXAMPLES::
@@ -648,12 +648,12 @@ cdef class RealDistribution(ProbabilityDistribution):
648
648
return self .name
649
649
650
650
def get_random_element (self ):
651
- """
651
+ r """
652
652
Get a random sample from the probability distribution.
653
653
654
654
EXAMPLES::
655
655
656
- sage: T = RealDistribution('gaussian', 1, seed = 0)
656
+ sage: T = RealDistribution( 'gaussian', 1, seed= 0)
657
657
sage: T. get_random_element( ) # rel tol 4e-16
658
658
0. 13391860811867587
659
659
@@ -688,7 +688,7 @@ cdef class RealDistribution(ProbabilityDistribution):
688
688
return sage.rings.real_double.RDF(result)
689
689
690
690
def set_distribution (self , name = ' uniform' , parameters = None ):
691
- """
691
+ r """
692
692
This method can be called to change the current probability distribution.
693
693
694
694
EXAMPLES::
@@ -821,12 +821,12 @@ cdef class RealDistribution(ProbabilityDistribution):
821
821
# def _get_random_element_c():
822
822
823
823
def reset_distribution (self ):
824
- """
825
- This method resets the distribution.
824
+ r """
825
+ Reset the distribution.
826
826
827
827
EXAMPLES::
828
828
829
- sage: T = RealDistribution('gaussian', 1, seed = 10)
829
+ sage: T = RealDistribution( 'gaussian', 1, seed= 10)
830
830
sage: [T.get_random_element() for _ in range(10) ] # rel tol 4e-16
831
831
[-0.7460999595745819, -0.004644606626413462, -0.8720538317207641, 0.6916259921666037, 2.67668674666043, 0.6325002813661014, -0.7974263521959355, -0.5284976893366636, 1.1353119849528792, 0.9912505673230749 ]
832
832
sage: T. reset_distribution( )
@@ -840,7 +840,7 @@ cdef class RealDistribution(ProbabilityDistribution):
840
840
# gsl_rng_env_setup()
841
841
842
842
def distribution_function (self , x ):
843
- """
843
+ r """
844
844
Evaluate the distribution function of the
845
845
probability distribution at ``x``.
846
846
@@ -882,7 +882,7 @@ cdef class RealDistribution(ProbabilityDistribution):
882
882
raise TypeError (" Not a supported probability distribution" )
883
883
884
884
def cum_distribution_function (self , x ):
885
- """
885
+ r """
886
886
Evaluate the cumulative distribution function of
887
887
the probability distribution at ``x``.
888
888
@@ -918,7 +918,7 @@ cdef class RealDistribution(ProbabilityDistribution):
918
918
raise TypeError (" Not a supported probability distribution" )
919
919
920
920
def cum_distribution_function_inv (self , x ):
921
- """
921
+ r """
922
922
Evaluate the inverse of the cumulative distribution
923
923
distribution function of the probability distribution at ``x``.
924
924
@@ -955,7 +955,7 @@ cdef class RealDistribution(ProbabilityDistribution):
955
955
raise TypeError (" Not a supported probability distribution" )
956
956
957
957
def plot (self , *args , **kwds ):
958
- """
958
+ r """
959
959
Plot the distribution function for the probability
960
960
distribution. Parameters to :func:`sage. plot. plot. plot` can be
961
961
passed through ``* args`` and ``** kwds``.
@@ -970,18 +970,18 @@ cdef class RealDistribution(ProbabilityDistribution):
970
970
971
971
972
972
cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
973
- """
973
+ r """
974
974
Create a discrete probability distribution.
975
975
976
976
INPUT:
977
977
978
- - ``P`` - list of probabilities. The list will automatically be
978
+ - ``P`` -- list of probabilities. The list will automatically be
979
979
normalised if ``sum( P) `` is not equal to 1.
980
980
981
- - ``rng`` - (optional) random number generator to use. May be
981
+ - ``rng`` -- ( optional) random number generator to use. May be
982
982
one of ``'default'``, ``'luxury'``, or ``'taus'``.
983
983
984
- - ``seed`` - (optional) seed to use with the random number
984
+ - ``seed`` -- ( optional) seed to use with the random number
985
985
generator.
986
986
987
987
OUTPUT:
@@ -991,7 +991,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
991
991
992
992
EXAMPLES:
993
993
994
- Constructs a ``GeneralDiscreteDistribution`` with the probability
994
+ Construct a ``GeneralDiscreteDistribution`` with the probability
995
995
distribution `P` where `P( 0) = 0. 3`, `P( 1) = 0. 4`, `P( 2) = 0. 3`::
996
996
997
997
sage: P = [0.3, 0.4, 0.3 ]
@@ -1013,7 +1013,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1013
1013
The distribution probabilities will automatically be normalised::
1014
1014
1015
1015
sage: P = [0.1, 0.3 ]
1016
- sage: X = GeneralDiscreteDistribution(P, seed = 0)
1016
+ sage: X = GeneralDiscreteDistribution( P, seed= 0)
1017
1017
sage: counts = [0, 0 ]
1018
1018
sage: for _ in range( 10000) :
1019
1019
.... : counts[X.get_random_element() ] + = 1
@@ -1042,7 +1042,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1042
1042
cdef gsl_ran_discrete_t * dist
1043
1043
cdef long seed
1044
1044
1045
- def __init__ (self , P , rng = ' default' , seed = None ):
1045
+ def __init__ (self , P , rng = ' default' , seed = None ):
1046
1046
r """
1047
1047
Given a list of probabilities P construct an instance of a gsl
1048
1048
discrete random variable generator.
@@ -1108,7 +1108,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1108
1108
sig_free(P_vec)
1109
1109
1110
1110
def set_seed (self , seed ):
1111
- """
1111
+ r """
1112
1112
Set the seed to be used by the random number generator.
1113
1113
1114
1114
EXAMPLES::
@@ -1121,8 +1121,8 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1121
1121
gsl_rng_set(self .r, seed)
1122
1122
self .seed = seed
1123
1123
1124
- def set_random_number_generator (self , rng = ' default' ):
1125
- """
1124
+ def set_random_number_generator (self , rng = ' default' ):
1125
+ r """
1126
1126
Set the random number generator to be used by gsl.
1127
1127
1128
1128
EXAMPLES::
@@ -1147,7 +1147,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1147
1147
gsl_ran_discrete_free(self .dist)
1148
1148
1149
1149
def get_random_element (self ):
1150
- """
1150
+ r """
1151
1151
Get a random sample from the probability distribution.
1152
1152
1153
1153
EXAMPLES::
@@ -1162,7 +1162,7 @@ cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
1162
1162
return sage.rings.integer.Integer(gsl_ran_discrete(self .r, self .dist))
1163
1163
1164
1164
def reset_distribution (self ):
1165
- """
1165
+ r """
1166
1166
This method resets the distribution.
1167
1167
1168
1168
EXAMPLES::
0 commit comments