Exemple #1
0
#%%
if __name__ == "__main__":
    print 'This file contains the Neural Network example'

    # Parameters and settings
    data_lag = 3
    N_input_units = data_lag
    N_hidden_units = 8
    N_output_units = 1
    net_fit_repeat = 5
    net_max_iter = 10000
    net_best_err = 9e9

    # Load the Sunspot dataset
    year, reading, lag_matrix = get_sunspot(data_lag)
    train, test = data_split(lag_matrix)

    # Repeat network fit to find the one with the lowest error
    net_best = None
    for net_fit_count in range(net_fit_repeat):
        net = NeuralNetwork(structure=(N_input_units - 1, N_hidden_units,
                                       N_output_units),
                            train_input=train[:, 1:],
                            train_target=train[:, 0],
                            test_input=test[:, 1:],
                            test_target=test[:, 0],
                            max_iter=net_max_iter)
        net.train()

        if net.e_test[-1] < net_best_err:
Exemple #2
0
#%%

if __name__ == "__main__":
    print 'This file contains the Gaussian Process example'

    # Parameters and settings
    N_SIG2 = 20
    N_BETA = 20
    MAX_BETA = 1
    MIN_BETA = 500
    MAX_SIG2 = 2
    MIN_SIG2 = 0.01

    # Load the sunspot dataset
    lag = 5
    year, reading, lag_matrix = get_sunspot(lag)
    empirical_var = np.var(lag_matrix[:, 0])  # Some statics (for later use)

    # Split data set into a train/test set
    train, test = data_split(lag_matrix)
    train_input = train[:, 1:]
    train_target = train[:, 0]
    test_input = test[:, 1:]
    test_target = test[:, 0]

    # Construct kernels
    K_train_train = kernel(train_input.T, train_input.T)
    K_test_train = kernel(test_input.T, train_input.T)
    K_test_test = kernel(test_input.T, test_input.T)
    """
    Initialize the algorihm.
Exemple #3
0
if __name__ == "__main__":
    print 'This file contains the Gaussian Process example'    
    
    # Parameters and settings
    N_SIG2 = 20
    N_BETA = 20
    MAX_BETA = 1
    MIN_BETA = 500
    MAX_SIG2 = 2
    MIN_SIG2 = 0.01
    
    
    # Load the sunspot dataset 
    lag = 5
    year, reading, lag_matrix = get_sunspot(lag)
    empirical_var = np.var(lag_matrix[:, 0])  # Some statics (for later use)
    
    # Split data set into a train/test set
    train, test = data_split(lag_matrix)
    train_input = train[:,1:]
    train_target = train[:,0]
    test_input = test[:,1:]
    test_target = test[:,0]
    
    # Construct kernels
    K_train_train = kernel(train_input.T, train_input.T)
    K_test_train = kernel(test_input.T, train_input.T)
    K_test_test = kernel(test_input.T, test_input.T)
    
    """
Exemple #4
0
#%%
if __name__ == "__main__":
    print 'This file contains the Neural Network example'
    
    # Parameters and settings
    data_lag = 3
    N_input_units = data_lag
    N_hidden_units = 8
    N_output_units = 1
    net_fit_repeat = 5
    net_max_iter = 10000
    net_best_err = 9e9
    
    # Load the Sunspot dataset
    year, reading, lag_matrix = get_sunspot(data_lag)
    train, test = data_split(lag_matrix)

    # Repeat network fit to find the one with the lowest error
    net_best = None
    for net_fit_count in range(net_fit_repeat):
        net = NeuralNetwork(structure=(N_input_units-1, N_hidden_units, N_output_units), train_input=train[:, 1:], train_target=train[:, 0], test_input=test[:, 1:], test_target=test[:, 0], max_iter=net_max_iter)
        net.train()

        if net.e_test[-1] < net_best_err:
            net_best = net
            net_best_err = net.e_test[-1]


    # Train and output error
    print 'Minimum test MSE:', str(min(net_best.e_test))