Lesson 1 Localization

蒙特卡洛机器人定位模型

sense 贝叶斯模型

move 全概率公式

localization练习

 # The function localize takes the following arguments:
 #
 # colors:
 #        2D list, each entry either 'R' (for red cell) or 'G' (for green cell)
 #
 # measurements:
 #        list of measurements taken by the robot, each entry either 'R' or 'G'
 #
 # motions:
 #        list of actions taken by the robot, each entry of the form [dy,dx],
 #        where dx refers to the change in the x-direction (positive meaning
 #        movement to the right) and dy refers to the change in the y-direction
 #        (positive meaning movement downward)
 #        NOTE: the *first* coordinate is change in y; the *second* coordinate is
 #              change in x
 #
 # sensor_right:
 #        float between 0 and 1, giving the probability that any given
 #        measurement is correct; the probability that the measurement is
 #        incorrect is 1-sensor_right
 #
 # p_move:
 #        float between 0 and 1, giving the probability that any given movement
 #        command takes place; the probability that the movement command fails
 #        (and the robot remains still) is 1-p_move; the robot will NOT overshoot
 #        its destination in this exercise
 #
 # The function should RETURN (not just show or print) a 2D list (of the same
 # dimensions as colors) that gives the probabilities that the robot occupies
 # each cell in the world.
 #
 # Compute the probabilities by assuming the robot initially has a uniform
 # probability of being in any cell.
 #
 # Also assume that at each step, the robot:
 # 1) first makes a movement,
 # 2) then takes a measurement.
 #
 # Motion:
 #  [0,0] - stay
 #  [0,1] - right
 #  [0,-1] - left
 #  [1,0] - down
 #  [-1,0] - up
 def sense(p,colors,measurement,sensor_right):
     q=[]
     for row in range(len(colors)):
         temp=[]
         for col in range(len(colors[0])):
             hit = (measurement == colors[row][col])
             temp.append(p[row][col] * (hit * sensor_right + (1-hit) * (1-sensor_right)))
         q.append(temp)
     s=0
     for row in range(len(q)):
         for col in range(len(q[0])):
             s += q[row][col]
     for row in range(len(p)):
         for col in range(len(q[0])):
             q[row][col] = q[row][col]/s
     return q

 def move(p, motion, p_move):
     q = []
     for row in range(len(colors)):
         temp=[]
         for col in range(len(colors[0])):
             s = p_move * p[(row - motion[0]) % len(colors)][(col - motion[1]) % len(colors[0])]
             s += (1-p_move) * p[row][col]
             temp.append(s)
         q.append(temp)
     return q

 def localize(colors,measurements,motions,sensor_right,p_move):
     # initializes p to a uniform distribution over a grid of the same dimensions as colors
     pinit = 1.0 / float(len(colors)) / float(len(colors[0]))
     p = [[pinit for row in range(len(colors[0]))] for col in range(len(colors))]

     # >>> Insert your code here <<<

     for k in range(len(motions)):
         p = move(p, motions[k],p_move)
         p = sense(p,colors,measurements[k],sensor_right)

     return p

 def show(p):
     rows = ['[' + ','.join(map(lambda x: '{0:.5f}'.format(x),r)) + ']' for r in p]
     print '[' + ',\n '.join(rows) + ']'

 #############################################################
 # For the following test case, your output should be
 # [[0.01105, 0.02464, 0.06799, 0.04472, 0.02465],
 #  [0.00715, 0.01017, 0.08696, 0.07988, 0.00935],
 #  [0.00739, 0.00894, 0.11272, 0.35350, 0.04065],
 #  [0.00910, 0.00715, 0.01434, 0.04313, 0.03642]]
 # (within a tolerance of +/- 0.001 for each entry)

 colors = [['R','G','G','R','R'],
           ['R','R','G','R','R'],
           ['R','R','G','G','R'],
           ['R','R','R','R','R']]
 measurements = ['G','G','G','G','G']
 motions = [[0,0],[0,1],[1,0],[1,0],[0,1]]
 p = localize(colors,measurements,motions,sensor_right = 0.7, p_move = 0.8)
 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. Square Coins(母函数)

    Square Coins 点我 Problem Description People in Silverland use square coins. Not only they have square ...

  2. TCP协议: SYN ACK FIN RST PSH URG 详解

    TCP的三次握手是怎么进行的了:发送端发送一个SYN=1,ACK=0标志的数据包给接收端,请求进行连接,这是第一次握手:接收端收到请求并且允许连接的话,就会发送一个SYN=1,ACK=1标志的数据包给 ...

  3. oracle表空间使用率统计查询

    今天发现有一张采样表从1月5号开始不记录数据了,所以想查看一下表空间使用率,在网上零零散散找了很多资料,现在记录如下,也不知道哪一个最准确.还有一个就是网上拷贝的sql代码格式太乱了,不好看,找到一个 ...

  4. 从setTimeout到浏览器线程机制

    看高性能javascipt 这本书时,看到这么一句话: Putting scripts at the top of the page in this way typically leads to a ...

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

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

  6. javascript数据类型、初始化

    Javascript数据类型有6种: 数值型数据类型(Number): 字符串(String): 布尔型数据(Boolean): 对象数据(Object): 空(Null): 未定义(Undefine ...

  7. 杭电oj 3361

    Tips:字符在计算机中都是以ASCII码形式保存,直接以char形式输出ASCII码即可. #include<stdio.h> int main() { int T; scanf(&qu ...

  8. java反射 实例

    首先介绍几个概念: 1.Java反射的概念 反射含义:可以获取正在运行的Java对象. 2.Java反射的功能 1)可以判断运行时对象所属的类 2)可以判断运行时对象所具有的成员变量和方法 3)通过反 ...

  9. Android使用Google推荐的联网框架Volley,让连接网络更加简单

    大家好.随着技术的进步.科技的发达,非常少有应用是单机的了,大部分都须要联网訪问server,曾经我们都用 httpclient和httpurlconnection,感觉是不是非常麻烦,而Google ...

  10. 一个loader加载多个swf

    var _swfLoader:Loader; var _swfRequest:URLRequest; var _swfPathArr:Array = new Array("00.swf&qu ...