2010-04-23 15:29:31 -07:00
|
|
|
#!/usr/bin/python2.6
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from grid.DD import random_grid
|
|
|
|
from baker import get_phis, run_baker
|
|
|
|
from baker.tools import exact_func, smberror, improved_answer
|
|
|
|
from glob import glob
|
|
|
|
from os import remove
|
|
|
|
|
2010-04-24 17:26:44 -07:00
|
|
|
import numpy as np
|
|
|
|
|
2010-04-23 15:29:31 -07:00
|
|
|
FILE_PREFIX='/tmp/qhull-'
|
|
|
|
|
|
|
|
for g in glob('%s*' % FILE_PREFIX):
|
|
|
|
remove(g)
|
|
|
|
|
|
|
|
try:
|
2010-04-24 17:26:44 -07:00
|
|
|
total_points = int(sys.argv[1])
|
|
|
|
random_points = int(sys.argv[2])
|
|
|
|
total_tries = int(sys.argv[3])
|
2010-04-23 15:29:31 -07:00
|
|
|
except:
|
2010-04-24 17:26:44 -07:00
|
|
|
print "usage: app.py [total points in random grid] [number of random points to attempt] [total attempts]"
|
2010-04-23 15:29:31 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
print "total points", total_points
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d = {True: 0, False: 0}
|
2010-04-24 17:26:44 -07:00
|
|
|
for cur_try in xrange(total_tries):
|
2010-04-23 15:29:31 -07:00
|
|
|
g = random_grid(total_points)
|
2010-04-24 17:26:44 -07:00
|
|
|
open('%s%0.3d.txt' % (FILE_PREFIX, cur_try), 'w').write(g.for_qhull())
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-24 17:26:44 -07:00
|
|
|
for i in xrange(random_points):
|
|
|
|
X = [np.random.rand(), np.random.rand()]
|
|
|
|
exact = exact_func(X)
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-24 17:26:44 -07:00
|
|
|
try:
|
|
|
|
answer = g.run_baker(X)
|
|
|
|
d[improved_answer(answer, exact)] += 1
|
|
|
|
except smberror as e:
|
|
|
|
print e
|
|
|
|
print d
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-24 17:26:44 -07:00
|
|
|
print d
|