当前位置: 首页>>代码示例>>Python>>正文


Python NN.main方法代码示例

本文整理汇总了Python中NN.main方法的典型用法代码示例。如果您正苦于以下问题:Python NN.main方法的具体用法?Python NN.main怎么用?Python NN.main使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NN的用法示例。


在下文中一共展示了NN.main方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start_thread

# 需要导入模块: import NN [as 别名]
# 或者: from NN import main [as 别名]
def start_thread(inp, activation, out_activ, outp, learn, thresh, mmntm, logger):
    global count
    training_inputs = []
    training_data = []
    count += 1
    print(out_activ)
    testNN = NN.main(inp, activation, out_activ, outp, learn, thresh, mmntm)
    print("DONE TRAINING")
    for i in inp:
        for j in i:
            training_inputs.append(random.randint(0, 4))  # create random inputs for testing
        training_data.append(training_inputs)
        training_inputs = []
    logger.info("ACTIVATION SET: ")
    logger.info(activation)
    logger.info("OUTPUT ACTIVATION: %s" % out_activ)
    logger.info("TESTING INPUT: ")
    logger.info(training_data)
    logger.info("OUTPUT: ")
    for x in training_data:
        testNN.SetStartingNodesValues(x)
        testNN.CalculateNNOutputs()
        logger.info(str(x))
        logger.info(testNN.GetNNResults())
        logger.info("RB OUTPUT: %s" % rb_test.rb_test(x))
开发者ID:Keydrain,项目名称:CSCI447-2015,代码行数:27,代码来源:2-1-handler.py

示例2: start_thread

# 需要导入模块: import NN [as 别名]
# 或者: from NN import main [as 别名]
def start_thread(inp, activation, out_activ, outp, learn, thresh, mmntm, logger):
    global count
    training_inputs = []
    training_data = []
    count += 1
    
    testNN = NN.main(inp, activation, out_activ, outp, learn, thresh, mmntm)
    print ("DONE TRAINING")
    for i in inp:
        for j in i:
            training_inputs.append(random.randint(0,4)) #create random inputs for testing
        training_data.append(training_inputs)
        training_inputs = []
    for x in training_data:
        testNN.SetStartingNodesValues(x)
        testNN.CalculateNNOutputs()
        logger.info(str(x))
        logger.info(testNN.GetNNResults())
开发者ID:Keydrain,项目名称:CSCI447-2015,代码行数:20,代码来源:handler_NN.py

示例3: train_test

# 需要导入模块: import NN [as 别名]
# 或者: from NN import main [as 别名]
def train_test():
    global cRate, mRate, threshold, generations, size, participants, victors, inFile, algo, dataset, resultsFile
    inputs = []
    outputs = []
    evolve()
    
    resultsFile.write("DATASET: " + dataset + "\n")
    #resultsFile.write("ALGORITHM | Generations | Size | Participants | Victors | mRate | cRate | Threshold \n")
    #resultsFile.write("   " + str(algo) + "      |     " + str(generations) + "      |  " +
    #          str(size) + "  |     " + str(participants) + "       |    " + str(victors) + 
    #          "    |  " + str(mRate) + "  |  " + str(cRate) + "  |   " + str(threshold) + "     \n")

    dataIn = dataHandler()
    inputs = dataIn[0]
    outputs = dataIn[1]
    testInput = []
    testOutput = []
    learnrate = 0.3
    momentum = 0.5
    # Need 20% of inputs for testing
    for i in range((int(len(inputs)*0.8)+1), len(inputs)):
        x = random.choice(inputs)
        testInput.append(x)
        testOutput.append(outputs[inputs.index(x)])
        del outputs[inputs.index(x)]
        del inputs[inputs.index(x)]
    resultsFile.write("\nTest inputs: \n")
    for i in range(len(testInput)):
        resultsFile.write("%s " % testInput[i])
    resultsFile.write("\nTest expected outputs: \n")
    for i in range(len(testOutput)):
        resultsFile.write("%s " % testOutput[i])
    # Which algorithm gets chosen to run
    if algo in 'G':
        print("DOING GA TRAINING...")
        resultsFile.write("\nALGORITHM | Generations | Size | Participants | Victors | mRate | cRate | Threshold \n")
        resultsFile.write("   " + str(algo) + "      |     " + str(generations) + "      |  " + str(size) + "  |     " + str(participants) + "       |    " + str(victors) + "    |  " + str(mRate) + "  |  " + str(cRate) + "  |   " + str(threshold) + "     \n")
        testNN = GA.train(inputs, outputs, size, participants, victors, generations, threshold, cRate, mRate)
    elif algo in 'E':
        print("DOING ES TRAINING...")
        resultsFile.write("\nALGORITHM | Generations | Size | Participants | Victors | mRate | cRate | Threshold \n")
        resultsFile.write("   " + str(algo) + "      |     " + str(generations) + "      |  " + str(size) + "  |     " + str(participants) + "       |    " + str(victors) + "    |  " + str(mRate) + "  |  " + str(cRate) + "  |   " + str(threshold) + "     \n")
        testNN = ES.train(inputs, outputs, size, participants, victors, generations, threshold, cRate, mRate)
    elif algo in 'D':
        print("DOING DE TRAINING...")
        resultsFile.write("\nALGORITHM | Generations | Size | mRate | cRate | Threshold \n")
        resultsFile.write("   " + str(algo) + "      |     " + str(generations) + "      |  " +  str(size) + "    |  " + str(mRate) + "  |  " + str(cRate) + "  |   " + str(threshold) + "     \n")
        testNN = DE.train(inputs, outputs, size, generations, threshold, cRate, mRate)
    elif algo in 'B':
        print("DOING BP TRAINING...")
        resultsFile.write("\nALGORITHM | Generations | learnrate | momentum | Threshold \n")
        resultsFile.write("   " + str(algo) + "      |     " + str(generations) + "      |  " + str(learnrate) + "  |  " + str(momentum) + "  |   " + str(threshold) + "     \n")
        testNN = NN.main(inputs, [['S','S','S'], ['S','S']], ['S'], outputs, generations, learnrate, threshold, momentum)
    else:
        print("Unrecognized algorithm!")
        sys.exit()
    # Print test input/expected output - could be made prettier in a table
    # Start testing testNN
    for x in testInput:
        resultsFile.write("\nSet starting node vals\n")
        resultsFile.write("%s \n" % testNN.SetStartingNodesValues(x))
        testNN.CalculateNNOutputs()
        resultsFile.write("\nTest Input: " + str(x) + "\n")
        resultsFile.write("\nTest results: %s\n" % testNN.GetNNResults())
    resultsFile.write("\nRelative Error: {:2.2%} \n".format(NN.calcRelativeError(testNN, testInput, testOutput)))
    resultsFile.write("\nLeast Squares Error: %s \n" % NN.calcLeastSquaresError(testNN, testInput, testOutput))
    resultsFile.write("\nLoss Squared Error: %s \n" % NN.calcLossSquared(testNN, testInput, testOutput))
    resultsFile.write("\nPercent Misidentified: {:2.2%} \n".format(NN.calcPercentIncorrect(testNN, testInput, testOutput)))
    resultsFile.close()
开发者ID:Keydrain,项目名称:CSCI447-2015,代码行数:71,代码来源:handler.py


注:本文中的NN.main方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。