예제 #1
0
    def random_instance(self, *args, **kwargs):
        U = util.orthogonal(self.d)
        D = np.random.rand(self.d)
        M = U.dot(np.diag(D)).dot(U.T)
        L = np.linalg.cholesky(M)

        return self.R, self.matrix_to_polys(M), L
예제 #2
0
파일: systems.py 프로젝트: sidaw/polymom
    def random_instance(self, *args, **kwargs):
        U = util.orthogonal(self.d)
        D = np.random.rand(self.d)
        M = U.dot(np.diag(D)).dot(U.T)
        L = np.linalg.cholesky(M)

        return self.R, self.matrix_to_polys(M), L
예제 #3
0
    def random_instance(self, *args, **kwargs):
        U = util.orthogonal(self.d)
        D = np.random.rand(self.d)
        M = U.dot(np.diag(D)).dot(U.T)

        print D, M

        return M, self.R, self.matrix_to_polys(M), D
예제 #4
0
파일: systems.py 프로젝트: sidaw/polymom
    def random_instance(self, *args, **kwargs):
        U = util.orthogonal(self.d)
        D = np.random.rand(self.d)
        M = U.dot(np.diag(D)).dot(U.T)

        print D, M

        return M, self.R, self.matrix_to_polys(M), D
예제 #5
0
def test_candecomp():
    """
    Test if it works
    """
    d = 3
    pi = rand(d)
    A = orthogonal(3)
    T = ten.ktensor( [A, A, A], pi ).totensor()
    pi_, A_, B_, C_ = candecomp( T, d )
    T_ = ten.ktensor( [A_, B_, C_], pi_ ).totensor()

    pi_ = match_columns_sign(np.atleast_2d(pi_), np.atleast_2d(pi)).flatten()
    A_ = match_columns_sign(A_, A)

    assert np.allclose(pi, pi_)
    assert np.allclose(A, A_)

    assert np.allclose( T, T_ )
예제 #6
0
def test_candecomp():
    """
    Test if it works
    """
    d = 3
    pi = rand(d)
    A = orthogonal(3)
    T = ten.ktensor([A, A, A], pi).totensor()
    pi_, A_, B_, C_ = candecomp(T, d)
    T_ = ten.ktensor([A_, B_, C_], pi_).totensor()

    pi_ = match_columns_sign(np.atleast_2d(pi_), np.atleast_2d(pi)).flatten()
    A_ = match_columns_sign(A_, A)

    assert np.allclose(pi, pi_)
    assert np.allclose(A, A_)

    assert np.allclose(T, T_)
예제 #7
0
    inputs = ordict(features=T.matrix("features"),
                    targets=T.ivector("targets"))
    x, y = inputs["features"], inputs["targets"]

    theano.config.compute_test_value = "warn"
    x.tag.test_value = np.random.random((11, 784)).astype(theano.config.floatX)
    y.tag.test_value = np.random.random_integers(low=0, high=9, size=(11,)).astype(np.int32)

    # move time axis before batch axis
    x = x.T

    # (time, batch, features)
    x = x.reshape((x.shape[0], x.shape[1], 1))

    Wx = theano.shared(util.orthogonal((1, nhidden)), name="Wx")
    bx = theano.shared(np.zeros((nhidden,), dtype=theano.config.floatX), name="bx")
    Wy = theano.shared(util.orthogonal((nhidden, nclasses)), name="Wy")
    by = theano.shared(np.zeros((nclasses,), dtype=theano.config.floatX), name="by")
    Wh = theano.shared(0.9*np.eye(nhidden, dtype=theano.config.floatX), name="Wh")
    h0 = theano.shared(np.zeros((nhidden,), dtype=theano.config.floatX), name="h0")

    parameters = ordict((var.name, var) for var in [Wx, bx, Wy, by, Wh, h0])

    taps = [-1] + [-m for m in args.skips]
    if args.instance_dependent:
        Wskip = theano.shared(np.zeros((nhidden, len(taps),), dtype=theano.config.floatX), name="Wskip")
        bskip = theano.shared(np.zeros((len(taps),), dtype=theano.config.floatX), name="bskip")
        parameters["Wskip"] = Wskip
        parameters["bskip"] = bskip