예제 #1
0
def c_optimal_parameters_supposed():
    batch_size = 50
    alpha = 0.01
    alpha_decay = 0.95
    min_alpha = 0.00005
    eta = 0.0001
    eta_inc = 0.01
    max_eta = 0.95
    layers = \
        [
            {
                "type": "fully_connected",
                "num_nodes": 50
            },
            {
                "type": "fully_connected",
                "num_nodes": 50
            }
        ]

    X, Y = load_sarcos("train")
    X_test, Y_test = load_sarcos("test")
    # Scale targets
    target_scaler = StandardScaler()
    Y = target_scaler.fit_transform(Y)
    Y_test = target_scaler.transform(Y_test)

    D = (X.shape[1], )
    F = Y.shape[1]

    model = MultilayerNeuralNetwork(D,
                                    F,
                                    layers,
                                    training="regression",
                                    std_dev=0.001,
                                    verbose=True)
    mbsgd = MiniBatchSGD(net=model,
                         epochs=100,
                         batch_size=batch_size,
                         alpha=alpha,
                         alpha_decay=alpha_decay,
                         min_alpha=min_alpha,
                         eta=eta,
                         eta_inc=eta_inc,
                         max_eta=max_eta,
                         random_state=0,
                         verbose=2)
    mbsgd.fit(X, Y)

    # Print nMSE on test set
    Y_pred = model.predict(X_test)
    for f in range(F):
        print("Dimension %d: nMSE = %.2f %%" %
              (f + 1, 100 * nMSE(Y_pred[:, f], Y_test[:, f])))

    # Store learned model, you can restore it with
    # model = pickle.load(open("sarcos_model.pickle", "rb"))
    # and use it in your evaluation script
    pickle.dump(model, open("sarcos_model.pickle", "wb"))
예제 #2
0
                                   training="regression",
                                   std_dev=0.01,
                                   verbose=1)
    mbsgd = MiniBatchSGD(net=mlnn,
                         epochs=epochs,
                         batch_size=16,
                         alpha=0.1,
                         eta=0.5,
                         random_state=0,
                         verbose=0)
    mbsgd.fit(X, Y)

    X_test = np.linspace(0, 1, 100)[:, np.newaxis]
    Y_test = np.sin(2 * np.pi * X_test)

    Y_test_prediction = mlnn.predict(X_test)

    # The following code assumes that these variables are defined:
    #
    # X : array, shape (200, 1)
    #     Inputs (training set), sampled uniformly from [0, 1] (or [0, 1))
    # Y : array, shape (200, 1)
    #     Targets (training set), sampled from sin(2*pi*x) + N(0, 0.01)
    # X_test : array, shape (100, 1)
    #     Inputs (test set), equally spaced values from [0, 1]
    # Y_test : array, shape (100, 1)
    #     Outputs (test set), sin(2*pi*X)
    # Y_test_prediction : array, shape (100, 1)
    #     Predicted values

    plt.figure()
예제 #3
0
                "type": "fully_connected",
                "num_nodes": 10
            }
        ]
    model = MultilayerNeuralNetwork(D,
                                    F,
                                    layers,
                                    training="regression",
                                    std_dev=0.01,
                                    verbose=True)
    mbsgd = MiniBatchSGD(net=model,
                         epochs=100,
                         batch_size=32,
                         alpha=0.005,
                         eta=0.5,
                         random_state=0,
                         verbose=2)
    mbsgd.fit(X, Y)
    ############################################################################

    # Print nMSE on test set
    Y_pred = model.predict(X_test)
    for f in range(F):
        print("Dimension %d: nMSE = %.2f %%" %
              (f + 1, 100 * nMSE(Y_pred[:, f], Y_test[:, f])))

    # Store learned model, you can restore it with
    # model = pickle.load(open("sarcos_model.pickle", "rb"))
    # and use it in your evaluation script
    pickle.dump(model, open("sarcos_model.pickle", "wb"))