def computeGeodesicMap(V, F, gt_interest_points, max_dist): distances = geodesic.geodesic([item for v in V for item in v], [item for f in F for item in f], gt_interest_points, max_dist) distances = np.array(distances).reshape(len(gt_interest_points), len(V)) distances_map = {} for i in range(0, len(gt_interest_points)): distances_map[gt_interest_points[i]] = distances[i]; return distances_map
# Integrate until the norm of the velocity has grown by a factor of 10 # and print out some diagnotistic along the way print("Iteration: %i, tau: %f, |v| = %f" % (len(geo.vs), geo.ts[-1], np.linalg.norm(geo.vs[-1]))) return np.linalg.norm(geo.vs[-1]) < 25.0 * np.linalg.norm(geo.vs[0]) # Calculate initial velocity v = InitialVelocity(x, jacobian, Avv) # Calculate geodesic geo = geodesic(func, jacobian, Avv, M, N, x, v, atol=1e-2, rtol=1e-2, callback=callback) geo.integrate(5.0) print('Got to t={0}'.format(geo.ts[-1])) Plotting.figure(2) plt.plot(geo.ts, geo.xs) # Calculate jtj approximation to hessian (in log params) and plot eigenvalue # spectrum j = model5_fit.m.jacobian_log_params_sens(geo.xs[-1, :]) jtj = np.dot(np.transpose(j), j) e, v = Utility.eig(jtj)
# and print out some diagnotistic along the way print("Iteration: %i, tau: %f, |v| = %f" % (len(geo.vs), geo.ts[-1], np.linalg.norm(geo.vs[-1]))) return np.linalg.norm(geo.vs[-1]) < 25.0 * np.linalg.norm(geo.vs[0]) # Calculate initial velocity v = InitialVelocity(x, jacobian, Avv) # Calculate geodesic geo = geodesic(func, jacobian, Avv, M, N, x, -v, atol=1e-2, rtol=1e-2, callback=callback, invSVD=True) geo.integrate(15.0) print('Got to t={0}'.format(geo.ts[-1])) Plotting.figure(2) plt.plot(geo.ts, geo.xs) # Calculate jtj approximation to hessian (in log params) and plot eigenvalue # spectrum j = model42_fit.m.jacobian_log_params_sens(geo.xs[-1, :]) jtj = np.dot(np.transpose(j), j)
# Choose starting parameters x = np.log([1.0, 1.0]) v = InitialVelocity(x, j, Avv) # Callback function used to monitor the geodesic after each step def callback(geo): # Integrate until the norm of the velocity has grown by a factor of 10 # and print out some diagnotistic along the way print("Iteration: %i, tau: %f, |v| = %f" %(len(geo.vs), geo.ts[-1], np.linalg.norm(geo.vs[-1]))) return np.linalg.norm(geo.vs[-1]) < 100.0 # Construct the geodesic # It is usually not necessary to be very accurate here, so we set small tolerances geo_forward = geodesic(r, j, Avv, 2, 2, x, v, atol = 1e-2, rtol = 1e-2, callback = callback) # Integrate geo_forward.integrate(25.0) import pylab # plot the geodesic path to find the limit # This should show the singularity at the "fold line" x[0] = x[1] pylab.figure() pylab.plot(geo_forward.ts, geo_forward.xs) pylab.xlabel("tau") pylab.ylabel("Parameter Values") pylab.show() ## Now do opposite direction
return (r(x + h * v) + r(x - h * v) - 2 * r(x)) / h / h # Choose starting parameters x = np.log([1.0, 2.0]) v = InitialVelocity(x, j, Avv) # Callback function used to monitor the geodesic after each step def callback(geo): # Integrate until the norm of the velocity has grown by a factor of 10 # and print out some diagnotistic along the way print("Iteration: %i, tau: %f, |v| = %f" % (len(geo.vs), geo.ts[-1], np.linalg.norm(geo.vs[-1]))) return np.linalg.norm(geo.vs[-1]) < 10.0 # Construct the geodesic # It is usually not necessary to be very accurate here, so we set small tolerances geo = geodesic(r, j, Avv, 2, 2, x, v, atol=1e-2, rtol=1e-2, callback=callback) # Integrate geo.integrate(25.0) import pylab # plot the geodesic path to find the limit # This should show the singularity at the "fold line" x[0] = x[1] pylab.plot(geo.ts, geo.xs) pylab.xlabel("tau") pylab.ylabel("Parameter Values") pylab.show()