Fix Homotopy generator using Groebner basis

This commit is contained in:
2025-03-27 17:32:38 +01:00
parent 38c28caf87
commit c2ab678c17
2 changed files with 52 additions and 59 deletions

View File

@@ -69,51 +69,59 @@ from hccd import path_tracker, homotopy_generator
def track_path(args):
H = np.array([[1, 1, 1]])
H = np.array([[1, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 1]])
# TODO: Make this work
homotopy = homotopy_generator.HomotopyGenerator(H)
print(f"G: {homotopy.G}")
print(f"F: {homotopy.F}")
print(f"H: {homotopy.H}")
print(f"DH: {homotopy.DH}")
tracker = path_tracker.PathTracker(homotopy, args.euler_step_size, args.euler_max_tries,
args.newton_max_iter, args.newton_convergence_threshold, args.sigma)
ys_start, ys_prime, ys_hat_e, ys = [], [], [], []
try:
y = np.zeros(3)
for i in range(args.num_iterations):
y_start, y_prime, y_hat_e, y = tracker.transparent_step(y)
ys_start.append(y_start)
ys_prime.append(y_prime)
ys_hat_e.append(y_hat_e)
ys.append(y)
print(f"Iteration {i}: {y}")
except Exception as e:
print(f"Error: {e}")
y = np.zeros(5) + np.array([0.5, 0.48, -0.1, 0.2, 0 ])
for i in range(args.num_iterations):
y_start, y_prime, y_hat_e, y = tracker.transparent_step(y)
ys_start.append(y_start)
ys_prime.append(y_prime)
ys_hat_e.append(y_hat_e)
ys.append(y)
print(f"Iteration {i}: {y}")
ys_start = np.array(ys_start)
ys_prime = np.array(ys_prime)
ys_hat_e = np.array(ys_hat_e)
ys = np.array(ys)
df = pd.DataFrame({"x1b": ys_start[:, 0],
"x2b": ys_start[:, 1],
"tb": ys_start[:, 2],
"x1p": ys_prime[:, 0],
"x2p": ys_prime[:, 1],
"tp": ys_prime[:, 2],
"x1e": ys_hat_e[:, 0],
"x2e": ys_hat_e[:, 1],
"te": ys_hat_e[:, 2],
"x1n": ys[:, 0],
"x2n": ys[:, 1],
"tn": ys[:, 2]
})
for y in np.transpose(ys):
plt.plot(y)
if args.output:
df.to_csv(args.output, index=False)
else:
print(df)
plt.show()
# df = pd.DataFrame({"x1b": ys_start[:, 0],
# "x2b": ys_start[:, 1],
# "tb": ys_start[:, 2],
# "x1p": ys_prime[:, 0],
# "x2p": ys_prime[:, 1],
# "tp": ys_prime[:, 2],
# "x1e": ys_hat_e[:, 0],
# "x2e": ys_hat_e[:, 1],
# "te": ys_hat_e[:, 2],
# "x1n": ys[:, 0],
# "x2n": ys[:, 1],
# "tn": ys[:, 2]
# })
#
# if args.output:
# df.to_csv(args.output, index=False)
# else:
# print(df)
def main():