Exemplo n.º 1
0
 def test_points_from_distances_ndarray(self):
     """Assert tuple type matching works in points_from_distances"""
     n = 2
     p = 3
     hilbert_curve = HilbertCurve(p, n)
     dists = np.arange(hilbert_curve.max_h + 1)
     points = hilbert_curve.points_from_distances(dists, match_type=True)
     target_type = type(dists)
     self.assertTrue(isinstance(points, target_type))
     self.assertTrue(all(isinstance(vec, target_type) for vec in points))
Exemplo n.º 2
0
 def test_reversibility(self):
     """Assert points_from_distances and distances_from_points
     are inverse operations."""
     n = 3
     p = 5
     hilbert_curve = HilbertCurve(p, n)
     n_h = 2**(n * p)
     distances = list(range(n_h))
     coordinates = hilbert_curve.points_from_distances(distances)
     distances_check = hilbert_curve.distances_from_points(coordinates)
     for dist, dist_check in zip(distances, distances_check):
         self.assertEqual(dist, dist_check)
Exemplo n.º 3
0
points = [[0,0], [0,1], [1,1], [1,0]]
dists = hilbert_curve.distances_from_points(points)
print("simple distances from points")
print("="*80)
for point, dist in zip(points, dists):
    print(f'distance(x={point}, p={p}, n={n}) = {dist}')
print()


# calculate coordinates given distances along a hilbert curve
p = 1
n = 2
hilbert_curve = HilbertCurve(p, n)

dists = list(range(4))
points = hilbert_curve.points_from_distances(dists)
print("simple points from distances")
print("="*80)
for point, dist in zip(points, dists):
    print(f'point(h={dist}, p={p}, n={n}) = {point}')
print()



# due to the magic of arbitrarily large integers in
# Python (https://www.python.org/dev/peps/pep-0237/)
# these calculations can be done with absurd numbers
p = 512
n = 10
hilbert_curve = HilbertCurve(p, n)
ii = 123456789101112131415161718192021222324252627282930
Exemplo n.º 4
0
if random:
    print("Using random data")
    TEKs = []
    pp = open("random.teks", "w")
    count = 0
    for i in range(randcount):
        t = secrets.randbits(128)
        TEKs.append(t)
        pp.write(hex(t)[2:].zfill(32) + "\n")
        count += 1
        if count % batch == 0:
            print("Random TEKs generated:", count)
    # save those in case
    pp.close()
    pp = open("random.points", "w")
    points = np.array(hilbert_curve.points_from_distances(TEKs))
    count = 0
    for point in points:
        pp.write(str(point[0]) + "," + str(point[1]) + "\n")
        count += 1
        if count % batch == 0:
            print("Random points stored:", count)
    pp.close()
    X, Y = points.T
    if heatmap:
        heatmap, xedges, yedges = np.histogram2d(X, Y, bins=bincount)
        extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
        plt.clf()
        plt.imshow(heatmap.T, extent=extent, origin='lower')
    else:
        plt.scatter(X, Y)