Topic: | Math@UNC environment |
Post date: | May 20, 2020 |
Due date: | May 21, 2020 |
This homework investigates consequences of the fundamental theorem of algebra and application of the singular value decomposition.
Consider a linear mapping , from vector space with basis , to , with basis .
Is a basis for ?
If must ?
If and for , what is the matrix representing ?
Since is a basis, the column vectors are linearly independent and the matrix is invertible,
The statement can be interpreted in one of two ways (these descriptions are said to be duals of one another, and distinguish between a vector as a geometrical entity and its coordinates in some given basis):
is a vector that contains the coordinates of the basis vector of in the basis, . Similarly, is a vector that contains the coordinates of the basis vector of in the basis, . In this case implies , and . This interpretation was emphasized in this course, and is appropriate for .
is the basis vector of , whose coordinates in that basis are given by . Similarly . The statement now implies , such that
and the matrix associated with the mapping would be . This interpretation is appropriate when mapping between different vector spaces of the same dimension, , .
Determine the singular value decomposition and pseudo-inverse of a matrix (i.e., a row vector).
with . By definition of the matrix -norm
Since ,
The largest possible value of when , is . The SVD is
with , (orthogonal).
The fudamental theorem of linear algebra partitions the domain and codomain of a linear mapping. The singular value decomposition provides orthogonal bases for each of the subspaces arising in the partition. The bases are ordered according to the amplification behavior of the linear mapping, expressed through the norm of successive restrictions of the mapping. This approach is closely aligned with typical problems in data science, and can be used in a variety of scenarios. In this homework linear algebra methods will first be used in a field far removed from the physical sciences: extracting the quirks of painter style from the overall composition of a painting, and applying one artist's style to another artist's composition. This is often-encountered data science problem: distinguishing between small and large scale features of data.
First steps in solving the homework questions will be carried out in class. Each of the following subsections is a homework question, with 1 grade point awarded for a correct solution. Here are some initial Octave instructions to define a directory to save images into and define a function to read an image.
octave] |
cd homework; mkdir hw03; cd hw03 |
octave] |
im=imread("/home/student/courses/MATH547ML/data/paintings/Andy_Warhol_127.jpg"); |
octave] |
imshow(im) |
octave] |
function im=pread(name) im=imread(strcat("/home/student/courses/MATH547ML/data/paintings/",name)); im=rgb2gray(im); end |
octave] |
im=pread("Andy_Warhol_127.jpg"); |
octave] |
imshow(im); size(im) |
ans =
360 357
octave] |
Define a linear mapping that rescales data within an image file to some specified size . Determine whether the mapping is data-preserving, and if not, quantify the amount of data loss.
octave] |
function im1=psize(im0,px,py) [mx,my]=size(im0); cx=floor(mx/2); cy=floor(my/2); px2=floor(px/2); py2=floor(py/2); im1 = im0(cx-px2:cx+px2,cy-py2:cy+py2); end |
octave] |
imshow(psize(im,256,256)) |
octave] |
imshow(psize(pread("Vincent_van_Gogh_167.jpg"),256,256)) |
octave] |
Take the largest possible portion of a painting of size with . Interpret the resulting image as a vector with . The image is thus specified as a linear combination of the columns of the identity matrix ,
and describes illumination on a pixel-by-pixel basis. A column vector of can be interpreted as the binary base representation of a natural number from the set , namely .
Note that is one choice among the possible combinations of objects chosen from a set with elements, . Even for small , the number of choices is enormous
Construct a new basis by random choice of numbers from and the mapping. Check if the basis is orthogonal.
octave] |
m=4*4; |
octave] |
B=randi(flintmax()-1,m,1); |
octave] |
C=zeros(m,m); for i=1:m for j=1:m C(i,j)=bitand(B(i),B(j)); end; end |
octave] |
max(max(C)) |
ans = 8.9756e+15
octave] |
Linear dependence is the same as equality in this binary representation.
octave] |
D=zeros(m,m); for i=1:m for j=i+1:m D(i,j) = B(i)==B(j); end; end |
octave] |
max(max(D)) |
ans = 0
octave] |
From above, a non-orthogonal basis is obtained.
Construct another basis that corresponds to successive halving of image regions by factors along the horizontal and vertical dimensions. Are basis vectors orthogonal?
First consider the simplest possible case. A image cannot be halved, hence start with images for which
give 6 possible patterns encoded by row vectors
Only four basis vectors are required and can be chosen as
octave] |
B=[1 0 1 0; 0 1 0 1; 1 1 0 0; 0 0 1 1; 1 0 0 1; 0 1 1 0]; C=[1 0 1 0; 1 1 0 0; 0 1 1 0; 0 0 1 1]; |
octave] |
[rank(B) rank(C)] |
ans =
4 4
octave] |
The pattern suggested by above is alternating groups of 1's and 0's, that are then shifted right by places. Define a function to generate alternating 1,0 bit groupings for images of size , . There are such numbers.
octave] |
q=2; p=2^q; m=p^2; disp([q p m]) |
2 4 16
octave] |
g=zeros(2^(2*q-1),1); o=2^m-1; for i=0:q k=2^i; l=2^k; disp([k l]); g(i+1) = bitshift(l-1,2^i); dec2bin(g(i+1)) end |
1 2
ans = 10
2 4
ans = 1100
4 16
ans = 11110000
octave] |
Map the binary digits from the positive checkerboard basis to integers . Check if the newly obtained basis is orthogonal. Display approximations of the image that result from the first basis vectors, .
Alternatively, an image can be interpreted as a matrix , hence a mapping. From
the image can be interpreted as the transformation of the image encoded by . Denote by the -rank approximation of from the singular value decomposition
Display the images that correspond to .
octave] |
function im=svdim(S,U,V,p) im=S(1,1)*U(:,1)*V(:,1)'; for k=2:p im=im+S(k,k)*U(:,k)*V(:,k)'; end; end |
octave] |
figure(3); clf; imshow(im) |
octave] |
[U,S,V]=svd(im,1); |
octave] |
figure(2); plot(log10(diag(S)),'o'); |
octave] |
figure(1); clf; imagesc(svdim(S,U,V,10)); colormap(gray); print -deps HW03Fig01.eps |
octave] |
figure(1); clf; imagesc(svdim(S,U,V,20)); colormap(gray); print -deps HW03Fig02.eps |
octave] |
figure(1); clf; imagesc(svdim(S,U,V,40)); colormap(gray); print -deps HW03Fig03.eps |
octave] |
|
|||
Figure 1. Successive SVD approximations of an
image with
rank-one updates.
|
Consider images from two different artists, and their singular value decompositions
Let , . Construct and display images that take the large scale features from combined with small scale features from ,
for where .
octave] |
ims=pread("Vincent_van_Gogh_50.jpg"); |
octave] |
figure(4); imshow(ims) |
octave] |
imC=psize(im,256,256); imS=psize(ims,256,256); |
octave] |
figure(1); clf; imshow(imC); print -deps Hw03Fig04.eps; |
octave] |
figure(2); clf; imshow(imS); print -deps HW03Fig05.eps; |
octave] |
[Uc,Sc,Vc]=svd(imC,1); [Us,Ss,Vs]=svd(imS,1); |
octave] |
function im=svdimpq(S,U,V,p,q) im=S(p,p)*U(:,p)*V(:,p)'; for k=p+1:q im=im+S(k,k)*U(:,k)*V(:,k)'; end; end |
octave] |
imCS = svdim(Sc,Uc,Vc,40) + svdimpq(Ss,Us,Vs,50,60); |
octave] |
figure(5); clf; imagesc(imCS); colormap(gray); print -deps Hw03Fig06.eps; |
octave] |
|
|||
Figure 2. Applying the style of Van Gogh to a
work by Warhol.
|