Lesson 1 Localization

蒙特卡洛机器人定位模型

sense 贝叶斯模型

move 全概率公式

localization练习

  1. # The function localize takes the following arguments:
  2. #
  3. # colors:
  4. # 2D list, each entry either 'R' (for red cell) or 'G' (for green cell)
  5. #
  6. # measurements:
  7. # list of measurements taken by the robot, each entry either 'R' or 'G'
  8. #
  9. # motions:
  10. # list of actions taken by the robot, each entry of the form [dy,dx],
  11. # where dx refers to the change in the x-direction (positive meaning
  12. # movement to the right) and dy refers to the change in the y-direction
  13. # (positive meaning movement downward)
  14. # NOTE: the *first* coordinate is change in y; the *second* coordinate is
  15. # change in x
  16. #
  17. # sensor_right:
  18. # float between 0 and 1, giving the probability that any given
  19. # measurement is correct; the probability that the measurement is
  20. # incorrect is 1-sensor_right
  21. #
  22. # p_move:
  23. # float between 0 and 1, giving the probability that any given movement
  24. # command takes place; the probability that the movement command fails
  25. # (and the robot remains still) is 1-p_move; the robot will NOT overshoot
  26. # its destination in this exercise
  27. #
  28. # The function should RETURN (not just show or print) a 2D list (of the same
  29. # dimensions as colors) that gives the probabilities that the robot occupies
  30. # each cell in the world.
  31. #
  32. # Compute the probabilities by assuming the robot initially has a uniform
  33. # probability of being in any cell.
  34. #
  35. # Also assume that at each step, the robot:
  36. # 1) first makes a movement,
  37. # 2) then takes a measurement.
  38. #
  39. # Motion:
  40. # [0,0] - stay
  41. # [0,1] - right
  42. # [0,-1] - left
  43. # [1,0] - down
  44. # [-1,0] - up
  45. def sense(p,colors,measurement,sensor_right):
  46. q=[]
  47. for row in range(len(colors)):
  48. temp=[]
  49. for col in range(len(colors[0])):
  50. hit = (measurement == colors[row][col])
  51. temp.append(p[row][col] * (hit * sensor_right + (1-hit) * (1-sensor_right)))
  52. q.append(temp)
  53. s=0
  54. for row in range(len(q)):
  55. for col in range(len(q[0])):
  56. s += q[row][col]
  57. for row in range(len(p)):
  58. for col in range(len(q[0])):
  59. q[row][col] = q[row][col]/s
  60. return q
  61.  
  62. def move(p, motion, p_move):
  63. q = []
  64. for row in range(len(colors)):
  65. temp=[]
  66. for col in range(len(colors[0])):
  67. s = p_move * p[(row - motion[0]) % len(colors)][(col - motion[1]) % len(colors[0])]
  68. s += (1-p_move) * p[row][col]
  69. temp.append(s)
  70. q.append(temp)
  71. return q
  72.  
  73. def localize(colors,measurements,motions,sensor_right,p_move):
  74. # initializes p to a uniform distribution over a grid of the same dimensions as colors
  75. pinit = 1.0 / float(len(colors)) / float(len(colors[0]))
  76. p = [[pinit for row in range(len(colors[0]))] for col in range(len(colors))]
  77.  
  78. # >>> Insert your code here <<<
  79.  
  80. for k in range(len(motions)):
  81. p = move(p, motions[k],p_move)
  82. p = sense(p,colors,measurements[k],sensor_right)
  83.  
  84. return p
  85.  
  86. def show(p):
  87. rows = ['[' + ','.join(map(lambda x: '{0:.5f}'.format(x),r)) + ']' for r in p]
  88. print '[' + ',\n '.join(rows) + ']'
  89.  
  90. #############################################################
  91. # For the following test case, your output should be
  92. # [[0.01105, 0.02464, 0.06799, 0.04472, 0.02465],
  93. # [0.00715, 0.01017, 0.08696, 0.07988, 0.00935],
  94. # [0.00739, 0.00894, 0.11272, 0.35350, 0.04065],
  95. # [0.00910, 0.00715, 0.01434, 0.04313, 0.03642]]
  96. # (within a tolerance of +/- 0.001 for each entry)
  97.  
  98. colors = [['R','G','G','R','R'],
  99. ['R','R','G','R','R'],
  100. ['R','R','G','G','R'],
  101. ['R','R','R','R','R']]
  102. measurements = ['G','G','G','G','G']
  103. motions = [[0,0],[0,1],[1,0],[1,0],[0,1]]
  104. p = localize(colors,measurements,motions,sensor_right = 0.7, p_move = 0.8)
  105. show(p) # displays your answer

simultaneous adj.同时的

Udacity-Artificial Intelligence for Robotics 课程笔记的更多相关文章

  1. (转)A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers

    A curated list of Artificial Intelligence (AI) courses, books, video lectures and papers. Updated 20 ...

  2. 学习笔记之人工智能(Artificial Intelligence)

    人工智能 - 维基百科,自由的百科全书 https://zh.wikipedia.org/wiki/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD 人工智能(英语:Artif ...

  3. (转) Artificial intelligence, revealed

    Artificial intelligence, revealed Yann LeCunJoaquin Quiñonero Candela It's 8:00 am on a Tuesday morn ...

  4. Andrew 机器学习课程笔记

    Andrew 机器学习课程笔记 完成 Andrew 的课程结束至今已有一段时间,课程介绍深入浅出,很好的解释了模型的基本原理以及应用.在我看来这是个很好的入门视频,他老人家现在又出了一门 deep l ...

  5. EECS 649 Introduction to Artificial Intelligence

    EECS 649 Introduction to Artificial IntelligenceExamElectronic Blackboard Submission Due: April 24, ...

  6. CS231n课程笔记翻译6:神经网络笔记 part1

    译者注:本文智能单元首发,译自斯坦福CS231n课程笔记Neural Nets notes 1,课程教师Andrej Karpathy授权翻译.本篇教程由杜客翻译完成,巩子嘉和堃堃进行校对修改.译文含 ...

  7. 【读书笔记与思考】Andrew 机器学习课程笔记

    Andrew 机器学习课程笔记 完成 Andrew 的课程结束至今已有一段时间,课程介绍深入浅出,很好的解释了模型的基本原理以及应用.在我看来这是个很好的入门视频,他老人家现在又出了一门 deep l ...

  8. Artificial Intelligence in Finance

    https://sigmoidal.io/real-applications-of-ai-in-finance/ Artificial Intelligence is taking the finan ...

  9. Artificial intelligence(AI)

    ORM: https://github.com/sunkaixuan/SqlSugar 微软DEMO: https://github.com/Microsoft/BotBuilder 注册KEY:ht ...

随机推荐

  1. 【测试环境】cywin的简单介绍

    有的时候,单位可能不会这么慷慨给你很多硬件设备供你在任何环境下面都能够工作,但我们有时候需要unix环境,这个时候cywin诞生了... 该工具非常强大,基本上能够满足您的基本需求: 1.安装cywi ...

  2. 利用Azure Automation实现云端自动化运维(4)

    在上述基本准备工作做完后,wo们看看如何实现利用Azure Automation实现定时自动开关机的操作,这种场景非常适合Dev/Test环境,因为Azure的虚拟机是按照分钟收费的,所以我们可以在开 ...

  3. 微软源代码管理工具TFS2013安装与使用图文教程

    微软源代码管理工具TFS2013安装与使用图文教程 这篇文章主要介绍了微软源代码管理工具TFS2013安装与使用图文教程,本文详细的给出了TFS2013的安装配置过程.使用教程,需要的朋友可以参考下 ...

  4. adb 异常报错----adb server is out of date. killing... ADB server didn't ACK * failed to start daemon *

    在Eclipse进行android开发的时候,由于要启动adb,但有时候其他的程序启动会占用adb程序的端口,这时候在对android程序进行调试的时候就会出现报错: 究其原因就是因为其他程序占用了a ...

  5. codec ruby和json格式输出

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat geoip.conf input {stdin {} } filter { geoip { ...

  6. AOP概念

    在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的 ...

  7. 深入理解JavaScript的闭包特性 如何给循环中的对象添加事件(转载)

    原文参考:http://blog.csdn.net/gaoshanwudi/article/details/7355794 初学者经常碰到的,即获取HTML元素集合,循环给元素添加事件.在事件响应函数 ...

  8. UVA - 11020 Efficient Solutions(Multiset)

    本题利用multiset解决.根据题意,如果我们用P(x,y)表示一个人,因为人可以相同,所以用multiset.我们会发现,如果所有人群都是有优势的,那么这些点呈现一个递减的趋势.如果刚刚插入一个人 ...

  9. 三十、Java图形化界面设计——布局管理器之BorderLayout(边界布局)

    边界布局管理器把容器的的布局分为五个位置:CENTER.EAST.WEST.NORTH.SOUTH.依次相应为:上北(NORTH).下南(SOUTH).左西(WEST).右东(EAST),中(CENT ...

  10. XML是什么,它能够做什么?——写给XML入门者

    XML就可以扩展标记语言(eXtensible Markup Language).标记是指计算机所能理解的信息符号,通过此种标记,计算机之间能够处理包括各种信息的文章等.怎样定义这些标记,既能够选择国 ...