source: issm/trunk-jpl/examples/LcurveAnalysis/runme.m@ 23752

Last change on this file since 23752 was 23752, checked in by tsantos, 6 years ago

NEW: example of a L-curve analysis for ice rigidity inversion

File size: 5.1 KB
Line 
1step=[1];
2if any(step==1)
3 % Generate observations
4 md = model;
5 md = triangle(md,'DomainOutline.exp',100000);
6 md = setmask(md,'all','');
7 md = parameterize(md,'Square.par');
8 md = setflowequation(md,'SSA','all');
9 md.cluster = generic('np',2);
10 md = solve(md,'Stressbalance');
11 plotmodel(md,'axis#all','tight','data',md.materials.rheology_B,'caxis',[ 1.3 1.9]*10^8,'title','"True" B',...
12 'data',md.results.StressbalanceSolution.Vel,'title','"observed velocities"')
13 save model1 md
14end
15if any(step==2)
16 % Modify rheology, now constant
17 loadmodel('model1.mat');
18 md.materials.rheology_B(:) = 1.8*10^8;
19
20 %results of previous run are taken as observations
21 md.inversion=m1qn3inversion();
22 md.inversion.vx_obs = md.results.StressbalanceSolution.Vx;
23 md.inversion.vy_obs = md.results.StressbalanceSolution.Vy;
24 md.inversion.vel_obs = md.results.StressbalanceSolution.Vel;
25
26 md = solve(md,'Stressbalance');
27 plotmodel(md,'axis#all','tight','data',md.materials.rheology_B,'caxis',[ 1.3 1.9]*10^8,'title','B first guess',...
28 'data',md.results.StressbalanceSolution.Vel,'title','modeled velocities')
29 save model2 md
30end
31if any(step==3)
32 % Perform L-curve analysis for ice rigidity inversion
33 loadmodel('model2.mat');
34
35 % Set up inversion parameters
36 maxsteps = 20;
37 md.inversion.iscontrol = 1;
38 md.inversion.control_parameters = {'MaterialsRheologyBbar'};
39 md.inversion.maxsteps = maxsteps;
40 md.inversion.cost_functions = [101 502];
41 md.inversion.cost_functions_coefficients = ones(md.mesh.numberofvertices,length(md.inversion.cost_functions));
42 md.inversion.min_parameters = cuffey(273)*ones(md.mesh.numberofvertices,1);
43 md.inversion.max_parameters = cuffey(200)*ones(md.mesh.numberofvertices,1);
44 md.verbose = verbose('solution',false,'control',true);
45
46 % Starting L-curve analysis:
47 %
48 % J = Jo + alpha*R.
49 % J: total cost function to be minimized.
50 % Jo: sum of the objective cost function(s) (ex.: 101, or 101+102, or 101+102+103).
51 % R: regularization term (ex.: 502).
52 % alpha: weight of the regularization term.
53 %
54 % L-curve analysis is a method to find the best value for alpha.
55 % Basicaly, it loops over different values of alpha. A plot can be generated for each
56 % respective value of Jo and R (R versus Jo).
57 %
58 min_alpha = 1.e-20;
59 max_alpha = 1.e-11;
60 nstep_alpha = 30;
61 log_step = (log10(max_alpha)-log10(min_alpha))/nstep_alpha;
62 log_alphas = [log10(min_alpha):log_step:log10(max_alpha)];
63 alphas = 10.^log_alphas;
64 J = zeros(length(alphas),length(md.inversion.cost_functions)+1);
65 % Loop over the alphas
66 for i=1:length(alphas),
67 disp('------------------------------------------------------------');
68 disp([' alpha iteration: ' int2str(i) '/' int2str(length(alphas)) ', alpha value: ' num2str(alphas(i))]);
69 disp('------------------------------------------------------------');
70 md.inversion.cost_functions_coefficients(:,end) = alphas(i);
71 md = solve(md,'Stressbalance');
72 J(i,:) = md.results.StressbalanceSolution.J(end,:); % J comes in [Jo, alphaR, J]. In this example: [101, alpha*502, 101+alpha*502]
73 end
74
75 % Plot the L-curve (log-log)
76 Jo = zeros(length(alphas),1);
77 for i=1:size(J,2)-2,
78 Jo = Jo + J(:,i); % sum of the cost functions (no regularization term). In this example, only 101
79 end
80 R = J(:,end-1)./alphas(:); % only the regularization term
81
82 % Tip:
83 % A rescale in the axes may be useful to visualize the L-curve.
84 %
85 % Remember: J = Jo + alpha*R
86 %
87 % Apply a linear transformation on the original axis (Jo, R):
88 %
89 % | 1 alpha | | Jo | | Jo + alpha*R | | J |
90 % | | | | = | | = | |
91 % | 1/alpha 1 | | R | | Jo/alpha + R | | J/alpha |
92 %
93 % Then, use:
94 % Jo2 = J(:,end);
95 % R2 = J(:,end)./alphas(:);
96 % loglog(Jo2,R2,...
97 %
98 loglog(Jo,R,'-s','Color',[.3 .8 .4],'MarkerSize',6,'MarkerFaceColor','m','MarkerEdgeColor','k','LineWidth',2)
99 voffset=0.1*R;
100 hoffset=0.1*Jo;
101 text(Jo+hoffset,R+voffset,[repmat('\alpha = ',length(alphas),1) num2str(alphas(:),'%2.0e')],...
102 'FontSize',10,'HorizontalAlignment','left','VerticalAlignment','Middle')
103 xlabel('$\mathrm{log}(\mathcal{J}_0$)','Interpreter','latex')
104 ylabel('$\mathrm{log}(\mathcal{R})$','Interpreter','latex')
105end
106if any(step==4)
107 %invert for ice rigidity
108 loadmodel('model2.mat');
109
110 %Set up inversion parameters
111 maxsteps = 20;
112 md.inversion.iscontrol = 1;
113 md.inversion.control_parameters = {'MaterialsRheologyBbar'};
114 md.inversion.maxsteps = maxsteps;
115 md.inversion.cost_functions = [101 502];
116 md.inversion.cost_functions_coefficients = ones(md.mesh.numberofvertices,1);
117 md.inversion.cost_functions_coefficients(:,2) = 4.e-17*ones(md.mesh.numberofvertices,1); % here you can use the best value found for alpha
118 md.inversion.min_parameters = cuffey(273)*ones(md.mesh.numberofvertices,1);
119 md.inversion.max_parameters = cuffey(200)*ones(md.mesh.numberofvertices,1);
120
121 %Go solve!
122 md.verbose=verbose(0);
123 md=solve(md,'Stressbalance');
124 plotmodel(md,'axis#all','tight','data',md.results.StressbalanceSolution.MaterialsRheologyBbar,'caxis',[ 1.3 1.9]*10^8,'title','inferred B',...
125 'data',md.results.StressbalanceSolution.Vel,'title','modeled velocities')
126end
Note: See TracBrowser for help on using the repository browser.