📄 examp.m
字号:
%forward modeling of the cross-well example, with refracted raysclear% convergence enhancementXFAC=1.5;%number of iterations in ray bendingNIT=50;%Travel-time convergence parameterCONV=.000002;%scale of problem (m)SCALE=1600;%scale of problem (receivers, sources and velocity nodes)PSCALE=8;% source and receiver coordinate matricesscz=linspace(0,SCALE,PSCALE); scx=zeros(size(scz));sc=[scx;scz]';rcz=linspace(0,SCALE,PSCALE); rcx=SCALE*ones(size(scz));rc=[rcx;rcz]';% node positions xn, znxn=linspace(-150,SCALE+150,PSCALE)';zn=xn;vbackground=2900;for i=1:PSCALE for j=1:PSCALE vtrue(i,j)=vbackground*...(1+0.10*exp(-.00004*((xn(i)-xn(3*PSCALE/4))^2+(zn(j)-zn(3*PSCALE/4))^2)))*...(1-0.15*exp(-.00004*((xn(i)-xn(PSCALE/2))^2+(zn(j)-zn(PSCALE/2))^2))); endend%linerly interpolate the velocity field for plottingfor i=1:PSCALE xnm(i,:)=xn'; znm(:,i)=zn;endxni=[-150:5:SCALE+150]'; zni=[-150:5:SCALE+150]';for i=1:length(xni) xnim(i,:)=xni'; znim(:,i)=zni;endvi=interp2(xnm,znm,vtrue,xnim,znim,'spline');%plot velocityfigure(1)bookfonts;imagesc(xni,zni,vi)colormap(gray)caxis([2600 3200])H=colorbar;set(H,'FontSize',18);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%now plot the travel times for the model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%hold on%run the forward modeling and plotting functiontstor=plotraypaths(SCALE,PSCALE,NIT,CONV,XFAC,xn,zn,vtrue,sc,rc);hold offtstor%save tstor.mat tstor vtrue%print -deps2 truevelrays.eps%inverse modeling of the cross-well example, with refracted raysclear% convergence enhancementXFAC=1.2;%Maximum number of iterations in ray bendingNIT=50;%Number of linearization stepsMAXITER=5;%tt convergence parameterCONV=1e-4;%noise level (s)NOISE = 0.001;%scale of problem (m)SCALE=1600;%scale of problem (receivers, sources and velocity nodes)PSCALE=8;% source and receiver coordinate matricesscz=linspace(0,SCALE,PSCALE); scx=zeros(size(scz));sc=[scx;scz]';rcz=linspace(0,SCALE,PSCALE); rcx=SCALE*ones(size(scz));rc=[rcx;rcz]';% node positions xn, znxn=linspace(-150,SCALE+150,PSCALE)';zn=xn;%interpolated node positionsxni=[-150:5:SCALE+150]'; zni=[-150:5:SCALE+150]';ivec=[1:length(xni)];xnim(ivec,:)=xni;znim(:,ivec)=zni';%construct the 2-d 2nd order roughening matrix (with model wrap-around)%% Construct a two-dimensional, second-order roughening matrix% for a PSCALE by PSCALE square nodal model (with % model wrap-around)%for i=1:PSCALE for j=1:PSCALE L((j-1)*PSCALE+i,(j-1)*PSCALE+i)=-4;%% Up% if (i>1) L((j-1)*PSCALE+i,(j-1)*PSCALE+i-1)=1; else L((j-1)*PSCALE+i,(j-1)*PSCALE+PSCALE)=1; end%% Down% if (i<PSCALE) L((j-1)*PSCALE+i,(j-1)*PSCALE+i+1)=1; else L((j-1)*PSCALE+i,(j-1)*PSCALE+1)=1; end%% Left% if (j>1) L((j-1)*PSCALE+i,(j-2)*PSCALE+i)=1; else L((j-1)*PSCALE+i,(PSCALE-1)*PSCALE+i)=1; end%% Right% if (j<PSCALE) L((j-1)*PSCALE+i,j*PSCALE+i)=1; else L((j-1)*PSCALE+i,i)=1; end endend%piter corresponds oto a particular choice of alphapiter=0;for piterexp=-2:0.25:1.75piter=piter+1;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%now evaluate the travel time data for this true model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%starting modelvbackground=2900;v=vbackground*ones(PSCALE,PSCALE);%convert velocity to slownessslow=1./v;%iterative slowness model vectorm=reshape(slow,PSCALE*PSCALE,1);wv=zeros(4);%load canned data%load tstorenoise.mat%noise free data and true velocity modelload tstor.mat%generate another realization of observed travel times with noise%ttobs=tstor+NOISE*randn(size(tstor));%save tstorenoise.mat ttobs%...or load a particular realizationload tstorenoise.matmtrue=reshape(1./vtrue,PSCALE*PSCALE,1);vstartvec=reshape(v,PSCALE*PSCALE,1);%path segmentsNSEG=PSCALE*2;% start of iterative model loopcalcrays=0;rpinit=0;for iter=1:MAXITER ttcal=zeros(PSCALE,PSCALE);%get the Jacobian matrix, J, and forward modeled travel times for the working model, v [J,ttcal,rpstore]=getj(SCALE,PSCALE,NIT,CONV,XFAC,xn,zn,v,sc,rc,calcrays,rpinit);%save raypaths to start the next iteration calcrays=1; rpinit=rpstore;%set the regularization tradeoff parameter here if (iter == 1) rparam=norm(J)*10^piterexp; end alphasq(piter)=rparam;%calculate the travel-time residual vector for this iteration r=ttcal-ttobs; rvec=reshape(r,PSCALE*PSCALE,1); rms(iter)=sqrt(rvec'*rvec);%LM, fixed alpha%J1= J'*J+rparam*L'*L;%rhs=J'*rvec;%dm=J1\rhs;%GN, explicit zeroth order regularization J1= J'*J+rparam*L'*L; rhs=-(J'*rvec+rparam*L'*L*m); dm=J1\rhs;%model update m=m+dm; slow=reshape(m,PSCALE,PSCALE); mnslow=mean(mean(slow)); v=1./slow;%run the forward model to document variance reduction at this step [K,tttry,rpstore]=getj(SCALE,PSCALE,NIT,CONV,XFAC,xn,zn,v,sc,rc,calcrays,rpinit); rtry=ttobs-tttry; dtry=reshape(rtry,PSCALE*PSCALE,1); rmstry=sqrt(dtry'*dtry); disp('rms, rmsnew, sqrt(chi^2)') [iter rmstry NOISE*PSCALE] misfit(piter,iter)=rmstry; mnorm(piter,iter)=norm(L*m);%rms difference wrt true model disp('rms(mtrue-slow):') mrms(piter,iter)= norm((mtrue-m)); figure(2) bookfonts%linerly interpolate the velocity field for plotting for i=1:PSCALE xnm(i,:)=xn'; znm(:,i)=zn; end vi=interp2(xnm,znm,v,xnim,znim,'spline'); caxis([2300 3200]) imagesc(xni,zni,vi) colormap('gray') H=colorbar set(H,'FontSize',18); drawnow; pause(0.1);% end of tomography inversion loopendvstore(piter,:,:)=vi;% end of regularization parameter loopend%show results for the various regularization parameters%plot convergence curvesfigure(3)bookfontsplot(1:iter,misfit)xlabel('Iteration')ylabel('Residual Norm, ||G(m)-d||_2')figure(4)bookfontssemilogy(1:iter,mnorm)xlabel('Iteration')ylabel('Solution Seminorm, ||Lm||_2')figure(5)bookfonts;loglog(misfit(1:piter,MAXITER),mnorm(1:piter,MAXITER),'ok-')xlabel('Residual Norm, ||G(m)-d||_2')ylabel('Solution Seminorm, ||Lm||_2')axis([.001 .1 .00001 .001])hold onloglog([NOISE*PSCALE,NOISE*PSCALE],[.00001,.001],'k--')for i=1:2:pitertext(misfit(i,MAXITER),mnorm(i,MAXITER),[' ',num2str(sqrt(alphasq(i)))]);endtext(NOISE*PSCALE,.000015,' \delta=0.008')hold off%print -deps2 bendlcurve.epsfigure(6)bookfonts;semilogx(sqrt(alphasq),mrms(1:piter,MAXITER),'ok-')xlabel('\alpha')ylabel('||m_{true}-m||_2')hold onsemilogx(sqrt(alphasq(9)),mrms(9,MAXITER),'*')for i=[1,9,16]text(sqrt(alphasq(i)),mrms(i,MAXITER)+.000002,[' ',num2str(sqrt(alphasq(i)))]);endhold off%print -deps2 mmisfit.epsfigure(7)for i=1:pitersubplot(4,4,i)vtmp1=vstore(i,:,:);vtmp(:,:)=vtmp1;imagesc(vtmp)caxis([2600 3200])axis squareset(gca,'xticklabel','')set(gca,'yticklabel','')title(['\alpha = ',num2str(sqrt(alphasq(i)))])colormap('gray')end%print -deps2 allmodels.epsfigure(8)bookfontsvtmp1=vstore(9,:,:);vtmp(:,:)=vtmp1;imagesc(xn,zn,vtmp)caxis([2600 3200])axis squarexlabel('m')ylabel('m')colormap('gray')H=colorbarset(H,'FontSize',18);%print -deps2 bestmodel.eps%% Save the results.%%save workspace.mat
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -