Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
47c6e1d9
Commit
47c6e1d9
authored
Dec 10, 2019
by
markus.meier01
Browse files
Changed a lot of small things in everything for CDP
parent
4b71000c
Changes
14
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Algorithms/AP_expert.py
View file @
47c6e1d9
...
...
@@ -5,10 +5,12 @@ Created on Mon Dec 14 13:08:06 2015
@author: rebecca
"""
from
math
import
sqrt
from
numpy
import
zeros
from
math
import
sqrt
,
exp
from
numpy
import
zeros
,
angle
from
numpy
import
all
as
a
from
scipy.linalg
import
norm
from
.algorithms
import
Algorithm
from
trace
import
Trace
class
AP_expert
(
Algorithm
):
"""
...
...
@@ -51,9 +53,10 @@ class AP_expert(Algorithm):
self
.
iters
=
0
if
'truth'
in
config
:
self
.
truth
=
config
[
'truth'
]
self
.
truth_dim
=
config
[
'truth_dim'
]
self
.
norm_truth
=
config
[
'norm_truth'
]
self
.
Truth
=
config
[
'truth'
]
self
.
Truth_dim
=
config
[
'truth_dim'
]
self
.
norm_Truth
=
config
[
'norm_truth'
]
def
run
(
self
,
u
,
tol
,
maxiter
):
"""
...
...
@@ -91,18 +94,18 @@ class AP_expert(Algorithm):
tmp1
=
prox2
.
work
(
tmp_u
);
tmp_change
=
0
;
tmp_gap
=
0
;
if
p
==
1
and
q
==
1
:
tmp_change
=
(
norm
(
u
-
tmp_u
,
'fro'
)
/
norm_data
)
**
2
tmp_gap
=
(
norm
(
tmp1
-
tmp_u
,
'fro'
)
/
norm_data
)
**
2
if
hasattr
(
self
,
'truth'
):
if
self
.
truth_dim
[
0
]
==
1
:
if
self
.
Truth_dim
[
0
]
==
1
:
z
=
tmp_u
[
0
,:]
elif
self
.
t
ruth_dim
[
1
]
==
1
:
elif
self
.
T
ruth_dim
[
1
]
==
1
:
z
=
tmp_u
[:,
0
]
else
:
z
=
tmp_u
Relerrs
[
iter
]
=
norm
(
self
.
t
ruth
-
exp
(
-
1j
*
angle
(
t
race
(
self
.
t
ruth
.
T
*
z
)))
*
z
,
'fro'
)
/
self
.
norm_
t
ruth
Relerrs
[
iter
]
=
norm
(
self
.
T
ruth
-
exp
(
-
1j
*
angle
(
T
race
(
self
.
T
ruth
.
T
*
z
)))
*
z
,
'fro'
)
/
self
.
norm_
T
ruth
elif
q
==
1
:
for
j
in
range
(
self
.
product_space_dimension
):
...
...
proxtoolbox/Algorithms/SimpleAlgortihm.py
View file @
47c6e1d9
...
...
@@ -53,9 +53,9 @@ class SimpleAlgorithm:
self
.
config
=
config
if
'truth'
in
config
:
self
.
t
ruth
=
config
[
'truth'
]
self
.
t
ruth_dim
=
config
[
'truth_dim'
]
self
.
norm_
t
ruth
=
config
[
'norm_truth'
]
self
.
T
ruth
=
config
[
'truth'
]
self
.
T
ruth_dim
=
config
[
'truth_dim'
]
self
.
norm_
T
ruth
=
config
[
'norm_truth'
]
if
'diagnostic'
in
config
:
self
.
diagnostic
=
True
...
...
@@ -143,15 +143,15 @@ class SimpleAlgorithm:
tmp_gap
=
phase_offset_compensated_norm
(
u1
,
u2
,
norm_factor
=
norm_data
,
norm_type
=
'fro'
)
**
2
if
hasattr
(
self
,
'truth'
):
if
self
.
t
ruth_dim
[
0
]
==
1
:
if
self
.
T
ruth_dim
[
0
]
==
1
:
z
=
u1
[
0
,
:]
elif
self
.
t
ruth_dim
[
1
]
==
1
:
elif
self
.
T
ruth_dim
[
1
]
==
1
:
z
=
u1
[:,
0
]
else
:
z
=
u1
# Relerrs[iter] = norm(self.truth - exp(-1j * angle(trace(self.truth.T * z))) * z,
# 'fro') / self.norm_truth
Relerrs
[
iter
]
=
phase_offset_compensated_norm
(
self
.
t
ruth
,
z
,
norm_factor
=
self
.
norm_
t
ruth
,
Relerrs
[
iter
]
=
phase_offset_compensated_norm
(
self
.
T
ruth
,
z
,
norm_factor
=
self
.
norm_
T
ruth
,
norm_type
=
'fro'
)
elif
q
==
1
:
...
...
@@ -164,8 +164,9 @@ class SimpleAlgorithm:
if
'diagnostic'
in
self
.
config
:
if
hasattr
(
self
,
'truth'
):
z
=
u1
[:,
:,
0
]
Relerrs
[
iter
]
=
norm
(
self
.
truth
-
exp
(
-
1j
*
angle
(
trace
(
self
.
truth
.
T
*
z
)))
*
z
,
'fro'
)
/
self
.
norm_truth
print
(
z
.
shape
)
print
(
self
.
Truth
.
T
.
shape
)
Relerrs
[
iter
]
=
norm
((
self
.
Truth
-
exp
(
-
1j
*
angle
(
trace
(
self
.
Truth
.
T
*
z
)))
*
z
),
'fro'
)
/
self
.
norm_Truth
else
:
if
'diagnostic'
in
self
.
config
:
...
...
@@ -181,8 +182,8 @@ class SimpleAlgorithm:
norm
(
u2
[:,
:,
k
,
j
]
-
shadow
[:,
:,
k
,
j
],
'fro'
)
/
(
norm_data
))
**
2
if
hasattr
(
self
,
'truth'
)
and
(
j
==
0
):
Relerrs
[
iter
]
=
Relerrs
[
iter
]
+
norm
(
self
.
t
ruth
-
exp
(
-
1j
*
angle
(
trace
(
self
.
truth
.
T
*
u1
[:,
:,
k
,
1
])))
*
u1
[:,
:,
k
,
1
],
'fro'
)
/
self
.
norm_
t
ruth
self
.
T
ruth
-
exp
(
-
1j
*
angle
(
trace
(
self
.
truth
.
T
*
u1
[:,
:,
k
,
1
])))
*
u1
[:,
:,
k
,
1
],
'fro'
)
/
self
.
norm_
T
ruth
change
[
iter
]
=
sqrt
(
tmp_change
)
if
'diagnostic'
in
self
.
config
:
...
...
proxtoolbox/Problems/Phase/CDP_1D_AltP_cold_in.py
View file @
47c6e1d9
...
...
@@ -20,7 +20,7 @@ new_config = {
'warmup_iter'
:
0
,
'
method
'
:
'AP_expert'
,
'
algorithm
'
:
'AP_expert'
,
'numruns'
:
100
,
'keep_log'
:
1
,
...
...
proxtoolbox/Problems/Phase/CDP_1D_AltP_warm_in.py
View file @
47c6e1d9
...
...
@@ -18,7 +18,7 @@ new_config = {
# 'Problem Parameter'
#::::::::::::::::::::::::::::::::::::::
# 'What is the name of data file'?
'
D
ata_
F
ilename'
:
'CDP_
P
rocessor'
,
'
d
ata_
f
ilename'
:
'CDP_
p
rocessor'
,
# What type of object are we working with?
...
...
@@ -28,13 +28,13 @@ new_config = {
# What type of constraints do we have?
# Options are: 'support only', 'real and support', 'nonnegative and support',
# 'amplitude only', 'sparse real', 'sparse complex', and 'hybrid'
'C
onstraint'
:
'Hybride'
,
'c
onstraint'
:
'Hybride'
,
# What type of measurements are we working with?
# Options are: 'single diffraction', 'JWST', 'CDP',
# 'ptychography', and 'complex'
'
E
xperiment'
:
'CDP'
,
'
e
xperiment'
:
'CDP'
,
# The input data are coded diffraction patterns about a random complex
...
...
@@ -46,7 +46,7 @@ new_config = {
'Nz'
:
1
,
# images are 1 or 2D
# Make masks and linear sampling operators
'
P
roduct_space_dimension'
:
10
,
# 6 for 1D signals % Number of masks
'
p
roduct_space_dimension'
:
10
,
# 6 for 1D signals % Number of masks
# Are the measurements in the far field or near field?
# Options are: 'far field' or 'near field',
...
...
@@ -64,7 +64,7 @@ new_config = {
# able to control ('without too much damage')
# 'Algorithm':
'Method
'
:
'AP'
,
#'Accelerated_AP_product_space',
'algorithm
'
:
'AP'
,
#'Accelerated_AP_product_space',
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
@@ -95,7 +95,7 @@ new_config = {
# 'Parameter for the data regularization
# need to discuss how/whether the user should
# put in information about the noise
'
Input.
data_ball'
:
1e-15
,
'data_ball'
:
1e-15
,
# the above is the percentage of the gap
# between the measured data and the
# initial guess satisfying the
...
...
proxtoolbox/Problems/Phase/CDP_1D_DRAP_warm_in.py
View file @
47c6e1d9
...
...
@@ -60,7 +60,7 @@ new_config = {
# able to control (without too much damage)
# 'Algorithm':
'
method
'
:
'DRAP'
,
#'Accelerated_AP_product_space',
'
algorithm
'
:
'DRAP'
,
#'Accelerated_AP_product_space',
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/CDP_1D_QNAP_cold_in.py
View file @
47c6e1d9
...
...
@@ -60,7 +60,7 @@ new_config = {
# able to control (without too much damage)
# Algorithm:
'
method
'
:
'QNAP'
,
# 'Accelerated_AP_product_space',
'
algorithm
'
:
'QNAP'
,
# 'Accelerated_AP_product_space',
'numruns'
:
100
,
# the only this parameter will be different than 1
# is when we are benchmarking...not something a normal user would be doing
'keep_log'
:
1
,
...
...
proxtoolbox/Problems/Phase/CDP_1D_RAAR_warm_in.py
View file @
47c6e1d9
...
...
@@ -57,7 +57,7 @@ new_config = {
# able to control (without too much damage)
# 'Algorithm':
'
method
'
:
'RAAR'
,
#'Accelerated_AP_product_space',
'
algorithm
'
:
'RAAR'
,
#'Accelerated_AP_product_space',
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/CDP_1D_Wirt_cold_in.py
View file @
47c6e1d9
...
...
@@ -39,9 +39,9 @@ new_config = {
# 'Valued image'.
# 'Make image'
'
n
y'
:
128
,
'
n
x'
:
1
,
# 1 for 1D signals
'
n
z'
:
1
,
# images are 1 or 2D
'
N
y'
:
128
,
'
N
x'
:
1
,
# 1 for 1D signals
'
N
z'
:
1
,
# images are 1 or 2D
# 'Make masks and linear sampling operators'
'product_space_dimension'
:
10
,
# 6 for 1D signals % Number of masks
...
...
proxtoolbox/Problems/Phase/CDP_2D_AltP_cold_in.py
View file @
47c6e1d9
...
...
@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'
method
'
:
'AP'
,
#'Accelerated_AP_product_space';
'
algorithm
'
:
'AP'
,
#'Accelerated_AP_product_space';
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/CDP_2D_DRAP_cold_in.py
View file @
47c6e1d9
...
...
@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'
method
'
:
'DRAP'
,
#'Accelerated_AP_product_space';
'
algorithm
'
:
'DRAP'
,
#'Accelerated_AP_product_space';
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/CDP_2D_QNAP_warm_in.py
View file @
47c6e1d9
...
...
@@ -56,7 +56,7 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'
method
'
:
'QNAP'
,
#'Accelerated_AP_product_space';
'
algorithm
'
:
'QNAP'
,
#'Accelerated_AP_product_space';
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/CDP_2D_Wirt_cold_in.py
View file @
47c6e1d9
...
...
@@ -56,7 +56,10 @@ new_config = {
## able to control (without too much damage)
## Algorithm:
'method'
:
'Wirtinger'
,
#'Accelerated_AP_product_space';
## IMPORTANT: algorithm used to be Wirtinger, not sure if AP also works
'algorithm'
:
'AP'
,
#'Accelerated_AP_product_space';
'numruns'
:
100
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
...
...
proxtoolbox/Problems/Phase/Graphics/Phase_graphics.py
View file @
47c6e1d9
...
...
@@ -38,6 +38,11 @@ def Phase_graphics(config, output):
#beta0 = config['beta_0']
#beta_max = config['beta_max']
u_0
=
config
[
'u_0'
]
u
=
output
[
'u1'
]
print
(
u
.
shape
)
if
output
[
'u1'
].
ndim
==
2
:
u
=
output
[
'u1'
]
u2
=
output
[
'u2'
]
...
...
proxtoolbox/ProxOperators/proxoperators.py
View file @
47c6e1d9
...
...
@@ -127,7 +127,6 @@ class P_diag(ProxOperator):
m
=
self
.
m
;
p
=
self
.
p
;
K
=
self
.
K
;
print
(
u
.
shape
)
if
m
==
1
:
tmp
=
sum
(
u
,
axis
=
0
,
dtype
=
u
.
dtype
)
...
...
@@ -137,9 +136,8 @@ class P_diag(ProxOperator):
tmp
=
zeros
((
m
,
n
),
dtype
=
u
.
dtype
)
for
k
in
range
(
K
):
tmp
+=
u
[:,
:,
k
]
print
(
tmp
)
else
:
tmp
=
zeros
((
m
,
n
,
p
),
dtype
=
u
.
dtype
)
tmp
=
zeros
((
m
,
n
,
p
),
dtype
=
u
.
dtype
)
for
k
in
range
(
K
):
tmp
+=
u
[:,
:,
:,
k
]
...
...
@@ -153,10 +151,9 @@ class P_diag(ProxOperator):
u_diag
=
empty
((
m
,
n
,
K
),
dtype
=
u
.
dtype
)
for
k
in
range
(
K
):
u_diag
[:,
:,
k
]
=
tmp
print
(
u_diag
.
shape
)
return
u_diag
else
:
u_diag
=
empty
((
n
,
m
,
p
,
K
),
dtype
=
u
.
dtype
)
u_diag
=
empty
((
m
,
n
,
p
,
K
),
dtype
=
u
.
dtype
)
for
k
in
range
(
K
):
u_diag
[:,
:,
:,
k
]
=
tmp
return
u_diag
...
...
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