Adds unrestricted model and adds util for normalising
Some checks failed
gitea-physics/pdme/pipeline/head There was a failure building this commit

This commit is contained in:
2022-01-02 18:32:10 -06:00
parent 5869691634
commit b8bbdf29f4
7 changed files with 149 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
from pdme.model import UnrestrictedModel
from pdme.measurement import OscillatingDipole, OscillatingDipoleArrangement
import logging
import numpy
import itertools
def test_unrestricted_model_solve_basic():
# Initialise our dipole arrangement and create dot measurements along a square.
dipoles = OscillatingDipoleArrangement([OscillatingDipole((.2, 0, 2), (1, 2, 4), 1)])
dot_inputs = list(itertools.chain.from_iterable(
(([1, 2, 0.01], f), ([1, 1, -0.2], f), ([1.5, 2, 0.01], f), ([1.5, 1, -0.2], f), ([2, 1, 0], f), ([2, 2, 0], f), ([0, 2, -.1], f), ([0, 1, 0.04], f), ([2, 0, 0], f), ([1, 0, 0], f)) for f in numpy.arange(1, 10, 2)
))
dots = dipoles.get_dot_measurements(dot_inputs)
model = UnrestrictedModel(1)
# from the dipole, these are the unspecified variables in ((0, 0, 2), (1, 2, 4), 1)
expected_solution = [0.2, 0, 2, 1, 2, 4, 1]
result = model.solve(dots)
logging.info(result)
assert result.success
numpy.testing.assert_allclose(result.normalised_x, expected_solution, err_msg="Even well specified problem solution was wrong.", rtol=1e-6, atol=1e-11)

View File

@@ -0,0 +1,38 @@
from pdme.model import UnrestrictedModel
from pdme.measurement import DotMeasurement
import logging
import numpy
def test_unrestricted_plane_model_repr():
model = UnrestrictedModel(6)
assert repr(model) == "UnrestrictedModel(6)"
def test_unrestricted_model_cost_and_jac_single():
model = UnrestrictedModel(1)
measured_v = 0.000191292 # from dipole with p=(0, 0, 2) at (1, 2, 4) with w = 1
dot = DotMeasurement(measured_v, (1, 2, 0), 5)
pt = [0, 0, 2, 2, 2, 4, 2]
cost_function = model.costs([dot])
expected_cost = [0.0000946746]
actual_cost = cost_function(pt)
numpy.testing.assert_allclose(actual_cost, expected_cost, err_msg="Cost wasn't as expected.", rtol=1e-6, atol=1e-11)
jac_function = model.jac([dot])
expected_jac = [
[
0.00007149165379592005, 0, 0.0002859666151836802,
-0.0001009293935942401, 0, -0.0002607342667851202,
0.0001035396365320221
]
]
actual_jac = jac_function(pt)
logging.warning(actual_jac)
numpy.testing.assert_allclose(actual_jac, expected_jac, err_msg="Jac wasn't as expected.", rtol=1e-6, atol=1e-11)