1
1
# sage.doctest: optional - numpy
2
- """
2
+ r """
3
3
Distributions used in implementing Hidden Markov Models
4
4
5
5
These distribution classes are designed specifically for HMM's and not
@@ -35,7 +35,7 @@ from sage.stats.time_series cimport TimeSeries
35
35
36
36
37
37
cdef double random_normal(double mean, double std, randstate rstate):
38
- """
38
+ r """
39
39
Return a floating point number chosen from the normal distribution
40
40
with given mean and standard deviation, using the given randstate.
41
41
The computation uses the box muller algorithm.
@@ -67,11 +67,11 @@ cdef double random_normal(double mean, double std, randstate rstate):
67
67
# Abstract base class for distributions used for hidden Markov models.
68
68
69
69
cdef class Distribution:
70
- """
70
+ r """
71
71
A distribution.
72
72
"""
73
73
def sample (self , n = None ):
74
- """
74
+ r """
75
75
Return either a single sample ( the default) or `n` samples from
76
76
this probability distribution.
77
77
@@ -96,7 +96,7 @@ cdef class Distribution:
96
96
raise NotImplementedError
97
97
98
98
def prob (self , x ):
99
- """
99
+ r """
100
100
The probability density function evaluated at `x`.
101
101
102
102
INPUT:
@@ -120,7 +120,7 @@ cdef class Distribution:
120
120
raise NotImplementedError
121
121
122
122
def plot (self , *args , **kwds ):
123
- """
123
+ r """
124
124
Return a plot of the probability density function.
125
125
126
126
INPUT:
@@ -141,7 +141,7 @@ cdef class Distribution:
141
141
return plot(self .prob, * args, ** kwds)
142
142
143
143
cdef class GaussianMixtureDistribution(Distribution):
144
- """
144
+ r """
145
145
A probability distribution defined by taking a weighted linear
146
146
combination of Gaussian distributions.
147
147
@@ -163,17 +163,17 @@ cdef class GaussianMixtureDistribution(Distribution):
163
163
False
164
164
"""
165
165
def __init__ (self , B , eps = 1e-8 , bint normalize = True ):
166
- """
166
+ r """
167
167
INPUT:
168
168
169
- - `B` -- a list of triples `(c_i, mean_i, std_i)`, where
170
- the `c_i` and `std_i` are positive and the sum of the
171
- `c_i` is `1`.
169
+ - ``B`` -- a list of triples `` ( c_i, mean_i, std_i) ` `, where
170
+ the `` c_i`` and `` std_i` ` are positive and the sum of the
171
+ `` c_i` ` is `1`.
172
172
173
- - eps -- positive real number; any standard deviation in B
173
+ - `` eps`` -- positive real number; any standard deviation in B
174
174
less than eps is replaced by eps.
175
175
176
- - normalize -- if True, ensure that the c_i are nonnegative
176
+ - `` normalize`` -- if `` True`` , ensure that the `` c_i`` are nonnegative
177
177
178
178
EXAMPLES::
179
179
@@ -202,12 +202,12 @@ cdef class GaussianMixtureDistribution(Distribution):
202
202
self .fixed = IntList(self .c0._length)
203
203
204
204
def __getitem__ (self , Py_ssize_t i ):
205
- """
205
+ r """
206
206
Return triple ( coefficient, mu, std) .
207
207
208
208
INPUT:
209
209
210
- - i -- integer
210
+ - ``i`` -- integer
211
211
212
212
OUTPUT:
213
213
@@ -239,7 +239,7 @@ cdef class GaussianMixtureDistribution(Distribution):
239
239
return self .param._values[3 * i], self .param._values[3 * i+ 1 ], self .param._values[3 * i+ 2 ]
240
240
241
241
def __reduce__ (self ):
242
- """
242
+ r """
243
243
Used in pickling.
244
244
245
245
EXAMPLES::
@@ -252,7 +252,7 @@ cdef class GaussianMixtureDistribution(Distribution):
252
252
self .c0, self .c1, self .param, self .fixed)
253
253
254
254
def __richcmp__ (self , other , op ):
255
- """
255
+ r """
256
256
EXAMPLES::
257
257
258
258
sage: G = hmm. GaussianMixtureDistribution( [(.1,1,2), (.9,0,1) ])
@@ -272,7 +272,7 @@ cdef class GaussianMixtureDistribution(Distribution):
272
272
other.__reduce__()[1 ], op)
273
273
274
274
def __len__ (self ):
275
- """
275
+ r """
276
276
Return the number of components of this GaussianMixtureDistribution.
277
277
278
278
EXAMPLES::
@@ -283,7 +283,7 @@ cdef class GaussianMixtureDistribution(Distribution):
283
283
return self .c0._length
284
284
285
285
cpdef is_fixed(self , i = None ):
286
- """
286
+ r """
287
287
Return whether or not this :class:`GaussianMixtureDistribution` is
288
288
fixed when using Baum-Welch to update the corresponding HMM.
289
289
@@ -312,7 +312,7 @@ cdef class GaussianMixtureDistribution(Distribution):
312
312
return bool (self .fixed[i])
313
313
314
314
def fix (self , i = None ):
315
- """
315
+ r """
316
316
Set that this :class:`GaussianMixtureDistribution` ( or its `i`-th
317
317
component) is fixed when using Baum-Welch to update
318
318
the corresponding HMM.
@@ -340,7 +340,7 @@ cdef class GaussianMixtureDistribution(Distribution):
340
340
self .fixed[i] = 1
341
341
342
342
def unfix (self , i = None ):
343
- """
343
+ r """
344
344
Set that this :class:`GaussianMixtureDistribution` ( or its `i`-th
345
345
component) is not fixed when using Baum-Welch to update the
346
346
corresponding HMM.
@@ -372,7 +372,7 @@ cdef class GaussianMixtureDistribution(Distribution):
372
372
373
373
374
374
def __repr__ (self ):
375
- """
375
+ r """
376
376
Return string representation of this mixed Gaussian distribution.
377
377
378
378
EXAMPLES::
@@ -383,7 +383,7 @@ cdef class GaussianMixtureDistribution(Distribution):
383
383
return ' + ' .join(" %s *N(%s ,%s )" % x for x in self )
384
384
385
385
def sample (self , n = None ):
386
- """
386
+ r """
387
387
Return a single sample from this distribution ( by default) , or
388
388
if `n>1`, return a :class:`TimeSeries` of samples.
389
389
@@ -435,12 +435,12 @@ cdef class GaussianMixtureDistribution(Distribution):
435
435
return T
436
436
437
437
cdef double _sample(self , randstate rstate):
438
- """
438
+ r """
439
439
Used internally to compute a sample from this distribution quickly.
440
440
441
441
INPUT:
442
442
443
- - rstate -- a randstate object
443
+ - `` rstate`` -- a randstate object
444
444
445
445
OUTPUT:
446
446
@@ -460,7 +460,7 @@ cdef class GaussianMixtureDistribution(Distribution):
460
460
raise RuntimeError (" invalid probability distribution" )
461
461
462
462
cpdef double prob(self , double x):
463
- """
463
+ r """
464
464
Return the probability of `x`.
465
465
466
466
Since this is a continuous distribution, this is defined to be
@@ -496,7 +496,7 @@ cdef class GaussianMixtureDistribution(Distribution):
496
496
return s
497
497
498
498
cpdef double prob_m(self , double x, int m):
499
- """
499
+ r """
500
500
Return the probability of `x` using just the `m`-th summand.
501
501
502
502
INPUT:
@@ -526,7 +526,7 @@ cdef class GaussianMixtureDistribution(Distribution):
526
526
527
527
def unpickle_gaussian_mixture_distribution_v1 (TimeSeries c0 , TimeSeries c1 ,
528
528
TimeSeries param , IntList fixed ):
529
- """
529
+ r """
530
530
Used in unpickling :class:`GaussianMixtureDistribution` objects.
531
531
532
532
EXAMPLES::
0 commit comments