2010-04-29 22:29:35 -07:00
|
|
|
#!/usr/bin/env python
|
2010-04-23 15:29:31 -07:00
|
|
|
|
|
|
|
import sys
|
|
|
|
from grid.DD import random_grid
|
|
|
|
from baker import get_phis, run_baker
|
2010-04-30 15:23:29 -07:00
|
|
|
from baker.tools import exact_func, smberror, improved_answer, smblog
|
2010-04-23 15:29:31 -07:00
|
|
|
from glob import glob
|
|
|
|
from os import remove
|
|
|
|
|
2010-04-24 17:26:44 -07:00
|
|
|
import numpy as np
|
|
|
|
|
2010-04-30 15:23:29 -07:00
|
|
|
import pylab
|
|
|
|
|
|
|
|
def draw_gb(bad, good):
|
|
|
|
pylab.xlabel('total runs')
|
|
|
|
pylab.ylabel('count')
|
|
|
|
pylab.grid(True)
|
|
|
|
pylab.plot(bad)
|
|
|
|
pylab.plot(good)
|
|
|
|
pylab.legend(('bad', 'good'))
|
|
|
|
|
|
|
|
pylab.show()
|
|
|
|
|
2010-04-23 15:29:31 -07:00
|
|
|
FILE_PREFIX='/tmp/qhull-'
|
|
|
|
|
|
|
|
|
2010-04-30 15:23:29 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
for g in glob('%s*' % FILE_PREFIX):
|
|
|
|
remove(g)
|
|
|
|
|
|
|
|
try:
|
|
|
|
total_points = int(sys.argv[1])
|
|
|
|
random_points = int(sys.argv[2])
|
|
|
|
total_tries = int(sys.argv[3])
|
|
|
|
except:
|
|
|
|
print "usage: app.py [total points in random grid] [number of random points to attempt] [total attempts]"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-05-05 22:03:12 -07:00
|
|
|
smblog.debug("total points: %d" % total_points)
|
2010-04-23 15:29:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-30 15:23:29 -07:00
|
|
|
d = {True: 0, False: 0}
|
|
|
|
good = []
|
|
|
|
bad = []
|
|
|
|
for cur_try in xrange(total_tries):
|
|
|
|
g = random_grid(total_points)
|
|
|
|
open('%s%0.3d.txt' % (FILE_PREFIX, cur_try), 'w').write(g.for_qhull())
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-30 15:23:29 -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-30 15:23:29 -07:00
|
|
|
try:
|
|
|
|
try:
|
|
|
|
answer = g.run_baker(X)
|
|
|
|
d[improved_answer(answer, exact)] += 1
|
|
|
|
except ValueError as e:
|
|
|
|
smblog.error(e)
|
|
|
|
except smberror as e:
|
|
|
|
print e
|
|
|
|
print d
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-30 15:23:29 -07:00
|
|
|
print d
|
|
|
|
bad.append(d[False])
|
|
|
|
good.append(d[True])
|
2010-04-23 15:29:31 -07:00
|
|
|
|
2010-04-30 15:23:29 -07:00
|
|
|
draw_gb(bad = bad, good = good)
|