Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Computational fluid dynamics wikipedia , lookup
Birthday problem wikipedia , lookup
Perturbation theory wikipedia , lookup
Pattern recognition wikipedia , lookup
Knapsack problem wikipedia , lookup
Computational complexity theory wikipedia , lookup
Inverse problem wikipedia , lookup
Least squares wikipedia , lookup
Homework 1 AERE 573 Fall 2014 DUE 9/8 (M) SOLUTION PROBLEM 1. (20 pts) [Book 3rd ed. 1.12 / 4th ed. 1.13] Let X~Uniform[0,2]. (a)(5pts) Sketch the PDF for X. f X (x) Solution: f X ( x) 0.5 for x [0,2] FX ( x) 1 for x 2 0.5 (b)(6pts) Compute the CDF for X, and then sketch it. Solution: FX ( x) 0.5x for x [0,2] 2 (c)(9pts) Calculate the following: (i) X E ( X ) , (ii) E ( X 2 ) , and (iii) X2 Var ( X ) . 2 2 Solution: X E ( X ) xf X ( x)dx 1 ; E ( X ) x 2 f X ( x)dx 4 / 3 ; X2 Var ( X ) E ( X 2 ) X2 1 / 3 2 0 0 PROBLEM 2.(20pts) [Book 1.15] Let X ~ f X ( x) e x ; x 0 . Such a random variable is said to have an exponential distribution, with parameter α. [Here, view X as time-to-failure.] (a)(10pts) Suppose X E ( X ) 10 4 . Find α. Solution: E ( X ) x e x dx 1 . Let u x and let dv e x dx . Then v e x , and so integration by parts gives 0 E ( X ) x e x dx uv x 0 v du 0 0 e x dx e x 0 0 1 . Hence, 10 4 (b)(10pts) Find the time, t, such that the failure probability in the interval [0, t] is 0.01. t t Solution: 0.01 Pr[ X t ] e x dx e x 1 e t 0 e t .99 t 0 ln(. 99) 100.5 sec PROBLEM 3 (20pts) Let X ~ N ( X 10, X 2) , and let { X k }nk 1 be data collection random variables that will be used to estimate X and X . (a)(5pts) Use the Matlab command normpdf to obtain a plot of f X (x) . In doing so, use the array of x-values x=0:.01:20. Be sure to label your axes, and include a caption for this plot. Call it Figure 1. Solution: The Matlab commands for this and subsequent problems are included in the Appendix. True (blue) & Es timated (red) PDFs 0.25 0.2 0.15 0.1 0.05 0 0 2 4 6 8 10 x 12 14 16 18 20 Figure 1. Plots of true (blue) and histogram-based (n=1000) estimate (red) pdf for X. (b)(5pts) Use the Matlab command normrnd to simulate measurements of { X k }nk 1 for n=1000. Use the commands mean and std to compute estimates X and X of the true mean and standard deviation. Then use the command hist to arrive at a 20-bin histogram-based estimate, call it f X (x ) , of f X (x) . Overlay this estimate in Figure 1. Finally, comment on how good of an estimate f X (x ) is. [NOTE: Save this data set. It will be used again in PROBLEM 5.] Solution: X = 10.08 X =2.01 Comment: These results seem reasonable. (c)(10pts) Use the measure of mean-squared error (mse) to quantify your answers in (b). To this end, at the center point, xk, of the kth bin, define the error ek [ f X ( x) f X ( x)] . Then, for an n-bin based estimate of f X (x) , the estimated mse is n mse (1 / n) ek2 . Solution: mse 105 k 1 PROBLEM 4 (30pts) To investigate the probability structure of your estimators of the mean and standard deviation used in (b), and of the mse estimator used in (c) PROBLEM 3, use 5000 simulations to obtain estimates of To investigate the probability structure of your estimators of the mean and standard deviation used in (b), and of the mse estimator used in (c) PROBLEM 3, use 5000 simulations to obtain estimates of the mean, standard deviation and pdf of each estimator. Solution: (a)(6pts) the mean: Answer: E ( X ) 10 ; E ( X ) 2 ; E ( mse ) 4(10 5 ) (b)(6pts) the standard deviation: Answer: Std ( X ) .06 ; Std ( X ) .046 ; Std (mse ) 2(10 5 ) (c)(18pts) a plot of the pdf of each estimator. PROBLEM 5 (10pts) Using the same data as was used in PROBLEM 3(b) above, view this data as associated with the 2D random variable (X,Y) which is the generation of two successive numbers using normrnd.m. Since each of these random variables is (marginally) the same as the 1-D random variable studied in 3. above, all that is necessary in this problem is to focus on joint properties. In particular, estimate and comment on: (a)(5pts) The covariance between X and Y 500 Solution: ( X ,Y ) .07 . The data is generated from iid { X k }500 k 1 and {Yk }k 1 , hence ( X ,Y ) should be small. Theoretically, it is zero. (b)(5pts) The joint PDF for (X,Y) (Use a 10x10 bin histogram on [0,20]x[0,20]) HINT: You can use an x-y scatter plot, on the grid, then count the number of points in each bin, and finally scale the results to unit volume. Solution: I used the 2D scaled histogram code given in Appendix II. This estimated joint pdf has a circular shape that suggests X and Y are uncorrelated. Histogram-Based Estimate of fXY 4 3 2 y 1 0 -1 -2 -3 -3 -2 -1 0 x 1 2 3 Appendix I %PROGRAM NAME: hw2.m % PROBLEM 3 % 3(a) mx=10; sx=2; x=0:.01:20; fx=normpdf(x,mx,sx); figure(1) plot(x,fx,'LineWidth',2) xlabel('x') title('PDF for X') grid pause % 3(b) n=1000; X=normrnd(mx,sx,n,1); mX=mean(X) sX=std(X) pause db=1;bc=db/2:db:20-db/2; fxhat = hist(X,bc); fxhat=fxhat/(n*db); hold on bar(bc,fxhat,'r') title('True (blue) & Estimated (red) PDFs ') pause fxbc=normpdf(bc,mx,sx); er = fxbc-fxhat; msehat=(er*er')/20 X3 = X; pause % PROBLEM 4 nsim = 5000; MX=[]; SX=[]; Msehat=[]; for m = 1:nsim X=normrnd(mx,sx,n,1); MX=[MX mean(X)]; SX=[SX std(X)]; fxhat = hist(X,bc); fxhat=fxhat/(n*db); er = fxbc-fxhat; Msehat=[Msehat (er*er')/20]; end dbmx=.04; bmx=9.7+dbmx/2:dbmx:10.5-dbmx/2; fmx=hist(MX,bmx); fmx=fmx/(nsim*dbmx); dbsx=.025; bsx=1.75+dbsx/2:dbsx:2.25-dbsx/2; fsx=hist(SX,bsx); fsx=fsx/(nsim*dbsx); dbe=.00025; be=dbe/2:dbe:.005-dbe/2; fe=hist(Msehat,be); fe=fe/(nsim*dbe); figure(2) subplot(3,1,1),bar(bmx,fmx) title('Estimated pdf for muhat') subplot(3,1,2), bar(bsx,fsx) title('Estimated pdf for sigmahat') subplot(3,1,3),bar(be,fe) title('Estimated pdf for msehat') pause mean(MX) std(MX) pause mean(SX) std(SX) pause mean(Msehat) std(Msehat) pause % PROBLEM 5 (The data was saved as X3) xx=X3(1:999); xy=X3(2:1000); covxy=cov(xx,xy) Alternative Code for Problem 4: %HW2 Problem 4 mx=10; sx=2; m=1000; n=5000; X = normrnd(mx,sx,m,n); %Data array %Estimated pdf for muhat: mxhat = mean(X); [fmuhat,bmhat] = hist(mxhat,20); db = bmhat(2)-bmhat(1); fmuhat = fmuhat/(n*db); figure(1) bar(bmhat,fmuhat) pause %Estimated pdf for sighat: sxhat = std(X); [fshat,bshat] = hist(sxhat,20); db = bshat(2)-bshat(1); fshat = fshat/(n*db); figure(2) bar(bshat,fshat) pause %Estimated pdf for mse: dx = 1; %bin width = 8-sigma/20 bx = dx/2 : dx : 20-dx/2; %bin centers fxhat = hist(X,bx)/(m*dx); fx = normpdf(bx,mx,sx); fx = fx'; fx = kron(fx,ones(1,n)); Err2 = (fx - fxhat).^2; Mse = mean(Err2); [fmse,bmse] = hist(Mse,20); db = bmse(2) - bmse(1); fmse = fmse/(n*db); figure(3) bar(bmse,fmse) Appendix II Matlab code for computation of histogram-based joint pdf %PROGRAM NAME: hist2dw.m % Suggested b William Lohry % REQUIRED INPUT: xy = an n x 2 data set nxy = length(xy); minxy = min(xy); maxxy = max(xy); nb = [20 20]; %User-Specified. Change at will. db = (maxxy - minxy)./nb; % Compute the xbin number of each x-value q1 = round((nb(1)-1)*(xy(:,1)-minxy(1))/(maxxy(1)-minxy(1))) + 1; % Compute the ybin number of each y-value q2 = round((nb(2)-1)*(xy(:,2)-minxy(2))/(maxxy(2)-minxy(2))) + 1; h = zeros(nb(2) , nb(1)); fhat = zeros(nb(2),nb(1)); for k = 1:nxy h(q2(k),q1(k)) = h(q2(k),q1(k)) + 1; end for k = 1:nxy fhat(q2(k),q1(k)) = h(q2(k),q1(k))/(nxy*db(1)*db(2)); end bctrx = minxy(1) + db(1)/2 : db(1) : maxxy(1) - db(1)/2; bctry = minxy(2) + db(2)/2 : db(2) : maxxy(2) - db(2)/2; %====================================== % The following is a series of 3 different plot formats figure(1) surface(bctrx,bctry,fhat) xlabel('x') ylabel('y') title('Histogram-Based Estimate of f_X_Y') pause figure(2) mesh(bctrx,bctry,fhat) xlabel('x') ylabel('y') title('Histogram-Based Estimate of f_X_Y') pause figure(3) contour(bctrx,bctry,fhat) xlabel('x') ylabel('y') title('Histogram-Based Estimate of f_X_Y') grid 'minor'