def get_net_prediction(train_data,
                       train_truth,
                       test_data,
                       test_truth,
                       hidden=(5, ),
                       weight_decay=0.0,
                       dropout_prob=0.0,
                       learning_rate=None,
                       epochs=25,
                       verbose=False,
                       iter_id=None):

    container = NeuralNetContainer()
    container.learning_rate = learning_rate
    container.dropout_prob = dropout_prob
    container.weight_decay = weight_decay
    container.epochs = epochs
    container.hidden_layers = hidden
    container.verbose = verbose
    container.plot = get_should_plot()

    mms = MinMaxScaler(feature_range=(-1, 1))  # Scale output from -1 to 1.
    train_y = mms.fit_transform(train_truth[:, np.newaxis])

    n_features = train_data.shape[1]

    collect_time_stats = get_is_time_stats()
    if collect_time_stats:
        start = time.time()

    # Find and return an effectively initialized network to start.
    container = _get_initial_net(container, n_features, train_data, train_y)

    # Train the network.
    if collect_time_stats:
        # Train a specific time, never terminating early.
        _train_net(container,
                   train_data,
                   train_y,
                   override_epochs=TIMING_EPOCHS,
                   is_check_train=False)
    else:
        # Normal training, enable all heuristics.
        _train_net(container, train_data, train_y)

    if collect_time_stats:
        end = time.time()
        print('Fitting took {} seconds'.format(end - start))
        print(
            json.dumps({
                'seconds': end - start,
                'hidden': container.hidden_layers
            }))

    # Unsupervised (test) dataset.
    predicted = _predict(container, test_data)
    predicted = mms.inverse_transform(predicted)

    return predicted.ravel()
Exemple #2
0
def main():
    params = { 'hidden': HIDDEN 
             , 'epochs'    : (EPOCHS,)
             }

    backend = PARALLEL_BACKEND
    if get_is_on_gpu() or get_is_time_stats() or get_should_plot():
        backend = SINGLE_CORE_BACKEND

    run_optimization( get_net_prediction, params, 'optimal_nn.shelf', 'N'
                    , sample_size_multiplier=DOUBLE_MULTIPLIER
                    , backend=backend, retry_nans=True)
def main():
    params = { 'hidden': HIDDEN 
             , 'dropout_prob': DROPOUT 
             , 'weight_decay': WEIGHT_DECAY 
             , 'epochs': (EPOCHS,)
             }

    backend = PARALLEL_BACKEND
    if get_is_on_gpu() or get_is_time_stats() or get_should_plot():
        backend = SINGLE_CORE_BACKEND

    run_optimization(get_net_prediction, params, 'optimal_wddonn.shelf', 'NWDDO', backend=backend, retry_nans=True)
def get_net_prediction( train_data, train_truth, test_data, test_truth
                      , hidden=(5,), weight_decay=0.0, dropout_prob=0.0
                      , learning_rate=None, epochs=25, verbose=False
                      , iter_id=None
                      ):

    container = NeuralNetContainer()
    container.learning_rate = learning_rate
    container.dropout_prob = dropout_prob
    container.weight_decay = weight_decay
    container.epochs = epochs
    container.hidden_layers = hidden
    container.verbose = verbose
    container.plot = get_should_plot()

    mms = MinMaxScaler(feature_range= (-1, 1)) # Scale output from -1 to 1.
    train_y = mms.fit_transform(train_truth[:,np.newaxis])

    n_features = train_data.shape[1]

    collect_time_stats = get_is_time_stats()
    if collect_time_stats: 
        start = time.time()

    # Find and return an effectively initialized network to start.
    container = _get_initial_net(container, n_features, train_data, train_y)

    # Train the network.
    if collect_time_stats:
        # Train a specific time, never terminating early.
        _train_net(container, train_data, train_y, override_epochs=TIMING_EPOCHS, is_check_train=False)
    else: 
        # Normal training, enable all heuristics.
        _train_net(container, train_data, train_y)

    if collect_time_stats: 
        end = time.time()
        print('Fitting took {} seconds'.format(end - start))
        print(json.dumps({'seconds': end - start, 'hidden': container.hidden_layers}))

    # Unsupervised (test) dataset.
    predicted = _predict(container, test_data)
    predicted = mms.inverse_transform(predicted)
    
    return predicted.ravel()