2010-05-04 22:03:07 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
2010-11-08 15:25:09 -08:00
|
|
|
from interp.grid.DDD import random_grid
|
|
|
|
from interp.baker import get_phis, run_baker
|
|
|
|
from interp.tools import exact_func, improved_answer, log
|
2010-05-04 22:03:07 -07:00
|
|
|
from glob import glob
|
|
|
|
from os import remove
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
FILE_PREFIX='/tmp/qhull-'
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
print "total points", total_points
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
for i in xrange(random_points):
|
|
|
|
X = [np.random.rand(), np.random.rand(), np.random.rand()]
|
|
|
|
exact = exact_func(X)
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
answer = g.run_baker(X)
|
|
|
|
d[improved_answer(answer, exact)] += 1
|
|
|
|
except ValueError as e:
|
2010-11-08 15:25:09 -08:00
|
|
|
log.error(e)
|
|
|
|
except Exception as e:
|
2010-05-04 22:03:07 -07:00
|
|
|
print e
|
|
|
|
print d
|
|
|
|
|
|
|
|
print d
|
|
|
|
bad.append(d[False])
|
|
|
|
good.append(d[True])
|
|
|
|
|
|
|
|
draw_gb(bad = bad, good = good)
|