Assignment Matrix Decomposition
-
Upload
noyeem-mahbub -
Category
Documents
-
view
223 -
download
0
Transcript of Assignment Matrix Decomposition
-
7/26/2019 Assignment Matrix Decomposition
1/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 1/9
[WS14/15] Mathematics for Robotics and Control:Assignment 004 - Matrix decomposition
First we will setup this notebook so that figures and plots can be shown in the notebook page.
In [93]:
Hint: Before you start solving the assignment, you might want to check the following numpy functions:
numpy.linalg.svd
Covariance matrix properties
Write a mathematically sound proof for each of the following properties of the covariance matrix:
1) That for a given matrix , where is the number of observations and is the number of
variables, the expression
yields the covariance matrix.
2) Under which conditions taking does the eigendecomposition of a matrix yield an orthonormal basis,
and for which vector space.
X
( ) ( )
1
N 1
try: shell = get_ipython() shell.enable_pylab("inline")exceptNameError: passimportnumpy.linalg asLA
importnumpyimportmatplotlibfrommatplotlib importpylab, mlab, pyplotnp = numpyplt = pyplotfromIPython.display importdisplayfromIPython.core.pylabtools importfigsize, getfigsimportIPythonfrompylab import*fromnumpy import*
-
7/26/2019 Assignment Matrix Decomposition
2/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 2/9
3) When applying Principal Components Analysis, each eigenvector points into the direction of one the
dataset's principal components and how much do the component contribute to the overall variance is
related to each eigenvector's eigenvalue.
Fitting lines to point clouds
Read this article about least squares fitting (http://mathworld.wolfram.com/LeastSquaresFitting.html).
Read this lecture about linear least squares and matrix decompositions
(http://classes.soe.ucsc.edu/cmps290c/Spring04/paps/lls.pdf). For all of the following fitting tasks,
use a singular value decomposition to fit a pair of lines to each of the given point clouds.
Detecting a hallway
The robot is driving in a hallway when it starts its Kinect obtaining the following ploint cloud.
http://classes.soe.ucsc.edu/cmps290c/Spring04/paps/lls.pdfhttp://mathworld.wolfram.com/LeastSquaresFitting.html -
7/26/2019 Assignment Matrix Decomposition
3/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 3/9
In [94]:
Out[94]:
importIPythonIPython.core.display.Image("images/hallway.png", embed=True)
-
7/26/2019 Assignment Matrix Decomposition
4/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 4/9
In [95]:
Your task is to fit a pair lines based on the points generated by the robot's Kinect.
%matplotlib inlineimportmatplotlib.pyplot asplt
defmatrix_calculation(filename):
line = np.load(filename)
x= line[:,0] y = line[:,1] A = np.column_stack((x, np.ones(len(x)))) m,c = svd_solver(A,y) returnx,m,c # x, y, m, c = matrix_calculation('data/Q1.npy') # print y
defplotting(line, halt): # to plotting the data from matrix calculation
plt.title('Scatter plot') #plotting the values of x, m, c plt.plot(line[0], line[1]*line[0] +line[2] , 'r', label = ' Fitted line d #plt.plot(x2, m1*x2+c1, 'r', label = ' Fitted line data')
plt.hold(halt)
ifnothalt: plt.legend() plt.show()
defsvd_solver(A, b): U,s,V= (LA.svd(A)) #print U.shape, s.shape, V.shape
#U = np.matrix(U),V inv = np.dot((V.T).dot(np.diag(s**(-1))), U[:,:2].T) #print inv x = np.dot(inv,b) #print x
returnx
-
7/26/2019 Assignment Matrix Decomposition
5/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 5/9
In [96]:
In [97]:
Detecting a corner
At the end of the hallway the robot detects a dramatic change in the point cloud.
defcompute_parallel_lines(first_line, second_line): plotting(first_line, True) plotting(second_line, False)
first_line=matrix_calculation('data/P1.npy')
second_line = matrix_calculation('data/Q1.npy')compute_parallel_lines(first_line,second_line)
-
7/26/2019 Assignment Matrix Decomposition
6/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 6/9
In [98]:
Your task is to fit a pair lines based on the points generated by the robot's Kinect.
In [99]:
Out[98]:
importIPythonIPython.core.display.Image("images/corner.png", embed=True)
defcompute_perpendicular_lines(first_line, second_line): plotting(first_line, True) plotting(second_line, False)
-
7/26/2019 Assignment Matrix Decomposition
7/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 7/9
In [100]:
Detecting a table
When the robot turns at a table near by the point cloud it receives is the following.
first_line=matrix_calculation('data/Q1.npy')
second_line = matrix_calculation('data/Q2.npy')compute_perpendicular_lines(first_line,second_line)
-
7/26/2019 Assignment Matrix Decomposition
8/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 8/9
In [101]:
In [102]:
Out[101]:
importIPythonIPython.core.display.Image("images/rectangle.png", embed=True)
defcompute_rectangle_lines(first_line, second_line, third_line, fourth_line): plotting(first_line, True) plotting(second_line, True) plotting(third_line, True) plotting(fourth_line, False)
-
7/26/2019 Assignment Matrix Decomposition
9/9
4/25/2016 assignment_matrix_decomposition-Copy2
http://localhost:8888/notebooks/Downloads/Lecture%202nd%20semester/MRC/%5B004%5D%20Applications%20of%20Singular 9/9
In [103]:
first_line=matrix_calculation('data/P2.npy')second_line = matrix_calculation('data/S2.npy')third_line = matrix_calculation('data/R2.npy')fourth_line=matrix_calculation('data/Q2.npy')
compute_rectangle_lines(first_line, second_line, third_line, fourth_line)