English subtitles

← Kalman Matrices - Artificial Intelligence for Robotics

Get Embed Code
3 Languages

Showing Revision 6 created 04/19/2017 by Udacity Robot.

  1. I have a new, challenging programming assignment for you that will take you a while,
  2. but I would like you to implement a multidimensional Kalman filter for the example
  3. I've just given you.
  4. The matrix class is a class for manipulating matrices that should make it really easy.
  5. It has a function that initializes matrices--I'll show you an example in a second.
  6. It can set them down to 0.
  7. It can compute an identity matrix.
  8. It can print out a matrix with show.
  9. It overloads operators like addition, subtraction,
  10. multiplication, and even computes the transpose of a matrix,
  11. and in some more extended code, it can actually invert a matrix
  12. using Cholesky factorization.
  13. There's a function here called inverse.
  14. This matrix class is available.
  15. It's a small version of what is found in typical libraries.
  16. I want to demonstrate it for you just for a second.
  17. You can make a matrix with a command like this with the argument in the parenthesis.
  18. It's a 2-dimensional matrix.
  19. In this case it's a vertical vector.
  20. With the show command, you can print out the result of the vertical vector.
  21. You can put the transpose as follows.
  22. If you run this, you'll find the horizontal vector.
  23. Say you wish to multiply a matrix by a vector,
  24. then we can make a 2 x 2 matrix with this initialization over here,
  25. a matrix of [12., 8.] and [6., 2.].
  26. We can print this matrix.
  27. Here it is: 12, 8, 6, 2.
  28. These are these values over here.
  29. And it can multiply F and a.
  30. So here b = F * a.
  31. And if we show the result, we get the vector 200 and 80.
  32. That's obtained by 10 x 12 + 10 x 8 is 200.
  33. 10 x 6 + 10 x 2 is 80.
  34. So using my matrix libraries, I set an initial state.
  35. This is a tracking in 1D where the state is the position
  36. and the velocity.
  37. I initialized both with 0 because I don't know the actual location and the velocity.
  38. I give an uncertainty matrix
  39. where I have a really high uncertainty in the position
  40. and a really high uncertainty in the velocity,
  41. and they're both uncorrelated.
  42. That's the matrix of 1000, 0, 0, 1000.
  43. I specify an external motion, but it's 0, 0, so it has no effect,
  44. so just ignore this.
  45. I build the next state function, which is the one we just discussed,
  46. [1., 1] [0, 1.].
  47. That assumes that the velocity is just being added to the position,
  48. and the velocity and expectation stays the same.
  49. I build a measurement function that extracts just the first
  50. of the 2 values, 1 and 0,
  51. so I can observe the location but not the velocity.
  52. I have a measurement uncertainty.
  53. It happens to be 1 in this example.
  54. And I have an identity matrix, [1., 0.] [0., 1.].
  55. And then I run a filter with these 3 measurements over here,
  56. and what should come out is that by running the filter,
  57. I can estimate the velocity
  58. and therefore make better predictions.
  59. In the filter that I want you to program,
  60. I want the measurement update first and then the motion update.
  61. Every time we run the filter,
  62. I want you to update the measurement first, then the motion.
  63. Here is my empty procedure filter that we have to fill in
  64. where I go through our measurements,
  65. and it builds the measurement update and then the motion update,
  66. the prediction, and then I just print out the resulting estimates.
  67. I do this a number of times, 3 times in this case.
  68. Once we fill this in and I hit the Run button,
  69. I get the following output.
  70. After my first measurement update,
  71. I observed the location 1, which gets copied over
  72. essentially to .99 over here.
  73. I learn nothing about the velocity, so it's still 0, just the way I initialized it.
  74. And then there's an updated uncertainty matrix
  75. which now shows what happens to be a strong correlation,
  76. 1000, 1000, 1000, 1000.
  77. That differs from the initial one only that we filled in
  78. the off-diagonal elements.
  79. It happens to be exactly what the Kalman filter does.
  80. And then I'll observe again the 2.
  81. I want the output to now tell me that my next prediction is 3.
  82. It's the observation plus the prediction.
  83. But now I have a really good estimate
  84. on what the velocity is.
  85. It's essentially 1, and the reason is
  86. my Kalman filter was able to use
  87. the Kalman filter equations to find this value.
  88. There's a new covariance matrix,
  89. and for the third observation followed by the prediction,
  90. the prediction is correctly effectively 4, 3.999.
  91. The velocity estimate is correctly 1, which is .99999,
  92. and I have yet another uncertainty matrix which illustrates
  93. that I have a high certainty in the velocity estimate.
  94. Notice a relatively high certainty in the position estimate
  95. compared to my initial uncertainties.
  96. So can you write the the algorithm: 'filter()'
  97. that outputs those exact values over here?
  98. This is an involved programming assignment.
  99. What you have to do is you have to essentially
  100. implement the equations I gave you.
  101. You have to familiarize yourself with the matrix class
  102. and then go and fill in the filter() code
  103. in accordance to the things that I showed you
  104. for the multivariate Kalman filter.