Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ttk
radioSphere
Commits
b7182bb9
Commit
b7182bb9
authored
Oct 25, 2021
by
Olga Stamati
Browse files
fix application of pertubation step at optimiseSensitivityFields()
parent
ef0c05bf
Pipeline
#78201
passed with stage
in 1 minute and 43 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_optimiser.py
View file @
b7182bb9
...
...
@@ -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\n
test_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\n
test_optimiseSensitivityFieldsMultiProj_ManySpheres(): Starting up"
)
# Lists of:
...
...
tools/optimisePositions.py
View file @
b7182bb9
...
...
@@ -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
(
"
\t
Iteration Number"
,
iterations
,
end
=
''
)
if
verbose
>
1
:
print
(
"
\t
perturbationMM:
\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
),
residual
MM
.
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
(
"
\t
Sphere {} 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\t
step:
\t
"
,
step
)
#
print("\t\tstep:\t",step)
print
(
"
\t\t
pos:
\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.5
f
}
"
,
end
=
'
\r
'
)
print
(
f
" |deltaMM|:
{
dX
:
0.5
f
}
"
,
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\t
optimiseSensitivityFields(): Got below {} in {} iterations"
.
format
(
minDeltaMM
,
iterations
))
else
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment