import matplotlib.pyplot as plt


N=5
interpolation_points = np.array([[1.,0,0], [-1.,0,0], [1., 0,0], [-1.,0,0], [1.,0,0]]) #spline interpolates these points
x = np.linspace(-1,1, N)
y = np.sin(5*np.pi*x)
#interpolation_points =np.vstack([x,y,np.ones(x.shape)]).T
interpolation_points = interpolation_points/np.array([np.linalg.norm(interpolation_points, axis=1)]).T
#initial and end velocities:
init_vel = np.array([-1.0,0.0,-1.0])
end_vel = np.array([-1.0,0.0,1.0])
#boundary_velocities=np.array([init_vel, end_vel])


b= implicitc2spline(interpolation_points, geometry=geometry.Sphere_geometry())
h = np.power(10.0, range(-2,-6,-1))
t=1.0
print((b(t+1.5*h)-3*b(t+0.5*h)+3*b(t-0.5*h)-b(t-1.5*h))/(h*h).reshape(h.shape +(1,))) 
print("If C_2, these should approach zero.")

# Plot using bspline.plotting (currently projected 2D plot)
if True:
	fig1=plt.figure(1)
	splt.plot(b, with_control_points=True)
	fig1.suptitle('Spline on S^2, stereographically projected onto R^2')
	t=np.floor(N/2)

# Plot geodesic acceleration second derivative
if True:
    hh=1e-5
alpha = 0.01
N=5
n=10
k=2
P1 = np.vstack((np.eye(k), np.zeros((n-k,k))))
interpolation_points= np.tile(P1, (N,1,1))

np.random.seed(0)
for i in range(1,N):
    P2 = P1+1.0*np.random.randn(n,k)
    interpolation_points[i] = np.linalg.qr(P2)[0]




b= implicitc2spline(interpolation_points, geometry=geometry.Grassmannian(), Maxiter=1000, tol = 1e-14)



if True:
    fig3=plt.figure(3)
    ax = fig3.add_subplot(111, projection='3d')
    tl = np.linspace(0.,N-1,1000)
    bvals =b(tl)
    bb = np.einsum('...ij,...kj', bvals,bvals)
    ax.plot(bb[:,0,0],bb[:,1,0],bb[:,2,0],linewidth=2)
    ax.plot(bb[:,0,1],bb[:,1,1],bb[:,2,1],linewidth=2)
    ax.plot(bb[:,0,2],bb[:,1,2],bb[:,2,2],linewidth=2 )
    ax.plot(np.array([0.]),np.array([0.]),np.array([0.]), marker = '.', markersize=20)
    
    
def bbloch(b, tt):
    return cp1tobloch(b(tt))

d=2
N=4
interpolation_points =np.random.randn(N, d)+ 1j*np.random.randn(N,d)
interpolation_points = interpolation_points/np.array([np.linalg.norm(interpolation_points, axis=1)]).T
#interpolation_points=np.array([[1,0], [np.sqrt(0.5),np.sqrt(0.5)*1j], [1,0]])
#initial and end velocities:
init_vel = np.zeros(d, dtype='complex128')
end_vel = np.zeros(d, dtype='complex128')
boundary_velocities=np.array([init_vel, end_vel])


b= implicitc2spline(interpolation_points, geometry=geometry.CP_geometry(), Maxiter=10000)
#h = np.power(10.0, range(-2,-6,-1))
#print((b(t+1.5*h)-3*b(t+0.5*h)+3*b(t-0.5*h)-b(t-1.5*h))/(h*h).reshape(h.shape +(1,))) 
#print("If C_2, these should approach zero.")

# Plot using bspline.plotting (currently projected 2D plot)
if True:
    fig1=plt.figure(1)
    splt.plot(b, with_control_points=False)
    fig1.suptitle('Spline on S^2, stereographically projected onto R^2')
    t=np.floor(N/2)    
    


# Plot second derivative
if True:
import matplotlib.pyplot as plt

alpha = 0.01
N = 5
n = 10
k = 2
P1 = np.vstack((np.eye(k), np.zeros((n - k, k))))
interpolation_points = np.tile(P1, (N, 1, 1))

np.random.seed(0)
for i in range(1, N):
    P2 = P1 + 1.0 * np.random.randn(n, k)
    interpolation_points[i] = np.linalg.qr(P2)[0]

b = implicitc2spline(interpolation_points,
                     geometry=geometry.Grassmannian(),
                     Maxiter=1000,
                     tol=1e-14)

if True:
    fig3 = plt.figure(3)
    ax = fig3.add_subplot(111, projection='3d')
    tl = np.linspace(0., N - 1, 1000)
    bvals = b(tl)
    bb = np.einsum('...ij,...kj', bvals, bvals)
    ax.plot(bb[:, 0, 0], bb[:, 1, 0], bb[:, 2, 0], linewidth=2)
    ax.plot(bb[:, 0, 1], bb[:, 1, 1], bb[:, 2, 1], linewidth=2)
    ax.plot(bb[:, 0, 2], bb[:, 1, 2], bb[:, 2, 2], linewidth=2)
    ax.plot(np.array([0.]),
            np.array([0.]),
            np.array([0.]),
            marker='.',
Exemple #5
0
    return cp1tobloch(b(tt))


d = 2
N = 4
interpolation_points = np.random.randn(N, d) + 1j * np.random.randn(N, d)
interpolation_points = interpolation_points / np.array(
    [np.linalg.norm(interpolation_points, axis=1)]).T
#interpolation_points=np.array([[1,0], [np.sqrt(0.5),np.sqrt(0.5)*1j], [1,0]])
#initial and end velocities:
init_vel = np.zeros(d, dtype='complex128')
end_vel = np.zeros(d, dtype='complex128')
boundary_velocities = np.array([init_vel, end_vel])

b = implicitc2spline(interpolation_points,
                     geometry=geometry.CP_geometry(),
                     Maxiter=10000)
#h = np.power(10.0, range(-2,-6,-1))
#print((b(t+1.5*h)-3*b(t+0.5*h)+3*b(t-0.5*h)-b(t-1.5*h))/(h*h).reshape(h.shape +(1,)))
#print("If C_2, these should approach zero.")

# Plot using bspline.plotting (currently projected 2D plot)
if True:
    fig1 = plt.figure(1)
    splt.plot(b, with_control_points=False)
    fig1.suptitle('Spline on S^2, stereographically projected onto R^2')
    t = np.floor(N / 2)

# Plot second derivative
if True:
    hh = 1e-5
Exemple #6
0
N = 5
interpolation_points = np.array([[1., 0, 0], [-1., 0, 0], [1., 0, 0],
                                 [-1., 0, 0],
                                 [1., 0,
                                  0]])  #spline interpolates these points
x = np.linspace(-1, 1, N)
y = np.sin(5 * np.pi * x)
#interpolation_points =np.vstack([x,y,np.ones(x.shape)]).T
interpolation_points = interpolation_points / np.array(
    [np.linalg.norm(interpolation_points, axis=1)]).T
#initial and end velocities:
init_vel = np.array([-1.0, 0.0, -1.0])
end_vel = np.array([-1.0, 0.0, 1.0])
#boundary_velocities=np.array([init_vel, end_vel])

b = implicitc2spline(interpolation_points, geometry=geometry.Sphere_geometry())
h = np.power(10.0, range(-2, -6, -1))
t = 1.0
print(
    (b(t + 1.5 * h) - 3 * b(t + 0.5 * h) + 3 * b(t - 0.5 * h) - b(t - 1.5 * h))
    / (h * h).reshape(h.shape + (1, )))
print("If C_2, these should approach zero.")

# Plot using bspline.plotting (currently projected 2D plot)
if True:
    fig1 = plt.figure(1)
    splt.plot(b, with_control_points=True)
    fig1.suptitle('Spline on S^2, stereographically projected onto R^2')
    t = np.floor(N / 2)

# Plot geodesic acceleration second derivative
Exemple #7
0
def test_maxiter(spline):
    with pytest.raises(Exception):
        b = implicitc2spline(spline['points'], spline['velocities'], geometry=spline['geometry'], Maxiter=2)
Exemple #8
0
def spline(request):
    data = request.param
    data['spline'] = implicitc2spline(data['points'], data['velocities'], geometry=data['geometry'])
    return data
import matplotlib.pyplot as plt


N=8
#interpolation_points = np.array([[1.,0,0], [0,0,1.], [0, np.sqrt(0.5), np.sqrt(0.5)], [0,1.,0]]) #spline interpolates these points
x = np.linspace(-1,1, N)
y = np.sin(5*np.pi*x)
interpolation_points =np.vstack([x,y,np.ones(x.shape)]).T
interpolation_points = interpolation_points/np.array([np.linalg.norm(interpolation_points, axis=1)]).T
#initial and end velocities:
init_vel = np.array([-1.0,0.0,-1.0])
end_vel = np.array([-1.0,0.0,1.0])
boundary_velocities=np.array([init_vel, end_vel])


b= implicitc2spline(interpolation_points, boundary_velocities, geometry=geometry.Sphere_geometry())
#h = np.power(10.0, range(-2,-6,-1))
#print((b(t+1.5*h)-3*b(t+0.5*h)+3*b(t-0.5*h)-b(t-1.5*h))/(h*h).reshape(h.shape +(1,))) 
#print("If C_2, these should approach zero.")

# Plot using bspline.plotting (currently projected 2D plot)
if True:
	fig1=plt.figure(1)
	splt.plot(b, with_control_points=False)
	fig1.suptitle('Spline on S^2, stereographically projected onto R^2')
	t=np.floor(N/2)

# Plot second derivative
if True:
	hh=1e-5
	ts = np.linspace(0.,N-1,(N-1)*100)[1:-1]