本文整理汇总了Python中interpreter.Interpreter.getBotPosition方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.getBotPosition方法的具体用法?Python Interpreter.getBotPosition怎么用?Python Interpreter.getBotPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.getBotPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import getBotPosition [as 别名]
class twodWorld:
def __init__(self):
self.bot = twodBot()
self.intprt = Interpreter(cfg.INITIALSTATE)
self.sensorVal = self.intprt.getInitialSensor()
def update(self):
bot = self.bot
motor = bot.getMotorCommand(self.sensorVal)
# two things happen here: robot receives sensory input; then
# it issues a motor command
self.sensorVal = self.intprt.getSensor(motor)
# similarly, the interpreter executes the motor command; then
# computes the new sensory input for the robot
# self.redraw(self.bot) #GRAPHICS
def redraw(self, bot):
pos = self.intprt.getBotPosition()
bot.x = pos[0]
bot.y = pos[1]
bot.shape.center = (bot.x, bot.y)
# bot.heading = pos[2] #HEADLINE
# x1 = bot.x + bot.radius * np.cos(bot.heading) #HEADLINE
# y1 = bot.y + bot.radius * np.sin(bot.heading) #HEADLINE
# plt.setp(bot.hline,'xdata', (bot.x, x1)) #HEADLINE
# plt.setp(bot.hline,'ydata', (bot.y, y1)) #HEADLINE
def printState(self):
self.intprt.printState()
# return
tree = self.bot.memTree
# error history from memTree
errors = tree.errors[cfg.TRAINING:]
errors1 = self.bot.getErrorHistory1()[cfg.TRAINING:]
fig = plt.figure(2,figsize=(20,9))
# ax1 = fig.add_subplot(211)
avgerrors = [sum(errors[i*10:i*10+9])/10 for i in xrange((cfg.NTICKS-cfg.TRAINING)/10)]
avgerrors1 = [sum(errors1[i*10:i*10+9])/10 for i in xrange((cfg.NTICKS-cfg.TRAINING)/10)]
# plt.plot(errors,'b')
# plt.plot(errors1,'r')
# plt.ylabel("prediction error")
# plt.ylabel("prediction error")
# ax2 = fig.add_subplot(212)
# ax2.axis([0,cfg.NTICKS,-1,3])
# sns0 = tree.sensors[:,0]
# plt.plot(sns0,'r')
# pred0 = tree.predictions[:,0]
# plt.plot(pred0,'b')
plt.plot(avgerrors,'b')
plt.plot(avgerrors1,'r')
plt.ylabel("average error")
testErr = np.mean(errors)
testErrFlat = np.mean(errors1)
print "testing error: {}".format(testErr)
print "flat: {}; ".format(testErrFlat)
def getErrorsPerRun(self):
tree = self.bot.memTree
# error history from memTree
errors = tree.errors[cfg.TRAINING:]
errors1 = self.bot.getErrorHistory1()[cfg.TRAINING:]
return [errors,errors1]
示例2: __init__
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import getBotPosition [as 别名]
class twodWorld:
def __init__(self):
self.bot = twodBot()
self.intprt = Interpreter(cfg.INITIALSTATE)
self.sensorVal = self.intprt.getInitialSensor()
def update(self):
bot = self.bot
motor = bot.getMotorCommand(self.sensorVal)
# two things happen here: robot receives sensory input; then
# it issues a motor command
self.sensorVal = self.intprt.getSensor(motor)
# similarly, the interpreter executes the motor command; then
# computes the new sensory input for the robot
if cfg.GRAPHICS:
self.redraw(self.bot) #GRAPHICS
def redraw(self, bot):
pos = self.intprt.getBotPosition()
bot.x = pos[0]
bot.y = pos[1]
bot.shape.center = (bot.x, bot.y)
# bot.heading = pos[2] #HEADLINE
# x1 = bot.x + bot.radius * np.cos(bot.heading) #HEADLINE
# y1 = bot.y + bot.radius * np.sin(bot.heading) #HEADLINE
# plt.setp(bot.hline,'xdata', (bot.x, x1)) #HEADLINE
# plt.setp(bot.hline,'ydata', (bot.y, y1)) #HEADLINE
def printState(self):
self.intprt.printState()
# return
tree = self.bot.memTree
# error history from memTree
errors = tree.errors
errors1 = self.bot.getErrorHistory1()
# minErrors = self.intprt.getErrors()
fig = plt.figure(2,figsize=(20,9))
avgerrors = [sum(errors[i*50:i*50+49])/50 for i in xrange((cfg.NTICKS)/50)]
avgerrors1 = [sum(errors1[i*50:i*50+49])/50 for i in xrange((cfg.NTICKS)/50)]
# avgerrorsMin = [sum(minErrors[i*50:i*50+49])/50 for i in xrange((cfg.NTICKS)/50)]
plt.plot(avgerrors,'b')
plt.plot(avgerrors1,'r')
# plt.plot(avgerrorsMin,'g')
plt.ylabel("average error")
Err = np.mean(errors[cfg.TRAINING:])
ErrFlat = np.mean(errors1[cfg.TRAINING:])
# ErrMin = np.mean(minErrors[cfg.TRAINING:])
print "testing error: {}".format(Err)
print "flat: {}; ".format(ErrFlat)
# print "minimum: {}; ".format(ErrMin)
def getErrorsPerRun(self):
tree = self.bot.memTree
# error history from memTree
errors = tree.errors
errors1 = self.bot.getErrorHistory1()
# errorsM = self.intprt.getErrors()
return [errors,errors1]
def getFootPrint(self):
return self.intprt.getFootPrint()