Commit 92a79911 authored by Philipp Arras's avatar Philipp Arras

Formatting

parent 76130897
Pipeline #65155 passed with stages
in 8 minutes and 31 seconds
......@@ -206,8 +206,7 @@ class _Normalization(Operator):
mode_multiplicity = pd.adjoint(full(pd.target, 1.)).val_rw()
zero_mode = (slice(None),)*self._domain.axes[space][0] + (0,)
mode_multiplicity[zero_mode] = 0
self._mode_multiplicity = makeField(self._domain,
mode_multiplicity)
self._mode_multiplicity = makeField(self._domain, mode_multiplicity)
self._specsum = _SpecialSum(self._domain, space)
def apply(self, x):
......@@ -299,14 +298,15 @@ class _Amplitude(Operator):
shift = DiagonalOperator(makeField(dom[space], foo), dom, space)
vslope = DiagonalOperator(
makeField(target[space],
_relative_log_k_lengths(target[space])),
makeField(target[space], _relative_log_k_lengths(target[space])),
target, space)
foo, bar = [np.zeros(target[space].shape) for _ in range(2)]
bar[1:] = foo[0] = totvol
vol0, vol1 = [DiagonalOperator(makeField(target[space], aa),
target, space) for aa in (foo, bar)]
vol0, vol1 = [
DiagonalOperator(makeField(target[space], aa), target, space)
for aa in (foo, bar)
]
# Prepare fields for Adder
shift, vol0 = [op(full(op.domain, 1)) for op in (shift, vol0)]
......@@ -413,13 +413,11 @@ class CorrelatedFieldMaker:
self._prefix + prefix + 'flexibility',
N)
asp = _LognormalMomentMatching(asperity_mean, asperity_stddev,
self._prefix + prefix + 'asperity',
N)
self._prefix + prefix + 'asperity', N)
avgsl = _normal(loglogavgslope_mean, loglogavgslope_stddev,
self._prefix + prefix + 'loglogavgslope', N)
amp = _Amplitude(PowerSpace(harmonic_partner),
fluct, flex, asp, avgsl, self._azm,
position_space[-1].total_volume,
amp = _Amplitude(PowerSpace(harmonic_partner), fluct, flex, asp, avgsl,
self._azm, position_space[-1].total_volume,
self._prefix + prefix + 'spectrum', dofdex)
if index is not None:
......
......@@ -16,55 +16,56 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import pytest
from numpy.testing import assert_allclose
from numpy.random import seed
from numpy.testing import assert_allclose
import nifty6 as ift
@pytest.mark.parametrize('sspace', [
ift.RGSpace(4),
ift.RGSpace((4, 4), (0.123,0.4)),
ift.RGSpace((4, 4), (0.123, 0.4)),
ift.HPSpace(8),
ift.GLSpace(4)
])
@pytest.mark.parametrize('rseed', [13, 2])
@pytest.mark.parametrize('Astds', [[1.,3.],[0.2,1.4]])
@pytest.mark.parametrize('offset_std', [1.,10.])
@pytest.mark.parametrize('Astds', [[1., 3.], [0.2, 1.4]])
@pytest.mark.parametrize('offset_std', [1., 10.])
def testAmplitudesConsistency(rseed, sspace, Astds, offset_std):
def stats(op,samples):
def stats(op, samples):
sc = ift.StatCalculator()
for s in samples:
sc.add(op(s.extract(op.domain)))
return sc.mean.val, sc.var.sqrt().val
seed(rseed)
nsam = 100
fsspace = ift.RGSpace((12,), (0.4,))
fa = ift.CorrelatedFieldMaker.make(offset_std, 1E-8, '')
fa.add_fluctuations(sspace, Astds[0], 1E-8, 1.1, 2., 2.1, .5,
-2, 1., 'spatial')
fa.add_fluctuations(fsspace, Astds[1], 1E-8, 3.1, 1., .5, .1,
-4, 1., 'freq')
fa.add_fluctuations(sspace, Astds[0], 1E-8, 1.1, 2., 2.1, .5, -2, 1.,
'spatial')
fa.add_fluctuations(fsspace, Astds[1], 1E-8, 3.1, 1., .5, .1, -4, 1.,
'freq')
op = fa.finalize()
samples = [ift.from_random('normal',op.domain) for _ in range(nsam)]
tot_flm, _ = stats(fa.total_fluctuation,samples)
offset_std,_ = stats(fa.amplitude_total_offset,samples)
intergated_fluct_std0,_ = stats(fa.average_fluctuation(0),samples)
intergated_fluct_std1,_ = stats(fa.average_fluctuation(1),samples)
samples = [ift.from_random('normal', op.domain) for _ in range(nsam)]
tot_flm, _ = stats(fa.total_fluctuation, samples)
offset_std, _ = stats(fa.amplitude_total_offset, samples)
intergated_fluct_std0, _ = stats(fa.average_fluctuation(0), samples)
intergated_fluct_std1, _ = stats(fa.average_fluctuation(1), samples)
slice_fluct_std0,_ = stats(fa.slice_fluctuation(0),samples)
slice_fluct_std1,_ = stats(fa.slice_fluctuation(1),samples)
slice_fluct_std0, _ = stats(fa.slice_fluctuation(0), samples)
slice_fluct_std1, _ = stats(fa.slice_fluctuation(1), samples)
sams = [op(s) for s in samples]
fluct_total = fa.total_fluctuation_realized(sams)
fluct_space = fa.average_fluctuation_realized(sams,0)
fluct_freq = fa.average_fluctuation_realized(sams,1)
fluct_space = fa.average_fluctuation_realized(sams, 0)
fluct_freq = fa.average_fluctuation_realized(sams, 1)
zm_std_mean = fa.offset_amplitude_realized(sams)
sl_fluct_space = fa.slice_fluctuation_realized(sams,0)
sl_fluct_freq = fa.slice_fluctuation_realized(sams,1)
sl_fluct_space = fa.slice_fluctuation_realized(sams, 0)
sl_fluct_freq = fa.slice_fluctuation_realized(sams, 1)
assert_allclose(offset_std, zm_std_mean, rtol=0.5)
assert_allclose(intergated_fluct_std0, fluct_space, rtol=0.5)
......@@ -74,14 +75,12 @@ def testAmplitudesConsistency(rseed, sspace, Astds, offset_std):
assert_allclose(slice_fluct_std1, sl_fluct_freq, rtol=0.5)
fa = ift.CorrelatedFieldMaker.make(offset_std, .1, '')
fa.add_fluctuations(fsspace, Astds[1], 1., 3.1, 1., .5, .1,
-4, 1., 'freq')
fa.add_fluctuations(fsspace, Astds[1], 1., 3.1, 1., .5, .1, -4, 1., 'freq')
m = 3.
x = fa.moment_slice_to_average(m)
fa.add_fluctuations(sspace, x, 1.5, 1.1, 2., 2.1, .5,
-2, 1., 'spatial', 0)
fa.add_fluctuations(sspace, x, 1.5, 1.1, 2., 2.1, .5, -2, 1., 'spatial', 0)
op = fa.finalize()
em, estd = stats(fa.slice_fluctuation(0),samples)
em, estd = stats(fa.slice_fluctuation(0), samples)
assert_allclose(m, em, rtol=0.5)
......
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