script for converting ASCII to sgf
[imago.git] / lhs.py
1 import random
2
3 def test():
4     bound = 10.
5     m = 25
6     l = latin_hypercube(2, bound, m)
7     import matplotlib.pyplot as pyplot
8     fig = pyplot.figure()
9     fig.add_subplot(121)
10     pyplot.plot([v[0] for v in l], [v[1] for v in l], 'o')
11     fig.add_subplot(122)
12     pyplot.plot([random.random() * 2 * bound - bound for _  in xrange(m)], 
13                 [random.random() * 2 * bound - bound for _  in xrange(m)], 'o')
14     pyplot.show()
15     import sys
16     sys.exit()
17
18 def latin_hypercube(dim, bound, m):
19     dv = (2 * bound) / float(m)
20     dim_p = [range(m) for _ in xrange(dim)] 
21     for p in dim_p:
22         random.shuffle(p)
23     points = [list(l) for l in zip(*dim_p)]
24     points = [[(float(l) + random.random()) * dv - bound  for l in p] for p in points]
25     return points