Commit d0941445 authored by Gordian Edenhofer's avatar Gordian Edenhofer
Browse files

Make CF treat no zm operator as fixed zm of zero

If no amplitude total offset (i.e. zero-mode of the amplitude operator)
is specified, the correlated field is still able to produce a useful
tensor-product of amplitudes. However, their overall zero-mode is of
course not determined. As convention, set the zero-mode of the final
amplitude operator to zero.
parent c4576acd
......@@ -69,18 +69,6 @@ def density_estimator(
# cfmaker.set_amplitude_total_offset(0., (1e-2, 1e-6))
correlated_field = cfmaker.finalize(0, normalize=False)
# HACK: Mask the zero-th entry of the to-be-learned parameters
mask_xi0_stack = []
for k, d in correlated_field.domain.items():
sel = ift.FieldAdapter(d, k)
if k == prefix + "xi":
m = np.zeros(d.shape, dtype=bool)
m.flat[0] = True
sel = ift.MaskOperator(ift.Field.from_raw(d, m)) @ sel
mask_xi0_stack.append(sel.adjoint @ sel)
mask_xi0 = reduce(lambda x, y: x + y, mask_xi0_stack)
correlated_field = correlated_field @ mask_xi0
domain_shape = tuple(d.shape for d in domain)
slc = ift.SliceOperator(, domain_shape)
......@@ -38,6 +38,7 @@ from ..operators.distributors import PowerDistributor
from ..operators.endomorphic_operator import EndomorphicOperator
from ..operators.harmonic_operators import HarmonicTransformOperator
from ..operators.linear_operator import LinearOperator
from ..operators.mask_operator import MaskOperator
from ..operators.normal_operators import LognormalTransform, NormalTransform
from ..operators.operator import Operator
from ..operators.simple_linear_operators import VdotOperator, ducktape
......@@ -719,9 +720,22 @@ class CorrelatedFieldMaker:
a[ii] = co.adjoint @ pd @ a[ii]
corr = reduce(mul, a)
if normalize:
op = ht(azm*corr*ducktape(hspace, None, self._prefix + 'xi'))
xi = ducktape(hspace, None, self._prefix + 'xi')
op = ht(azm * corr * xi)
op = ht(corr*ducktape(hspace, None, self._prefix + 'xi'))
if self._total_N > 0:
re = (
"initializing a correlated field without an amplitude total"
" offset with `total_N` larger than zero is not supported"
raise RuntimeError(re)
m = np.zeros(hspace.shape, dtype=bool)
m.flat[0] = True
mask_zm = MaskOperator(Field(hspace, m))
xi = ducktape(mask_zm.adjoint.domain, None, self._prefix + "xi")
xi = mask_zm.adjoint @ xi
op = ht(corr * xi)
if self._offset_mean is not None:
offset = self._offset_mean
Supports Markdown
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