-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurprise_number.py
33 lines (29 loc) · 1.16 KB
/
surprise_number.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
from datetime import datetime
from streams.surprise_ams import AmsAlgorithm
import streams.surprise_exact as se
from optparse import OptionParser
usage = "usage: %prog [options] arg1"
parser = OptionParser(usage=usage)
parser.add_option("-e", "--exact",
action="store_true", dest="exact", default=False,
help="Execute the exact method for computing the surprise number")
parser.add_option("-n", type="int", dest="num_variables",
help="Number of variables to compute the AMS method")
(options, args) = parser.parse_args()
stream_file = "data/Norvig.txt"
print "... Surprise Number ..."
if options.exact:
print "Method: Exact"
start = datetime.now()
exact_result = se.surprise_number(stream_file)
print "Exact result:", exact_result
print "Execution time (s):", (datetime.now() - start).seconds
else:
print "Method: AMS"
print "Variables:", options.num_variables
start = datetime.now()
ams = AmsAlgorithm(options.num_variables, stream_file)
ams.start_stream()
result = ams.surprise_number()
print "AMS result:", result
print "Execution time (s):", (datetime.now() - start).seconds