Replies: 5 comments 2 replies
-
Hi Tim, I think there is a better approach to solve your problem using the using HomotopyContinuation
using StaticArrays
function factorbiq_system()
@var A0[1:3] b0[1:2] A1[1:3] b1[1:2]
@var g0[1:2] g1[1:2] H0[1:2, 1:2] H1[1:2, 1:2]
A0m, A1m = @SMatrix([A0[1] A0[2]; A0[2] A0[3]]), @SMatrix([A1[1] A1[2]; A1[2] A1[3]])
b0v, b1v = @SVector([b0[1]; b0[2]]), @SVector([b1[1]; b1[2]])
e = SVector(1, 1)
q0e = (e' * A0m * e) / 2 + e' * b0v + 1
q1z = (e' * A1m * e) / 2 - e' * b1v + 1
H0eq = q1z * A0m + b0v * (-A1m * e + b1v)' + (-A1m * e + b1v) * b0v' + A1m - H0
H1eq = A0m + b1v * (A0m * e + b0v)' + (A0m * e + b0v) * b1v' + q0e * A1m - H1
g0eq = q1z * b0v - A1m * e + b1v - g0
g1eq = q0e * b1v + A0m * e + b0v - g1
# TODO: elide the steps of the polyalgorithm to make this more precompilable
System([
g0eq[1]; g0eq[2]; g1eq[1]; g1eq[2];
H0eq[1, 1]; H0eq[1, 2]; H0eq[2, 2];
H1eq[1, 1]; H1eq[1, 2]; H1eq[2, 2]
]; parameters=[g0; g1; H0[:]; H1[:]])
end
F = factorbiq_system()
# First solve using monodromy
R0 = monodromy_solve(F)
# THe system has 6 solutions in general.
# This is non-deterministic, so we need to run it a few times possibly.
for r in 1:10
if nsolutions(R0) == 6
break
end
R0 = monodromy_solve(F)
end
# Now we have 6 solutions. Store the good solutions on disc
S0 = write_solutions("S0.txt", solutions(R0))
# Now we have 6 solutions. Store the good solutions on disc
p0 = write_parameters("p0.txt", parameters(R0))
# In a clean session we can just load the solutions and parameters
# and solve the system.
S0 = read_solutions("S0.txt")
p0 = read_parameters("p0.txt")
# Now solve for the specific values we are interested in.
g0, g1 = [-2.0572295698118172e9, -1.0946872831524246e10], [-2.654355654346107e9, -1.8026431499130545e9]
H0 = [-5.799857157583843e9 2.2112130890346775e9; 2.2112130890346746e9 1.1904739805563393e10]
H1 = [-9.605191673340421e8 2.881331173461073e9; 2.881331173461075e9 1.971553859807829e9]
p1 = [g0; g1; H0[:]; H1[:]]
R1 = solve(F, S0; target_parameters=p1, start_parameters=p0)
real_solutions(R1) This returns 2 solutions
Looking at the scaling of your parameters it could also make sense to find a "generic" solution that is similarly scaled but I don't have to little insight in your specific problem for that. |
Beta Was this translation helpful? Give feedback.
-
Parameter homotopy with computing the initial solutions by s = System([
g0eq[1]; g0eq[2]; g1eq[1]; g1eq[2];
H0eq[1, 1]; H0eq[1, 2]; H0eq[2, 2];
H1eq[1, 1]; H1eq[1, 2]; H1eq[2, 2]
]; parameters=[g0; g1; H0[:]; H1[:]])
g00, g10 = [-2.0572295698118172e9, -1.0946872831524246e10], [-2.654355654346107e9, -1.8026431499130545e9]
H00 = [-5.799857157583843e9 2.2112130890346775e9; 2.2112130890346746e9 1.1904739805563393e10]
H10 = [-9.605191673340421e8 2.881331173461073e9; 2.881331173461075e9 1.971553859807829e9]
interesting_parameters=[g00; g10; H00[:]; H10[:]]
random_parameters = randn(ComplexF64, 12)
result0 = solve(s; target_parameters = random_parameters)
result = solve(s, result0, start_parameters = random_parameters, target_parameters = interesting_parameters) Notice that the first |
Beta Was this translation helpful? Give feedback.
-
I will move this into the discussion section, since it's not really an issue or a bug, but rather the way homotopy continuation works (which can be subtle sometimes). |
Beta Was this translation helpful? Give feedback.
-
One more comment: If you solve a system more than one time for multiple parameters, you should follow this guide. |
Beta Was this translation helpful? Give feedback.
-
Want to add (as thanks, and in case anyone else reads this) that I've now implemented parameter caching. I wish I had done it earlier: I'm particularly impressed at the improved precision, that and the fact that solutions are now 100% repeatable are doing wondrous good for my application. Many thanks for the advice and demonstrations! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If you run the following script multiple times, you'll see you get different results each time, and it only rarely finds the valid real solution:
Note that the equations we're trying to solve are the same each time, and we keep trying until we find a non-singular real solution.
As one example, I got the following:
It succeeded on the last try (which is why it quit), but if found different non-real solutions on each prior attempt.
In my application, I'm bothered somewhat by the non-reproducibility of the solutions, but I'm bothered even more if it fails to find a genuine solution.
This could partially be a duplicate of #647 (which is much simpler than this example), but I wasn't sure so I thought it would be better to file a separate issue.
Beta Was this translation helpful? Give feedback.
All reactions