<jupyter_start><jupyter_text>Solve for initial marker locations and deformation parameters using the doming model approach<jupyter_code># generate doming model data
y_dm = dom.F(true_θxs, true_θzs, true_p1, true_p2) 
y_dm.shape
# optimize for initial locations and deformation parameters
history_dm = dom.doming_model_opt(y_dm, 
                                                    np.zeros_like(true_θxs), 
                                                    np.zeros_like(true_θzs), 
                                                    np.zeros(6), np.zeros(6), iters=25)

# show final result
θxs_dm = history_dm[-1][1]
θzs_dm = history_dm[-1][2]
p1_dm = history_dm[-1][3]
p2_dm = history_dm[-1][4]

plt.scatter(θxs_dm, θzs_dm)
plt.scatter(true_θxs, true_θzs)

print(p2_dm, true_p2)
# show deformation field
import alignment.motion_model as mm
num_grid_pts_v = 100
grid_x_v = np.linspace(-0.5, 0.5,num_grid_pts_v)
grid_y_v = np.linspace(-0.5,0.5,num_grid_pts_v)

grid_v = np.meshgrid(grid_x_v, grid_y_v)
grid_pts_v = np.vstack([grid_v[0].ravel(), grid_v[1].ravel()])

plt.figure(figsize=(15,5))
plt.subplot(131)
plt.title('Ground truth')
plt.imshow((mm.deformation(true_p1, true_p2, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]),
           cmap='jet')
plt.axis('off')
plt.colorbar()
plt.subplot(132)
plt.title('Reconstruction')
plt.imshow((mm.deformation(p1_dm, p2_dm, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]),
          cmap='jet')
plt.axis('off')
plt.colorbar()
plt.subplot(133)
plt.title('Difference')
plt.imshow((mm.deformation(true_p1, true_p2, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]) -
           (mm.deformation(p1_dm, p2_dm, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]), 
           cmap='jet')
plt.colorbar()
plt.axis('off')
plt.show()<jupyter_output><empty_output><jupyter_text>Solve for initial marker locations and deformation parameters using SparseAlign<jupyter_code># generate SparseAlign data
y = sa.F(true_ws, true_θxs, true_θzs, true_p1, true_p2)
y.shape
history_sa = sa.SparseAlign(y,num_true_θs+1,all_at_once=True)
# show final result
θxs_sa = history_sa[-1][1]
θzs_sa = history_sa[-1][2]
p1_sa = history_sa[-1][4]
p2_sa = history_sa[-1][5]

plt.scatter(θxs_dm, θzs_dm, c='b', label='DM')
plt.scatter(θxs_sa, θzs_sa, c='r', label='SparseAlign')
plt.scatter(true_θxs, true_θzs, c='g', marker='x', label='Ground truth')

plt.legend()

print(true_p2, p2_dm, p2_sa)
# show deformation field


plt.figure(figsize=(15,5))
plt.subplot(131)
plt.title('Ground truth')
plt.imshow((mm.deformation(true_p1, true_p2, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]),
           cmap='jet')
plt.axis('off')
plt.colorbar()
plt.subplot(132)
plt.title('Reconstruction')
plt.imshow((mm.deformation(p1_sa, p2_sa, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]),
          cmap='jet')
plt.axis('off')
plt.colorbar()
plt.subplot(133)
plt.title('Difference')
plt.imshow((mm.deformation(true_p1, true_p2, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]) -
           (mm.deformation(p1_sa, p2_sa, grid_pts_v[0], grid_pts_v[1]))[1].reshape([num_grid_pts_v,num_grid_pts_v]), 
           cmap='jet')
plt.colorbar()
plt.axis('off')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16004742145820983, 'fraction_numerical': 0.03289863663307647, 'mean_word_length': 4.9628975265017665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '442241', 'license': 'MIT', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1421, 'n_words': 195, 'path': 'example_2d.ipynb', 'repo_name': 'poulamisganguly/SparseAlign', 'size': '3374'}