implemented a function that will be used to provide a generic n-th order, nth-dimension error approximation function
This commit is contained in:
parent
c5adab295b
commit
3a1c13bcac
12
bin/pattern.py
Executable file
12
bin/pattern.py
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from baker import pattern
|
||||||
|
from baker.tools import smblog
|
||||||
|
|
||||||
|
smblog.info(pattern(power = 2, phicount = 3, offset = -1))
|
||||||
|
smblog.info()
|
||||||
|
smblog.info(pattern(power = 2, phicount = 4, offset = -1))
|
||||||
|
smblog.info()
|
||||||
|
smblog.info(pattern(power = 3, phicount = 3, offset = -1))
|
||||||
|
smblog.info()
|
||||||
|
smblog.info(pattern(power = 3, phicount = 4, offset = -1))
|
69
bin/test3d-connectivity.py
Executable file
69
bin/test3d-connectivity.py
Executable file
@ -0,0 +1,69 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from grid.DDD import random_grid
|
||||||
|
from baker import get_phis, run_baker
|
||||||
|
from baker.tools import exact_func, smberror, improved_answer, smblog
|
||||||
|
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:
|
||||||
|
smblog.error(e)
|
||||||
|
except smberror as e:
|
||||||
|
print e
|
||||||
|
print d
|
||||||
|
|
||||||
|
print d
|
||||||
|
bad.append(d[False])
|
||||||
|
good.append(d[True])
|
||||||
|
|
||||||
|
draw_gb(bad = bad, good = good)
|
@ -3,6 +3,7 @@ from baker.tools import smblog
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import itertools
|
||||||
from tools import smberror
|
from tools import smberror
|
||||||
|
|
||||||
def get_phis(X, R):
|
def get_phis(X, R):
|
||||||
@ -305,3 +306,30 @@ def run_baker_3D(X, R, S):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
def _boxings(n, k):
|
||||||
|
"""\
|
||||||
|
source for this function:
|
||||||
|
http://old.nabble.com/Simple-combinatorics-with-Numpy-td20086915.html
|
||||||
|
http://old.nabble.com/Re:-Simple-combinatorics-with-Numpy-p20099736.html
|
||||||
|
"""
|
||||||
|
seq, i = [n] * k + [0], k
|
||||||
|
while i:
|
||||||
|
yield tuple(seq[i] - seq[i+1] for i in xrange(k))
|
||||||
|
i = seq.index(0) - 1
|
||||||
|
seq[i:k] = [seq[i] - 1] * (k-i)
|
||||||
|
|
||||||
|
def _samples_ur(items, k, offset = 0):
|
||||||
|
"""Returns k unordered samples (with replacement) from items."""
|
||||||
|
n = len(items)
|
||||||
|
for sample in _boxings(k, n):
|
||||||
|
selections = [[items[i]]*count for i,count in enumerate(sample)]
|
||||||
|
yield tuple([x + offset for sel in selections for x in sel])
|
||||||
|
|
||||||
|
def pattern(power, phicount, offset = 0):
|
||||||
|
smblog.debug("(power = %s, phicount = %s)" % (power, phicount))
|
||||||
|
r = []
|
||||||
|
for i in _samples_ur(range(1, phicount + 1), power, offset):
|
||||||
|
if not len(set(i)) == 1:
|
||||||
|
r.append(i)
|
||||||
|
return r
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from grid import grid as basegrid
|
from grid import grid as basegrid
|
||||||
from baker.tools import exact_func_3D
|
from baker.tools import exact_func_3D, smblog
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@ -88,6 +88,13 @@ class random_grid(rect_grid):
|
|||||||
|
|
||||||
r = np.random
|
r = np.random
|
||||||
|
|
||||||
|
appx_side_res = int(np.power(num_points, 1/3.0))
|
||||||
|
smblog.debug("appx_side_res: %d" % appx_side_res)
|
||||||
|
delta = 1.0 / float(appx_side_res)
|
||||||
|
|
||||||
|
for x in xrange(appx_side_res + 1):
|
||||||
|
pass
|
||||||
|
|
||||||
for i in xrange(num_points):
|
for i in xrange(num_points):
|
||||||
cur_x = r.rand()
|
cur_x = r.rand()
|
||||||
cur_y = r.rand()
|
cur_y = r.rand()
|
||||||
|
Loading…
Reference in New Issue
Block a user