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

Last change on this file was 25986, checked in by jdquinn, 4 years ago

CHG: Cleanup

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