-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_cdf.m
More file actions
70 lines (49 loc) · 1.41 KB
/
plot_cdf.m
File metadata and controls
70 lines (49 loc) · 1.41 KB
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
function rmse_err = plot_cdf (samples, pd)
% Ali Mohammadi_INS/GNSS
% plot_cdf: plots cumulative distribution function (CDF) from samples
% (empirical CDF) and compares to inferred CDF (reference CDF)
%
% INPUT
% samples: Nx1 samples.
% pd: probality distribution object from ProbabilityDistribution class.
%
% OUTPUT
% rmse_err: RMSE between the two curves.
% figure with real CDF and ideal CDF.
%% PLOT PARAMETERS
font_tick = 12;
font_label = 16;
line_wd = 3;
blue_new = [0 0.4470 0.7410];
orange_new = [0.8500 0.3250 0.0980];
%% Only plot 1-sigma elements
M = 1;
sig = pd.sigma;
mu = pd.mu;
edge = abs(M * sig + mu);
idx = find (samples > -edge, 1, 'first');
fdx = find (samples < edge, 1, 'last');
samples = samples(idx:fdx);
%% IDEAL CDF
N = length(samples);
x = linspace(min(samples), max(samples), N );
ideal_cdf = normcdf(x, mu, sig)';
%% REAL CDF
x_sort = sort(samples);
real_cdf = ( (1:N) - 0.5)' ./ N;
% Root mean squared error
rmse_err = rmse(ideal_cdf, real_cdf);
%% PLOT
h = plot(x, ideal_cdf, '--', 'LineWidth', 2, 'Color', orange_new);
hold on
s = stairs(x_sort, real_cdf,'-.', 'LineWidth', 2, 'Color', blue_new);
legend([h, s], 'Ideal CDF', 'Real CDF' )
xl = xlabel('Samples');
% yl = ylabel('Cumulative probability (CDF)');
grid
hold off
set(h,'Linewidth', line_wd );
set(gca, 'YTickMode', 'auto', 'FontSize', font_tick);
set(xl,'FontSize', font_label);
% set(yl,'FontSize', font_label);
end