import numpy as np import laff import flame m = 8 n = 8 k = 3 # Random matrix of size mxn B = np.matrix( np.random.rand( m, n ) ) # A is k columns of B taken at even intervals if 2*k <= n: #k is less than half of n interval = np.ceil( n/k ) A = B[ :, ::interval ] # These are slices in python. # This says take all rows of B, and columns # from 0 to the end at interval steps else: A = B[ :, :k] #If k is greater than half of n, then just take the first k columns print( 'A = ' ) print( A ) print( 'B = ' ) print( B ) C = np.transpose( A ) * A print( 'C = ' ) print( C ) V = np.transpose( A ) * B # Insert your LU_unb_var5 method here LU_unb_var5( C ) # Insert Code Here... # Use laff.trsm(uplo, transpose, diag, A, B) to solve A X = B overwriting B with X def RankKApprox( B, k ): m,n = B.shape # A is k columns of B taken at even intervals if 2*k <= n: #k is less than half of n interval = np.ceil( n/k ) A = B[ :, ::interval ] # These are slices in python. # This says take all rows of B, and columns # from 0 to the end at interval steps else: A = B[ :, :k] #If k is greater than half of n, then just take the first k columns #------------------------------------------------------------# # Replace the comments below with their respective operations from the notebook # C = A^T A # W = A^T B # Overwrite C with its LU factorization # Solve L(UX) = W, overwriting W with X #------------------------------------------------------------# # Return A * W return A * W %pylab inline from im_approx import * # Try varying the number of columns used for the approximation numCols = 40 # Load an image filename = 'building.png' img = np.matrix(read_image( filename )) # Make the approximations using normal equations and the SVD # This step might take a while as it is a lot of computation. normalApprox, SVDApprox = create_approximations( img, k=numCols, approximator=RankKApprox ) #Now plot the approximations that we have created # Note that we're having some issues with our # approximations being somewhat darker than the # real image and are investigating. plot_approximations( img, normalApprox, SVDApprox, k=numCols )