more robust tests and slight tweaks to algorithm

This commit is contained in:
2021-08-04 19:50:54 -05:00
parent 0c8527704d
commit c51c477579
2 changed files with 27 additions and 18 deletions

View File

@@ -36,9 +36,11 @@ def test_find_sols():
x, y = pt
return numpy.array([[-2 * x, -2 * y], [-2 * (x - 8), -2 * (y + 8)]])
print(costs([3, 4]))
result = pathfinder.gradient_descent.find_sols(costs, jac, step_size=0.01, max_iterations=5000, initial=(2, 10), desired_cost=1e-6)
print(result)
message, iterations, result = pathfinder.gradient_descent.find_sols(costs, jac, step_size=0.01, max_iterations=5000, initial=(2, 10), desired_cost=1e-6)
numpy.testing.assert_almost_equal(
result, (3, 4),
decimal=7, err_msg='the result was off', verbose=True
)
def dipole_cost(vn, xn_raw):
@@ -59,11 +61,11 @@ def test_actual_dipole_finding():
p = pt[0:3]
return (p.dot(p) - 35)
v1 = -0.0554777
v2 = -0.0601857
v3 = -0.0636403
v4 = -0.0648838
v5 = -0.0629715
v1 = -0.05547767706400186526225414
v2 = -0.06018573388098888319642888
v3 = -0.06364032191901859480476888
v4 = -0.06488383879243851188402150
v5 = -0.06297148063759813929659130
# the 0 here is a red herring for index purposes later
vns = [0, v1, v2, v3, v4, v5]
@@ -106,5 +108,8 @@ def test_actual_dipole_finding():
jac_row(5)(pt),
])
result = pathfinder.gradient_descent.find_sols(costs, jac, step_size=0.01, max_iterations=10000, initial=(1, 2, 3, 4, 5, 6), desired_cost=1e-6, step_size_tries=25)
print(result)
_, _, result = pathfinder.gradient_descent.find_sols(costs, jac, step_size=1, max_iterations=10000, initial=(1, 2, 3, 4, 5, 6), desired_cost=1e-6, step_size_tries=30)
numpy.testing.assert_allclose(
result, (1, 3, 5, 5, 6, 7),
rtol=5e-2, err_msg='the result was off', verbose=True
)