Ejemplo n.º 1
0
    def sample_signal_details(self, rhs=None,
                              norm_order=None, max_iterations=10000,
                              eps=None, raise_error=True,
                              find_mean=False):
        P, L = self.P_L

        if eps is None:
            eps = self.eps
            
        if rhs is None:
            rhs = self.sample_rhs(find_mean=find_mean)

        self.logger.info('Starting CG iterations')
        t0 = get_times()

        cg_logger = make_sublogger(self.logger, 'cg')
        x0 = harmonic_sphere_map(0, self.lmin, self.lmax, is_complex=False)
        x, info = CG(self.cg_mul_lhs, rhs, x0=x0, precond=self.preconditioner,
                     norm_order=norm_order, maxit=max_iterations, eps=eps,
                     raise_error=raise_error, logger=cg_logger)

        self.logger.info('CG done, %d its, %.2e res. (%s)',
                         info['iterations'],
                         info['residuals'][-1],
                         timestats(t0))

        # Got x; need to scale back -- x = L^-1 sdraw
        sdraw = harmonic_sphere_map(P.H * (L * (P * x)), self.lmin, self.lmax, is_complex=False)
        return sdraw, info, x
Ejemplo n.º 2
0
 def __call__(self, B):
     x0 = harmonic_sphere_map(0, self.lmin, self.lmax, is_complex=False)
     x, info = CG(self.cg_mul_lhs, B, x0=x0, precond=self.child,
                  norm_order=None, maxit=self.max_iterations,
                  eps=self.eps,
                  raise_error=True,
                  logger=self.cg_logger)
     return x
Ejemplo n.º 3
0
 def __call__(self, B):
     X_list = []
     for child, start, stop in self.child_start_stop:
         sub_X = child(B[start:stop])
         X_list.append(sub_X)
     X = harmonic_sphere_map(np.hstack(X_list), self.lmin, self.lmax,
                             is_complex=False)
     return X
Ejemplo n.º 4
0
#    SPeven = butterfly(P[:, ::2])
#    SPodd = butterfly(P[:, 1::2])
#    print 'Compression', SPeven.size() / DenseMatrix(P[:, ::2]).size()
#    print 'Compression', SPodd.size() / DenseMatrix(P[:, 1::2]).size()

if 0:
    x = np.cos(get_ring_thetas(Nside))
    x[np.abs(x) < 1e-10] = 0
    xneg = x[x < 0]
    xpos = x[x > 0]
    assert np.allclose(-xneg[::-1], xpos)
    X = InnerSumPerM(m, x[x >= 0], lmax)
    P_even_arr = X.P_even_arr.copy('F')
    P_even = X.P_even
    a_l_even = a_l[::2].copy()

    
if 0:
    map = alm2map(m, a_l, Nside)

    from cmb.maps import pixel_sphere_map, harmonic_sphere_map
    pixel_sphere_map(map).plot(title='fast')

    alm_fid = harmonic_sphere_map(0, lmin=0, lmax=lmax, is_complex=False)
    assert m != 0
    for l in range(m, lmax + 1):
        alm_fid[l**2 + l + m] = np.sqrt(2) * a_l[l - m] # real is repacked
    print 'Diff', np.linalg.norm(map - alm_fid.to_pixel(Nside))
    alm_fid.to_pixel(Nside).plot(title='fiducial')
    #(map - alm_fid.to_pixel(Nside)).plot(title='diff')
Ejemplo n.º 5
0
 def __call__(self, B):
     return harmonic_sphere_map(
         self.A.solve_right(B, algorithm='cholesky', check=False),
         self.lmin, self.lmax, is_complex=False)
Ejemplo n.º 6
0
#    as_matrix(np.log(np.abs(Peven))).plot()
#    SPeven = butterfly(P[:, ::2])
#    SPodd = butterfly(P[:, 1::2])
#    print 'Compression', SPeven.size() / DenseMatrix(P[:, ::2]).size()
#    print 'Compression', SPodd.size() / DenseMatrix(P[:, 1::2]).size()

if 0:
    x = np.cos(get_ring_thetas(Nside))
    x[np.abs(x) < 1e-10] = 0
    xneg = x[x < 0]
    xpos = x[x > 0]
    assert np.allclose(-xneg[::-1], xpos)
    X = InnerSumPerM(m, x[x >= 0], lmax)
    P_even_arr = X.P_even_arr.copy('F')
    P_even = X.P_even
    a_l_even = a_l[::2].copy()

if 0:
    map = alm2map(m, a_l, Nside)

    from cmb.maps import pixel_sphere_map, harmonic_sphere_map
    pixel_sphere_map(map).plot(title='fast')

    alm_fid = harmonic_sphere_map(0, lmin=0, lmax=lmax, is_complex=False)
    assert m != 0
    for l in range(m, lmax + 1):
        alm_fid[l**2 + l + m] = np.sqrt(2) * a_l[l - m]  # real is repacked
    print 'Diff', np.linalg.norm(map - alm_fid.to_pixel(Nside))
    alm_fid.to_pixel(Nside).plot(title='fiducial')
    #(map - alm_fid.to_pixel(Nside)).plot(title='diff')