Commit cd2f623e authored by Azat Garifullin's avatar Azat Garifullin
Browse files

a wee fix

parent 25c797b1
......@@ -51,32 +51,32 @@ def main():
xv, yv = np.meshgrid(xs, ys)
xy_grid = np.stack([xv.ravel(), yv.ravel()], axis=1)
# xy_grid_1 = xy_grid[labels == 0]
# dist_mtx_1 = spatial.distance.cdist(xy_grid_1, xy_grid_1)
# loss_1 = make_gp_loss(mix_field[labels == 0], dist_mtx_1, noise_sigma)
# print("debug: GT loss_1: {}".format(loss_1(gt_theta[:3])))
# print("debug: GT_2 loss_1: {}".format(loss_1(gt_theta[3:])))
# opt_res_1 = optimize.differential_evolution(loss_1, bounds=theta_bounds, tol=1e-4,
# disp=True, seed=42)
# print(opt_res_1.x)
#
# xy_grid_2 = xy_grid[labels == 1]
# dist_mtx_2 = spatial.distance.cdist(xy_grid_2, xy_grid_2)
# loss_2 = make_gp_loss(mix_field[labels == 1], dist_mtx_2, noise_sigma)
# print("debug: GT loss_2: {}".format(loss_2((gt_theta[3:]))))
# print("debug: GT_2 loss_1: {}".format(loss_2((gt_theta[:3]))))
# opt_res_2 = optimize.differential_evolution(loss_2, bounds=theta_bounds, tol=1e-4,
# disp=True, seed=42)
# print(opt_res_2.x)
xy_grid_1 = xy_grid[labels == 0]
dist_mtx_1 = spatial.distance.cdist(xy_grid_1, xy_grid_1)
loss_1 = make_gp_loss(mix_field[labels == 0], dist_mtx_1, noise_sigma)
print("debug: GT loss_1: {}".format(loss_1(gt_theta[:3])))
print("debug: GT_2 loss_1: {}".format(loss_1(gt_theta[3:])))
opt_res_1 = optimize.differential_evolution(loss_1, bounds=theta_bounds, tol=1e-4,
disp=True, seed=42)
print(opt_res_1.x)
xy_grid_2 = xy_grid[labels == 1]
dist_mtx_2 = spatial.distance.cdist(xy_grid_2, xy_grid_2)
loss_2 = make_gp_loss(mix_field[labels == 1], dist_mtx_2, noise_sigma)
print("debug: GT loss_2: {}".format(loss_2((gt_theta[3:]))))
print("debug: GT_2 loss_1: {}".format(loss_2((gt_theta[:3]))))
opt_res_2 = optimize.differential_evolution(loss_2, bounds=theta_bounds, tol=1e-4,
disp=True, seed=42)
print(opt_res_2.x)
gating = MLPClassifier(hidden_layer_sizes=(16, 16), solver='lbfgs', max_iter=300)
gating.fit(xy_grid, labels)
gate_labels = gating.predict(xy_grid)
gate_probas = gating.predict_proba(xy_grid)
# with open('optimization.pickle', 'wb') as optfile:
# thetas = (opt_res_1.x, opt_res_2.x)
# pickle.dump((thetas, gating), optfile)
with open('optimization.pickle', 'wb') as optfile:
thetas = (opt_res_1.x, opt_res_2.x)
pickle.dump((thetas, gating), optfile)
plt.figure()
plt.imshow(labels.reshape(ys.size, xs.size), cmap='gray')
......
......@@ -66,6 +66,12 @@ def main():
axs[1].imshow(all_masks[i].reshape((ys.size, xs.size)), cmap='gray')
fig.suptitle('Iteration {}'.format(i))
rel_errs = [np.linalg.norm(est - gt_mix_field) / np.linalg.norm(est) for est in all_fields]
plt.figure()
plt.plot(rel_errs)
plt.ylabel('Relative error')
plt.xlabel('Iteration')
plt.show()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment