1classdef EmpiricalCDF < Distribution
2 % Empirical Cdf
for a distribution
4 % Copyright (c) 2012-2026, Imperial College London
13 function self = EmpiricalCDF(xdata,cdfdata)
14 % SELF = EMPIRICAL(data)
15 self@Distribution(
'EmpiricalCdf',2,[-Inf,Inf]);
19 self.data = unique([cdfdata,xdata],
'rows');
23 function X = sample(self, n)
25 % Get n samples from the distribution
27 xset = find(self.data(:,1)<1); % remove duplicates when numerically F(x)=1
28 X = interp1(self.data(xset,1),self.data(xset,2),Y(:),
'spline',
'extrap');
31 function RATE = getRate(self)
33 % Get distribution rate
34 RATE = 1 / getMean(self);
37 function MEAN = getMean(self)
39 % Get distribution mean
40 MEAN = getMoments(self);
43 function SCV = getSCV(self)
45 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
46 [~,~,~,SCV,~] = getMoments(self);
49 function VAR = getVar(self)
51 % Get distribution variance
52 VAR = getSCV(self)*getMean(self)^2;
55 function SKEW = getSkewness(self)
56 % SKEW = GETSKEWNESS()
57 % Get distribution skewness
58 [~,~,~,~,SKEW] = getMoments(self);
61 function Ft = evalCDF(self,t)
62 % FT = EVALCDF(SELF,T)
63 % Evaluate the cumulative distribution function at t
64 xset = find(self.data(:,1)<1); % remove duplicates when numerically F(x)=1
65 self.data(xset,1),self.data(xset,2)
66 Ft = interp1(self.data(xset,1),self.data(xset,2),t,
'spline',
'extrap');
69 function L = evalLST(self, s)
71 % Evaluate the Laplace transform of the distribution function at t
73 row = size(cdfdata,1);
74 L = 0; % the first moment
76 x = ((cdfdata(i+1,2)-cdfdata(i,2))/2+cdfdata(i,2));
77 bin1 = exp(-s*x)*((cdfdata(i+1,1)-cdfdata(i,1)));
82 function [m1,m2,m3,SCV,SKEW] = getMoments(self)
84 row = size(cdfdata,1);
85 m1 = 0; % the first moment
86 m2 = 0; % the second moment
87 m3 = 0; % the third moment
89 x = ((cdfdata(i+1,2)-cdfdata(i,2))/2+cdfdata(i,2));
90 bin1 = x*((cdfdata(i+1,1)-cdfdata(i,1)));
91 bin2 = x^2*((cdfdata(i+1,1)-cdfdata(i,1)));
92 bin3 = x^3*((cdfdata(i+1,1)-cdfdata(i,1)));
98 SKEW = (m3-3*m1*(m2-m1^2)-m1^3)/((m2-m1^2)^(3/2));