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
ift
NIFTy
Commits
e954b8bf
Commit
e954b8bf
authored
Feb 14, 2018
by
Martin Reinecke
Browse files
renamings
parent
7f0d49de
Pipeline
#24889
failed with stage
in 60 minutes and 4 seconds
Changes
15
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/nonlinear_critical_filter.py
View file @
e954b8bf
...
@@ -59,9 +59,8 @@ if __name__ == "__main__":
...
@@ -59,9 +59,8 @@ if __name__ == "__main__":
d_space
=
MeasurementOperator
.
target
d_space
=
MeasurementOperator
.
target
Projection
=
ift
.
PowerProjectionOperator
(
domain
=
h_space
,
Distributor
=
ift
.
PowerDistributor
(
target
=
h_space
,
power_space
=
p_space
)
power_space
=
p_space
)
power
=
Distributor
(
ift
.
exp
(
0.5
*
log_p
))
power
=
Projection
.
adjoint_times
(
ift
.
exp
(
0.5
*
log_p
))
# Creating the mock data
# Creating the mock data
true_sky
=
nonlinearity
(
HT
(
power
*
sh
))
true_sky
=
nonlinearity
(
HT
(
power
*
sh
))
noiseless_data
=
MeasurementOperator
(
true_sky
)
noiseless_data
=
MeasurementOperator
(
true_sky
)
...
@@ -75,7 +74,7 @@ if __name__ == "__main__":
...
@@ -75,7 +74,7 @@ if __name__ == "__main__":
m0
=
ift
.
power_synthesize
(
ift
.
Field
(
p_space
,
val
=
1e-7
))
m0
=
ift
.
power_synthesize
(
ift
.
Field
(
p_space
,
val
=
1e-7
))
t0
=
ift
.
Field
(
p_space
,
val
=-
4.
)
t0
=
ift
.
Field
(
p_space
,
val
=-
4.
)
power0
=
Projection
.
adjoint_
times
(
ift
.
exp
(
0.5
*
t0
))
power0
=
Distributor
.
times
(
ift
.
exp
(
0.5
*
t0
))
IC1
=
ift
.
GradientNormController
(
name
=
"IC1"
,
iteration_limit
=
100
,
IC1
=
ift
.
GradientNormController
(
name
=
"IC1"
,
iteration_limit
=
100
,
tol_abs_gradnorm
=
1e-3
)
tol_abs_gradnorm
=
1e-3
)
...
@@ -87,7 +86,7 @@ if __name__ == "__main__":
...
@@ -87,7 +86,7 @@ if __name__ == "__main__":
inverter
=
ift
.
ConjugateGradient
(
controller
=
ICI
)
inverter
=
ift
.
ConjugateGradient
(
controller
=
ICI
)
for
i
in
range
(
20
):
for
i
in
range
(
20
):
power0
=
Projection
.
adjoint_times
(
ift
.
exp
(
0.5
*
t0
))
power0
=
Distributor
(
ift
.
exp
(
0.5
*
t0
))
map0_energy
=
ift
.
library
.
NonlinearWienerFilterEnergy
(
map0_energy
=
ift
.
library
.
NonlinearWienerFilterEnergy
(
m0
,
d
,
MeasurementOperator
,
nonlinearity
,
HT
,
power0
,
N
,
S
,
m0
,
d
,
MeasurementOperator
,
nonlinearity
,
HT
,
power0
,
N
,
S
,
inverter
=
inverter
)
inverter
=
inverter
)
...
@@ -103,7 +102,7 @@ if __name__ == "__main__":
...
@@ -103,7 +102,7 @@ if __name__ == "__main__":
power0_energy
=
ift
.
library
.
NonlinearPowerEnergy
(
power0_energy
=
ift
.
library
.
NonlinearPowerEnergy
(
position
=
t0
,
d
=
d
,
N
=
N
,
xi
=
m0
,
D
=
D0
,
ht
=
HT
,
position
=
t0
,
d
=
d
,
N
=
N
,
xi
=
m0
,
D
=
D0
,
ht
=
HT
,
Instrument
=
MeasurementOperator
,
nonlinearity
=
nonlinearity
,
Instrument
=
MeasurementOperator
,
nonlinearity
=
nonlinearity
,
Projection
=
Projection
,
sigma
=
1.
,
samples
=
2
,
inverter
=
inverter
)
Distributor
=
Distributor
,
sigma
=
1.
,
samples
=
2
,
inverter
=
inverter
)
power0_energy
=
minimizer
(
power0_energy
)[
0
]
power0_energy
=
minimizer
(
power0_energy
)[
0
]
...
...
demos/wiener_filter_via_hamiltonian.py
View file @
e954b8bf
...
@@ -70,7 +70,8 @@ if __name__ == "__main__":
...
@@ -70,7 +70,8 @@ if __name__ == "__main__":
# Generate plots
# Generate plots
zmax
=
max
(
ht
(
sh
).
max
(),
ht
(
m
).
max
())
zmax
=
max
(
ht
(
sh
).
max
(),
ht
(
m
).
max
())
zmin
=
min
(
ht
(
sh
).
min
(),
ht
(
m
).
min
())
zmin
=
min
(
ht
(
sh
).
min
(),
ht
(
m
).
min
())
plotdict
=
{
"zmax"
:
zmax
,
"zmin"
:
zmin
,
"colormap"
:
"Planck-like"
}
plotdict
=
{
"zmax"
:
zmax
,
"zmin"
:
zmin
,
"colormap"
:
"Planck-like"
}
plotdict2
=
{
"colormap"
:
"Planck-like"
}
ift
.
plot
(
ht
(
sh
),
name
=
"mock_signal.png"
,
**
plotdict
)
ift
.
plot
(
ht
(
sh
),
name
=
"mock_signal.png"
,
**
plotdict
)
ift
.
plot
(
ht
(
m
),
name
=
"reconstruction.png"
,
**
plotdict
)
ift
.
plot
(
ht
(
m
),
name
=
"reconstruction.png"
,
**
plotdict
)
...
@@ -79,10 +80,10 @@ if __name__ == "__main__":
...
@@ -79,10 +80,10 @@ if __name__ == "__main__":
sample_mean
=
ift
.
Field
.
zeros
(
s_space
)
sample_mean
=
ift
.
Field
.
zeros
(
s_space
)
mean
,
variance
=
ift
.
probe_with_posterior_samples
(
curv
,
ht
,
50
)
mean
,
variance
=
ift
.
probe_with_posterior_samples
(
curv
,
ht
,
50
)
ift
.
plot
(
variance
,
name
=
"posterior_variance.png"
,
**
plotdict
)
ift
.
plot
(
variance
,
name
=
"posterior_variance.png"
,
**
plotdict
2
)
ift
.
plot
(
mean
+
ht
(
m
),
name
=
"posterior_mean.png"
,
**
plotdict
)
ift
.
plot
(
mean
+
ht
(
m
),
name
=
"posterior_mean.png"
,
**
plotdict
)
# try to do the same with diagonal probing
# try to do the same with diagonal probing
variance
=
ift
.
probe_diagonal
(
ht
*
curv
.
inverse
*
ht
.
adjoint
,
100
)
variance
=
ift
.
probe_diagonal
(
ht
*
curv
.
inverse
*
ht
.
adjoint
,
100
)
#sm = ift.FFTSmoothingOperator(s_space, sigma=0.0
1
5)
#sm = ift.FFTSmoothingOperator(s_space, sigma=0.0
0
5)
ift
.
plot
(
variance
,
name
=
"posterior_variance2.png"
,
**
plotdict
)
ift
.
plot
(
variance
,
name
=
"posterior_variance2.png"
,
**
plotdict
2
)
docs/source/concepts/operators.rst
View file @
e954b8bf
...
@@ -12,7 +12,7 @@ Description of Operators
...
@@ -12,7 +12,7 @@ Description of Operators
ScalingOperator <../mod/nifty4.operators.scaling_operator>
ScalingOperator <../mod/nifty4.operators.scaling_operator>
DiagonalOperator <../mod/nifty4.operators.diagonal_operator>
DiagonalOperator <../mod/nifty4.operators.diagonal_operator>
HarmonicTransformOperator <../mod/nifty4.operators.harmonic_transform_operator>
HarmonicTransformOperator <../mod/nifty4.operators.harmonic_transform_operator>
Power
ProjectionOperator
<../mod/nifty4.operators.power_
projection_opera
tor>
Power
Distributor
<../mod/nifty4.operators.power_
distribu
tor>
.. toctree::
.. toctree::
:maxdepth: 1
:maxdepth: 1
...
@@ -26,7 +26,7 @@ Description of Operators
...
@@ -26,7 +26,7 @@ Description of Operators
.. Adjoint <../mod/nifty4.operators.adjoint_operator>
.. Adjoint <../mod/nifty4.operators.adjoint_operator>
.. Chain <../mod/nifty4.operators.chain_operator>
.. Chain <../mod/nifty4.operators.chain_operator>
.. DOF
Projection
<../mod/nifty4.operators.dof_
projection_opera
tor>
.. DOF
Distributor
<../mod/nifty4.operators.dof_
distribu
tor>
.. Inverse <../mod/nifty4.operators.inverse_operator>
.. Inverse <../mod/nifty4.operators.inverse_operator>
.. Laplace <../mod/nifty4.operators.linear_operator>
.. Laplace <../mod/nifty4.operators.linear_operator>
.. Sum <../mod/nifty4.operators.sum_operator>
.. Sum <../mod/nifty4.operators.sum_operator>
nifty4/library/critical_power_energy.py
View file @
e954b8bf
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
from
..minimization.energy
import
Energy
from
..minimization.energy
import
Energy
from
..operators.smoothness_operator
import
SmoothnessOperator
from
..operators.smoothness_operator
import
SmoothnessOperator
from
..operators.power_
projection_opera
tor
import
Power
ProjectionOpera
tor
from
..operators.power_
distribu
tor
import
Power
Distribu
tor
from
.critical_power_curvature
import
CriticalPowerCurvature
from
.critical_power_curvature
import
CriticalPowerCurvature
from
..utilities
import
memo
from
..utilities
import
memo
from
..
import
Field
,
exp
from
..
import
Field
,
exp
...
@@ -86,17 +86,17 @@ class CriticalPowerEnergy(Energy):
...
@@ -86,17 +86,17 @@ class CriticalPowerEnergy(Energy):
self
.
_inverter
=
inverter
self
.
_inverter
=
inverter
if
w
is
None
:
if
w
is
None
:
P
=
Power
ProjectionOperator
(
domain
=
self
.
m
.
domain
,
Dist
=
Power
Distributor
(
target
=
self
.
m
.
domain
,
power_space
=
self
.
position
.
domain
[
0
])
power_space
=
self
.
position
.
domain
[
0
])
if
self
.
D
is
not
None
:
if
self
.
D
is
not
None
:
w
=
Field
.
zeros
(
self
.
position
.
domain
,
dtype
=
self
.
m
.
dtype
)
w
=
Field
.
zeros
(
self
.
position
.
domain
,
dtype
=
self
.
m
.
dtype
)
for
i
in
range
(
self
.
samples
):
for
i
in
range
(
self
.
samples
):
sample
=
self
.
D
.
draw_sample
()
+
self
.
m
sample
=
self
.
D
.
draw_sample
()
+
self
.
m
w
+=
P
(
abs
(
sample
)
**
2
)
w
+=
Dist
.
adjoint_times
(
abs
(
sample
)
**
2
)
w
*=
1.
/
self
.
samples
w
*=
1.
/
self
.
samples
else
:
else
:
w
=
P
(
abs
(
self
.
m
)
**
2
)
w
=
Dist
.
adjoint_times
(
abs
(
self
.
m
)
**
2
)
self
.
_w
=
w
self
.
_w
=
w
self
.
_theta
=
exp
(
-
self
.
position
)
*
(
self
.
q
+
self
.
_w
*
0.5
)
self
.
_theta
=
exp
(
-
self
.
position
)
*
(
self
.
q
+
self
.
_w
*
0.5
)
...
...
nifty4/library/noise_energy.py
View file @
e954b8bf
...
@@ -25,7 +25,7 @@ from ..minimization.energy import Energy
...
@@ -25,7 +25,7 @@ from ..minimization.energy import Energy
class
NoiseEnergy
(
Energy
):
class
NoiseEnergy
(
Energy
):
def
__init__
(
self
,
position
,
d
,
xi
,
D
,
t
,
ht
,
Instrument
,
def
__init__
(
self
,
position
,
d
,
xi
,
D
,
t
,
ht
,
Instrument
,
nonlinearity
,
alpha
,
q
,
Projec
tion
,
samples
=
3
,
nonlinearity
,
alpha
,
q
,
Distribu
tion
,
samples
=
3
,
xi_sample_list
=
None
,
inverter
=
None
):
xi_sample_list
=
None
,
inverter
=
None
):
super
(
NoiseEnergy
,
self
).
__init__
(
position
=
position
)
super
(
NoiseEnergy
,
self
).
__init__
(
position
=
position
)
self
.
xi
=
xi
self
.
xi
=
xi
...
@@ -40,8 +40,8 @@ class NoiseEnergy(Energy):
...
@@ -40,8 +40,8 @@ class NoiseEnergy(Energy):
self
.
alpha
=
alpha
self
.
alpha
=
alpha
self
.
q
=
q
self
.
q
=
q
self
.
Projection
=
Projec
tion
self
.
Distribution
=
Distribu
tion
self
.
power
=
self
.
Projection
.
adjoint_times
(
exp
(
0.5
*
self
.
t
))
self
.
power
=
self
.
Distribution
(
exp
(
0.5
*
self
.
t
))
if
xi_sample_list
is
None
:
if
xi_sample_list
is
None
:
if
samples
is
None
or
samples
==
0
:
if
samples
is
None
or
samples
==
0
:
xi_sample_list
=
[
xi
]
xi_sample_list
=
[
xi
]
...
@@ -51,7 +51,7 @@ class NoiseEnergy(Energy):
...
@@ -51,7 +51,7 @@ class NoiseEnergy(Energy):
self
.
xi_sample_list
=
xi_sample_list
self
.
xi_sample_list
=
xi_sample_list
self
.
inverter
=
inverter
self
.
inverter
=
inverter
A
=
Projection
.
adjoint_times
(
exp
(.
5
*
self
.
t
))
A
=
Distribution
(
exp
(.
5
*
self
.
t
))
self
.
_gradient
=
None
self
.
_gradient
=
None
for
sample
in
self
.
xi_sample_list
:
for
sample
in
self
.
xi_sample_list
:
...
@@ -81,7 +81,7 @@ class NoiseEnergy(Energy):
...
@@ -81,7 +81,7 @@ class NoiseEnergy(Energy):
return
self
.
__class__
(
return
self
.
__class__
(
position
,
self
.
d
,
self
.
xi
,
self
.
D
,
self
.
t
,
self
.
ht
,
position
,
self
.
d
,
self
.
xi
,
self
.
D
,
self
.
t
,
self
.
ht
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
alpha
,
self
.
q
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
alpha
,
self
.
q
,
self
.
Projec
tion
,
xi_sample_list
=
self
.
xi_sample_list
,
self
.
Distribu
tion
,
xi_sample_list
=
self
.
xi_sample_list
,
samples
=
self
.
samples
,
inverter
=
self
.
inverter
)
samples
=
self
.
samples
,
inverter
=
self
.
inverter
)
@
property
@
property
...
...
nifty4/library/nonlinear_power_energy.py
View file @
e954b8bf
...
@@ -52,7 +52,7 @@ class NonlinearPowerEnergy(Energy):
...
@@ -52,7 +52,7 @@ class NonlinearPowerEnergy(Energy):
"""
"""
def
__init__
(
self
,
position
,
d
,
N
,
xi
,
D
,
ht
,
Instrument
,
nonlinearity
,
def
__init__
(
self
,
position
,
d
,
N
,
xi
,
D
,
ht
,
Instrument
,
nonlinearity
,
Projec
tion
,
sigma
=
0.
,
samples
=
3
,
xi_sample_list
=
None
,
Distribu
tion
,
sigma
=
0.
,
samples
=
3
,
xi_sample_list
=
None
,
inverter
=
None
):
inverter
=
None
):
super
(
NonlinearPowerEnergy
,
self
).
__init__
(
position
)
super
(
NonlinearPowerEnergy
,
self
).
__init__
(
position
)
self
.
xi
=
xi
self
.
xi
=
xi
...
@@ -64,7 +64,7 @@ class NonlinearPowerEnergy(Energy):
...
@@ -64,7 +64,7 @@ class NonlinearPowerEnergy(Energy):
self
.
ht
=
ht
self
.
ht
=
ht
self
.
Instrument
=
Instrument
self
.
Instrument
=
Instrument
self
.
nonlinearity
=
nonlinearity
self
.
nonlinearity
=
nonlinearity
self
.
Projection
=
Projec
tion
self
.
Distribution
=
Distribu
tion
self
.
sigma
=
sigma
self
.
sigma
=
sigma
if
xi_sample_list
is
None
:
if
xi_sample_list
is
None
:
if
samples
is
None
or
samples
==
0
:
if
samples
is
None
or
samples
==
0
:
...
@@ -75,7 +75,7 @@ class NonlinearPowerEnergy(Energy):
...
@@ -75,7 +75,7 @@ class NonlinearPowerEnergy(Energy):
self
.
xi_sample_list
=
xi_sample_list
self
.
xi_sample_list
=
xi_sample_list
self
.
inverter
=
inverter
self
.
inverter
=
inverter
A
=
Projection
.
adjoint_times
(
exp
(.
5
*
position
))
A
=
Distribution
(
exp
(.
5
*
position
))
map_s
=
self
.
ht
(
A
*
xi
)
map_s
=
self
.
ht
(
A
*
xi
)
Tpos
=
self
.
T
(
position
)
Tpos
=
self
.
T
(
position
)
...
@@ -83,7 +83,7 @@ class NonlinearPowerEnergy(Energy):
...
@@ -83,7 +83,7 @@ class NonlinearPowerEnergy(Energy):
for
xi_sample
in
self
.
xi_sample_list
:
for
xi_sample
in
self
.
xi_sample_list
:
map_s
=
self
.
ht
(
A
*
xi_sample
)
map_s
=
self
.
ht
(
A
*
xi_sample
)
LinR
=
LinearizedPowerResponse
(
LinR
=
LinearizedPowerResponse
(
self
.
Instrument
,
self
.
nonlinearity
,
self
.
ht
,
self
.
Projec
tion
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
ht
,
self
.
Distribu
tion
,
self
.
position
,
xi_sample
)
self
.
position
,
xi_sample
)
residual
=
self
.
d
-
\
residual
=
self
.
d
-
\
...
@@ -106,7 +106,7 @@ class NonlinearPowerEnergy(Energy):
...
@@ -106,7 +106,7 @@ class NonlinearPowerEnergy(Energy):
def
at
(
self
,
position
):
def
at
(
self
,
position
):
return
self
.
__class__
(
position
,
self
.
d
,
self
.
N
,
self
.
xi
,
self
.
D
,
return
self
.
__class__
(
position
,
self
.
d
,
self
.
N
,
self
.
xi
,
self
.
D
,
self
.
ht
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
ht
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
Projec
tion
,
sigma
=
self
.
sigma
,
self
.
Distribu
tion
,
sigma
=
self
.
sigma
,
samples
=
len
(
self
.
xi_sample_list
),
samples
=
len
(
self
.
xi_sample_list
),
xi_sample_list
=
self
.
xi_sample_list
,
xi_sample_list
=
self
.
xi_sample_list
,
inverter
=
self
.
inverter
)
inverter
=
self
.
inverter
)
...
@@ -124,5 +124,5 @@ class NonlinearPowerEnergy(Energy):
...
@@ -124,5 +124,5 @@ class NonlinearPowerEnergy(Energy):
def
curvature
(
self
):
def
curvature
(
self
):
return
NonlinearPowerCurvature
(
return
NonlinearPowerCurvature
(
self
.
position
,
self
.
ht
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
position
,
self
.
ht
,
self
.
Instrument
,
self
.
nonlinearity
,
self
.
Projec
tion
,
self
.
N
,
self
.
T
,
self
.
xi_sample_list
,
self
.
Distribu
tion
,
self
.
N
,
self
.
T
,
self
.
xi_sample_list
,
self
.
inverter
)
self
.
inverter
)
nifty4/library/response_operators.py
View file @
e954b8bf
...
@@ -23,8 +23,9 @@ def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m):
...
@@ -23,8 +23,9 @@ def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m):
return
Instrument
*
nonlinearity
.
derivative
(
m
)
*
ht
*
power
return
Instrument
*
nonlinearity
.
derivative
(
m
)
*
ht
*
power
def
LinearizedPowerResponse
(
Instrument
,
nonlinearity
,
ht
,
Projection
,
tau
,
xi
):
def
LinearizedPowerResponse
(
Instrument
,
nonlinearity
,
ht
,
Distribution
,
tau
,
xi
):
power
=
exp
(
0.5
*
tau
)
power
=
exp
(
0.5
*
tau
)
position
=
ht
(
Projection
.
adjoint_times
(
power
)
*
xi
)
position
=
ht
(
Distribution
(
power
)
*
xi
)
linearization
=
nonlinearity
.
derivative
(
position
)
linearization
=
nonlinearity
.
derivative
(
position
)
return
0.5
*
Instrument
*
linearization
*
ht
*
xi
*
Projection
.
adjoint
*
power
return
0.5
*
Instrument
*
linearization
*
ht
*
xi
*
Distribution
*
power
nifty4/operators/__init__.py
View file @
e954b8bf
...
@@ -7,10 +7,10 @@ from .fft_operator import FFTOperator
...
@@ -7,10 +7,10 @@ from .fft_operator import FFTOperator
from
.fft_smoothing_operator
import
FFTSmoothingOperator
from
.fft_smoothing_operator
import
FFTSmoothingOperator
from
.geometry_remover
import
GeometryRemover
from
.geometry_remover
import
GeometryRemover
from
.laplace_operator
import
LaplaceOperator
from
.laplace_operator
import
LaplaceOperator
from
.power_
projection_opera
tor
import
Power
ProjectionOpera
tor
from
.power_
distribu
tor
import
Power
Distribu
tor
from
.inversion_enabler
import
InversionEnabler
from
.inversion_enabler
import
InversionEnabler
__all__
=
[
"LinearOperator"
,
"EndomorphicOperator"
,
"ScalingOperator"
,
__all__
=
[
"LinearOperator"
,
"EndomorphicOperator"
,
"ScalingOperator"
,
"DiagonalOperator"
,
"HarmonicTransformOperator"
,
"FFTOperator"
,
"DiagonalOperator"
,
"HarmonicTransformOperator"
,
"FFTOperator"
,
"FFTSmoothingOperator"
,
"GeometryRemover"
,
"FFTSmoothingOperator"
,
"GeometryRemover"
,
"LaplaceOperator"
,
"Power
ProjectionOpera
tor"
,
"InversionEnabler"
]
"LaplaceOperator"
,
"Power
Distribu
tor"
,
"InversionEnabler"
]
nifty4/operators/dof_
projection_opera
tor.py
→
nifty4/operators/dof_
distribu
tor.py
View file @
e954b8bf
...
@@ -25,15 +25,15 @@ from .. import dobj
...
@@ -25,15 +25,15 @@ from .. import dobj
from
..domains.dof_space
import
DOFSpace
from
..domains.dof_space
import
DOFSpace
class
DOF
ProjectionOpera
tor
(
LinearOperator
):
class
DOF
Distribu
tor
(
LinearOperator
):
def
__init__
(
self
,
dofdex
,
domain
=
None
,
space
=
None
):
def
__init__
(
self
,
dofdex
,
target
=
None
,
space
=
None
):
super
(
DOF
ProjectionOpera
tor
,
self
).
__init__
()
super
(
DOF
Distribu
tor
,
self
).
__init__
()
if
domain
is
None
:
if
target
is
None
:
domain
=
dofdex
.
domain
target
=
dofdex
.
domain
self
.
_
domain
=
DomainTuple
.
make
(
domain
)
self
.
_
target
=
DomainTuple
.
make
(
target
)
space
=
infer_space
(
self
.
_
domain
,
space
)
space
=
infer_space
(
self
.
_
target
,
space
)
partner
=
self
.
_
domain
[
space
]
partner
=
self
.
_
target
[
space
]
if
not
isinstance
(
dofdex
,
Field
):
if
not
isinstance
(
dofdex
,
Field
):
raise
TypeError
(
"dofdex must be a Field"
)
raise
TypeError
(
"dofdex must be a Field"
)
if
not
len
(
dofdex
.
domain
)
==
1
:
if
not
len
(
dofdex
.
domain
)
==
1
:
...
@@ -64,41 +64,41 @@ class DOFProjectionOperator(LinearOperator):
...
@@ -64,41 +64,41 @@ class DOFProjectionOperator(LinearOperator):
def
_init2
(
self
,
dofdex
,
space
,
other_space
):
def
_init2
(
self
,
dofdex
,
space
,
other_space
):
self
.
_space
=
space
self
.
_space
=
space
tgt
=
list
(
self
.
_
domain
)
dom
=
list
(
self
.
_
target
)
tgt
[
self
.
_space
]
=
other_space
dom
[
self
.
_space
]
=
other_space
self
.
_
target
=
DomainTuple
.
make
(
tgt
)
self
.
_
domain
=
DomainTuple
.
make
(
dom
)
if
dobj
.
default_distaxis
()
in
self
.
_domain
.
axes
[
self
.
_space
]:
if
dobj
.
default_distaxis
()
in
self
.
_domain
.
axes
[
self
.
_space
]:
dofdex
=
dobj
.
local_data
(
dofdex
)
dofdex
=
dobj
.
local_data
(
dofdex
)
else
:
# dofdex must be available fully on every task
else
:
# dofdex must be available fully on every task
dofdex
=
dobj
.
to_global_data
(
dofdex
)
dofdex
=
dobj
.
to_global_data
(
dofdex
)
self
.
_dofdex
=
dofdex
.
ravel
()
self
.
_dofdex
=
dofdex
.
ravel
()
firstaxis
=
self
.
_
domain
.
axes
[
self
.
_space
][
0
]
firstaxis
=
self
.
_
target
.
axes
[
self
.
_space
][
0
]
lastaxis
=
self
.
_
domain
.
axes
[
self
.
_space
][
-
1
]
lastaxis
=
self
.
_
target
.
axes
[
self
.
_space
][
-
1
]
arrshape
=
dobj
.
local_shape
(
self
.
_
domain
.
shape
,
0
)
arrshape
=
dobj
.
local_shape
(
self
.
_
target
.
shape
,
0
)
presize
=
np
.
prod
(
arrshape
[
0
:
firstaxis
],
dtype
=
np
.
int
)
presize
=
np
.
prod
(
arrshape
[
0
:
firstaxis
],
dtype
=
np
.
int
)
postsize
=
np
.
prod
(
arrshape
[
lastaxis
+
1
:],
dtype
=
np
.
int
)
postsize
=
np
.
prod
(
arrshape
[
lastaxis
+
1
:],
dtype
=
np
.
int
)
self
.
_hshape
=
(
presize
,
self
.
_
target
[
self
.
_space
].
shape
[
0
],
postsize
)
self
.
_hshape
=
(
presize
,
self
.
_
domain
[
self
.
_space
].
shape
[
0
],
postsize
)
self
.
_pshape
=
(
presize
,
self
.
_dofdex
.
size
,
postsize
)
self
.
_pshape
=
(
presize
,
self
.
_dofdex
.
size
,
postsize
)
def
_times
(
self
,
x
):
def
_adjoint
_times
(
self
,
x
):
arr
=
dobj
.
local_data
(
x
.
val
)
arr
=
dobj
.
local_data
(
x
.
val
)
arr
=
arr
.
reshape
(
self
.
_pshape
)
arr
=
arr
.
reshape
(
self
.
_pshape
)
oarr
=
np
.
zeros
(
self
.
_hshape
,
dtype
=
x
.
dtype
)
oarr
=
np
.
zeros
(
self
.
_hshape
,
dtype
=
x
.
dtype
)
np
.
add
.
at
(
oarr
,
(
slice
(
None
),
self
.
_dofdex
,
slice
(
None
)),
arr
)
np
.
add
.
at
(
oarr
,
(
slice
(
None
),
self
.
_dofdex
,
slice
(
None
)),
arr
)
if
dobj
.
distaxis
(
x
.
val
)
in
x
.
domain
.
axes
[
self
.
_space
]:
if
dobj
.
distaxis
(
x
.
val
)
in
x
.
domain
.
axes
[
self
.
_space
]:
oarr
=
dobj
.
np_allreduce_sum
(
oarr
).
reshape
(
self
.
_
target
.
shape
)
oarr
=
dobj
.
np_allreduce_sum
(
oarr
).
reshape
(
self
.
_
domain
.
shape
)
res
=
Field
(
self
.
_
target
,
dobj
.
from_global_data
(
oarr
))
res
=
Field
(
self
.
_
domain
,
dobj
.
from_global_data
(
oarr
))
else
:
else
:
oarr
=
oarr
.
reshape
(
dobj
.
local_shape
(
self
.
_
target
.
shape
,
oarr
=
oarr
.
reshape
(
dobj
.
local_shape
(
self
.
_
domain
.
shape
,
dobj
.
distaxis
(
x
.
val
)))
dobj
.
distaxis
(
x
.
val
)))
res
=
Field
(
self
.
_
target
,
res
=
Field
(
self
.
_
domain
,
dobj
.
from_local_data
(
self
.
_
target
.
shape
,
oarr
,
dobj
.
from_local_data
(
self
.
_
domain
.
shape
,
oarr
,
dobj
.
default_distaxis
()))
dobj
.
default_distaxis
()))
return
res
return
res
def
_adjoint
_times
(
self
,
x
):
def
_times
(
self
,
x
):
res
=
Field
.
empty
(
self
.
_
domain
,
dtype
=
x
.
dtype
)
res
=
Field
.
empty
(
self
.
_
target
,
dtype
=
x
.
dtype
)
if
dobj
.
distaxis
(
x
.
val
)
in
x
.
domain
.
axes
[
self
.
_space
]:
if
dobj
.
distaxis
(
x
.
val
)
in
x
.
domain
.
axes
[
self
.
_space
]:
arr
=
dobj
.
to_global_data
(
x
.
val
)
arr
=
dobj
.
to_global_data
(
x
.
val
)
else
:
else
:
...
...
nifty4/operators/power_
projection_opera
tor.py
→
nifty4/operators/power_
distribu
tor.py
View file @
e954b8bf
...
@@ -16,20 +16,20 @@
...
@@ -16,20 +16,20 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
# and financially supported by the Studienstiftung des deutschen Volkes.
from
.dof_
projection_operator
import
DOFProjectionOpera
tor
from
.dof_
distributor
import
DOFDistribu
tor
from
..domain_tuple
import
DomainTuple
from
..domain_tuple
import
DomainTuple
from
..utilities
import
infer_space
from
..utilities
import
infer_space
from
..domains.power_space
import
PowerSpace
from
..domains.power_space
import
PowerSpace
class
Power
ProjectionOperator
(
DOFProjectionOpera
tor
):
class
Power
Distributor
(
DOFDistribu
tor
):
def
__init__
(
self
,
domain
,
power_space
=
None
,
space
=
None
):
def
__init__
(
self
,
target
,
power_space
=
None
,
space
=
None
):
# Initialize domain and target
# Initialize domain and target
self
.
_
domain
=
DomainTuple
.
make
(
domain
)
self
.
_
target
=
DomainTuple
.
make
(
target
)
self
.
_space
=
infer_space
(
self
.
_
domain
,
space
)
self
.
_space
=
infer_space
(
self
.
_
target
,
space
)
hspace
=
self
.
_
domain
[
self
.
_space
]
hspace
=
self
.
_
target
[
self
.
_space
]
if
not
hspace
.
harmonic
:
if
not
hspace
.
harmonic
:
raise
ValueError
(
"Operator
acts on
harmonic
spaces only
"
)
raise
ValueError
(
"Operator
requires
harmonic
target space
"
)
if
power_space
is
None
:
if
power_space
is
None
:
power_space
=
PowerSpace
(
hspace
)
power_space
=
PowerSpace
(
hspace
)
else
:
else
:
...
...
nifty4/sugar.py
View file @
e954b8bf
...
@@ -21,7 +21,7 @@ from .domains.structured_domain import StructuredDomain
...
@@ -21,7 +21,7 @@ from .domains.structured_domain import StructuredDomain
from
.domains.power_space
import
PowerSpace
from
.domains.power_space
import
PowerSpace
from
.field
import
Field
,
sqrt
from
.field
import
Field
,
sqrt
from
.operators.diagonal_operator
import
DiagonalOperator
from
.operators.diagonal_operator
import
DiagonalOperator
from
.operators.power_
projection_opera
tor
import
Power
ProjectionOpera
tor
from
.operators.power_
distribu
tor
import
Power
Distribu
tor
from
.operators.harmonic_transform_operator
import
HarmonicTransformOperator
from
.operators.harmonic_transform_operator
import
HarmonicTransformOperator
from
.domain_tuple
import
DomainTuple
from
.domain_tuple
import
DomainTuple
from
.
import
dobj
,
utilities
from
.
import
dobj
,
utilities
...
@@ -45,8 +45,8 @@ def PS_field(pspace, func, dtype=None):
...
@@ -45,8 +45,8 @@ def PS_field(pspace, func, dtype=None):
def
_single_power_analyze
(
field
,
idx
,
binbounds
):
def
_single_power_analyze
(
field
,
idx
,
binbounds
):
power_domain
=
PowerSpace
(
field
.
domain
[
idx
],
binbounds
)
power_domain
=
PowerSpace
(
field
.
domain
[
idx
],
binbounds
)
p
po
=
Power
ProjectionOpera
tor
(
field
.
domain
,
power_domain
,
idx
)
p
d
=
Power
Distribu
tor
(
field
.
domain
,
power_domain
,
idx
)
return
p
po
(
field
.
weight
(
1
)).
weight
(
-
1
)
# divides by bin size
return
p
d
.
adjoint_times
(
field
.
weight
(
1
)).
weight
(
-
1
)
# divides by bin size
def
power_analyze
(
field
,
spaces
=
None
,
binbounds
=
None
,
def
power_analyze
(
field
,
spaces
=
None
,
binbounds
=
None
,
...
@@ -125,8 +125,8 @@ def power_synthesize_nonrandom(field, spaces=None):
...
@@ -125,8 +125,8 @@ def power_synthesize_nonrandom(field, spaces=None):
spec
=
sqrt
(
field
)
spec
=
sqrt
(
field
)
for
i
in
spaces
:
for
i
in
spaces
:
result_domain
[
i
]
=
field
.
domain
[
i
].
harmonic_partner
result_domain
[
i
]
=
field
.
domain
[
i
].
harmonic_partner
p
po
=
Power
ProjectionOpera
tor
(
result_domain
,
field
.
domain
[
i
],
i
)
p
d
=
Power
Distribu
tor
(
result_domain
,
field
.
domain
[
i
],
i
)
spec
=
p
po
.
adjoint_times
(
spec
)
spec
=
p
d
(
spec
)
return
spec
return
spec
...
@@ -203,7 +203,7 @@ def create_power_field(domain, power_spectrum, dtype=None):
...
@@ -203,7 +203,7 @@ def create_power_field(domain, power_spectrum, dtype=None):
power_domain
=
PowerSpace
(
domain
)
power_domain
=
PowerSpace
(
domain
)
fp
=
PS_field
(
power_domain
,
power_spectrum
,
dtype
)
fp
=
PS_field
(
power_domain
,
power_spectrum
,
dtype
)
return
Power
ProjectionOpera
tor
(
domain
,
power_domain
)
.
adjoint_times
(
fp
)
return
Power
Distribu
tor
(
domain
,
power_domain
)(
fp
)
def
create_power_operator
(
domain
,
power_spectrum
,
space
=
None
,
dtype
=
None
):
def
create_power_operator
(
domain
,
power_spectrum
,
space
=
None
,
dtype
=
None
):
...
...
test/test_energies/test_map.py
View file @
e954b8bf
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Copyright(C) 2013-201
7
Max-Planck-Society
# Copyright(C) 2013-201
8
Max-Planck-Society
#
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
# and financially supported by the Studienstiftung des deutschen Volkes.
...
@@ -39,12 +39,12 @@ class Energy_Tests(unittest.TestCase):
...
@@ -39,12 +39,12 @@ class Energy_Tests(unittest.TestCase):
ht
=
ift
.
HarmonicTransformOperator
(
hspace
,
target
=
space
)
ht
=
ift
.
HarmonicTransformOperator
(
hspace
,
target
=
space
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
hspace
,
logarithmic
=
False
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
hspace
,
logarithmic
=
False
)
pspace
=
ift
.
PowerSpace
(
hspace
,
binbounds
=
binbounds
)
pspace
=
ift
.
PowerSpace
(
hspace
,
binbounds
=
binbounds
)
P
=
ift
.
Power
ProjectionOperator
(
domain
=
hspace
,
power_space
=
pspace
)
Dist
=
ift
.
Power
Distributor
(
target
=
hspace
,
power_space
=
pspace
)
xi0
=
ift
.
Field
.
from_random
(
domain
=
hspace
,
random_type
=
'normal'
)
xi0
=
ift
.
Field
.
from_random
(
domain
=
hspace
,
random_type
=
'normal'
)
def
pspec
(
k
):
return
1
/
(
1
+
k
**
2
)
**
dim
def
pspec
(
k
):
return
1
/
(
1
+
k
**
2
)
**
dim
pspec
=
ift
.
PS_field
(
pspace
,
pspec
)
pspec
=
ift
.
PS_field
(
pspace
,
pspec
)
A
=
P
.
adjoint_times
(
ift
.
sqrt
(
pspec
))
A
=
Dist
(
ift
.
sqrt
(
pspec
))
n
=
ift
.
Field
.
from_random
(
domain
=
space
,
random_type
=
'normal'
)
n
=
ift
.
Field
.
from_random
(
domain
=
space
,
random_type
=
'normal'
)
s0
=
xi0
*
A
s0
=
xi0
*
A
Instrument
=
ift
.
ScalingOperator
(
10.
,
space
)
Instrument
=
ift
.
ScalingOperator
(
10.
,
space
)
...
@@ -85,12 +85,12 @@ class Energy_Tests(unittest.TestCase):
...
@@ -85,12 +85,12 @@ class Energy_Tests(unittest.TestCase):
ht
=
ift
.
HarmonicTransformOperator
(
hspace
,
target
=
space
)
ht
=
ift
.
HarmonicTransformOperator
(
hspace
,
target
=
space
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
hspace
,
logarithmic
=
False
)
binbounds
=
ift
.
PowerSpace
.
useful_binbounds
(
hspace
,
logarithmic
=
False
)
pspace
=
ift
.
PowerSpace
(
hspace
,
binbounds
=
binbounds
)