Exemple #1
0
 def weingarten_map(self, X, roll=True):
     g = np.rollaxis(self.metric_tensor(X), 2)
     h = np.rollaxis(self.shape_tensor(X), 2)
     res = np.einsum("aio, abi -> abo", np.linalg.inv(g), h)
     if roll:
         return np.rollaxis(res, 0, 3)
     else:
         return res
Exemple #2
0
def stamps2array(gstamps):
    stamps = []
    for gstamp in gstamps:
        template = gstamp.replace('-g-', '-%s-')
        bands = ['u', 'g', 'r', 'i', 'z']
        imgs = [FitsImage(b, fits_file_template=template) for b in bands]
        img_array = np.array([img.nelec for img in imgs])
        stamps.append( np.rollaxis(img_array, 0, 3) )
    stamps = np.array(stamps)
    return stamps
Exemple #3
0
def make_img_col(imgs, filter_shape=(5, 5), verbose=False):
    """ Takes a stack of images with shape [N, color, y, x]
        outputs a column stack of images with shape
        [N, filter_x*filter_y, conv_out_y*conv_out_x]
    """
    imgs = np.rollaxis(imgs, 1, 4)
    img0 = im2col(imgs[0, :, :, :], filter_shape)
    col_imgs = np.zeros((imgs.shape[0], img0.shape[0], img0.shape[1]))
    for i, img in enumerate(imgs):
        if i % 5000 == 0 and verbose:
            print "%d of %d" % (i, len(imgs))
        col_imgs[i, :, :] = im2col(img, filter_shape)
    return col_imgs
Exemple #4
0
def make_img_col(imgs, filter_shape=(5,5), verbose=False):
    """ Takes a stack of images with shape [N, color, y, x]
        outputs a column stack of images with shape
        [N, filter_x*filter_y, conv_out_y*conv_out_x]
    """
    imgs     = np.rollaxis(imgs, 1, 4)
    img0     = im2col(imgs[0, :, :, :], filter_shape)
    col_imgs = np.zeros((imgs.shape[0], img0.shape[0], img0.shape[1]))
    for i, img in enumerate(imgs):
        if i % 5000 == 0 and verbose:
            print "%d of %d"%(i, len(imgs))
        col_imgs[i,:,:] = im2col(img, filter_shape)
    return col_imgs
    def sample(cls, params=None, nat_params=None, size=1):
        # Sample from P( x | Ѳ; α )
        assert (params is None) ^ (nat_params is None)

        (alpha, ) = params if params is not None else cls.natToStandard(
            *nat_params)

        ans = np.empty(alpha.shape + (size, ))
        for indices in itertools.product(*[range(s)
                                           for s in alpha.shape[:-1]]):
            ans[indices] = Dirichlet.sample(params=(alpha[indices], ),
                                            size=size).T

        ans = np.rollaxis(ans, -1)

        cls.checkShape(ans)
        return ans
Exemple #6
0
    # samps and stamps now aligned
    stamps = stamps[chain_mask, :, :, :]
    samps  = np.array(samps)
    return stamps, samps


if __name__=="__main__":

    # load in stamp/samp pairs
    gstamps = glob("stamps/*stamp-g*.fits")
    stamps, samps = load_stamps_and_samps(gstamps)
    print "Loaded %d stamp/samp pairs"%stamps.shape[0]

    # fit the damn thing
    train_images = np.rollaxis(stamps, 3, 1)
    N_data = train_images.shape[0]

    # Network parameters
    L2_reg = 100.
    input_shape = train_images.shape[1:]
    layer_specs = [#fast_conv_layer((5, 5), 6, input_shape[1:]),
                   cv.conv_layer((12, 12), 10),
                   cv.maxpool_layer((2, 2)),
                   #cv.conv_layer((5, 5), 16),
                   #fast_conv_layer((5, 5), 16, (12, 12)),
                   #cv.maxpool_layer((2, 2)),
                   cv.tanh_layer(300),
                   cv.linear_layer(100),
                   cv.linear_layer(16)]
Exemple #7
0
anp.diag.defjvp(lambda g, ans, gvs, vs, x, k=0: anp.diag(g, k))
anp.flipud.defjvp(lambda g, ans, gvs, vs, x, : anp.flipud(g))
anp.fliplr.defjvp(lambda g, ans, gvs, vs, x, : anp.fliplr(g))
anp.rot90.defjvp(lambda g, ans, gvs, vs, x, k=1: anp.rot90(g, k))
anp.trace.defjvp(lambda g, ans, gvs, vs, x, offset=0: anp.trace(g, offset))
anp.full.defjvp(lambda g, ans, gvs, vs, shape, fill_value, dtype=None: anp.
                full(shape, g, dtype),
                argnum=1)
anp.triu.defjvp(lambda g, ans, gvs, vs, x, k=0: anp.triu(g, k=k))
anp.tril.defjvp(lambda g, ans, gvs, vs, x, k=0: anp.tril(g, k=k))
anp.clip.defjvp(lambda g, ans, gvs, vs, x, a_min, a_max: g * anp.logical_and(
    ans != a_min, ans != a_max))
anp.swapaxes.defjvp(
    lambda g, ans, gvs, vs, x, axis1, axis2: anp.swapaxes(g, axis1, axis2))
anp.rollaxis.defjvp(
    lambda g, ans, gvs, vs, a, axis, start=0: anp.rollaxis(g, axis, start))
anp.real_if_close.defjvp(lambda g, ans, gvs, vs, x: npg.match_complex(vs, g))
anp.real.defjvp(lambda g, ans, gvs, vs, x: anp.real(g))
anp.imag.defjvp(lambda g, ans, gvs, vs, x: npg.match_complex(vs, -1j * g))
anp.conj.defjvp(lambda g, ans, gvs, vs, x: anp.conj(g))
anp.angle.defjvp(lambda g, ans, gvs, vs, x: npg.match_complex(
    vs,
    g * anp.conj(x * 1j) / anp.abs(x)**2))
anp.where.defjvp(lambda g, ans, gvs, vs, c, x=None, y=None: anp.where(
    c, g, anp.zeros(anp.shape(g))),
                 argnum=1)
anp.where.defjvp(lambda g, ans, gvs, vs, c, x=None, y=None: anp.where(
    c, anp.zeros(g.shape), g),
                 argnum=2)
anp.cross.defjvp(lambda g, ans, gvs, vs, a, b, axisa=-1, axisb=-1, axisc=-1,
                 axis=None: anp.cross(g, b, axisa, axisb, axisc, axis),
Exemple #8
0
 def area_element(self, X):
     g = np.rollaxis(self.metric_tensor(X), 2)
     return np.linalg.det(g)