From 71e38722dba6a33a2f91d0e78eab8b4856d9d94b Mon Sep 17 00:00:00 2001 From: Lukas Platz <lplatz@mpa-garching.mpg.de> Date: Mon, 10 Feb 2020 17:04:30 +0100 Subject: [PATCH] concise CorrelatedField offset parametrization --- nifty6/library/correlated_fields.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nifty6/library/correlated_fields.py b/nifty6/library/correlated_fields.py index 1d645e346..6d703d6f6 100644 --- a/nifty6/library/correlated_fields.py +++ b/nifty6/library/correlated_fields.py @@ -352,18 +352,19 @@ class _Amplitude(Operator): class CorrelatedFieldMaker: - def __init__(self, amplitude_offset, prefix, total_N): - if not isinstance(amplitude_offset, Operator): - raise TypeError("amplitude_offset needs to be an operator") + def __init__(self, offset_mean, offset_fluctuations_op, prefix, total_N): + if not isinstance(offset_fluctuations_op, Operator): + raise TypeError("offset_fluctuations_op needs to be an operator") self._a = [] self._position_spaces = [] - self._azm = amplitude_offset + self._offset_mean = offset_mean + self._azm = offset_fluctuations_op self._prefix = prefix self._total_N = total_N @staticmethod - def make(offset_amplitude_mean, offset_amplitude_stddev, prefix, + def make(offset_mean, offset_variation_mean, offset_variation_stddev, prefix, total_N=0, dofdex=None): if dofdex is None: @@ -371,13 +372,13 @@ class CorrelatedFieldMaker: elif len(dofdex) != total_N: raise ValueError("length of dofdex needs to match total_N") N = max(dofdex) + 1 if total_N > 0 else 0 - zm = _LognormalMomentMatching(offset_amplitude_mean, - offset_amplitude_stddev, + zm = _LognormalMomentMatching(offset_variation_mean, + offset_variation_stddev, prefix + 'zeromode', N) if total_N > 0: zm = _Distributor(dofdex, zm.target, UnstructuredDomain(total_N)) @ zm - return CorrelatedFieldMaker(zm, prefix, total_N) + return CorrelatedFieldMaker(offset_mean, zm, prefix, total_N) def add_fluctuations(self, position_space, @@ -470,12 +471,13 @@ class CorrelatedFieldMaker: corr = reduce(mul, a) return ht(azm*corr*ducktape(hspace, None, self._prefix + 'xi')) - def finalize(self, offset=None, prior_info=100): + def finalize(self, prior_info=100): """ offset vs zeromode: volume factor """ op = self._finalize_from_op() - if offset is not None: + if self._offset_mean is not None: + offset = self._offset_mean # Deviations from this offset must not be considered here as they # are learned by the zeromode if isinstance(offset, (Field, MultiField)): -- GitLab