Adds test for 6 dots and adds some perfect satisfaction checks
This commit is contained in:
parent
2b022927b5
commit
60e194853e
@ -37,5 +37,8 @@ class DotDipoleModel():
|
|||||||
return jac_to_return
|
return jac_to_return
|
||||||
|
|
||||||
def sol(self):
|
def sol(self):
|
||||||
initial = numpy.zeros(6 * self.n)
|
initial = numpy.zeros(6 * self.n) + .1
|
||||||
|
if self.m == 6 * self.n:
|
||||||
|
# We are perfectly specified
|
||||||
|
return scipy.optimize.root(self.costs(), initial, jac=self.jac(), tol=1e-12)
|
||||||
return scipy.optimize.least_squares(self.costs(), initial, jac=self.jac(), ftol=1e-15, gtol=3e-16)
|
return scipy.optimize.least_squares(self.costs(), initial, jac=self.jac(), ftol=1e-15, gtol=3e-16)
|
||||||
|
32
tests/model/test_model_sol.py
Normal file
32
tests/model/test_model_sol.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import numpy
|
||||||
|
import pathfinder.model
|
||||||
|
|
||||||
|
|
||||||
|
def print_result(msg, result):
|
||||||
|
print(msg)
|
||||||
|
print(f"\tResult: {result.x}")
|
||||||
|
print(f"\tSuccess: {result.success}. {result.message}")
|
||||||
|
try:
|
||||||
|
print(f"\tFunc evals: {result.nfev}")
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
print(f"\tJacb evals: {result.njev}")
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_dipole_six_dot():
|
||||||
|
# setup
|
||||||
|
dot_positions = [[0, 0, 0], [-1, 0, 0], [-2, 0, 0], [-1, -1, 0], [-1, -1, 1], [0, -2, 0]]
|
||||||
|
dipole = pathfinder.model.StaticDipole([1, 2, 3], [0, 4, 0])
|
||||||
|
expected_result = numpy.array([1, 2, 3, 0, 4, 0])
|
||||||
|
dipole_arrangement = pathfinder.model.StaticDipoleArrangement([dipole])
|
||||||
|
dot_measurements = dipole_arrangement.get_dot_measurements(dot_positions)
|
||||||
|
|
||||||
|
model = pathfinder.model.DotDipoleModel(dot_measurements, 1)
|
||||||
|
res = model.sol()
|
||||||
|
|
||||||
|
print_result("one dipole six dots", res)
|
||||||
|
assert res.success, "The solution for a single dipole and six dots should have succeeded."
|
||||||
|
numpy.testing.assert_allclose(res.x, expected_result, err_msg="Dipole wasn't as expected.", rtol=1e-6, atol=1e-6)
|
Reference in New Issue
Block a user