% EE3025 S2001: Recitation 8 % N. Sidiropoulos, March 8, 2001. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % First part of recitation: Linear MMSE estimation of one RV from two RVs. % This part uses the weather data of Recitation 7 - these should be in % your working directory. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all; load AMES94.weather; load MASONCITY94.weather; load NEVADA94.weather; load ANAMOSA94.weather; % AMES94 is a 184 (days) x 5 matrix. % Column 1 is date; column 3 Tmax, column 4 Tmin, column 5 precipitation % and similarly for the other three matrices % Drop first few and last several days (season transients!): AMES94 = AMES94(20:150,:); MASONCITY94 = MASONCITY94(20:150,:); NEVADA94 = NEVADA94(20:150,:); figure(1); clf; subplot(2,2,1); plot(AMES94(:,4)); legend('AMES94,Tmin'); subplot(2,2,2); plot(NEVADA94(:,4)); legend('NEVADA94,Tmin'); subplot(2,2,4); plot(MASONCITY94(:,4)); legend('MASONCITY94,Tmin'); % Linear MMSE estimation of one RV from two RVs. % Cf. Extra Problem in HW5. x = AMES94(:,4); y = MASONCITY94(:,4); z = NEVADA94(:,4); % Either: % A = [mean(y.*y) mean(y.*z) mean(y) % mean(y.*z) mean(z.*z) mean(z) % mean(y) mean(z) 1]; % d = [mean(x.*y); mean(x.*z); mean(x)]; % % or, to see dependence on corco: a11 = (std(y))^2+(mean(y))^2; a12 = std(y)*std(z)*corco(y,z)+mean(y)*mean(z); a13 = mean(y); a21 = a12; a22 = (std(z))^2+(mean(z))^2; a23 = mean(z); a31 = a13; a32 = a23; a33 = 1; A = [a11 a12 a13 a21 a22 a23 a31 a32 a33]; d1 = std(x)*std(y)*corco(x,y)+mean(x)*mean(y); d2 = std(x)*std(z)*corco(x,z)+mean(x)*mean(z); d3 = mean(x); d = [d1 d2 d3]; w = inv(A)*d; a = w(1); b = w(2); c = w(3); xhat = a*y+b*z+c; figure(2); clf; subplot(2,1,1); plot(x,'o'); hold on; plot(xhat,'r*-'); legend('x (Tmin, AMES)','xhat (LMMSE estimate, based on Tmin, MASONCITY, NECADA'); subplot(2,1,2); plot(x-xhat,'ko-'); legend('estimation error'); % resulting squared error: esaccruedYZ = (1/length(x))*norm(x-xhat,'fro')^2 % Compare with estimation based on x only: a = corco(x,y)*(std(x)/std(y)); b = mean(x) - a*mean(y); xhat = a*y+b; esaccruedY = (1/length(x))*norm(x-xhat,'fro')^2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Second part of recitation: Joint Gaussian PDF plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all; figure(3); % We will employ the bivariate Gaussian distribution with zero means, % variances 1, and correlation coefficient rho. The matlab syntax % for this density function is: % 1/(2*pi*sqrt(1-rho^2))*exp(-(X^2-2*rho*X*Y+Y^2)/(2*(1-rho^2))) % Follow the script: x=-4:.2:4; % This creates your x-axis y=x; % This creates your y-axis [X,Y]=meshgrid(x,y); % X and Y are 41x41 matrices; mesh(X), mesh(Y) % to understand what's happening here rho=0; Z=1/(2*pi*sqrt(1-rho^2))*exp(-(X.^2-2*rho*X.*Y+Y.^2)/(2*(1-rho^2))); colormap(gray); mesh(X,Y,Z); % more plots of the same thing: surfl(X,Y,Z); surfl(X,Y,Z), shading interp contour(X,Y,Z); contour(X,Y,Z,40); % Repeat the above with rho = 0.5: rho = 0.5; Z=1/(2*pi*sqrt(1-rho^2))*exp(-(X.^2-2*rho*X.*Y+Y.^2)/(2*(1-rho^2))); colormap(gray); mesh(X,Y,Z); % more plots of the same thing: surfl(X,Y,Z); surfl(X,Y,Z), shading interp contour(X,Y,Z); contour(X,Y,Z,40); % What do you observe? % Repeat the above with rho = 0.9, and then rho = -0.9. What do you observe? % Repeat the above with rho = 0.99. What do you observe? % Generate the Z for rho = 0.5: rho = 0.5; Z=1/(2*pi*sqrt(1-rho^2))*exp(-(X.^2-2*rho*X.*Y+Y.^2)/(2*(1-rho^2))); z1=Z(:,15); z2=Z(:,20); z3=Z(:,25); z4=Z(:,30); plot(y,z1,y,z2,y,z3,y,z4) % What do these plots represent? z1=Z(15,:)'; z2=Z(20,:)'; z3=Z(25,:)'; z4=Z(30,:)'; plot(x,z1,x,z2,x,z3,x,z4) % What do these plots represent? % Answer (scaled) conditional PDFs.