Skip to content
GitLab
Menu
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
15617c75
Commit
15617c75
authored
Oct 05, 2018
by
Philipp Arras
Browse files
Add GaussShiftModel and simplifications
parent
659c833c
Changes
2
Show whitespace changes
Inline
Side-by-side
nifty5/__init__.py
View file @
15617c75
...
...
@@ -74,7 +74,7 @@ from .minimization.kl_energy import KL_Energy
from
.sugar
import
*
from
.plot
import
Plot
from
.library.amplitude_model
import
AmplitudeModel
from
.library.amplitude_model
import
AmplitudeModel
,
GaussShiftModel
from
.library.inverse_gamma_model
import
InverseGammaModel
from
.library.los_response
import
LOSResponse
...
...
nifty5/library/amplitude_model.py
View file @
15617c75
...
...
@@ -86,7 +86,23 @@ def CepstrumModel(logk_space, ceps_a, ceps_k):
return
sym
(
qht
(
makeOp
(
sqrt
(
cepstrum
))))
class
SlopeModel
(
Operator
):
class
GaussShiftModel
(
Operator
):
# FIXME Remove this operator as soon as operators support addition with
# constant fields
def
__init__
(
self
,
mean
,
std
):
dom
=
mean
.
domain
dom1
=
std
.
domain
if
not
dom
==
dom1
:
raise
TypeError
(
'mean and std need to have the same domain.'
)
self
.
_domain
=
self
.
_target
=
dom
self
.
_mean
,
self
.
_std
=
mean
,
std
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
return
self
.
_std
*
x
+
self
.
_mean
def
SlopeModel
(
logk_space
,
sm
,
sv
,
im
,
iv
):
'''
Parameters
----------
...
...
@@ -94,34 +110,20 @@ class SlopeModel(Operator):
sm, sv : slope_mean = expected exponent of power law (e.g. -4),
slope_variance (default=1)
im, iv : y-intercept_mean, y-intercept_
variance
of power_slope
im, iv : y-intercept_mean, y-intercept_
std
of power_slope
'''
def
__init__
(
self
,
logk_space
,
sm
,
sv
,
im
,
iv
):
from
..operators.slope_operator
import
SlopeOperator
phi_mean
=
np
.
array
([
sm
,
im
+
sm
*
logk_space
.
t_0
[
0
]])
phi_sig
=
np
.
array
([
sv
,
iv
])
slope
=
SlopeOperator
(
logk_space
)
phi_mean
=
Field
.
from_global_data
(
slope
.
domain
,
phi_mean
)
phi_sig
=
Field
.
from_global_data
(
slope
.
domain
,
phi_sig
)
gaussshift
=
GaussShiftModel
(
phi_mean
,
phi_sig
)
return
slope
(
gaussshift
)
self
.
_slope
=
SlopeOperator
(
logk_space
)
self
.
_slope
=
self
.
_slope
(
makeOp
(
Field
.
from_global_data
(
self
.
_slope
.
domain
,
phi_sig
)))
self
.
_norm_phi_mean
=
Field
.
from_global_data
(
self
.
_slope
.
domain
,
phi_mean
/
phi_sig
)
self
.
_domain
=
self
.
_slope
.
domain
self
.
_target
=
self
.
_slope
.
target
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
return
self
.
_slope
(
x
+
self
.
_norm_phi_mean
)
@
property
def
norm_phi_mean
(
self
):
return
self
.
_norm_phi_mean
class
AmplitudeModel
(
Operator
):
def
AmplitudeModel
(
s_space
,
Npixdof
,
ceps_a
,
ceps_k
,
sm
,
sv
,
im
,
iv
,
keys
=
[
'tau'
,
'phi'
]):
'''
Computes a smooth power spectrum.
Output lives in PowerSpace.
...
...
@@ -140,7 +142,7 @@ class AmplitudeModel(Operator):
im, iv : y-intercept_mean, y-intercept_variance of power_slope
'''
def
__init__
(
self
,
s_space
,
Npixdof
,
ceps_a
,
ceps_k
,
sm
,
sv
,
im
,
iv
,
keys
=
[
'tau'
,
'phi'
]):
from
..operators.exp_transform
import
ExpTransform
from
..operators.simple_linear_operators
import
FieldAdapter
from
..operators.scaling_operator
import
ScalingOperator
...
...
@@ -152,20 +154,8 @@ class AmplitudeModel(Operator):
smooth
=
CepstrumModel
(
logk_space
,
ceps_a
,
ceps_k
)
linear
=
SlopeModel
(
logk_space
,
sm
,
sv
,
im
,
iv
)
self
.
_qht
,
self
.
_ceps
=
smooth
.
qht
,
smooth
.
ceps
self
.
_norm_phi_mean
=
linear
.
norm_phi_mean
fa_smooth
=
FieldAdapter
(
smooth
.
domain
,
keys
[
0
])
fa_linear
=
FieldAdapter
(
linear
.
domain
,
keys
[
1
])
fac
=
ScalingOperator
(
0.5
,
smooth
.
target
)
self
.
_op
=
et
((
fac
(
smooth
(
fa_smooth
)
+
linear
(
fa_linear
))).
exp
())
self
.
_domain
,
self
.
_target
=
self
.
_op
.
domain
,
self
.
_op
.
target
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
return
self
.
_op
(
x
)
@
property
def
norm_phi_mean
(
self
):
return
self
.
_norm_phi_mean
return
et
((
fac
(
smooth
(
fa_smooth
)
+
linear
(
fa_linear
))).
exp
())
Write
Preview
Supports
Markdown
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