Recursive construction of hyper-spheres
Here we describe an algorithm that enables one to sample hyper-spheres of any dimension.
\[\begin{align} \xi_i & = cos(\theta_i)\xi_{i-1} \triangledown^? sin(\theta_i) \\ \xi_1 & = 1 \end{align}\]Implementation (Python)
from src.typeclass.VFF import VFF
from math import sin, cos
from numpy import hstack, array
class Sphere(VFF):
def __call__(self, ts):
return self.recursive_call(array([1]), ts)
def recursive_call(self, arr, ts):
t, *ts = ts
arr = hstack((cos(t)*arr, sin(t)))
if ts: return self.recursive_call(arr, ts)
else : return arr