MATH347: Linear algebra for applications in data scienceJune 4, 2021

Final Examination: Application

Solve the following problems (5 course points each). Present a brief motivation of your method of solution. This is an open-book test, and you are free to consult the textbook. Your submission must however reflect your individual effort with no aid from any other person. Draft your solution in TeXmacs in this file. Spaces for your solution have been provided in this file for text, formulas, figures, Octave commands. If Octave does not work within TeXmacs, verify your commands in the stand-alone Octave application and paste the commands into the appropriate spaces in this file without executing them. Upload your answer into Sakai both as a TeXmacs, and pdf. Allow at least 10 minutes before the submission cut-off time to ensure you can upload your file.

Problem 1

Data 𝒟={(tj,xj),j=1,2,,m} can be represented in multiple ways. The course desribed the least squares solution to representing the data as a polynomial, for instance a quadratic polynomial p(t)=c0+c1t+c2t2 the coefficients of which are found by solving

min𝒂3||𝒙-𝑨𝒄||,𝒄=[ c1 c2 c3 ],𝒙=[ x1 x2 xm ],𝒕k=[ t1k t2k tmk ],𝑨=[ 𝒕0 𝒕1 𝒕2 ]. (1)

Notice that p(t) is a linear combination of {1,t,t2} with scaling coefficients c0,c1,c2, and recall that ti0=1.

  1. Consider another representation of the data as a trigonometric polynomial q(t)=a0+a1sin(t)+a2cos(t). State the least squares problem by modifying (1) to reflect the new representation.

    Solution. The columns of 𝑨 change

    min𝒂3||𝒙-𝑨𝒄||,𝒄=[ c1 c2 c3 ],𝒙=[ x1 x2 xm ],𝒕k=[ t1k t2k tmk ],𝑨=[ 𝟏 sin(𝒕) cos(𝒕) ]. (2)
  2. For m=100, tj=2πj/m for j=1,2,,m, arbitrarily choose some values for a0,a1,a2[-1,1], and construct data vectors 𝒕,𝒙m in Octave.

    Solution.

    octave] 
    m=100; t=2*pi*(1:m)'/m;
    octave] 
    a0=-0.5; a1=0.5; a2=1.0; aEX=[a0; a1; a2];
    octave] 
    x=a0+a1*sin(t)+a2*cos(t);
    octave] 

  3. Solve in Octave the least squares problem you stated in point 1. Do you recover the coefficients a0,a1,a2 you chose?

    octave] 
    A=[t.^0 sin(t) cos(t)];
    octave] 
    [Q,R]=qr(A,0); b=Q'*x; aLS=R\b; aLS'

    ans =

    -0.50000 0.50000 1.00000

    octave] 

    Coefficients are exactly recovered.

  4. Perturb the data to mimic measurement noise 𝒚s=𝒙+s𝒓, where 𝒓 is a vector of random numbers in the interval [-1,1] scaled by s=1. Solve the least squares problem for the new, noisy data to obtain the perturbed coefficients 𝒂.

    octave] 
    y = x + 2*(rand(m,1)-0.5);
    octave] 
    b=Q'*y; aLS=R\b; aLS'

    ans =

    -0.34031 0.50169 1.04731

    octave] 

  5. Write an Octave loop over the scaling coefficient values s=1,2,,n with n=10, and compute the norm of the change in the coefficients es=||𝒂-𝒂|| for each s value. Construct a plot of (s,es) and comment on the effect of the magnitude of the noise as measured by s upon recovery of the exact coefficients 𝒂.

    octave] 
    n=10; err=zeros(n,1);
    for s=1:n
      y = x + 2*s*(rand(m,1)-0.5);
      b=Q'*y; aLS=R\b;
      err(s) = norm(aLS-aEX);
    end
    octave] 
    plot(1:n,err,'o')
    octave] 
    cd ~/courses/MATH347DS; print -depsc 'errplot.eps'
    octave] 

    Figure 1. Error es=||𝒂s-𝒂|| grows with s

Problem 2

Continuing the above, suppose the measurement noise is modulated in time,

𝒚s=𝒙+s𝒓sin(𝒕)+4s𝒓sin(2𝒕). (3)

Investigate now the utility of the singular value decomposition to gain insight into the data.

  1. Construct a data matrix of the modulated noise measurements specified in formula (3)

    𝒀=[ 𝒚1 𝒚2 𝒚10 ]
    octave] 
    n=10; Y = zeros(m,n); err=zeros(n,1);
    for s=1:n
      y = x + s*2*(rand(m,1)-0.5).*sin(t) + 4*s*2*(rand(m,1)-0.5).*sin(2*t);
      Y(:,s) = y;
    end
    octave] 

  2. Compute the mean of the measurements 𝒚, and construct the centered data matrix

    𝒀0=[ 𝒚1-𝒚 𝒚2-𝒚 𝒚10-𝒚 ]
    octave] 
    yAV = mean(Y')'; size(yAV)

    ans =

    100 1

    octave] 
    Y0=Y-yAV;
    octave] 
  3. Compute the first 3 singular vectors of 𝒀0 using the svds Octave function.

    octave] 
    [U S V]=svds(Y0,3);
    octave] 

  4. The largest 10 singular values are found through the instruction sigma=svds(Y,10,'L'). Display these values and comment on your observations.

    octave] 
    sigma=svds(Y,10,'L')'

    sigma =

    Columns 1 through 8:

    189.757 161.290 139.115 115.779 96.063 84.466 64.798 48.051

    Columns 9 and 10:

    31.548 16.625

    octave] 

    Singular values decay quickly.

  5. Plot the first 3 singular vectors. What features of the data 𝒀 is revealed by the dominant singular vectors?

    octave] 
    plot(t,U(:,1),t,U(:,2),t,U(:,3))
    octave] 
    print -depsc 'uplot.eps'
    octave] 

    Figure 2. The singular vectors capture the noice modulation sin(t),sin(2t)