Beispiel #1
0
def run_simple():
    del_shared()
    n_in = X.shape[-1]
    n_hid = 20
    n_out = y.shape[-1]

    random_state = np.random.RandomState(42)
    h_init = np.zeros((minibatch_size, n_hid)).astype("float32")

    h0 = tensor.fmatrix()

    l1 = simple_fork([X_sym], [n_in], n_hid, name="l1",
                     random_state=random_state)

    def step(in_t, h_tm1):
        h_t = simple(in_t, h_tm1, n_hid, name="rec", random_state=random_state)
        return h_t

    h, _ = theano.scan(step, sequences=[l1], outputs_info=[h0])

    pred = linear([h], [n_hid], n_out, name="l2", random_state=random_state)
    cost = ((y_sym - pred) ** 2).sum()
    params = list(get_params().values())

    grads = tensor.grad(cost, params)
    learning_rate = 0.000000000001
    opt = sgd(params, learning_rate)
    updates = opt.updates(params, grads)

    f = theano.function([X_sym, y_sym, h0], [cost, h], updates=updates,
                        mode="FAST_COMPILE")
    f(X, y, h_init)
Beispiel #2
0
all_sines = full_sines[:n_timesteps]
n_full = 10 * n_timesteps
X = all_sines[:-1]
y = all_sines[1:]

n_in = 1
n_hid = 20
n_out = 1

X_sym = tensor.tensor3()
y_sym = tensor.tensor3()
h0 = tensor.fmatrix()

random_state = np.random.RandomState(1999)
X_fork = simple_fork([X_sym], [n_in],
                     n_hid,
                     name="h1",
                     random_state=random_state)


def step(in_t, h_tm1):
    h_t = simple(in_t, h_tm1, n_hid, name="rec", random_state=random_state)
    return h_t


h, _ = theano.scan(step, sequences=[X_fork], outputs_info=[h0])

y_pred = linear([h], [n_hid], n_out, name="h2", random_state=random_state)

cost = ((y_sym - y_pred)**2).sum()
params = list(get_params().values())
params = params
Beispiel #3
0
full_sines = make_sines(10 * n_timesteps, minibatch_size)
all_sines = full_sines[:n_timesteps]
n_full = 10 * n_timesteps
X = all_sines[:-1]
y = all_sines[1:]

n_in = 1
n_hid = 20
n_out = 1

X_sym = tensor.tensor3()
y_sym = tensor.tensor3()
h0 = tensor.fmatrix()

random_state = np.random.RandomState(1999)
X_fork = simple_fork([X_sym], [n_in], n_hid, name="h1",
                     random_state=random_state)


def step(in_t, h_tm1):
    h_t = simple(in_t, h_tm1, n_hid, name="rec", random_state=random_state)
    return h_t

h, _ = theano.scan(step,
                   sequences=[X_fork],
                   outputs_info=[h0])

y_pred = linear([h], [n_hid], n_out, name="h2", random_state=random_state)

cost = ((y_sym - y_pred) ** 2).sum()
params = list(get_params().values())
params = params