-
-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathplot_cdf.m
More file actions
executable file
·77 lines (64 loc) · 2.04 KB
/
plot_cdf.m
File metadata and controls
executable file
·77 lines (64 loc) · 2.04 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
71
72
73
74
75
76
function rmse_err = plot_cdf (data, pd, x_label, x_title)
% 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.
% x_label: label for X axis (string).
% x_title: title for the figure (string).
%
% OUTPUT
% rmse_err: RMSE between the two curves.
% figure with empirical CDF and reference CDF.
%
% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.
%
% This file is part of NaveGo, an open-source MATLAB toolbox for
% simulation of integrated navigation systems.
%
% NaveGo is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License (LGPL)
% version 3 as published by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this program. If not, see
% <http://www.gnu.org/licenses/>.
%
% Reference:
%
%
% Version: 003
% Date: 2021/03/02
% Author: Rodrigo Gonzalez <rodralez@frm.utn.edu.ar>
% URL: https://github.com/rodralez/navego
%% REFERENCE CDF
N = length(data);
sig = pd.sigma;
mu = pd.mu;
x = linspace(min(data), max(data), N );
ref_cdf = normcdf(x, mu, sig)';
%% EMPIRICAL CDF
x_sort = sort(data);
emp_cdf = ( (1:N) - 0.5)' ./ N;
% Root mean squared error
rmse_err = rmse(ref_cdf, emp_cdf);
%% PLOT
blue_new = [0 0.4470 0.7410];
orange_new = [0.8500 0.3250 0.0980];
figure
p1 = plot(x, ref_cdf, '-.', 'LineWidth', 2, 'Color', orange_new);
hold on
p2 = stairs(x_sort, emp_cdf,'-', 'LineWidth', 2, 'Color', blue_new);
xlabel(x_label);
ylabel('Cumulative probability (CDF)');
legend([p1, p2], 'Reference CDF', 'Empirical CDF' )
title(x_title)
grid
hold off
end