1.MATH547 Homework 1

Topic: Math@UNC environment
Post date: May 14, 2020
Due date: May 15, 2020

1.1.Background

This homework is meant as a tutorial on matrix computations, in particular:

1.2.Theoretical questions

1.2.1.Vector addition and scaling

Problem

Consider n random walks on the real line with m unit steps starting from the origin. What is the mean distance and mean squared distance from the origin?

Answer

Denote distance by d, and the random walk steps as u1,u2,

d=u1+u2++um=i=1mui,ui{-1,1}.

Denote by μ(d) the average distance over n walks which is the sum of the average displacement in each step

μ(d)=i=1mμ(ui)

Assuming that both left and right steps are equiprobable, μ(ui)=0 and μ(d)=0.

The squared distance is

d2=(u1+u2++um)2=i=1mui2+2i=1mj=i+1muiuj

The average is

μ(d2)=i=1mμ(ui2)+2i=1mj=i+1mμ(uiuj).

Since ui2=1 the average is μ(ui2)=1. The possible values of uiuj=±1 with equal probability μ(uiuj)=0. The average squared distance is

μ(d2)=m.
𝑨m×n,m1,n

octave] 
m=100; n=500; U=2*(rand(m,n)<0.5)-1; mean(mean(U))

ans = -0.0063600

octave] 
function md=meand(m,n)
  U=2*(rand(m,n)<0.5)-1;
  md=mean(mean(U));
end
octave] 
Nmax=1000; md=zeros(50,1);
for k=1:50
  md(k) = meand(m,100*k);
end;
octave] 
plot(100:100:5000,abs(md),'o')
octave] 
pwd

ans = /home/student/courses/MATH547ML

octave] 
mkdir homework

ans = 1

octave] 
cd homework
octave] 
pwd

ans = /home/student/courses/MATH547ML/homework

octave] 
mkdir hw01;
octave] 
cd hw01
octave] 
print -deps hw01fig01.eps
octave] 
pwd

ans = /home/student/courses/MATH547ML/homework/hw01

octave] 
ls

hw01fig01.eps untitled.ofig

Figure 1. Experiment on statsitc to evaluate mean of random walk distance μ(d)

1.2.2.Norms in Em

Problem

Show that for a1,a2>0, f:2+ defined by

f(𝒙)=a1x12+a2x22,

is a norm in E2.

Answer

Let y1=a1x1, y2=a2x2, or in vector form f(𝒙)=g(𝒚)=y12+y22.

𝒚=𝑨𝒙,𝑨=[ a1 0 0 a2 ],

Since g(𝒚) does not satisfy scaling property ||a𝒖||=|a|||𝒖||, neither if f a norm. However f=g would be.

1.2.3.Norms in Em

Problem

Show that for a1,a2>0, f:2+ defined by

f(𝒙)=a1x12-a2x22

is not a norm in E2.

Answer

No f(𝒙)=0 for 𝒙=(1,a1/a2)𝟎

1.2.4.Inner product in Em

Problem

Show that for a1,a2>0, s:2×2 defined by

s(𝒙,𝒚)=a1x1y1+a2x2y2,

is a scalar product in E2.

Answer

Recall that

t(𝒙,𝒚)=[ x1 x2 ][ y1 y2 ]=x1y1+x2y2

is a scalar product. From

s(𝒙,𝒚)=t(𝑨𝒙,𝒚)=t(𝒙,𝑨𝒚),with𝑨=[ a1 0 0 a2 ],

and fact that t is a scalar product, deduce s is also a scalar product.

1.2.5.Inner product in Em

Problem

Show that for a1,a2>0, s:2×2 defined by

s(𝒙,𝒚)=a1x1y1-a2x2y2,

is not a scalar product in E2.

Answer

From s(𝒙,𝒙)=a1x12-a2x22 notice that s(𝒙,𝒙) can be negative, hence s is not a scalar product.

1.2.6.Matrix-matrix products

Problem

Find examples of matrices for which 𝑨𝑩=𝑩𝑨, and 𝑪𝑫𝑫𝑪.

Answer

octave] 
A=[2 1; 1 2]; B=[2 0; 0 2]; A*B-B*A

ans =

0 0

0 0

octave] 
C=[2 1; -1 1]; D=[0 -2; 1 -1]; C*D-D*C

ans =

-1 -3

-2 1

octave] 
Octave]

1.3.Linear functionals and mappings in analysis of EEG data

Electroencephalograms (EEGs) are recordings of the electric potential on cranium skin. Research on brain activity uses EEGs to determine specific activity patterns in the brain. For example, epileptic seizures have a distinctive EEG signature. EEG data can be loaded from the course data directory.

octave] 
load /home/student/courses/MATH547ML/data/eeg/eeg;
octave] 
data=EEG.data'; [m n]=size(data); disp([m n]);

30504 32

octave] 

There are n=32 sensor recordings with m=30504 components each. A first common operation is scaling of the data.

octave] 
pdata=data./max(data)+meshgrid(0:n-1,0:m-1);
octave] 
hold on;
for j=1:n
  plot(pdata(:,j));
end;
hold off;
octave] 
cd /home/student/courses/MATH547ML/homework/hw01
octave] 
print -deps eeg.eps;

GL2PS info: OpenGL feedback buffer overflow

warning: gl2ps_renderer::draw: retrying with buffer size: 8.4E+06 B

GL2PS info: OpenGL feedback buffer overflow

warning: gl2ps_renderer::draw: retrying with buffer size: 1.7E+07 B

octave] 

Figure 2.

1.3.1.Functional relationships in the data

Over some time subinterval can the data from a sensor be expressed as a function of data from another sensor?

octave] 
cd /home/student/courses/MATH547ML/homework/hw01;
octave] 
[m,n]=size(data); 
octave] 
mt=5000:5005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02a.eps
octave] 
mt=6000:6005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02b.eps
octave] 
mt=7000:7005; plot(data(mt,1),data(mt,2),'-o'); print -deps hw01Fig02c.eps
octave] 

Figure 3. From above figures, sensors 1,2 are not in a functional relation.

1.3.2.Data magnitude (norm)

Partition sensor data into time subintervals. Over each subinterval, evaluate the p-norm of centered data, for p=1,2,3, p. Plot the p-norms over the entire time history.

octave] 
mud=mean(data);
octave] 
cdata=data-mud;
octave] 
m1=1000; m2=1100; cdata(m1:m2,:)

ans =

30504 32

octave] 
function nrmd=normd(m1,m2,d)
  [m,n]=size(d);
  nrmd=zeros(4,n);
  for k=1:n
    nrmd(1,k)=norm(d(m1:m2,k),1);
    nrmd(2,k)=norm(d(m1:m2,k),2);
    nrmd(3,k)=norm(d(m1:m2,k),3);
    nrmd(4,k)=norm(d(m1:m2,k),Inf);
  end;
end;
octave] 
tnrm=zeros(100,4,n);
for j=1:100
  tnrm(j,:,:) = normd(100*j,100*(j+1),cdata);
end;
octave] 
it=1:100; plot(it,tnrm(:,1,1),'r',it,tnrm(:,2,1),'k',it,tnrm(:,3,1),'g',it,tnrm(:,4,1),'b')
octave] 
plot(it,tnrm(:,1,1),'r',it,tnrm(:,1,2),'k',it,tnrm(:,1,3),'g')
octave] 
figure(); plot(it,tnrm(:,2,1),'r',it,tnrm(:,2,2),'k',it,tnrm(:,2,3),'g')
octave] 
figure();
octave] 
jt=8900:9200; plot(jt,cdata(jt,1),'r',jt,cdata(jt,2),'k',jt,cdata(jt,3),'g')
octave] 
figure(1); pwd

ans = /home/student/courses/MATH547ML/homework/hw01

octave] 
print -deps hw01fig03.eps
octave] 

Figure 4.

1.3.3.Orthogonality of sensor data (inner product)

Over some time interval, determine the angle between sensor data. Is sensor data orthogonal? Plot the angle between sensor data over the entire time history.

octave] 
function angd=angld(m1,m2,n1,d)
  [m,n]=size(d);
  angd=zeros(n1,n);
  for k=1:n
    angd(k)=d(m1:m2,n1)'*d(m1:m2,k)/norm(d(m1:m2,n1))/norm(d(m1:m2,k));
  end
end;
octave] 
tang=zeros(100,n);
for j=1:100
  tang(j,:) = angld(100*j,100*(j+1),1,cdata);
end;
octave] 
it=1:100; plot(it,tang(:,1),'r',it,tang(:,2),'k',it,tang(:,3),'g')
octave] 
figure(4)
octave] 
plot(tang)
octave] 

1.3.4.Periodic representation of data (linear mapping)

Use template from Lesson01 to construct a representation of the data through periodic functions.

octave] 
ns=5; A=[]; it=100:400; dt=0.1; t=it*dt; t=t'; A = [A ones(size(t))];
octave] 
for k=1:ns
  A = [A sin(k*t) cos(k*t)];
end
octave] 
bt=cdata(it,1);
octave] 
x=A\bt;
octave] 
b=A*x;
octave] 
plot(t,bt,'ok',t,b,'r');
octave] 
print -deps hw01fig04.eps
octave] 

Figure 5. Data from sensor 1 is not accurately captured by a trigonometric series.