Пример #1
0
def test_dsrnn():
    l = SupervisedRecurrentNetwork(2, [3] * 2, 1, ['sigmoid'] * 2, 'identity', 'squared')
    f = l.function(['inpt', 'target'], 'loss', mode='FAST_COMPILE')
    d_loss_wrt_pars = T.grad(l.exprs['loss'], l.parameters.flat)
    fprime = l.function(['inpt', 'target'], d_loss_wrt_pars,
                        mode='FAST_COMPILE')

    X = np.random.random((10, 3, 2)).astype(theano.config.floatX)
    Z = np.random.random((10, 3, 1)).astype(theano.config.floatX)

    f(X, Z)
    fprime(X, Z)
Пример #2
0
def test_srnn():
    l = SupervisedRecurrentNetwork(2, 3, 1, 'sigmoid', 'identity', 'squared')
    f = l.function(['inpt', 'target'], 'loss', mode='FAST_COMPILE')
    d_loss_wrt_pars = T.grad(l.exprs['loss'], l.parameters.flat)
    fprime = l.function(['inpt', 'target'],
                        d_loss_wrt_pars,
                        mode='FAST_COMPILE')

    X = np.random.random((10, 3, 2)).astype(theano.config.floatX)
    Z = np.random.random((10, 3, 1)).astype(theano.config.floatX)

    f(X, Z)
    fprime(X, Z)
Пример #3
0
def test_pooling_rnn():
    l = SupervisedRecurrentNetwork(2, [3], 1, hidden_transfers=['sigmoid'],
                        pooling='mean', loss='ncac')

    l = SupervisedRecurrentNetwork(2, 3, 1, 'sigmoid', 'identity', 'ncac', 'mean')
    f = l.function(['inpt', 'target'], 'loss', mode='FAST_COMPILE')
    d_loss_wrt_pars = T.grad(l.exprs['loss'], l.parameters.flat)
    fprime = l.function(['inpt', 'target'], d_loss_wrt_pars,
                        mode='FAST_COMPILE')

    X = np.random.random((10, 30, 2)).astype(theano.config.floatX)
    Z = np.random.random((30, 1)).astype(theano.config.floatX)

    f(X, Z)
    fprime(X, Z)
Пример #4
0
def test_pooling_rnn():
    l = SupervisedRecurrentNetwork(2, [3],
                                   1,
                                   hidden_transfers=['sigmoid'],
                                   pooling='mean',
                                   loss='ncac')

    l = SupervisedRecurrentNetwork(2, 3, 1, 'sigmoid', 'identity', 'ncac',
                                   'mean')
    f = l.function(['inpt', 'target'], 'loss', mode='FAST_COMPILE')
    d_loss_wrt_pars = T.grad(l.exprs['loss'], l.parameters.flat)
    fprime = l.function(['inpt', 'target'],
                        d_loss_wrt_pars,
                        mode='FAST_COMPILE')

    X = np.random.random((10, 30, 2)).astype(theano.config.floatX)
    Z = np.random.random((30, 1)).astype(theano.config.floatX)

    f(X, Z)
    fprime(X, Z)