Commit 15617c75 authored by Philipp Arras's avatar Philipp Arras
Browse files

Add GaussShiftModel and simplifications

parent 659c833c
......@@ -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
......@@ -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):
return self._std*x + self._mean
def SlopeModel(logk_space, sm, sv, im, iv):
......@@ -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,
self._domain = self._slope.domain
self._target =
def apply(self, x):
return self._slope(x + self._norm_phi_mean)
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,
self._op = et((fac(smooth(fa_smooth) + linear(fa_linear))).exp())
self._domain, self._target = self._op.domain,
def apply(self, x):
return self._op(x)
def norm_phi_mean(self):
return self._norm_phi_mean
return et((fac(smooth(fa_smooth) + linear(fa_linear))).exp())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment