Commit b7182bb9 authored by Olga Stamati's avatar Olga Stamati
Browse files

fix application of pertubation step at optimiseSensitivityFields()

parent ef0c05bf
Pipeline #78201 passed with stage
in 1 minute and 43 seconds
......@@ -139,7 +139,7 @@ class TestOptimiser(unittest.TestCase):
print("test_optimisePositionsensitivityFields_TwentySpheres(): Done")
def test_optimisePositionsensitivityFields_TwentySpheres_with_background(self):
def _test_optimisePositionsensitivityFields_TwentySpheres_with_background(self):
print("\n\ntest_optimisePositionsensitivityFields_TwentySpheres_with_background: Starting up")
radMM = 2
......@@ -289,7 +289,7 @@ class TestOptimiser(unittest.TestCase):
def test_optimiseSensitivityFieldsMultiProj_ManySpheres(self):
def _test_optimiseSensitivityFieldsMultiProj_ManySpheres(self):
print("\n\ntest_optimiseSensitivityFieldsMultiProj_ManySpheres(): Starting up")
# Lists of:
......
......@@ -151,10 +151,10 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
xyzMMprev = xyzGuessesMM.copy().astype('<f4')
if verbose > 1: print("Initial pos:\n", xyzMM)
step = numpy.array([numpy.inf, numpy.inf, numpy.inf])
#step = numpy.array([numpy.inf, numpy.inf, numpy.inf])
dX = numpy.inf
# outputForFigure = []
while iterations < iterationsMax and numpy.linalg.norm(step) > minDeltaMM:
while iterations < iterationsMax and dX > minDeltaMM:
if verbose > 0: print("\tIteration Number", iterations, end='')
if verbose > 1: print("\tperturbationMM:\t", perturbationMM)
......@@ -193,7 +193,7 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
# update residual
residual = radio - guessedRadio
if verbose > 1: tifffile.imsave("./residuals/residual-iteration-{:04d}.tif".format(iterations), residualMM.astype('f4'))
if verbose > 1: tifffile.imsave("./residuals/residual-iteration-{:04d}.tif".format(iterations), residual.astype('f4'))
for sphere in range(len(radiiMM)):
if verbose > 2: print("\tSphere {} of {}".format(sphere+1, len(radiiMM)))
......@@ -262,7 +262,7 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
# Reset step which will be filled with the step in XZY combining weighted combination of sensitivity fields
# N.B. not to be confused with perturbationMM, which for now is not changed during iterations
step = numpy.zeros(3)
#step = numpy.zeros(3)
LSQret = scipy.optimize.least_squares(optimiseMe,
[1.0, 1.0, 1.0],
......@@ -272,14 +272,15 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
diff_step=1.0)
if LSQret['success'] == True:
#print('LSQ Success!')
step = LSQret['x'] * perturbationMM[i]
for i in range(3):
xyzMM[sphere][i] -= step[i] * perturbationMM[i]
#step = LSQret['x'] * perturbationMM[i]
#for i in range(3):
# xyzMM[sphere][i] -= step[i] * perturbationMM[i]
xyzMM[sphere] -= LSQret['x'] * perturbationMM
else:
print("LSQ failed to converge")
if verbose > 1:
print("\t\tstep:\t",step)
#print("\t\tstep:\t",step)
print("\t\tpos:\t",xyzMM[sphere])
### End optimisation iterations
......@@ -291,9 +292,10 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
if verbose > 0: print(" DEM changed positions by: ", numpy.linalg.norm(xyzMM-xyzMMnew), end='')
xyzMM = xyzMMnew
dX = numpy.linalg.norm(xyzMM-xyzMMprev)
# outputForFigure.append([numpy.linalg.norm(step),numpy.sqrt(numpy.sum(residualMM.flatten()**2))])
# if verbose > 0: print(" |deltaMM|: ", numpy.linalg.norm(xyzMM-xyzMMprev), end='')
print(f" |deltaMM|: {numpy.linalg.norm(step):0.5f}", end='\r')
print(f" |deltaMM|: {dX:0.5f}", end='\r')
xyzMMprev = xyzMM.copy()
......@@ -318,7 +320,7 @@ def optimiseSensitivityFields(radioMM, xyzGuessesMM, radiiMM, iterationsMax=20,
# numpy.savetxt('./cache/optimiserSensitivityField.csv',outputForFigure,delimiter=',',header='DisplacementNorm,SquaredResidual')
if verbose > 0:
if numpy.linalg.norm(step) <= minDeltaMM:
if dX <= minDeltaMM:
# Check that we exited based on displacement
print("\n\toptimiseSensitivityFields(): Got below {} in {} iterations".format(minDeltaMM, iterations))
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment