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
ift
NIFTy
Commits
1b278d87
Commit
1b278d87
authored
Jan 14, 2019
by
Philipp Arras
Browse files
Docs and AmplitudeOperator -> SLAmplitude
parent
ff8ae4c1
Changes
5
Hide whitespace changes
Inline
Side-by-side
demos/getting_started_3.py
View file @
1b278d87
...
...
@@ -65,7 +65,7 @@ if __name__ == '__main__':
'im'
:
.
4
,
# y-intercept mean
'iv'
:
.
3
# relatively high y-intercept variance
}
A
=
ift
.
Amplitude
Operator
(
**
dct
)
A
=
ift
.
SL
Amplitude
(
**
dct
)
# Build the operator for a correlated signal
power_distributor
=
ift
.
PowerDistributor
(
harmonic_space
,
power_space
)
...
...
docs/source/code.rst
View file @
1b278d87
...
...
@@ -212,7 +212,7 @@ specific inference problems. Currently these are:
.. currentmodule:: nifty5.library
- :class:`~
amplitude_operator.
Amplitude
Operator
`, which returns a smooth power spectrum.
- :class:`~
smooth_linear_amplitude.SL
Amplitude`, which returns a smooth power spectrum.
- :class:`~inverse_gamma_operator.InverseGammaOperator`, which models point sources which are
distributed according to a inverse-gamma distribution.
- :class:`~correlated_fields.CorrelatedField`, which models a diffuse log-normal field. It takes an
...
...
nifty5/__init__.py
View file @
1b278d87
...
...
@@ -73,7 +73,7 @@ from .minimization.kl_energy import KL_Energy
from
.sugar
import
*
from
.plot
import
Plot
from
.library.amplitude
_operator
import
Amplitude
Operator
from
.library.
smooth_linear_
amplitude
import
SL
Amplitude
from
.library.inverse_gamma_operator
import
InverseGammaOperator
from
.library.los_response
import
LOSResponse
from
.library.dynamic_operator
import
(
dynamic_operator
,
...
...
nifty5/library/amplitude
_operator
.py
→
nifty5/library/
smooth_linear_
amplitude.py
View file @
1b278d87
...
...
@@ -65,42 +65,18 @@ def CepstrumOperator(domain, a, k0):
return
sym
@
qht
@
makeOp
(
cepstrum
.
sqrt
())
def
SlopeOperator
(
domain
,
sm
,
sv
,
im
,
iv
):
'''
Parameters
----------
sm, sv : slope_mean = expected exponent of power law (e.g. -4),
slope_variance (default=1)
im, iv : y-intercept_mean, y-intercept_std of power_slope
'''
from
..operators.slope_operator
import
SlopeOperator
from
..operators.offset_operator
import
OffsetOperator
if
sv
<=
0
or
iv
<=
0
:
raise
ValueError
phi_mean
=
np
.
array
([
sm
,
im
+
sm
*
domain
.
t_0
[
0
]])
phi_sig
=
np
.
array
([
sv
,
iv
])
slope
=
SlopeOperator
(
domain
)
phi_mean
=
Field
.
from_global_data
(
slope
.
domain
,
phi_mean
)
phi_sig
=
Field
.
from_global_data
(
slope
.
domain
,
phi_sig
)
return
slope
(
OffsetOperator
(
phi_mean
)(
makeOp
(
phi_sig
)))
def
AmplitudeOperator
(
target
,
n_pix
,
a
,
k0
,
sm
,
sv
,
im
,
iv
,
keys
=
[
'tau'
,
'phi'
]):
'''Operator for parametrizing smooth power spectra.
def
SLAmplitude
(
target
,
n_pix
,
a
,
k0
,
sm
,
sv
,
im
,
iv
,
keys
=
[
'tau'
,
'phi'
]):
'''Operator for parametrizing smooth amplitudes (square roots of power
spectra).
The general guideline for setting up generative models in IFT is to
transform the problem into the eigenbase of the prior and formulate the
generative model in this base. This is done here for the case of a
power
spectrum
which is smooth and has a linear component (both on
generative model in this base. This is done here for the case of a
n
amplitude
which is smooth and has a linear component (both on
double-logarithmic scale).
This function assembles an :class:`Operator` which maps two a-priori white
Gaussian random fields to a smooth
power spectrum
which is composed out of
Gaussian random fields to a smooth
amplitude
which is composed out of
a linear and a smooth component.
On double-logarithmic scale, i.e. both x and y-axis on logarithmic scale,
...
...
@@ -108,7 +84,7 @@ def AmplitudeOperator(
AmplitudeOperator = 0.5*(smooth_component + linear_component)
This is then exponentiated and exponentially binned (
via a :class:`ExpTransform`
).
This is then exponentiated and exponentially binned (
in this order
).
The prior on the linear component is parametrized by four real numbers,
being expected value and prior variance on the slope and the y-intercept
...
...
@@ -128,13 +104,13 @@ def AmplitudeOperator(
k0 : float
Cutoff of smothness prior in quefrency space (see :class:`CepstrumOperator`).
sm : float
Expected exponent of power law
(see :class:`SlopeOperator`).
Expected exponent of power law
. FIXME
sv : float
Prior variance of exponent of power law
(see :class:`SlopeOperator`)
.
Prior variance of exponent of power law.
im : float
Expected y-intercept of power law
(see :class:`SlopeOperator`).
Expected y-intercept of power law
. FIXME
iv : float
Prior variance of y-intercept of power law
(see :class:`SlopeOperator`)
.
Prior variance of y-intercept of power law.
Returns
-------
...
...
@@ -144,20 +120,34 @@ def AmplitudeOperator(
smooth and a linear part.
'''
from
..operators.exp_transform
import
ExpTransform
from
..operators.slope_operator
import
SlopeOperator
from
..operators.offset_operator
import
OffsetOperator
if
not
(
isinstance
(
n_pix
,
int
)
and
isinstance
(
target
,
PowerSpace
)):
raise
TypeError
a
,
k0
=
float
(
a
),
float
(
k0
)
sm
,
sv
,
im
,
iv
=
float
(
sm
),
float
(
sv
),
float
(
im
),
float
(
iv
)
if
sv
<=
0
or
iv
<=
0
:
raise
ValueError
et
=
ExpTransform
(
target
,
n_pix
)
dom
=
et
.
domain
[
0
]
# Smooth component
dct
=
{
'a'
:
a
,
'k0'
:
k0
}
smooth
=
CepstrumOperator
(
dom
,
**
dct
).
ducktape
(
keys
[
0
])
dct
=
{
'sm'
:
sm
,
'sv'
:
sv
,
'im'
:
im
,
'iv'
:
iv
}
linear
=
SlopeOperator
(
dom
,
**
dct
).
ducktape
(
keys
[
1
])
# Linear component
phi_mean
=
np
.
array
([
sm
,
im
+
sm
*
dom
.
t_0
[
0
]])
phi_sig
=
np
.
array
([
sv
,
iv
])
slope
=
SlopeOperator
(
dom
)
phi_mean
=
Field
.
from_global_data
(
slope
.
domain
,
phi_mean
)
phi_sig
=
Field
.
from_global_data
(
slope
.
domain
,
phi_sig
)
linear
=
slope
(
OffsetOperator
(
phi_mean
)(
makeOp
(
phi_sig
))).
ducktape
(
keys
[
1
])
# Combine linear and smooth component
loglog_ampl
=
0.5
*
(
smooth
+
linear
)
return
et
((
0.5
*
(
smooth
+
linear
)).
exp
())
# Go from loglog-space to linear-linear-space
return
et
(
loglog_ampl
.
exp
())
test/test_model_gradients.py
View file @
1b278d87
...
...
@@ -92,8 +92,7 @@ def testModelLibrary(space, seed):
Npixdof
,
ceps_a
,
ceps_k
,
sm
,
sv
,
im
,
iv
=
4
,
0.5
,
2.
,
3.
,
1.5
,
1.75
,
1.3
np
.
random
.
seed
(
seed
)
domain
=
ift
.
PowerSpace
(
space
.
get_default_codomain
())
model
=
ift
.
AmplitudeOperator
(
domain
,
Npixdof
,
ceps_a
,
ceps_k
,
sm
,
sv
,
im
,
iv
)
model
=
ift
.
SLAmplitude
(
domain
,
Npixdof
,
ceps_a
,
ceps_k
,
sm
,
sv
,
im
,
iv
)
assert_
(
isinstance
(
model
,
ift
.
Operator
))
S
=
ift
.
ScalingOperator
(
1.
,
model
.
domain
)
pos
=
S
.
draw_sample
()
...
...
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