本文整理汇总了Python中brain.Brain.getBins方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.getBins方法的具体用法?Python Brain.getBins怎么用?Python Brain.getBins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.getBins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import getBins [as 别名]
class AI:
def __init__(self, inputFile=False, trainMode=False, realtimeMode=False, loadNeuralNetwork=False):
# Object variables for initialisation
self.inputFile = inputFile
self.trainMode = trainMode
self.realtimeMode = realtimeMode
self.loadNeuralNetwork = loadNeuralNetwork
self.neuralNet = FeedForwardNetwork()
inLayer = LinearLayer(7)
hiddenLayer = SigmoidLayer(5)
outLayer = LinearLayer(1)
self.neuralNet.addInputModule(inLayer)
self.neuralNet.addModule(hiddenLayer)
self.neuralNet.addOutputModule(outLayer)
self.neuralNet.addConnection(FullConnection(inLayer, hiddenLayer))
self.neuralNet.addConnection(FullConnection(hiddenLayer, outLayer))
self.neuralNet.sortModules()
DEBUG("Neural Network:")
DEBUG(self.neuralNet)
DEBUG("--------")
if self.loadNeuralNetwork:
self.neuralNet = NetworkReader.readFrom("lastNetwork.xml")
if self.inputFile:
if not os.path.exists(inputFile):
print "File for CSV parsing does not exist!"
return
savedData = self.readCSVData(self.inputFile)
# train upon the given data
if self.trainMode:
ds = self.makeTrainingSet(savedData)
for inpt, target in ds:
DEBUG("Input Values from training:")
DEBUG(inpt)
DEBUG("Correction factor from training:")
DEBUG(target)
trainer = BackpropTrainer(self.neuralNet, ds, verbose=True)
trainer.trainUntilConvergence(maxEpochs=10)
self.printGraph(ds)
NetworkWriter.writeToFile(self.neuralNet, "lastNetwork.xml")
# read the saved data and use it in the network
for line in savedData:
DEBUG("Used Data: ")
DEBUG(line)
result = self.neuralNet.activate(line)
DEBUG(result)
DEBUG("Final weigths:")
DEBUG(self.neuralNet.params)
# now fun begins. this is the standard mode this module runs in.
if self.realtimeMode:
print "We should start now!"
self.brain = Brain()
if os.path.isfile("lastNetwork.xml"):
while True:
lines = self.brain.getBins()
print (lines)
else:
# we do a realtime training of the neural network
print "No trained network exists!"
time.sleep(1)
print "Will do on-line training!"
time.sleep(1)
print "Hold tight for 10 seconds"
tempBinWriter = csv.writer(open("temp.csv", "ab"))
for i in range(1, 10):
time.sleep(1)
bins = self.brain.getBins()
print bins
tempBinWriter.writerow(bins)
tempSavedData = self.readCSVData("temp.csv")
ds = self.makeTrainingSet(tempSavedData)
trainer = BackpropTrainer(self.neuralNet, ds, verbose=True)
trainer.trainUntilConvergence(maxEpochs=10)
def getRandomness(self):
if self.realtimeMode:
bins = self.brain.getBins()
rand = 1
for i in range(7):
rand *= bins[i] * 100
return rand
def getNeuralResult(self):
return self.neuralNet.activate(self.brain.getBins())
def makeTrainingSet(self, savedData):
# init a dataset with seven input and one output value
#.........这里部分代码省略.........