Example #1
0
def main():
    Ws, bs = get_params(['model_reinforcement.pickle', 'model.pickle'])
    Ws_s, bs_s = train.get_parameters(Ws=Ws, bs=bs)
    f_pred = get_predict(Ws_s, bs_s)
    f_train = get_update(Ws_s, bs_s)

    i, n, l, c = 0, 0.0, 0.0, 0.0

    base_learning_rate = 1e-2
    t0 = time.time()

    while True:
        learning_rate = base_learning_rate * math.exp(-(time.time() - t0) / 86400)
        r = game(f_pred, f_train, learning_rate)
        if r is None:
            continue
        i += 1
        n_t, l_t, c_t = r
        n = n*0.999 + n_t
        l = l*0.999 + l_t*n_t
        c = c*0.999 + c_t*n_t
        print '%6d %9.5f %9.5f %9.5f' % (i, learning_rate, l / n, c / n)

        if i % 100 == 0:
            print 'dumping model...'
            dump(Ws_s, bs_s)
def main():
    Ws, bs = get_params(['model_reinforcement.pickle', 'model.pickle'])
    Ws_s, bs_s = train.get_parameters(Ws=Ws, bs=bs)
    f_pred = get_predict(Ws_s, bs_s)
    f_train = get_update(Ws_s, bs_s)

    i, n, l, c = 0, 0.0, 0.0, 0.0

    base_learning_rate = 1e-2
    t0 = time.time()

    while True:
        learning_rate = base_learning_rate * math.exp(
            -(time.time() - t0) / 86400)
        r = game(f_pred, f_train, learning_rate)
        if r is None:
            continue
        i += 1
        n_t, l_t, c_t = r
        n = n * 0.999 + n_t
        l = l * 0.999 + l_t * n_t
        c = c * 0.999 + c_t * n_t
        print '%6d %9.5f %9.5f %9.5f' % (i, learning_rate, l / n, c / n)

        if i % 100 == 0:
            print 'dumping model...'
            dump(Ws_s, bs_s)
Example #3
0
def get_model_from_pickle(fn):
    f = open(fn)
    Ws, bs = pickle.load(f)

    Ws_s, bs_s = train.get_parameters(Ws=Ws, bs=bs)
    x, p = train.get_model(Ws_s, bs_s)

    predict = theano.function(inputs=[x], outputs=p)

    return predict
Example #4
0
def get_model_from_pickle(fn):
    f = open(fn)
    Ws, bs = pickle.load(f)
    
    Ws_s, bs_s = train.get_parameters(Ws=Ws, bs=bs)
    x, p = train.get_model(Ws_s, bs_s)
    
    predict = theano.function(
        inputs=[x],
        outputs=p)

    return predict
Example #5
0
def predict():
    cur_pvs = np.zeros([24, 19], dtype=np.float32)
    paras = train.get_parameters("vapor_press_trained_parameters.npz")
    pvs = get_a_line()
    while True:
        time.sleep(5)
        line = next(pvs)
        cur_pvs = np.delete(cur_pvs, -1, axis=0)
        cur_pvs = np.insert(cur_pvs, 0, line, axis=0)
        cur_pvs_trans = cur_pvs.reshape(-1, 1)
        pre_val = train.forward_propagation(cur_pvs_trans, paras)
        sess = tf.Session()
        val = sess.run(pre_val)
        val = val * 50 + 50
        print(val)