Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Merge Requests
15
Merge Requests
15
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
ef214849
Commit
ef214849
authored
Jul 17, 2017
by
Jakob Knollmueller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "added some distribution_strategy's for mpirun, fixed some errors in WienerFilterEnergy"
This reverts commit
03cc7f7e
parent
03cc7f7e
Pipeline
#14965
passed with stage
in 7 minutes and 7 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
93 deletions
+67
-93
demos/wiener_filter_via_hamiltonian.py
demos/wiener_filter_via_hamiltonian.py
+60
-81
nifty/library/wiener_filter/wiener_filter_energy.py
nifty/library/wiener_filter/wiener_filter_energy.py
+3
-4
nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py
...rs/invertible_operator_mixin/invertible_operator_mixin.py
+4
-8
No files found.
demos/wiener_filter_via_hamiltonian.py
View file @
ef214849
...
...
@@ -10,78 +10,73 @@ rank = comm.rank
np
.
random
.
seed
(
42
)
#
class AdjointFFTResponse(LinearOperator):
#
def __init__(self, FFT, R, default_spaces=None):
#
super(AdjointFFTResponse, self).__init__(default_spaces)
#
self._domain = FFT.target
#
self._target = R.target
#
self.R = R
#
self.FFT = FFT
#
#
def _times(self, x, spaces=None):
#
return self.R(self.FFT.adjoint_times(x))
#
#
def _adjoint_times(self, x, spaces=None):
#
return self.FFT(self.R.adjoint_times(x))
#
@property
#
def domain(self):
#
return self._domain
#
#
@property
#
def target(self):
#
return self._target
#
#
@property
#
def unitary(self):
#
return False
#
class
AdjointFFTResponse
(
LinearOperator
):
def
__init__
(
self
,
FFT
,
R
,
default_spaces
=
None
):
super
(
AdjointFFTResponse
,
self
).
__init__
(
default_spaces
)
self
.
_domain
=
FFT
.
target
self
.
_target
=
R
.
target
self
.
R
=
R
self
.
FFT
=
FFT
def
_times
(
self
,
x
,
spaces
=
None
):
return
self
.
R
(
self
.
FFT
.
adjoint_times
(
x
))
def
_adjoint_times
(
self
,
x
,
spaces
=
None
):
return
self
.
FFT
(
self
.
R
.
adjoint_times
(
x
))
@
property
def
domain
(
self
):
return
self
.
_domain
@
property
def
target
(
self
):
return
self
.
_target
@
property
def
unitary
(
self
):
return
False
if
__name__
==
"__main__"
:
distribution_strategy
=
'
equal
'
distribution_strategy
=
'
not
'
# Set up position space
s
ignal_space
=
RGSpace
([
256
,
256
])
s
_space
=
RGSpace
([
128
,
128
])
# s_space = HPSpace(32)
harmonic_space
=
FFTOperator
.
get_default_codomain
(
signal_space
)
fft
=
FFTOperator
(
harmonic_space
,
target
=
signal_space
,
domain_dtype
=
np
.
complex
,
target_dtype
=
np
.
float
)
# Define harmonic transformation and associated harmonic space
fft
=
FFTOperator
(
s_space
)
h_space
=
fft
.
target
[
0
]
# Setting up power space
power_space
=
PowerSpace
(
harmonic_space
,
distribution_strategy
=
distribution_strategy
)
p_space
=
PowerSpace
(
h_space
,
distribution_strategy
=
distribution_strategy
)
# Choosing the prior correlation structure and defining correlation operator
p
ower_spectrum
=
(
lambda
k
:
(
42
/
(
k
+
1
)
**
3
))
p
_spec
=
(
lambda
k
:
(
42
/
(
k
+
1
)
**
3
))
S
=
create_power_operator
(
h
armonic_space
,
power_spectrum
=
power_spectrum
,
S
=
create_power_operator
(
h
_space
,
power_spectrum
=
p_spec
,
distribution_strategy
=
distribution_strategy
)
# Drawing a sample sh from the prior distribution in harmonic space
sp
=
Field
(
p
ower_space
,
val
=
power_spectrum
,
sp
=
Field
(
p
_space
,
val
=
p_spec
,
distribution_strategy
=
distribution_strategy
)
sh
=
sp
.
power_synthesize
(
real_signal
=
True
)
ss
=
fft
(
sh
)
ss
=
fft
.
adjoint_times
(
sh
)
# Choosing the measurement instrument
# Instrument = SmoothingOperator(s_space, sigma=0.05)
mask
=
Field
(
signal_space
,
val
=
1
,
distribution_strategy
=
distribution_strategy
)
mask
.
val
[
63
:
127
,
63
:
127
]
=
0.
Instrument
=
DiagonalOperator
(
signal_space
,
diagonal
=
mask
)
Instrument
=
DiagonalOperator
(
s_space
,
diagonal
=
1.
)
# Instrument._diagonal.val[200:400, 200:400] = 0
#Adding a harmonic transformation to the instrument
R
=
ComposedOperator
([
fft
,
Instrument
],
default_spaces
=
[
0
,
0
]
)
R
=
AdjointFFTResponse
(
fft
,
Instrument
)
signal_to_noise
=
1.
N
=
DiagonalOperator
(
signal_space
,
diagonal
=
ss
.
var
()
/
signal_to_noise
,
bare
=
True
,
distribution_strategy
=
distribution_strategy
)
n
=
Field
.
from_random
(
domain
=
signal_space
,
N
=
DiagonalOperator
(
s_space
,
diagonal
=
ss
.
var
()
/
signal_to_noise
,
bare
=
True
)
n
=
Field
.
from_random
(
domain
=
s_space
,
random_type
=
'normal'
,
std
=
ss
.
std
()
/
np
.
sqrt
(
signal_to_noise
),
mean
=
0
,
distribution_strategy
=
distribution_strategy
)
mean
=
0
)
# Creating the mock data
d
=
R
(
sh
)
+
n
...
...
@@ -100,50 +95,34 @@ if __name__ == "__main__":
minimizer
=
RelaxedNewton
(
convergence_tolerance
=
0
,
iteration_limit
=
1
,
callback
=
convergence_measure
)
minimizer
=
VL_BFGS
(
convergence_tolerance
=
0
,
iteration_limit
=
50
0
,
callback
=
convergence_measure
,
max_history_length
=
3
)
#
#
minimizer = VL_BFGS(convergence_tolerance=0,
# iteration_limit=5
0,
#
callback=convergence_measure,
#
max_history_length=3)
#
inverter
=
ConjugateGradient
(
convergence_level
=
3
,
convergence_tolerance
=
1e-5
,
preconditioner
=
None
)
# Setting starting position
m0
=
Field
(
harmonic_space
,
val
=
.
0
,
distribution_strategy
=
distribution_strategy
)
m0
=
Field
(
h_space
,
val
=
.
0
)
# Initializing the Wiener Filter energy
energy
=
WienerFilterEnergy
(
position
=
m0
,
d
=
d
,
R
=
R
,
N
=
N
,
S
=
S
,
inverter
=
inverter
)
energy
=
WienerFilterEnergy
(
position
=
m0
,
d
=
d
,
R
=
R
,
N
=
N
,
S
=
S
,
inverter
=
inverter
)
D0
=
energy
.
curvature
# Solving the problem analytically
m0
=
D0
.
inverse_times
(
j
)
# solution, convergence = minimizer(energy)
# m0 = solution.position
m0_s
=
Field
(
signal_space
,
val
=
fft
(
m0
).
val
.
get_full_data
().
real
)
plotter
=
plotting
.
RG2DPlotter
()
plotter
.
title
=
'mock_signal.html'
;
plotter
(
ss
)
plotter
.
title
=
'data.html'
plotter
(
Field
(
signal_space
,
val
=
Instrument
.
adjoint_times
(
d
).
val
.
get_full_data
()
\
.
reshape
(
signal_space
.
shape
)))
plotter
.
title
=
'map.html'
;
plotter
(
m0_s
)
#
# sample_variance = Field(sh.domain,val=0. + 0j,
# distribution_strategy=distribution_strategy)
# sample_mean = Field(sh.domain,val=0. + 0j,
# distribution_strategy=distribution_strategy)
#
# # sampling the uncertainty map
# n_samples = 1
# for i in range(n_samples):
# sample = sugar.generate_posterior_sample(m0,D0)
# sample_variance += sample**2
# sample_mean += sample
# variance = sample_variance/n_samples - (sample_mean/n_samples)**2
sample_variance
=
Field
(
sh
.
domain
,
val
=
0.
+
0j
)
sample_mean
=
Field
(
sh
.
domain
,
val
=
0.
+
0j
)
# sampling the uncertainty map
n_samples
=
1
for
i
in
range
(
n_samples
):
sample
=
sugar
.
generate_posterior_sample
(
m0
,
D0
)
sample_variance
+=
sample
**
2
sample_mean
+=
sample
variance
=
sample_variance
/
n_samples
-
(
sample_mean
/
n_samples
)
nifty/library/wiener_filter/wiener_filter_energy.py
View file @
ef214849
...
...
@@ -29,7 +29,7 @@ class WienerFilterEnergy(Energy):
self
.
R
=
R
self
.
N
=
N
self
.
S
=
S
self
.
inverter
=
inverter
def
at
(
self
,
position
):
return
self
.
__class__
(
position
=
position
,
d
=
self
.
d
,
R
=
self
.
R
,
N
=
self
.
N
,
S
=
self
.
S
,
inverter
=
self
.
inverter
)
...
...
@@ -47,9 +47,8 @@ class WienerFilterEnergy(Energy):
@
property
@
memo
def
curvature
(
self
):
return
WienerFilterCurvature
(
R
=
self
.
R
,
N
=
self
.
N
,
S
=
self
.
S
,
inverter
=
self
.
inverter
)
@
property
return
WienerFilterCurvature
(
R
=
self
.
R
,
N
=
self
.
N
,
S
=
self
.
S
)
@
memo
def
_Dx
(
self
):
return
self
.
curvature
(
self
.
position
)
...
...
nifty/operators/invertible_operator_mixin/invertible_operator_mixin.py
View file @
ef214849
...
...
@@ -71,8 +71,7 @@ class InvertibleOperatorMixin(object):
def
_times
(
self
,
x
,
spaces
,
x0
=
None
):
if
x0
is
None
:
x0
=
Field
(
self
.
target
,
val
=
0.
,
dtype
=
x
.
dtype
,
distribution_strategy
=
x
.
distribution_strategy
)
x0
=
Field
(
self
.
target
,
val
=
0.
,
dtype
=
x
.
dtype
)
(
result
,
convergence
)
=
self
.
__inverter
(
A
=
self
.
inverse_times
,
b
=
x
,
...
...
@@ -81,8 +80,7 @@ class InvertibleOperatorMixin(object):
def
_adjoint_times
(
self
,
x
,
spaces
,
x0
=
None
):
if
x0
is
None
:
x0
=
Field
(
self
.
domain
,
val
=
0.
,
dtype
=
x
.
dtype
,
distribution_strategy
=
x
.
distribution_strategy
)
x0
=
Field
(
self
.
domain
,
val
=
0.
,
dtype
=
x
.
dtype
)
(
result
,
convergence
)
=
self
.
__inverter
(
A
=
self
.
adjoint_inverse_times
,
b
=
x
,
...
...
@@ -91,8 +89,7 @@ class InvertibleOperatorMixin(object):
def
_inverse_times
(
self
,
x
,
spaces
,
x0
=
None
):
if
x0
is
None
:
x0
=
Field
(
self
.
domain
,
val
=
0.
,
dtype
=
x
.
dtype
,
distribution_strategy
=
x
.
distribution_strategy
)
x0
=
Field
(
self
.
domain
,
val
=
0.
,
dtype
=
x
.
dtype
)
(
result
,
convergence
)
=
self
.
__inverter
(
A
=
self
.
times
,
b
=
x
,
...
...
@@ -101,8 +98,7 @@ class InvertibleOperatorMixin(object):
def
_adjoint_inverse_times
(
self
,
x
,
spaces
,
x0
=
None
):
if
x0
is
None
:
x0
=
Field
(
self
.
target
,
val
=
0.
,
dtype
=
x
.
dtype
,
distribution_strategy
=
x
.
distribution_strategy
)
x0
=
Field
(
self
.
target
,
val
=
0.
,
dtype
=
x
.
dtype
)
(
result
,
convergence
)
=
self
.
__inverter
(
A
=
self
.
adjoint_times
,
b
=
x
,
...
...
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