-
Notifications
You must be signed in to change notification settings - Fork 0
/
series.py
37 lines (29 loc) · 1.16 KB
/
series.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''
Bryan Bonvallet
2009
This module stores classes that can contain an ordered
series of values.
FiniteSequence stores a discrete, finite series of values.
InfiniteSequence stores a discrete, pseudo-infinite or
maintains a calculation to represent a discrete, infinite sequence.
These classes expect to be subclassed with PMF classes.
'''
class FiniteSequence():
''' Contains features common to finite sequences.
Currently, this controls how to print out the sequence. '''
def __str__(self):
''' Convert to string by printing the contained distribution. '''
return str(self.getDistribution())
class InfiniteSequence():
''' Contains features common to infinite sequences.
Currently, this controls how to print out the sequence. '''
# Max terms determines the max number of terms to print out.
# This is merely an aesthetic variable.
maxterms = 40
def __str__(self):
''' Convert to string by printing the contained distribution, but
limit number of displayed values. '''
if (len(self) <= self.maxterms):
return str(self.distribution)
else:
return str(self.distribution[:,0:self.maxterms])