How many units of memory does it take to store the matrix

Assignment Help Python Programming
Reference no: EM132966858

Applications/Programming Problems

For this question, answer all relevant writing parts in your homework report.

Consider the case where you are given access to some data, but you discover that the data is too bulky for you to carry around. You will eventually want to use this data for some downstream task: if your data is weather statistics, you may want to use it to build a prediction model, or if it's an image, you may want to include it in a presentation. Unfortunately, you have no information about what this downstream task is- all you know is that you want to compress your data so that it fits in the memory that you have available, and that you have less memory available than what the data occupies right now. In this case, it is reasonable to assume you want to attempt the following:

- To the best of your ability, you want to go for lossless compression. This means that you want to eliminate all the possible redundancies in your data. For example, say that your data is a matrix of n columns in Rd but only m < n of these columns are linearly independent. Then storing the remaining of the n - m columns in their entirety is a redundancy, and there is room for lossless compression.

- If lossless compression is not possible, you want to work toward lossy compression that incurs the least amount of data loss. This means that in the pursuit of compression, you will loose some information, but you still want to quantify how much information you lost and minimize some notion of this quantity.

We will see how Singular Value Decomposition can help us achieve either of these outcomes. Let us consider the application of compression to image data. We will say that matrix X ∈ Rm×n represents a grayscale image, with each element of these matrix representing the grayscale value at that pixel location. Assume through this question that it takes 1 unit of memory to store one element of a matrix

1. How many units of memory does it take to store the matrix M ? Your answer should be in terms of m and n.

2. Assume now that you have access to some algorithm A that provides you with a low-rank approximation of M. Essentially, given M, the algorithm A returns a matrix L and another matrix R such that M ≈ LRT where L and R are taller than they are wide. Let us label the number of columns in L and R as k. How many rows must L and R have respectively?

3. This makes L and R a new representation of our matrix M, because (an approximation of) M can be recovered from them (since M ≈ LRT ). Given your answer in (2), what can you 3.This makes L and R a new representation of our matrix M , because (an approximation of) say about how many units of memory it takes to store this new representation of M ? Give an inequality relating k, m and n that describes the condition that must be met for L and R to be a more memory-efficient representation of our matrix M.

4. In parts (2) and (3), you assumed that an algorithm could magically give you the matrices L tion. If the full-rank SVD of M = USVT, then you can simply take L = US and R = V to and R. However, you have already learnt one such algorithm: the Singular Value decomposi- get the left and right matrices. In the full-rank approximation, we have that our estimate LRT exactly equals the original M. How many units of memory are required to store this matrix? Is it better or worse than part (1)?

To turn exact equality into an approximation that gives us a lower rank approximation of M, we should take only the first k columns of our decomposition matrices. Then, we can model L = UkSk and R = Vk where Uk Rm×k, Sk ∈ Rk×k and Vk Rn×k and recover M~k = LRT as an approximation of M.

Why does this make for a good approximation of our original M? And under what notion of approximation is this M˜k close to M.? A common metric of measuring the distance between Why does this make for a good approximation of our original M ? And under what notion of matrices is the Frobenius norm. The Frobenius norm is the matrix generalization of the typical vector norm that we are familiar with. Then, we can measure the distance between two matrices of the same size using the Frobenius norm of their difference:

||M - M˜k||F = √Σij(M - M˜k)2ij

Consider M = USVT = Σi=1r σiuiviT where v1, v2, ..., vr are the right singular vectors of M and u1, u2, ..., ur are the left singular vector of M, all corresponding to M 's top singular values (arranged in descending order of size) σ1, σ2, ..., σr. Then M˜k = Σi=1k σiuiviT where k ≤ r.

5. This notation makes it explicit that M˜k has rank k . Why?

It can be shown that M˜k is the best rank-k approximation of M under the Frobenius norm. Intuitively, this can be argued as follows: the rows of M˜k are the projections of the rows of M onto the subspace spanned by the first k singular vectors of M . Hence the rows of M˜k represent some notion of the "best-fit" k-dimensional subspace of M . Since we are working
with the Frobenius norm as the metric, we can carry over our intuition for "best-fit" from vector norms. We will test this notion empericially.
We will now move onto the programming parts.

6. Download the image provided in the HW release titled camera.png, which is a 226 226 full-rank matrix. You should open it using the Image.open function from the Pillow library. This should give you a [226, 226, 3] matrix of which you should only take the first channel, yielding a [226, 226] matrix. You can then check (approximately) that this matrix is full rank using the matrix rank function in the numpy.linalg library.

(a) Study the documentation for numpy.linalg.svd function to calculate SVD carefully, and make sure how it returns the singular values and the left and right singular vectors. Using this function, calculate the SVD of M and recover S, U and V . Reorder S, U and V in decreasing order of the size of the singular values (this should be easy in NumPy). Make a plot where the horizontal axis is the rank of your singular value and the vertical axis is the nth largest singular value in S. Precisely, your horizontal axis should range from 1 to 226, and the corresponding points on the vertical axis should be the largest and the smallest singular values. Include this plot in your report titled Singular, and retain the matrices for S, U and V in your code for further parts.

(b) Use the method outlined above to get Sk, Uk and Vk for four different values of k 226. Compute L and R using these matrices and visualize your corresponding M˜k. Include what you observe. Remember that if you use k = 226, computing LRT should recover all your images in the report, labelled with corresponding values of k, and reflect on the original image exactly (barring numerical issues).

(c) For a particular value of k define Ik as the weight of the first k singular values relative to the total sum of all singular values. Therefore

Ik = ∑ki=1 σi/∑128i=1 σi

This is a representation of the percent "information" about M carried by the first k singular vectors. Make another plot with the same horizontal axis as (a) ranging from k = 1 to k = 226 and vertical axis as Ik. Include this plot in your report, titled Information.

(d) Finally, make a third plot with the same horizontal axis as (a) and (c) ranging from k = 1 to k = 226 and the vertical axis referring to the memory usage in units of memory using your formula in part (3). Include this plot in your report, titled Memory.

(e) Using your graphs in part (a), (c) and (d), visual intuition from part (b), and your inequal-constraints. Justify why this would make a good value for k. Include the resulting M˜k ity from (3), pick a value of k that is suitable for storing the given image with memory in your report titled Image of rank k.

Reference no: EM132966858

Questions Cloud

Evaluate jeffery conspiracy with respect to taxation : Evaluate Jeffery's conspiracy with respect to taxation. Jeffery used to work for Beqa Island Resort 2 years ago. He had recently won $10,000 dollars
What is the debit to retained earnings : Ordinary shares, $10, par value; authorized, 2,000,000 shares; issued 400,000 shares $4,000,000. What is the debit to retained earnings
Calculate the issuance price for michael incorporated : Calculate the issuance price if the market rate of interest is 9%. On January 1, 2011, Michael's Incorporated issued $8,000,000 of 10-year bonds.
Compute the inventory cost at the end of June : Angel Company provided the following data for June 30: June 1 Balance 5,000 units @ P20.00 each. Compute the inventory cost at the end of June
How many units of memory does it take to store the matrix : How many units of memory does it take to store the matrix M ? Your answer should be in terms of m and n and How many rows must L and R have respectively
How much is the gain or loss on the retirement : On January 1, 2019, XYC Company issued P6,000,000 of its 8%, 6 year bonds at P110. How much is the gain or loss on the retirement
What the net income reported by bonita industries for year : During the year the business recorded $631000 in revenues, $330000 in expenses, and dividends of $64000. The net income reported by Bonita Industries for year?
What amount would john record initial investment in jinxtor : What amount would John record initial investment in Jinxtor? John invested plant and equipment with a book value of $500,000
Show what are the accounting entries made by mother : Show what are the accounting entries made by MOTHER in relation to the different events that occurred during period X

Reviews

Write a Review

Python Programming Questions & Answers

  Calculate the nth number in the fibonnaci sequence

Write a psudocode to calculate the Nth number in the fibonnaci sequence while the input is N. The response paper should be in APA format.

  Find and display the union of set1 and set2

Generate 5 random integers between 1 and 10, inclusive. Store the random integers in another set named set2. Display the set.

  Determine an athletes final score for the event

To determine an athlete's final score for the event, the highest and lowest judges' scores are discarded and then the average of the rest of the scores.

  Construct a python function that returns title case version

Construct a python function that returns the title case version of a string, according to the rules above. Only use upper function and not title function

  Define a definition for the function and recursive function

Define a definition for the function, pow(x, N), to compute x N for integer x and integer N, e.g. 3 1001 . Write a recursive function.

  Write a python program to hold information on a course

Write a Python program to hold information on a course. Add a method to enter teacher name and a method to enter credits. Use a try catch block to verify that.

  Develop a script containing three new methods

"Object-Oriented Programming," of Introduction to Computing and Programming in Python, a Turtle is an object from the class Turtle with the following features.

  What do you think the script will output

How does execution differ if you are running this code from within the interactive interpreter? Try it and write down the results.

  Reinforce topic material on simple functions

Select 3 sets of test data that will demonstrate the correct 'normal' operation of your program. Select another 2 sets of test data that will demonstrate the "abnormal" operation of your program.

  Write a function that works exactly like pythons random

Write a function random_cho ice that works exactly like Python's random. choice function: it takes a list as an argument and returns one of it's elements.

  How to handle errors like this using error checking pattern

How to handle errors like this using the error checking pattern - Choosing this option will end the main menu and then display the report again.

  Write a python class definition for class sumi

Write a python class definition for class ‘Sumi' with a single instance variable self.num of type ‘int' and single instance method called "sum_of_digits".

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd