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