Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
2fe46b65
Commit
2fe46b65
authored
May 10, 2019
by
jansen31
Browse files
code readability
parent
b7137122
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Algorithms/RAAR.py
View file @
2fe46b65
...
...
@@ -19,7 +19,7 @@ class RAAR(SimpleAlgorithm):
beta_max
=
self
.
config
[
'beta_max'
]
beta_switch
=
self
.
config
[
'beta_switch'
]
tmp1
=
2
*
self
.
prox2
.
work
(
u
)
-
u
tmp2
=
self
.
prox1
.
work
(
tmp1
)
tmp2
=
self
.
prox1
.
work
(
tmp1
)
# update
beta
=
exp
((
-
iter
/
beta_switch
)
**
3
)
*
beta0
+
(
1
-
exp
((
-
iter
/
beta_switch
)
**
3
))
*
beta_max
# unrelaxes as the
unew
=
(
beta
*
(
2
*
tmp2
-
tmp1
)
+
(
1
-
beta
)
*
tmp1
+
u
)
/
2
...
...
proxtoolbox/Problems/OrbitalTomog/Coronene_demo.py
View file @
2fe46b65
import
sys
# sys.path.append('../proxtoolbox/Problems/Phase')
sys
.
path
.
append
(
'..'
)
from
.
import
coronene_test
from
.phase
import
Phase
# sys.path.append('../proxtoolbox/Problems/Phase')
orbit
=
Phase
(
coronene_test
.
new_config
)
...
...
proxtoolbox/Problems/OrbitalTomog/phase.py
View file @
2fe46b65
...
...
@@ -15,8 +15,7 @@ class Phase(Problem):
"""
Phase Problem
"""
config
=
{
}
config
=
{
}
# This line does not do anything.
def
__init__
(
self
,
new_config
=
{}):
"""
...
...
proxtoolbox/Problems/Phase/Goettingen_data_processor.py
View file @
2fe46b65
This diff is collapsed.
Click to expand it.
proxtoolbox/Problems/Phase/tasse_ap_in.py
View file @
2fe46b65
#
# This is the input file that the user sees/modifies. It should be simple,
#
# avoid jargon or acronyms, and should be a model for a menu-driven GUI
# This is the input file that the user sees/modifies. It should be simple,
# avoid jargon or acronyms, and should be a model for a menu-driven GUI
new_config
=
{
## We start very general.
##==========================================
## Problem parameters
##==========================================
## What is the name of the data file?
'data_filename'
:
'Goettingen_data_processor'
,
## What type of object are we working with?
## Options are: 'phase', 'real', 'nonnegative', 'complex'
'object'
:
'nonnegative'
,
## 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'
'constraint'
:
'nonnegative and support'
,
## What type of measurements are we working with?
## Options are: 'single diffraction', 'diversity diffraction',
## 'ptychography', and 'complex'
'experiment'
:
'CDI'
,
## Next we move to things that most of our users will know
## better than we will. Some of these may be overwritten in the
## data processor file which the user will most likely write.
## Are the measurements in the far field or near field?
## Options are: 'far field' or 'near field',
'distance'
:
'far field'
,
## What are the dimensions of the measurements?
'Nx'
:
128
,
'Ny'
:
128
,
'fresnel_nr'
:
0
,
#moved this to phase
#if(strcmp('distance,'near field'))
# 'fresnel_nr' : 1*2*pi*'Nx,
#else
# 'fresnel_nr' : 0, #1*2*pi*'Nx,
'magn'
:
1
,
## What are the noise characteristics (Poisson or Gaussian)?
'noise'
:
'Poisson'
,
##==========================================
## Algorithm parameters
##==========================================
## Now set some algorithm parameters that the user should be
## able to control (without too much damage)
## Algorithm:
'algorithm'
:
'AP'
,
# used to be 'Projection',
'numruns'
:
1
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
# would be doing.
## The following are parameters specific to RAAR, HPR, and HAAR that the
## user should be able to set/modify. Surely
## there will be other algorithm specific parameters that a user might
## want to play with. Don't know how best
## to do this. Thinking of a GUI interface, we could hard code all the
## parameters the user might encounter and have the menu options change
## depending on the value of the 'method field.
## do different things depending on the chosen algorithm:
#if(strcmp('method,'RAAR')||strcmp('method,'AP')||...
# strcmp('method,'HPR')||strcmp('method,'HAAR'))
# We start very general.
# =========================================
# Problem parameters
# =========================================
# What is the name of the data file?
'data_filename'
:
'Goettingen_data_processor'
,
# What type of object are we working with?
# Options are: 'phase', 'real', 'nonnegative', 'complex'
'object'
:
'nonnegative'
,
# 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'
'constraint'
:
'nonnegative and support'
,
# What type of measurements are we working with?
# Options are: 'single diffraction', 'diversity diffraction',
# 'ptychography', and 'complex'
'experiment'
:
'CDI'
,
# Next we move to things that most of our users will know
# better than we will. Some of these may be overwritten in the
# data processor file which the user will most likely write.
# Are the measurements in the far field or near field?
# Options are: 'far field' or 'near field',
'distance'
:
'far field'
,
# What are the dimensions of the measurements?
'Nx'
:
128
,
'Ny'
:
128
,
'fresnel_nr'
:
0
,
# moved this to phase
# if(strcmp('distance,'near field'))
# 'fresnel_nr' : 1*2*pi*'Nx,
# else
# 'fresnel_nr' : 0, #1*2*pi*'Nx,
'magn'
:
1
,
# What are the noise characteristics (Poisson or Gaussian)?
'noise'
:
'Poisson'
,
# ==========================================
# Algorithm parameters
# ==========================================
# Now set some algorithm parameters that the user should be
# able to control (without too much damage)
# Algorithm:
'algorithm'
:
'AP'
,
# used to be 'Projection',
'numruns'
:
1
,
# the only time this parameter will
# be different than 1 is when we are
# benchmarking...not something a normal user
# would be doing.
# The following are parameters specific to RAAR, HPR, and HAAR that the
# user should be able to set/modify. Surely
# there will be other algorithm specific parameters that a user might
# want to play with. Don't know how best
# to do this. Thinking of a GUI interface, we could hard code all the
# parameters the user might encounter and have the menu options change
# depending on the value of the 'method field.
# do different things depending on the chosen algorithm:
# if(strcmp('method,'RAAR')||strcmp('method,'AP')||...
# strcmp('method,'HPR')||strcmp('method,'HAAR'))
# the following just points this driver to a patch that communicates
# the parameters defined at this level to the structures used in the
# algorithms developed by Russell.
'problem_family'
:
'Phase'
,
#
else # moreregularization parameters for Thorsten's algorithms:
# prbl' : complete_itreg_par(prbl),
'problem_family'
:
'Phase'
,
#
else # moreregularization parameters for Thorsten's algorithms:
# prbl' : complete_itreg_par(prbl),
# This is just a patch to Thorsten's tools. May want to change this
# later
#'problem_family='Hohage',
#end
#if(strcmp('problem_family,'Phase'))
## maximum number of iterations and tolerances
'MAXIT'
:
5000
,
'TOL'
:
1e-10
,
## relaxaton parameters in RAAR, HPR and HAAR
'beta_0'
:
0.85
,
#0.95 # starting relaxation prameter (only used with
# HAAR, HPR and RAAR)
'beta_max'
:
0.50
,
# maximum relaxation prameter (only used with
# HAAR, RAAR, and HPR)
'beta_switch'
:
30
,
# iteration at which beta moves from beta_0 -> beta_max
## parameter for the data regularization
## need to discuss how/whether the user should
## put in information about the noise
'data_ball'
:
.
999826
,
# 'problem_family='Hohage',
# end
# if(strcmp('problem_family,'Phase'))
# maximum number of iterations and tolerances
'MAXIT'
:
5000
,
'TOL'
:
1e-10
,
# relaxaton parameters in RAAR, HPR and HAAR
'beta_0'
:
0.85
,
# 0.95 # starting relaxation parameter (only used with HAAR, HPR and RAAR)
'beta_max'
:
0.50
,
# maximum relaxation prameter (only used with HAAR, RAAR, and HPR)
'beta_switch'
:
30
,
# iteration at which beta moves from beta_0 -> beta_max
# parameter for the data regularization
# need to discuss how/whether the user should
# put in information about the noise
'data_ball'
:
.
999826
,
# 'data_ball' : .9998261e-0,
# the above is the percentage of the gap
# between the measured data and the
...
...
@@ -112,50 +106,49 @@ new_config = {
# Ultimately the size of the gap depends
# on the inconsistency of the measurement model
# with the qualitative constraints.
#
elseif(strcmp('problem_family,'Hohage'))
# 'alpha0' : 1e4,
# 'N_CG' : 70,
#
end
# ##==========================================
# ## parameters for plotting and diagnostics
# ##==========================================
# 'plotWhat.n1=2,
# 'plotWhat.n2=3,
# 'plotWhat.plots' : 'PYWpyw',
# 'verbose' : 1, # options are 0 or 1
# 'graphics' : 1, # whether or not to display figures, options are 0 or 1.
# # default is 1.
# 'anim' : 1, # whether or not to disaply ``real time" reconstructions
# # options are 0=no, 1=yes, 2=make a movie
# # default is 1.
# 'graphics_display' : [], # unless specified, a default
# # plotting subroutine will generate
# # the graphics. Otherwise, the user
# # can write their own plotting subroutine
#
##
==========================================
#
# parameters for plotting and diagnostics
##
==========================================
'diagnostic'
:
True
,
'verbose'
:
1
,
# options are 0 or 1
'graphics'
:
1
,
# whether or not to display figures, options are 0 or 1.
# default is 1.
'anim'
:
2
,
# whether or not to disaply ``real time" reconstructions
# options are 0=no, 1=yes, 2=make a movie
# default is 1.
'graphics_display'
:
'Phase_graphics'
# unless specified, a default
# plotting subroutine will generate
# the graphics. Otherwise, the user
# can write their own plotting subroutine
#
elseif(strcmp('problem_family,'Hohage'))
# 'alpha0' : 1e4,
# 'N_CG' : 70,
#
end
# ##==========================================
# ## parameters for plotting and diagnostics
# ##==========================================
# 'plotWhat.n1=2,
# 'plotWhat.n2=3,
# 'plotWhat.plots' : 'PYWpyw',
# 'verbose' : 1, # options are 0 or 1
# 'graphics' : 1, # whether or not to display figures, options are 0 or 1.
# # default is 1.
# 'anim' : 1, # whether or not to disaply ``real time" reconstructions
# # options are 0=no, 1=yes, 2=make a movie
# # default is 1.
# 'graphics_display' : [], # unless specified, a default
# # plotting subroutine will generate
# # the graphics. Otherwise, the user
# # can write their own plotting subroutine
#
#
==========================================
# parameters for plotting and diagnostics
#
==========================================
'diagnostic'
:
True
,
'verbose'
:
1
,
# options are 0 or 1
'graphics'
:
1
,
# whether or not to display figures, options are 0 or 1.
# default is 1.
'anim'
:
2
,
# whether or not to disaply ``real time" reconstructions
# options are 0=no, 1=yes, 2=make a movie
# default is 1.
'graphics_display'
:
'Phase_graphics'
# unless specified, a default
# plotting subroutine will generate
# the graphics. Otherwise, the user
# can write their own plotting subroutine
}
##======================================================================
## Technical/software specific parameters
##======================================================================
## Given the parameter values above, the following technical/algorithmic
## parameters are automatically set. The user does not need to know
## about these details, and so probably these parameters should be set in
## a module one level below this one.
# =====================================================================
# Technical/software specific parameters
# =====================================================================
# Given the parameter values above, the following technical/algorithmic
# parameters are automatically set. The user does not need to know
# about these details, and so probably these parameters should be set in
# a module one level below this one.
proxtoolbox/Problems/problems.py
View file @
2fe46b65
...
...
@@ -7,14 +7,14 @@ Created on Wed Oct 15 11:36:27 2014
import
time
__all__
=
[
"Problem"
]
class
Problem
:
"""
Generic interface for ProxToolbox problems
"""
def
__init__
(
self
,
config
=
{}):
"""
Initialization method
...
...
@@ -26,7 +26,7 @@ class Problem:
If unspecified, a default configuration will be used.
"""
raise
NotImplementedError
(
"This is just an abstract interface"
)
def
_presolve
(
self
):
"""
Preprocessing data.
...
...
@@ -39,14 +39,14 @@ class Problem:
This procedure solves the problem.
"""
raise
NotImplementedError
(
"This is just an abstract interface"
)
def
_postsolve
(
self
):
"""
Postprocessing data.
This procedure is called after the problem has been solved.
"""
raise
NotImplementedError
(
"This is just an abstract interface"
)
def
solve
(
self
):
"""
Solves the problem, as specified by _presolve, _solve and _postsolve.
...
...
@@ -54,14 +54,14 @@ class Problem:
This is NOT intended to be overloaded. Overload _presolve, _solve and
_postsolve instead.
"""
self
.
_presolve
()
;
t
=
time
.
time
()
;
self
.
_solve
()
;
self
.
elapsed_time
=
time
.
time
()
-
t
;
self
.
_postsolve
()
;
self
.
_presolve
()
t
=
time
.
time
()
self
.
_solve
()
self
.
elapsed_time
=
time
.
time
()
-
t
self
.
_postsolve
()
def
show
(
self
):
"""
This procedure realizes textual and/or graphical output of the Problem's result.
...
...
proxtoolbox/ProxOperators/P_M.py
View file @
2fe46b65
from
proxoperators
import
ProxOperator
,
magproj
from
.
proxoperators
import
ProxOperator
,
magproj
import
numpy
as
np
class
P_M
(
ProxOperator
):
"""
Projection onto Fourier magnitude constraints
"""
"""
Projection onto Fourier magnitude constraints
"""
def
__init__
(
self
,
config
):
"""
Initialization
def
__init__
(
self
,
config
):
"""
Initialization
Parameters
----------
config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
'M' : array_like - nonegative real FOURIER DOMAIN CONSTRAINT
"""
self
.
M
=
config
[
'M'
]
'M' : array_like - nonegative real FOURIER DOMAIN CONSTRAINT
"""
self
.
M
=
config
[
'M'
]
def
work
(
self
,
u
):
"""
def
work
(
self
,
u
):
"""
Applies the proxoperator P_M
Parameters
...
...
@@ -28,8 +29,8 @@ class P_M(ProxOperator):
Returns
-------
array_like - [p_M,phat_M] ,where p_M = the projection IN THE PHYSICAL (time) DOMAIN and phat_M = projection IN THE FOURIER DOMAIN
"""
m
=
self
.
M
a
=
np
.
fft
.
fft2
(
u
)
b
=
magproj
(
a
,
m
)
return
np
.
fft
.
ifft2
(
b
)
"""
m
=
self
.
M
a
=
np
.
fft
.
fft2
(
u
)
b
=
magproj
(
a
,
m
)
return
np
.
fft
.
ifft2
(
b
)
proxtoolbox/ProxOperators/proxoperators.py
View file @
2fe46b65
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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