<jupyter_start><jupyter_text>Test hyperboloid calculationsMainly a question of plotting...<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib import collections, lines, path, patches
%matplotlib inline
from geometry import *<jupyter_output><empty_output><jupyter_text>Tests of dot:Null vector dotted with unit vector, expect zero  Tests of dot:Null vector dotted with unit vector, expect zero in both cases<jupyter_code>u = np.ones(2)
v = np.zeros(2)
print("Spherical = {}, hyperbolic = {}".format(dot(u, v), dot(u, v, geometry="hyperbolic")))<jupyter_output>Spherical = 0.0, hyperbolic = 0.0<jupyter_text>Dot parallel unit vectors, expect spherical = 2 and hyperbolic = 0<jupyter_code>u = np.ones(2)
v = np.array([1, 1])
print("Spherical = {}, hyperbolic = {}".format(dot(u, v), dot(u, v, geometry="hyperbolic")))<jupyter_output>Spherical = 2.0, hyperbolic = 0.0<jupyter_text>Dot anti-parallel unit vectors, expect spherical = -2 and hyperbolic = 0<jupyter_code>v = -v
print("Spherical = {}, hyperbolic = {}".format(dot(u, v), dot(u, v, geometry="hyperbolic")))<jupyter_output>Spherical = -2.0, hyperbolic = 0.0<jupyter_text>Dot perpendicular vectors, expect spherical = 0 and hyperbolic = 2<jupyter_code>u = np.ones(2)
v = np.array([1, -1])
print("Spherical = {}, hyperbolic = {}".format(dot(u, v), dot(u, v, geometry="hyperbolic")))<jupyter_output>Spherical = 0.0, hyperbolic = 2.0<jupyter_text>Plot a hyperboloid<jupyter_code>theta = np.linspace(-0.323*np.pi, 0.323*np.pi, 1000)
x0 = np.sinh(theta)
x1 = np.cosh(theta)
x = np.array([np.array([x0i, x1i]) for x0i, x1i in zip(x0, x1)])
#print(x)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.2])
plt.scatter(x0, x1)<jupyter_output><empty_output><jupyter_text>Calculate tangentsThis is (presumably) less straightforward than in Euclidean space? Test using the projection operator to find the tangent vector<jupyter_code>point_on_manifold = np.array([0., 1.])
displacement = np.array([1., 0.])
projection = project_to_tangent(point_on_manifold, displacement, geometry="hyperbolic")
print(projection)
tangent_space_line = [point_on_manifold - projection, point_on_manifold + projection]
euclidean_tangent_vector = np.array([[0, -1], [1, 0]]).dot(point_on_manifold)
eucl_tangent_space_line = [point_on_manifold - euclidean_tangent_vector,
                           point_on_manifold + euclidean_tangent_vector]
print((-0.6*point_on_manifold[0]-1)/point_on_manifold[1])
np.testing.assert_array_equal(-projection, euclidean_tangent_vector)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.2])
plt.scatter(x0, x1, s=1)
plt.scatter(point_on_manifold[0], point_on_manifold[1], color='r')
ax.add_line(lines.Line2D([tangent_space_line[0][0], tangent_space_line[1][0]],
                          [tangent_space_line[0][1], tangent_space_line[1][1]],
                          color="r", linestyle=(1,[2,1])))
ax.add_line(lines.Line2D([eucl_tangent_space_line[0][0], eucl_tangent_space_line[1][0]],
                          [eucl_tangent_space_line[0][1], eucl_tangent_space_line[1][1]],
                          color="g", linestyle=(0,[2,1])))

point_on_manifold = np.array([np.sinh(0.481), np.cosh(0.481)])
displacement = np.array([1., 0.])
projection = project_to_tangent(point_on_manifold, displacement, geometry="hyperbolic")
tangent_space_line = [point_on_manifold - projection, point_on_manifold + projection]
euclidean_tangent_vector = np.array([[0, -1], [1, 0]]).dot(point_on_manifold)
eucl_tangent_space_line = [point_on_manifold - euclidean_tangent_vector,
                           point_on_manifold + euclidean_tangent_vector]
alt_tangent_space_line = [[-0.6,(-0.6*point_on_manifold[0]-1)/point_on_manifold[1]],
                          [0.6, (0.6*point_on_manifold[0]-1)/point_on_manifold[1]]   
                         ]
#np.testing.assert_array_equal(-projection, euclidean_tangent_vector)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.2], ylim=[0., 1.6])
plt.scatter(x0, x1, s=1)
plt.scatter(point_on_manifold[0], point_on_manifold[1], color='r')
ax.add_line(lines.Line2D([tangent_space_line[0][0], tangent_space_line[1][0]],
                          [tangent_space_line[0][1], tangent_space_line[1][1]],
                          color="r", linestyle=(1,[2,1])))
ax.add_line(lines.Line2D([eucl_tangent_space_line[0][0], eucl_tangent_space_line[1][0]],
                          [eucl_tangent_space_line[0][1], eucl_tangent_space_line[1][1]],
                          color="g", linestyle=(0,[2,1])))
#ax.add_line(lines.Line2D([alt_tangent_space_line[0][0], alt_tangent_space_line[1][0]],
#                          [alt_tangent_space_line[0][1], alt_tangent_space_line[1][1]],
#                          color="b", linestyle='-'))<jupyter_output><empty_output><jupyter_text>Direction of the tangent line is quite different in this case, since spherical and hyperboloid geometries don't coincidentally agree here.<jupyter_code>point_on_manifold = np.array([np.sinh(0.481), np.cosh(0.481)])
displacement = np.array([0.4, 0.])
projection = project_to_tangent(point_on_manifold, displacement, geometry="hyperbolic")
tangent_space_line = [point_on_manifold - 1*projection, point_on_manifold + 1*projection]  
#np.testing.assert_array_equal(-projection, euclidean_tangent_vector)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.5], ylim=[0.8, 1.6])
plt.scatter(x0, x1, s=1)
plt.scatter(point_on_manifold[0], point_on_manifold[1], color='r')
ax.add_line(lines.Line2D([tangent_space_line[0][0], tangent_space_line[1][0]],
                          [tangent_space_line[0][1], tangent_space_line[1][1]],
                          color="r", linestyle=(1,[2,1])))
ax.annotate(r"$P$", xy=point_on_manifold-(0.03,0.03), xytext=point_on_manifold-(0.05,0.05), fontsize=18, color='r')
ax.annotate(r"$T_P\mathcal{H}^1$", xy=tangent_space_line[0]-(0.03,0.03), xytext=tangent_space_line[0]-(0.03,0.03),
            fontsize=18, color='r')
ax.arrow(point_on_manifold[0], point_on_manifold[1], displacement[0], displacement[1], 
        width=0.01, length_includes_head=True)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.5], ylim=[0.8, 1.6])
plt.scatter(x0, x1, s=1)
plt.scatter(point_on_manifold[0], point_on_manifold[1], color='r')
ax.add_line(lines.Line2D([tangent_space_line[0][0], tangent_space_line[1][0]],
                          [tangent_space_line[0][1], tangent_space_line[1][1]],
                          color="r", linestyle=(1,[2,1])))
ax.annotate(r"$P$", xy=point_on_manifold-(0.03,0.03), xytext=point_on_manifold-(0.05,0.05), fontsize=18, color='r')
ax.annotate(r"$T_P\mathcal{H}^1$", xy=tangent_space_line[0]-(0.03,0.03), xytext=tangent_space_line[0]-(0.03,0.03),
            fontsize=18, color='r')
ax.arrow(point_on_manifold[0], point_on_manifold[1], displacement[0], displacement[1], 
        width=0.01, length_includes_head=True)
ax.add_line(lines.Line2D([(point_on_manifold+displacement)[0], 
                          (point_on_manifold+projection)[0]
                         ],
                         [(point_on_manifold+displacement)[1], 
                          (point_on_manifold+projection)[1]
                         ], linestyle="--"
                        )
           )
ax.arrow(point_on_manifold[0], point_on_manifold[1], projection[0], projection[1], 
        width=0.01, length_includes_head=True, facecolor='b')
displacement_manifold = exponential_map(projection, point_on_manifold, geometry="hyperbolic")
print(displacement_manifold)
fig = plt.figure(figsize=(8,8))
ax = plt.gca(xlim=[-1.2, 1.5], ylim=[0.8, 1.6])
plt.scatter(x0, x1, s=1)
plt.scatter(point_on_manifold[0], point_on_manifold[1], color='r')
ax.add_line(lines.Line2D([tangent_space_line[0][0], tangent_space_line[1][0]],
                          [tangent_space_line[0][1], tangent_space_line[1][1]],
                          color="r", linestyle=(1,[2,1])))
ax.annotate(r"$P$", xy=point_on_manifold-(0.03,0.03), xytext=point_on_manifold-(0.05,0.05), fontsize=18, color='r')
ax.annotate(r"$T_P\mathcal{H}^1$", xy=tangent_space_line[0]-(0.03,0.03), xytext=tangent_space_line[0]-(0.03,0.03),
            fontsize=18, color='r')
ax.arrow(point_on_manifold[0], point_on_manifold[1], displacement[0], displacement[1], 
        width=0.01, length_includes_head=True)
ax.add_line(lines.Line2D([(point_on_manifold+displacement)[0], 
                          (point_on_manifold+projection)[0]
                         ],
                         [(point_on_manifold+displacement)[1], 
                          (point_on_manifold+projection)[1]
                         ], linestyle="--"
                        )
           )
ax.arrow(point_on_manifold[0], point_on_manifold[1], projection[0], projection[1], 
        width=0.01, length_includes_head=True, facecolor='b')
ax.scatter(displacement_manifold[0], displacement_manifold[1])
distance_along_geodesic = distance(displacement_manifold, point_on_manifold, geometry="hyperbolic")
dotprod = dot(displacement_manifold, point_on_manifold, geometry="hyperbolic")
print("x.p = {:3g}, distance = {:3g}".format(dotprod, distance_along_geodesic))
distance_eucl = distance(displacement_manifold, point_on_manifold, geometry="euclidean")
distance_along_geodesic = distance(displacement_manifold, point_on_manifold, geometry="spherical")
dotprod = dot(displacement_manifold, point_on_manifold, geometry="spherical")
print("x.p = {:3g}, distance = {:3g}, euclidean distance = {:.3g}".format(dotprod, distance_along_geodesic, distance_eucl))<jupyter_output>x.p = 2.16845, distance = nan, euclidean distance = 0.664
{'fraction_non_alphanumeric': 0.1622551062942893, 'fraction_numerical': 0.044810337640683616, 'mean_word_length': 4.440476190476191, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '611063', 'license': 'MIT', 'n_tokens_mistral': 3924, 'n_tokens_neox': 3545, 'n_words': 496, 'path': 'Hyperboloid.ipynb', 'repo_name': 'DRWardrope/GeometryTests', 'size': '9596'}