Example #1
0
def testPPO(sp, dtype):
    _check_repr(ift.PowerDistributor(target=sp))
    ps = ift.PowerSpace(
        sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3))
    _check_repr(ift.PowerDistributor(target=sp, power_space=ps))
    ps = ift.PowerSpace(
        sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3))
    _check_repr(ift.PowerDistributor(target=sp, power_space=ps))
Example #2
0
def testPPO(sp, dtype):
    op = ift.PowerDistributor(target=sp)
    ift.extra.consistency_check(op, dtype, dtype)
    ps = ift.PowerSpace(
        sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=False, nbin=3))
    op = ift.PowerDistributor(target=sp, power_space=ps)
    ift.extra.consistency_check(op, dtype, dtype)
    ps = ift.PowerSpace(
        sp, ift.PowerSpace.useful_binbounds(sp, logarithmic=True, nbin=3))
    op = ift.PowerDistributor(target=sp, power_space=ps)
    ift.extra.consistency_check(op, dtype, dtype)
def test_gaussian_energy(space, nonlinearity, noise, seed):
    np.random.seed(seed)
    dim = len(space.shape)
    hspace = space.get_default_codomain()
    ht = ift.HarmonicTransformOperator(hspace, target=space)
    binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
    pspace = ift.PowerSpace(hspace, binbounds=binbounds)
    Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
    xi0 = ift.Field.from_random(domain=hspace, random_type='normal')

    def pspec(k):
        return 1 / (1 + k**2)**dim

    pspec = ift.PS_field(pspace, pspec)
    A = Dist(ift.sqrt(pspec))
    N = ift.ScalingOperator(noise, space)
    n = N.draw_sample()
    R = ift.ScalingOperator(10., space)

    def d_model():
        if nonlinearity == "":
            return R(ht(ift.makeOp(A)))
        else:
            tmp = ht(ift.makeOp(A))
            nonlin = getattr(tmp, nonlinearity)()
            return R(nonlin)

    d = d_model()(xi0) + n

    if noise == 1:
        N = None

    energy = ift.GaussianEnergy(d, N)(d_model())
    ift.extra.check_jacobian_consistency(energy, xi0, ntries=10, tol=5e-8)
    # Specify harmonic space corresponding to signal
    harmonic_space = position_space.get_default_codomain()

    # Harmonic transform from harmonic space to position space
    HT = ift.HarmonicTransformOperator(harmonic_space, target=position_space)

    # Set prior correlation covariance with a power spectrum leading to
    # homogeneous and isotropic statistics
    def power_spectrum(k):
        return 100. / (20. + k**3)

    # 1D spectral space on which the power spectrum is defined
    power_space = ift.PowerSpace(harmonic_space)

    # Mapping to (higher dimensional) harmonic space
    PD = ift.PowerDistributor(harmonic_space, power_space)

    # Apply the mapping
    prior_correlation_structure = PD(ift.PS_field(power_space, power_spectrum))

    # Insert the result into the diagonal of an harmonic space operator
    S = ift.DiagonalOperator(prior_correlation_structure)
    # S is the prior field covariance

    # Build instrument response consisting of a discretization, mask
    # and harmonic transformaion

    # Data is defined on a geometry-free space, thus the geometry is removed
    GR = ift.GeometryRemover(position_space)

    # Masking operator to model that parts of the field have not been observed
Example #5
0
        position_space = ift.HPSpace(128)
        exposure = ift.Field.full(position_space, 100.)

    # Define harmonic space and harmonic transform
    harmonic_space = position_space.get_default_codomain()
    HT = ift.HarmonicTransformOperator(harmonic_space, position_space)

    # Domain on which the field's degrees of freedom are defined
    domain = ift.DomainTuple.make(harmonic_space)

    # Define amplitude (square root of power spectrum)
    def sqrtpspec(k):
        return 1. / (20. + k**2)

    p_space = ift.PowerSpace(harmonic_space)
    pd = ift.PowerDistributor(harmonic_space, p_space)
    a = ift.PS_field(p_space, sqrtpspec)
    A = pd(a)

    # Define sky operator
    sky = ift.exp(HT(ift.makeOp(A)))

    M = ift.DiagonalOperator(exposure)
    GR = ift.GeometryRemover(position_space)
    # Define instrumental response
    R = GR(M)

    # Generate mock data and define likelihood operator
    d_space = R.target[0]
    lamb = R(sky)
    mock_position = ift.from_random('normal', domain)