Esempio n. 1
0
def cycleTesting2Layer(stock,
                       length,
                       lrs,
                       activations,
                       nodes,
                       epoch,
                       batches,
                       saveName,
                       saveBase,
                       reshape=False):

    # Obtain the stock data
    (train_d, train_t, test_d,
     test_t) = sf.getInputData(stock, length, reshape)

    result = 0
    bestResult = 0
    count = 1
    totalRuns = len(lrs) * len(activations) * len(nodes) * len(batches) * len(
        nodes)
    startTime = time.time()
    for lr in lrs:
        for func in activations:
            for depth in nodes:
                for depth1 in nodes:
                    for mbs in batches:
                        func1 = func
                        sf.printProgress2(startTime, count, totalRuns, lr,
                                          func, func1, depth, depth1, mbs,
                                          length, result, bestResult)
                        count += 1
                        model = tflearn.DNN(
                            ann_two_level(length, (depth, depth1), lr,
                                          (func, func1)))
                        model.fit(train_d,
                                  train_t,
                                  n_epoch=epoch,
                                  shuffle=False,
                                  validation_set=(test_d, test_t),
                                  show_metric=False,
                                  batch_size=mbs)
                        result = test_model2(model, length, test_d, test_t)
                        if result > bestResult:
                            bestResult = result
                            bestLr = lr
                            bestFunc = func
                            bestFunc1 = func1
                            bestDepth = depth
                            bestDepth1 = depth1
                            bestMBS = mbs
                            sf.writeFile2Level(length, epoch, bestResult,
                                               bestLr, bestFunc, bestFunc1,
                                               bestDepth, bestDepth1, bestMBS,
                                               saveName, saveBase)
                            model.save(saveBase + 'nets/ann/twoLayer/' +
                                       saveName + '.pck')
                        tf.reset_default_graph()
Esempio n. 2
0
def confirmTestingAccuracy(stock, netStyle, netName, layers):

    # Load network parameters.
    (netStyle, memory, lr, funcs,
     depths) = sf.load("results/" + netStyle + "/" + sf.intToString(layers) +
                       "Level/" + netName + ".pck")

    # Obtain the data.
    data = sf.getInputData(stock, memory, netStyle == 'conv')

    # Build the network and make a prediction.
    network = getPredictionNet(netName, netStyle, layers, memory, lr, funcs,
                               depths)
    accuracy = test_model2(network, memory, data[2], data[3],
                           netStyle == 'conv')
    tf.reset_default_graph()
    return accuracy
Esempio n. 3
0
def train_net(stock,
              length,
              netStyle,
              epoch,
              mbs,
              lr,
              funcs,
              depths,
              saveName,
              saveBase,
              reshape=False):

    # Make the network build
    build = getTrainingBuild(netStyle, length, lr, depths, funcs)

    # Obtain the stock data
    (train_d, train_t, test_d,
     test_t) = sf.getInputData(stock, length, reshape)

    # Build and train the network
    model = tflearn.DNN(build)
    model.fit(train_d,
              train_t,
              n_epoch=epoch,
              shuffle=False,
              validation_set=(test_d, test_t),
              show_metric=True,
              batch_size=mbs)
    tf.reset_default_graph()

    # Save the network and other training files.
    model.save('nets/' + netStyle + '/' + sf.intToString(len(funcs)) +
               'Layer/' + saveName + '.pck')
    sf.chooseFileWriter(length, netStyle, epoch,
                        test_model2(model, length, test_d, test_t, reshape),
                        lr, funcs, depths, mbs, saveName, saveBase)