Esempio n. 1
0
def make_P4H2V2_z2_indices(ksize):
    assert ksize % 2 == 1  # TODO
    x = np.random.randn(1, ksize, ksize) # 1 relates to stabilizer size of input channel
    f = Z2FuncArray(v=x) # input channel related
    uv = f.left_translation_indices(P4H2V2.flatten()[:, None, None, None]) # this adds the output channel stabilizer # output channel related
    m1m2r = np.zeros(uv.shape[:-1] + (1,))
    m1m2ruv = np.c_[m1m2r, uv]
    return m1m2ruv.astype('int32')
Esempio n. 2
0
def make_d4_z2_indices(ksize):
    assert ksize % 2 == 1  # TODO
    x = np.random.randn(1, ksize, ksize)
    f = Z2FuncArray(v=x)
    uv = f.left_translation_indices(D4.flatten()[:, None, None, None])
    mr = np.zeros(uv.shape[:-1] + (1, ))
    mruv = np.c_[mr, uv]
    return mruv.astype('int32')
Esempio n. 3
0
def make_c4_z2_indices(ksize):
    x = np.random.randn(1, ksize, ksize)
    f = Z2FuncArray(v=x)

    if ksize % 2 == 0:
        uv = f.left_translation_indices(C4_halfshift[:, None, None, None])
    else:
        uv = f.left_translation_indices(C4[:, None, None, None])
    r = np.zeros(uv.shape[:-1] + (1, ))
    ruv = np.c_[r, uv]
    return ruv.astype('int32')
Esempio n. 4
0
def make_c4_z2_indices(ksize):
    x = np.random.randn(1, ksize, ksize) # input channel related
    f = Z2FuncArray(v=x) # input channel related

    if ksize % 2 == 0:
        uv = f.left_translation_indices(C4_halfshift[:, None, None, None]) # left_translation = g*i2g at a high-level, # output channel related
    else:
        uv = f.left_translation_indices(C4[:, None, None, None]) # C4 here is the group
    r = np.zeros(uv.shape[:-1] + (1,))
    ruv = np.c_[r, uv]
    return ruv.astype('int32')
Esempio n. 5
0
def make_d6_z2_indices(ksize):
    assert ksize % 2 == 1, "Only uneven filters are supported"

    import groupy.garray.p6m_array as p6ma
    import groupy.garray.D6_array as d6a
    x = np.random.randn(1, ksize, ksize)

    f = Z2FuncArray(v=x)
    uv = f.left_translation_indices(d6a.D6.flatten()[:, None, None, None])

    mr = np.zeros(uv.shape[:-1] + (1,))
    mruv = np.c_[mr, uv]

    # Set invalid indices to the weight which is known to be zero.    
    mruv[np.min(mruv[..., -2:], axis=-1) < 0, :] = np.zeros(mruv.shape[-1])
    mruv[np.max(mruv[..., -2:], axis=-1) >=ksize, :] = np.zeros(mruv.shape[-1])

    return mruv.astype('int32')
Esempio n. 6
0
def make_c3_z2_indices(ksize):
    import groupy.garray.p3_array as p3a
    import groupy.garray.C3_array as c3a

    assert ksize % 2 == 1, "Only uneven filters are supported"

    x = np.random.randn(1, ksize, ksize)
    f = Z2FuncArray(v=x)

    uv = f.left_translation_indices(c3a.C3.flatten()[:, None, None, None])

    r = np.zeros(uv.shape[:-1] + (1, ))
    ruv = np.c_[r, uv]

    # Set invalid indices to the weight which is known to be zero.
    ruv[np.min(ruv[..., -2:], axis=-1) < 0, :] = np.zeros(ruv.shape[-1])
    ruv[np.max(ruv[..., -2:], axis=-1) >= ksize, :] = np.zeros(ruv.shape[-1])

    return ruv.astype('int32')
Esempio n. 7
0
def test_z2_func():
    from groupy.gfunc.z2func_array import Z2FuncArray
    import groupy.garray.C4_array as c4a
    import groupy.garray.C4_array as d4a

    v = np.random.randn(2, 6, 5, 5)
    f = Z2FuncArray(v=v)

    g = c4a.rand(size=(1, ))
    h = c4a.rand(size=(1, ))
    check_associative(g, h, f)
    check_identity(c4a, f)
    check_invertible(g, f)
    check_i2g_g2i_invertible(f)

    g = d4a.rand(size=(1, ))
    h = d4a.rand(size=(1, ))
    check_associative(g, h, f)
    check_identity(d4a, f)
    check_invertible(g, f)
    check_i2g_g2i_invertible(f)
Esempio n. 8
0
 def rotate_flip_z2_func(im, flip, theta_index):
     imf = Z2FuncArray(im)
     rot = D4Array([flip, theta_index], 'int')
     rot_imf = rot * imf
     return rot_imf.v
Esempio n. 9
0
 def rotate_z2_func(im, r):
     imf = Z2FuncArray(im)
     rot = C4Array([r], 'int')
     rot_imf = rot * imf
     return rot_imf.v