Commit 2e872c5d authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'noflexibilityorasperity' into 'NIFTy_7'

No flexibility or asperity for simple correlated field maker

See merge request !555
parents 8c8530ce 12803f1c
Pipeline #77578 passed with stages
in 26 minutes and 4 seconds
......@@ -60,24 +60,19 @@ def main():
args = {
'offset_mean': 0,
'offset_std_mean': 1e-3,
'offset_std_std': 1e-6,
'offset_std': (1e-3, 1e-6),
# Amplitude of field fluctuations
'fluctuations_mean': 2.0, # 1.0
'fluctuations_stddev': 1.0, # 1e-2
'fluctuations': (2., 1.), # 1.0, 1e-2
# Exponent of power law power spectrum component
'loglogavgslope_mean': -2.0, # -3.0
'loglogavgslope_stddev': 0.5, # 0.5
'loglogavgslope': (-2., 0.5), # -3.0, 0.5
# Amplitude of integrated Wiener process power spectrum component
'flexibility_mean': 2.5, # 1.0
'flexibility_stddev': 1.0, # 0.5
'flexibility': (2.5, 1.), # 1.0, 0.5
# How ragged the integrated Wiener process component is
'asperity_mean': 0.5, # 0.1
'asperity_stddev': 0.5 # 0.5
'asperity': (0.5, 0.5) # 0.1, 0.5
}
correlated_field = ift.SimpleCorrelatedField(position_space, **args)
......
......@@ -40,51 +40,57 @@ class SimpleCorrelatedField(Operator):
spectrum, i.e. only one call of
:func:`~nifty7.library.correlated_fields.CorrelatedFieldMaker.add_fluctuations`.
"""
def __init__(self, target, offset_mean, offset_std_mean, offset_std_std,
fluctuations_mean, fluctuations_stddev, flexibility_mean,
flexibility_stddev, asperity_mean, asperity_stddev,
loglogavgslope_mean, loglogavgslope_stddev, prefix='',
def __init__(self, target, offset_mean, offset_std, fluctuations,
flexibility, asperity, loglogavgslope, prefix='',
harmonic_partner=None):
if harmonic_partner is None:
harmonic_partner = target.get_default_codomain()
else:
target.check_codomain(harmonic_partner)
harmonic_partner.check_codomain(target)
fluct = LognormalTransform(fluctuations_mean, fluctuations_stddev,
prefix + 'fluctuations', 0)
flex = LognormalTransform(flexibility_mean, flexibility_stddev,
prefix + 'flexibility', 0)
asp = LognormalTransform(asperity_mean, asperity_stddev,
prefix + 'asperity', 0)
avgsl = NormalTransform(loglogavgslope_mean, loglogavgslope_stddev,
prefix + 'loglogavgslope', 0)
zm = LognormalTransform(offset_std_mean, offset_std_std,
prefix + 'zeromode', 0)
for kk in [offset_std, fluctuations, loglogavgslope]:
if len(kk) != 2:
raise TypeError
for kk in [flexibility, asperity]:
if not (kk is None or len(kk) == 2):
raise TypeError
if flexibility is None and asperity is not None:
raise ValueError
fluct = LognormalTransform(*fluctuations, prefix + 'fluctuations', 0)
avgsl = NormalTransform(*loglogavgslope, prefix + 'loglogavgslope', 0)
zm = LognormalTransform(*offset_std, prefix + 'zeromode', 0)
pspace = PowerSpace(harmonic_partner)
twolog = _TwoLogIntegrations(pspace)
dom = twolog.domain[0]
vflex = np.zeros(dom.shape)
vasp = np.zeros(dom.shape)
shift = np.ones(dom.shape)
vflex[0] = vflex[1] = np.sqrt(_log_vol(pspace))
vasp[0] = 1
shift[0] = _log_vol(pspace)**2/12.
vflex = makeOp(makeField(dom, vflex))
vasp = makeOp(makeField(dom, vasp))
shift = makeField(dom, shift)
vslope = makeOp(makeField(pspace, _relative_log_k_lengths(pspace)))
expander = ContractionOperator(twolog.domain, 0).adjoint
ps_expander = ContractionOperator(pspace, 0).adjoint
vslope = makeOp(makeField(pspace, _relative_log_k_lengths(pspace)))
slope = vslope @ ps_expander @ avgsl
sig_flex = vflex @ expander @ flex
sig_asp = vasp @ expander @ asp
xi = ducktape(dom, None, prefix + 'spectrum')
smooth = xi*sig_flex*(Adder(shift) @ sig_asp).ptw("sqrt")
smooth = _SlopeRemover(pspace, 0) @ twolog @ smooth
a = _Normalization(pspace, 0) @ (slope + smooth)
a = slope
if flexibility is not None:
flex = LognormalTransform(*flexibility, prefix + 'flexibility', 0)
dom = twolog.domain[0]
vflex = np.zeros(dom.shape)
vflex[0] = vflex[1] = np.sqrt(_log_vol(pspace))
vflex = makeOp(makeField(dom, vflex))
sig_flex = vflex @ expander @ flex
xi = ducktape(dom, None, prefix + 'spectrum')
shift = np.ones(dom.shape)
shift[0] = _log_vol(pspace)**2/12.
shift = makeField(dom, shift)
if asperity is None:
asp = makeOp(shift.ptw("sqrt")) @ (xi*sig_flex)
else:
asp = LognormalTransform(*asperity, prefix + 'asperity', 0)
vasp = np.zeros(dom.shape)
vasp[0] = 1
vasp = makeOp(makeField(dom, vasp))
sig_asp = vasp @ expander @ asp
asp = xi*sig_flex*(Adder(shift) @ sig_asp).ptw("sqrt")
a = a + _SlopeRemover(pspace, 0) @ twolog @ asp
a = _Normalization(pspace, 0) @ a
maskzm = np.ones(pspace.shape)
maskzm[0] = 0
maskzm = makeOp(makeField(pspace, maskzm))
......
......@@ -139,20 +139,15 @@ def test_complicated_vs_simple(seed, domain):
loglogavgslope_stddev = _posrand()
prefix = 'foobar'
hspace = domain.get_default_codomain()
scf = ift.SimpleCorrelatedField(domain,
offset_mean,
offset_std_mean,
offset_std_std,
fluctuations_mean,
fluctuations_stddev,
flexibility_mean,
flexibility_stddev,
asperity_mean,
asperity_stddev,
loglogavgslope_mean,
loglogavgslope_stddev,
prefix=prefix,
harmonic_partner=hspace)
scf = ift.SimpleCorrelatedField(
domain,
offset_mean, (offset_std_mean, offset_std_std),
(fluctuations_mean, fluctuations_stddev),
(flexibility_mean, flexibility_stddev),
(asperity_mean, asperity_stddev),
(loglogavgslope_mean, loglogavgslope_stddev),
prefix=prefix,
harmonic_partner=hspace)
cfm = ift.CorrelatedFieldMaker.make(offset_mean, offset_std_mean,
offset_std_std, prefix)
cfm.add_fluctuations(domain,
......@@ -176,3 +171,24 @@ def test_complicated_vs_simple(seed, domain):
op0 = scf.amplitude
assert_(op0.domain is op1.domain)
ift.extra.assert_allclose(op0.force(inp), op1.force(inp))
@pmp('asperity', [None, (_posrand(), _posrand())])
@pmp('flexibility', [None, (_posrand(), _posrand())])
def test_simple_without_asp_fluct(asperity, flexibility):
domain = ift.RGSpace((4, 4), (0.123, 0.4))
offset_mean = _rand()
offset_std = _posrand(), _posrand()
fluctuations = _posrand(), _posrand()
loglogavgslope = _posrand(), _posrand()
prefix = 'foobar'
hspace = domain.get_default_codomain()
args = (domain, offset_mean, offset_std, fluctuations, flexibility,
asperity, loglogavgslope, prefix, hspace)
if asperity is not None and flexibility is None:
with pytest.raises(ValueError):
scf = ift.SimpleCorrelatedField(*args)
else:
scf = ift.SimpleCorrelatedField(*args)
inp = ift.from_random(scf.domain)
ift.extra.check_operator(scf, inp, ntries=10)
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