% This is the top-level program. It first runs probsetup.m to construct the arrays % of probabilities in the form required by the model. We then form the array W of % boundary conditions for the final half inning, and the run the program inning.m % to compute the array V of win probabilities in the various states. From V we compute % a new boundary array W applicable to the chronologically prior half inning, then % use inning.m again, and so on. % Copyright 2004 William S. Krasker numextrainnings=8; maxlead=25; dtop=2*maxlead+1; W=zeros(dtop,9,9); % compute the required probabilities probsetup % boundary conditions for bottom half of final extra inning for i=1:9 for j=1:9 for d=1:dtop if d <= maxlead W(d,i,j)=0; elseif d==maxlead+1 W(d,i,j)=0.5; else W(d,i,j)=1; end end end end % set parameters for bottom half of final extra inning psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; % run bottom half of final extra inning inning % boundary conditions for top half of final extra inning for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end % set parameters for top half of final extra inning psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; % run top half of final extra inning inning %------------------------------------------------------------------ % loop for regular (non-final) extra innings for count=1:numextrainnings for i=1:9 for j=1:9 for d=1:dtop if d <= maxlead W(d,i,j)=0; elseif d==maxlead+1 W(d,i,j)=1-V(i,d,outs0,b0,nobody,j); else W(d,i,j)=1; end end end end psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning end %------------------------------------------------------------------ % bottom of 10th for i=1:9 for j=1:9 for d=1:dtop if d <= maxlead W(d,i,j)=0; elseif d==maxlead+1 W(d,i,j)=1-V(i,d,outs0,b0,nobody,j); else W(d,i,j)=1; end end end end psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 10th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 9th for i=1:9 for j=1:9 for d=1:dtop if d <= maxlead W(d,i,j)=0; elseif d==maxlead+1 W(d,i,j)=1-V(i,d,outs0,b0,nobody,j); else W(d,i,j)=1; end end end end Wbot9=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 9th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop9=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 8th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot8=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 8th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop8=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 7th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot7=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 7th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop7=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 6th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot6=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 6th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop6=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 5th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot5=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 5th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop5=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 4th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot4=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 4th for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop4=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 3rd for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot3=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 3rd for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop3=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 2nd for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot2=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 2nd for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop2=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning %------------------------------------------------------------------ % bottom of 1st for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wbot1=W; psteal=pstealhome; sacbunt=sacbunthome; probs=probshome; inning % top of 1st for i=1:9 for j=1:9 for d=1:dtop W(d,i,j)=1-V(i,dtop-d+1,outs0,b0,nobody,j); end end end Wtop1=W; psteal=pstealaway; sacbunt=sacbuntaway; probs=probsaway; inning