forked from tsipkens/odias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_dma.m
155 lines (113 loc) · 3.05 KB
/
main_dma.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
% MAIN Inversion of mobility distributions.
% AUTHOR: Timothy Sipkens, 2020-04-11
%=========================================================================%
clear;
close all;
addpath cmap;
d = logspace(log10(10), log10(1e3), 500)'; % reconstruction points
d_star = logspace(log10(13.1), log10(200), 114)'; % mobility setpoints
% 763.5
prop = tfer.prop_dma;
A = kernel.gen_smps(d_star, d, [], prop);
mu_d = [200, 200/3];
s_d = [1.55, 1.55 / 1.15];
w_d = [1, 0.5];
%{
mu_d = 200;
s_d = 1.2;
w_d = 1;
%}
[b, Lb, x0] = tools.gen_data(A, d, mu_d, s_d, w_d, d_star);
% [b, Lb, x0] = tools.gen_data(A, d, 75, 1.1, w_d, d_star);
% b = A * x0; Lb = eye(length(b));
%%
disp(' ');
%-- Least-squares ---------%
disp('Running least-squares ...');
x_lsq = invert.lsq(Lb * A, Lb * b);
tools.textdone();
disp(' ');
%-- Twomey ----------------%
disp('Running Twomey:');
xi = invert.get_init(Lb * A, Lb * b, d, d_star);
x_two = invert.twomey(Lb * A, Lb * b, xi, [], 1, 1);
disp(' ');
%-- Twomey-Markowski ------%
disp('Running Twomey-Markowski:');
xi = invert.get_init(Lb * A, Lb * b, d, d_star);
x_twomark = invert.twomark(Lb * A, Lb * b, length(xi), xi);
disp(' ');
%-- 1st order Tikhonov ----%
disp('Running Tikhonov (1st) ...');
lambda_tk1 = 3.8e1;
[x_tk1, ~, ~, Gpo_inv_tk1] = ...
invert.tikhonov(Lb * A, Lb * b, lambda_tk1, 1);
Gpo_tk1 = inv(Gpo_inv_tk1);
e.tk1 = (x_tk1 - x0)' * Gpo_inv_tk1 * (x_tk1 - x0);
tools.textdone();
disp(' ');
%-- 2nd order Tikhonov ----%
disp('Running Tikhonov (2nd) ...');
lambda_tk2 = 1e3;
[x_tk2, ~, ~, Gpo_inv_tk2] = ...
invert.tikhonov(Lb * A, Lb * b, lambda_tk2, 2);
Gpo_tk2 = inv(Gpo_inv_tk2);
e.tk2 = (x_tk2 - x0)' * Gpo_inv_tk2 * (x_tk2 - x0);
tools.textdone();
disp(' ');
%-- Two-step 2nd order Tikhonov --%
disp('Running Tikhonov (2nd, two-step) ...');
lambda_tk2 = 3e3;
[x_tk22, ~, ~, Gpo_inv_tk22] = ...
invert.tikhonov(Lb * A, Lb * b, lambda_tk2, 2, [], 1);
Gpo_tk22 = inv(Gpo_inv_tk22);
e.tk22 = (x_tk22 - x0)' * Gpo_inv_tk2 * (x_tk22 - x0);
tools.textdone();
disp(' ');
%-- Exponential distance --%
disp('Running exponential distance ...');
lambda_ed = 1e1;
ld = log10(s_d(1));
[x_ed, ~, ~, Gpo_inv_ed] = ...
invert.exp_dist(Lb * A, Lb * b, lambda_ed, ld, d);
Gpo_ed = inv(Gpo_inv_ed);
e.ed = (x_ed - x0)' * Gpo_inv_ed * (x_ed - x0);
tools.textdone();
disp(' ');
disp(' ');
e
%%
figure(2);
x_tk = x_tk22;
Gpo_tk = Gpo_tk22;
subplot(2, 3, 1);
tools.plotci(d, x_tk1, Gpo_tk1, x0);
title('Tikhonov (1st)');
subplot(2, 3, 2);
tools.plotci(d, x_tk2, Gpo_tk2, x0);
title('Tikhonov (2nd)');
subplot(2, 3, 3);
tools.plotci(d, x_tk, Gpo_tk, x0);
title('Tikhonov (2nd, two-step)');
subplot(2, 3, 4);
tools.plotci(d, x_ed, Gpo_ed, x0);
title('Exponential distance');
subplot(2, 3, 5);
tools.plotci(d, x_two, [], x0);
title('Twomey');
hold on;
plot(d, xi, 'b--');
hold off;
subplot(2, 3, 6);
tools.plotci(d, x_twomark, [], x0);
title('Twomey-Markowski');
hold on;
plot(d, xi, 'b--');
hold off;
%%
% Optimize Tikhonov + show Bayes factor.
%{
[a0, a1, a2] = invert.tikhonov_op(Lb*A,Lb*b,[1e-1,1e3],2);
figure(3);
semilogx([a2.lambda], -[a2.B]);
%}