CompetencyIn this project, you will demonstrate your mastery of the following competencies:Interpret the properties of vector spacesUtilize advanced matrix techniques to solve complex linear...

1 answer below »

Competency




In this project, you will demonstrate your mastery of the following competencies:





  • Interpret the properties of vector spaces

  • Utilize advanced matrix techniques to solve complex linear problems




Scenario




You are employed as a computer programmer for a popular social media

site that stores a large amount of user media files. You believe you

have found a way to reduce costs by compressing image files using

singular-value decomposition (SVD). The compressed files would require

less storage space, which would result in savings for the company. You

think it will work, but you want to test your theory and record the

steps you take to use as a reference when sharing your idea with

management.




Directions




In order to guarantee that management fully understands the process,

you have mapped out the following steps to ensure you have captured the

process and have data to support your findings and to share with

management. Your plan is to demonstrate computations on a simple 3 x 3

matrix where the computations are easier to follow. Then you will

perform similar computations on a large image to compress the image data

without significantly degrading image quality.




To develop your idea proposal, work the problems described below. As

you complete each part, make sure to show your work and carefully

describe how you arrive at your final answer. Any MATLAB code or MATLAB

terminal outputs you generate should be included in your idea proposal

to support your answers and work.




MAT 350 Project Two SVD and Image Compression Overview SVD and Image Compression Overview Consider the matrix with entries represented by “one-byte” integers. One byte equals 8 bits of information, so each value in the matrix is represented by an integer in the range from 0 to 255. Since each matrix entry requires one byte of storage, the total matrix requires bytes of storage space. The singular value decomposition (SVD) can be used to compute an orthogonal decomposition of a matrix. Given the matrix , the SVD can be used to decompose the matrix as , where is an orthogonal matrix, is an orthogonal matrix, and is a rectangular diagonal matrix whose diagonal contains the singular values of . This representation is very similar to the eigenvalue diagonalization (called eigendecomposition) already studied in the course. However, a primary difference between SVD and eigendecomposition is that SVD can be used for rectangular matrices, while eigendecomposition can be used only on square matrices. SVD can be used to construct a low-rank approximation of the original matrix. If only the first singular values are used, then can be approximated by the matrix defined as: where is a matrix containing the first columns of , is a matrix containing the first rows and columns of , and is a matrix containing the first columns of . Observe that this approximation essentially throws away all of the information stored in the dimensions and higher. After computing the image approximation, we must be careful to make sure that the approximation has the correct data format. Each value in the matrix must be an unsigned 8-bit integer data type. Since the approximation now likely has real-valued quantities in it, we will round these entries to the closest integer and then cast the data type to an integer. This allows the image to be properly displayed in software programs such as MATLAB. So, after computing , we’ll typically execute a command similar to the following: Ak = uint8(round(Ak)) The matrix has a total of entries that must be stored. Since is a diagonal matrix, only its diagonal elements need to be stored. The matrix has entries that must be stored. Thus, the total number of values to store for the low-rank matrix is . Compared to the original storage requirement of , using only singular values to approximate with achieves a compression ratio of To provide a specific example, if , , and , this would result in a compression ratio of While the low-rank approximation can require significantly less storage space than the original matrix, it is an approximation that in general is not equal to the original matrix. To quantify the error between and , we can compute the root mean square error as: The matrix norm above is the Frobenius norm, which is defined as the square root of the sum of absolute squares of its elements. In general, the RMSE will increase as the value for decreases, i.e., the less storage used, the larger the approximation and the larger the error. This tradeoff between compression and error will be investigated graphically in the project. Additional Useful MATLAB Commands MATLAB can compute the singular value decomposition (SVD) of a matrix using the svd() function. The outputs of the svd() function are the three matrices comprising the SVD decomposition. The MATLAB command is: [U,S,V] = svd(A); To display an image in MATLAB, you first need to load the file into the workspace. There are several ways to do this, but one option is the load command. To display an image in MATLAB, an empty figure must first be initialized. The MATLAB command is: figure; This command initializes an empty figure. The next command that plots or displays information will appear in the figure. The MATLAB command imshow() can be used to display an image in a figure. If the image is stored in matrix , the image can be displayed with the command: imshow(A); The MATLAB command title() can be used to title a figure. The argument of the title() function is a string with the desired title, e.g., title(‘My Image Title’) Files can be easily uploaded to or downloaded from the MATLAB Online interface. Under the Home tab, there are Upload and Download buttons. Clicking the Upload button will prompt the user to select the file to upload. If a single file is selected (e.g., project01Solution.pdf), the Download button can be clicked to download the file to the user’s local computer. Figure: A folder in MATLAB with the project01Solution.pdf file selected 3 Firefox File Edit View History Bookmarks Tools Window Help rm STORE 0 vc oc | wx © SY QO 8 #2 https/flearn.snhu.edu/d2l/le/content/1158805/viewContent/20334144 View 9 4 £3 Most Visited @) Import to Loox [Bll RE my license (@) App Store | Apporto, [NTIS To develop your idea proposal, work the problems described below. As you complete each part, make sure to show your work and carefully describe how you arrive at your final answer. Any MATLAB code or MATLAB terminal outputs you generate should be included in your idea proposal to support your answers and work. 2 A= 5 8 Use the svd() function in MATLAB to compute A1, the rank-1 approximation of A. Clearly state what A1 is, rounded to 4 decimal places. Also, compute the root mean square error (RMSE) between A and Ax. 2. Use the svd() function in MATLAB to compute Az, the rank-2 approximation of A. Clearly state what Az is, rounded to 4 decimal places. Also, compute the root mean square error (RMSE) between A and A2. Which approximation is better, A1 or A? Explain. 3.For the 3 x 3matrix A, the singular value decomposition is A = USV’ where U = [u; uz us] Use MATLAB to compute the dot product di = dot(us, uz), Also, use MATLAB to compute the cross product ¢ = cross(u1. uz)and dot product d2 = dot(€, us). Clearly state the values for each of these computations. Do these values make sense? Explain. 4. Using the matrixU = [u1 u2 us], determine whether or not the columns of r span R3. Explain your approach. 5. Use the MATLAB imshow() function to load and display the image A stored in the provided MATLAB image.mat file (available in the Supporting Materials area). For the loaded image, derive the value of k that will result in a compression ratio of CR = 2. For this value of k, construct the rank-k approximation of the image. 6. Display the image and compute the root mean square error (RMSE) between the approximation and the original image. Make sure to include a copy of the approximate image in your report. 7.Repeat steps 5 and 6 for CR ~ 10, CR ~ 25, and CR ~ 75. Explain what trends you observe in the image approximation as cr increases and provide your recommendation for the best cr based on your observations. Make sure to include a copy of the approximate images in your 1. Consider the matrix: 3 x 3: 12 3 4 6 7
Answered 1 days AfterOct 09, 2022

Answer To: CompetencyIn this project, you will demonstrate your mastery of the following competencies:Interpret...

Aditi answered on Oct 10 2022
66 Votes
Problem 1
(
%Generate Matrix A.
)Solution:
    A = [1
    2
    2;
    3
    4 5; 6 7 8]
    A = 3×3
1
    
    
2
    
    
2
    3
    
    4
    
    5
    6
    
    7
    
    8
    [U S V] =
U = 3×3
    svd(A)
    
    -0.2055
    -0.6658
    -0.7172
    -0.4900
    -0.5644
    0.6643
    -0.8471
    0.4880
    -0.2103
    S = 3×3
    
    
    14.4042
    0
    0
    0
    0.6450
    0
    0
    0
    0.3229
    V = 3×3
    
    
    -0.4692
    0.8820
    0.0433
    -0.5763
    -0.2687
    -0.7718
    -0.6691
    -0.3871
    0.6344
(
%Calculate the Rank 1 approximation of A.
A1 = U
(:,

1:1) * S(1:1, 1:1) * V(:,1:1)'
)
A1 = 3×3
    1.3889
    1.7059
    1.9807
    3.3118
    4.0678
    4.7230
    5.7253
    7.0322
    8.1649
(
%Verify rank = 1
rank(A1)
)
(
10
)
ans = 1
(
%Calculate the root-mean square error (RMSE) between A and A1.
RMSE1

=

norm(A-A1,
'fro'
)
/(
3*3)
)
RMSE1 = 0.0801
Problem 2
(
%Calculate the Rank 2 approximation of A.
A2 = U
(:,
1:2) * S(1:2, 1:2) * V(:,1:2)'
)Solution:
A2 = 3×3
    1.0100
    1.8213
    2.1469
    2.9907
    4.1656
    4.8639
    6.0029
    6.9476
    8.0431
(
%Verify that rank = 2.
rank(A2)
)
(
%Calculate the root-mean square error between A and A2.
RMSE2

=

norm(A-A2,
'fro'
)
/(
3*3)
)ans = 2
RMSE2 = 0.0359
Explain: According to the Project Two SVD Document, when K drops, the root-mean square error (RSME) increases, leading to a greater average error. This is accurate since RSME1 is equal to 0.0801 and RSME2 to 0.0359. These calculations plus the fact that A2's average error is lower than A1's would lead us to conclude that A2 is the better approximation, at least in terms of the average error noted before. When addressing compression ratios in Problems 6 and 7, this idea will be expanded upon further.
Problem 3
.
(
%
Seperate
U into three different vectors
in order to
calculate cross/dot
%
product
.
U1 = [-0.2055; -0.4900; -0.8471]
)Solution:
U1 = 3×1
-0.2055
-0.4900
(
U2 = [-0.6658; -0.5644; 0.4880]
)-0.8471
U2 = 3×1
-0.6658
-0.5644
(
U3 = [-0.7172; 0.6643; -0.2103]
)0.4880
U3 = 3×1
-0.7172
0.6643
(
%Calculate the dot product d1.
d1 =
dot(
U1, U2)
)-0.2103
d1 = -6.9000e-06
(
%Calculate the cross product(c), which should equal U3.
c = cross (U1, U2)
)
c = 3×1
-0.7172
0.6643
(
%Calculate the dot product d2.
d2 =
dot(
c, U3)
)-0.2103
d2 = 0.9999
Explain: Given that it equals U3, the cross product of U1 & U2 makes sense. This suggests that U1 & U2 are perpendicular vectors based on the knowledge gained through zyBooks. This result may be manually calculated, and its accuracy can be demonstrated by writing it down. The computation looks like this: (-0.4900 * 0.4880) \s- (-0.8471 * -0.5644) = -0.7172. Then, (-0.8471 * -0.6658) - (-0.2055 * 0.4880) = 0.6643. Last but not least, (-0.2055 * -0.5644) - (-0.4900 * -0.6658) = -0.2103.
Since c and U3 are identical in this product, the dot product d2 makes perfect sense to be 0.9999 (essentially 1), and this product may also be typed out directly like (-0.7172 * -0.7172) + (0.6642 * 0.6642) + (-0.2103 * -0.2103) = 0.5413 + 0.4411 + 0.0442 = 0.9999.
Problem 4
(
%Put the column vectors back into U.
U = [U1 U2 U3]
)Solution:
U = 3×3
    -0.2055
    -0.6658
    -0.7172
    -0.4900
    -0.5644
    0.6643
    -0.8471
    0.4880
    -0.2103
(
%The reduced matrix will have 3 pivot columns if the columns of U span R3.
reducedU
=
rref
(U)
)
reducedU = 3×3
    1
    0
    0
    0
    1
    0
    0
    0
    1
(
%Check the rank of the
the
reduced U matrix, which should be 3.
rank(
reducedU
)
)
ans = 3
Explain: The columns of U span R3 because there are no zero rows in the reduced echelon form of U and there are three pivot columns in the reduced matrix. The rank of reducedU is 3, which further supports this.
Problem 5
(
%Load the image.

load

image.mat
;
% The dimensions are M = 3072
abd
N = 4608.
)Solution:
(
imshow
(A)
)
(
%Perform the
svd
function on A and put the results into U S V.
[U

S V] =
svd
(double(A))
) (
U =

3072×3072
-0.0220
0.0337
-0.0276
0.0071
-0.0003
0.0114
-0.0108
0.0043
-0.0220
0.0335
-0.0273
0.0066
-0.0002
0.0106
-0.0112
0.0037
-0.0220
0.0335
-0.0271
0.0062
-0.0003
0.0100
-0.0113
0.0029
-0.0220
0.0333
-0.0271
0.0057
-0.0003
0.0094
-0.0110
0.0023
-0.0219
0.0331
-0.0273
0.0053
-0.0003
0.0083
-0.0109
0.0020
-0.0219
0.0329
-0.0274
0.0049
-0.0007
0.0066
-0.0107
0.0017
-0.0219
0.0325
-0.0274
0.0041
-0.0012
0.0048
-0.0106
0.0012
-0.0218
0.0322
-0.0277
0.0037
-0.0012
0.0027
-0.0104
0.0008
-0.0218
0.0321
-0.0281
0.0028
-0.0020
0.0008
-0.0097
0.0003
-0.0218
0.0319
-0.0281
0.0020
-0.0025
-0.0009
-0.0093
-0.0001
S =
3072×4608
10
5

×
5.7986
0
0
0
0
0
0
0
0
0.6755
0
0
0
0
0
0
0
0
0.3657
0
0
0
0
0
0
0
0
0.3129
0
0
0
0
0
0
0
0
0.2842
0
0
0
0
0
0
0
0
0.2423
0
0
0
0
0
0
0
0
0.2325
0
0
0
0
0
0
0
0
0.2217
)
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    V =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here