This repository has been archived on 2022-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
pathfinder/tests/model/test_dot.py
Deepak c279f1b470
All checks were successful
gitea-physics/pathfinder/pipeline/head This commit looks good
Removes gradient descent and begins refactor
2021-08-29 10:54:36 -05:00

46 lines
1.6 KiB
Python

import numpy
import numpy.testing
import pathfinder.model as model
def test_dot():
dot = model.DotMeasurement(0.235, (1, 2, 3))
assert dot.v == 0.235
numpy.testing.assert_array_equal(dot.r, (1, 2, 3), "These arrays should have been equal!")
def test_dot_v_from_dipole():
# for a dot located at (1, 2, 3)
dot = model.DotMeasurement(50, (1, 2, 3))
# and dipole located at (4, 7, 11) with p=(8, 9, 10)
pt = numpy.array((8, 9, 10, 4, 7, 11))
# V should be -0.153584
target = -0.1535844174880402
cost = -50.1535844174880402
numpy.testing.assert_allclose(dot.v_for_point(pt), target, err_msg="v from dipole at a dot was incorrect!")
numpy.testing.assert_allclose(dot.cost(pt), cost, err_msg="cost from dipole at a dot was incorrect!")
def test_dot_jac():
# for a dot located at (1, 2, 3)
dot = model.DotMeasurement(50, (1, 2, 3))
# and dipole located at (4, 7, 11) with p=(8, 9, 10)
pt = numpy.array((8, 9, 10, 4, 7, 11))
target_jac_pt = [-0.003092303707812889, -0.005153839513021483, -0.00824614322083437, 0.0058585481811285, 0.01423090787983279, 0.02730483137919137]
# assume a second dipole at (12, 13, -5), with p = (-1, -2, -3)
second_target = [-0.002054993939616119, -0.002054993939616119, 0.001494541046993541, 5.494636202182148e-6, 0.0001923122670763748, 0.0006923241614749492]
pt2 = numpy.array((-1, -2, -3, 12, 13, -5))
jac_row_target = target_jac_pt + second_target
pts = numpy.append(pt, pt2)
assert len(dot.jac_pt(pt)) == 6
numpy.testing.assert_allclose(dot.jac_pt(pt), target_jac_pt, err_msg="Jac pt doesn't match Mathematica result.")
numpy.testing.assert_allclose(dot.jac(pts), jac_row_target, err_msg="whole row should match")