本文整理汇总了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))
示例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())
示例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()