本文整理汇总了Python中neuralnet.NeuralNet.learnFromExample方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNet.learnFromExample方法的具体用法?Python NeuralNet.learnFromExample怎么用?Python NeuralNet.learnFromExample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neuralnet.NeuralNet
的用法示例。
在下文中一共展示了NeuralNet.learnFromExample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NNPlayer
# 需要导入模块: from neuralnet import NeuralNet [as 别名]
# 或者: from neuralnet.NeuralNet import learnFromExample [as 别名]
#.........这里部分代码省略.........
for op in oppSide:
state.append(float(op))
return state
def gameOver(self, myScore, oppScore):
""" notifies learner that the game is over,
update the Q function based on win or loss and the move list """
if not self.learn:
return
reward = float(myScore) - float(oppScore)
self.movelist[self.id].append(reward)
self._updateGameRecord(self.movelist[self.id])
self.movelist[self.id] = []
self._learnFromGameRecord()
def _learnFromGameRecord(self):
for i in self.recentGames:
self._learnFromGame(self.recentGames[i])
def _learnFromGame(self, movelist):
reward = float(movelist[-1])
# update Q function
sap = movelist[-2]
state = sap.state
action = sap.action
example = []
example.append(float(action))
example.extend(state[:self.inputSize-1])
oldQ = self.Q.calculate(example)
newQ = float((1.0 - self.alpha) * oldQ + self.alpha * reward)
self.Q.learnFromExample(example, newQ)
nextState = state[:]
nextAction = action
nextExample = example[:]
for i in range(3, len(movelist)):
sap = movelist[len(movelist)-i]
reward = sap.reward
state = sap.state
action = sap.action
example = []
example.append(float(action))
example.extend(state[:self.inputSize-1])
# find expected rewards
qVals = []
for i in range(self.rowSize):
nextExample[0] = float(i)
qVals[i] = self.Q.calculate(nextExample)
maxVal = max(qVals)
oldQ = self.Q.calculate(example)
newQ = float((1.0 - self.alpha) * oldQ + self.alpha * (reward + self.discount * maxVal))
self.Q.learnFromExample(example, newQ)
def _updateGameRecord(self, moves):
""" updates statistics """
while len(self.recentGames) > self.numRecent:
del self.recentGames[0]
self.recentGames.extend(moves)