Commit 94782c75 authored by Pumpe, Daniel (dpumpe)'s avatar Pumpe, Daniel (dpumpe)

Merge branch 'master' of gitlab.mpcdf.mpg.de:ift/NIFTy

parents 58ca8d1a 846cc966
...@@ -117,13 +117,13 @@ if __name__ == "__main__": ...@@ -117,13 +117,13 @@ if __name__ == "__main__":
# Solving the problem analytically # Solving the problem analytically
m0 = D0.inverse_times(j) m0 = D0.inverse_times(j)
sample_variance = Field(sh.domain, val=0. + 0j) sample_variance = Field(sh.domain, val=0.)
sample_mean = Field(sh.domain, val=0. + 0j) sample_mean = Field(sh.domain, val=0.)
# sampling the uncertainty map # sampling the uncertainty map
n_samples = 1 n_samples = 10
for i in range(n_samples): for i in range(n_samples):
sample = sugar.generate_posterior_sample(m0, D0) sample = fft(sugar.generate_posterior_sample(0., D0))
sample_variance += sample**2 sample_variance += sample**2
sample_mean += sample sample_mean += sample
variance = sample_variance/n_samples - (sample_mean/n_samples) variance = (sample_variance - sample_mean**2)/n_samples
...@@ -24,7 +24,7 @@ from .field import Field ...@@ -24,7 +24,7 @@ from .field import Field
__all__ = ['cos', 'sin', 'cosh', 'sinh', 'tan', 'tanh', 'arccos', 'arcsin', __all__ = ['cos', 'sin', 'cosh', 'sinh', 'tan', 'tanh', 'arccos', 'arcsin',
'arccosh', 'arcsinh', 'arctan', 'arctanh', 'sqrt', 'exp', 'log', 'arccosh', 'arcsinh', 'arctan', 'arctanh', 'sqrt', 'exp', 'log',
'conjugate', 'clipped_exp', 'limited_exp'] 'conjugate', 'clipped_exp', 'limited_exp', 'limited_exp_deriv']
def _math_helper(x, function): def _math_helper(x, function):
...@@ -101,15 +101,28 @@ def clipped_exp(x): ...@@ -101,15 +101,28 @@ def clipped_exp(x):
def limited_exp(x): def limited_exp(x):
thr = 200 return _math_helper(x, _limited_exp_helper)
expthr = np.exp(thr)
return _math_helper(x, lambda z: _limited_exp_helper(z, thr, expthr)) def _limited_exp_helper(x):
thr = 200.
mask = x>thr
if np.count_nonzero(mask) == 0:
return np.exp(x)
result = ((1.-thr) + x)*np.exp(thr)
result[~mask] = np.exp(x[~mask])
return result
def _limited_exp_helper(x, thr, expthr): def limited_exp_deriv(x):
mask = (x > thr) return _math_helper(x, _limited_exp_deriv_helper)
result = np.exp(x)
result[mask] = ((1-thr) + x[mask])*expthr def _limited_exp_deriv_helper(x):
thr = 200.
mask = x>thr
if np.count_nonzero(mask) == 0:
return np.exp(x)
result = np.empty_like(x)
result[mask] = np.exp(thr)
result[~mask] = np.exp(x[~mask])
return result return result
......
...@@ -330,7 +330,7 @@ class Field(Loggable, Versionable, object): ...@@ -330,7 +330,7 @@ class Field(Loggable, Versionable, object):
Returns Returns
------- -------
out : Field out : Field
The output object. It's domain is a PowerSpace and it contains The output object. Its domain is a PowerSpace and it contains
the power spectrum of 'self's field. the power spectrum of 'self's field.
See Also See Also
......
...@@ -28,7 +28,7 @@ class LineSearch(with_metaclass(abc.ABCMeta, type('NewBase', (Loggable, object), ...@@ -28,7 +28,7 @@ class LineSearch(with_metaclass(abc.ABCMeta, type('NewBase', (Loggable, object),
"""Class for determining the optimal step size along some descent direction. """Class for determining the optimal step size along some descent direction.
Initialize the line search procedure which can be used by a specific line Initialize the line search procedure which can be used by a specific line
search method. Its finds the step size in a specific direction in the search method. It finds the step size in a specific direction in the
minimization process. minimization process.
Attributes Attributes
......
...@@ -108,7 +108,7 @@ def generate_posterior_sample(mean, covariance): ...@@ -108,7 +108,7 @@ def generate_posterior_sample(mean, covariance):
R = covariance.R R = covariance.R
N = covariance.N N = covariance.N
power = S.diagonal().power_analyze()**.5 power = sqrt(S.diagonal().power_analyze())
mock_signal = power.power_synthesize(real_signal=True) mock_signal = power.power_synthesize(real_signal=True)
noise = N.diagonal(bare=True) noise = N.diagonal(bare=True)
......
Markdown is supported
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