-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathferum_cdf.m
221 lines (159 loc) · 6.67 KB
/
ferum_cdf.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
function P = ferum_cdf(type,x,param)
% Cumulative Density Function
%
%! P = ferum_cdf(type,x,param)
%
% Evaluates the cumulative distribution function and returns the probability.
%
% Output: - P = cumulative density value
% Input: - type = probability distribution type (1: normal, 2: lognormal, ...)
% - x = 'Abscissa' value(s)
%! - param(1) = parameter #1 of the random variable
%! - param(2) = parameter #2 of the random variable (if applicable)
%! - param(3) = parameter #3 of the random variable (if applicable)
%! - param(4) = parameter #4 of the random variable (if applicable)
switch type
case 1 % Normal marginal distribution
mean = param(1);
stdv = param(2);
%!param(3) not relevant
n = param(4);
P = (0.5+erf(((x-mean)/stdv)/sqrt(2))/2).^n;
case 2 % Lognormal marginal distribution
lambda = param(1);
zeta = param(2);
%!param(3) not relevant
n = param(4);
z = ( log(x) - lambda ) / zeta;
P = (0.5+erf(z/sqrt(2))/2).^n;
case 3 % Gamma distribution
lambda = param(1);
k = param(2);
%!param(3) not relevant
n = param(4);
P = (gammainc(lambda*x,k)).^n;
case 4 % Shifted exponential distribution
lambda = param(1);
x_zero = param(2);
%!param(3) not relevant
n = param(4);
P = (1 - exp( -lambda*(x-x_zero) )).^n;
case 5 % Shifted Rayleigh distribution
a = param(1);
x_zero = param(2);
%!param(3) not relevant
n = param(4);
P = (1 - exp( -0.5*( (x-x_zero)/a ).^2 )).^n;
case 6 % Uniform distribution
a = param(1);
b = param(2);
%!param(3) not relevant
n = param(4);
P = ((x-a) / (b-a)).^n;
case 7 % Beta distribution
q = param(1);
r = param(2);
a = param(3);
b = param(4);
x01 = (x-a) / (b-a);
P = betainc(x01,q,r);
case 8 % Chi-square distribution
nu = param(1);
lambda = 0.5;
k = nu/2;
%!param(2) not relevant
%!param(3) not relevant
n = param(4);
P = (gammainc(lambda*x,k)).^n;
case 11 % Type I largest value distribution ( same as Gumbel distribution )
u_n = param(1); % location
a_n = param(2); % inverse scale
%!param(3) not relevant
n = param(4);
P = (exp( -exp( -a_n*(x-u_n) ) )).^n;
case 12 % Type I smallest value distribution
u_1 = param(1);
a_1 = param(2);
%!param(3) not relevant
n = param(4);
P = (1 - exp( -exp( a_1*(x-u_1) ) )).^n;
case 13 % Type II largest value distribution
u_n = param(1);
k = param(2);
%!param(3) not relevant
n = param(4);
P = (exp( -(u_n./x).^k )).^n;
case 14 % Type III smallest value distribution
u_1 = param(1);
k = param(2);
epsilon = param(3);
n = param(4);
P = (1 - exp( -( (x-epsilon) / (u_1-epsilon) ).^k )).^n;
case 15 % Gumbel distribution ( same as type I largest value distribution )
u_n = param(1);
a_n = param(2);
%!param(3) not relevant
n = param(4);
P = (exp( -exp( -a_n*(x-u_n) ) )).^n;
case 16 % Weibull distribution ( same as Type III smallest value distribution with epsilon = 0 )
u_1 = param(1);
k = param(2);
%!param(3) not relevant
n = param(4);
P = (1 - exp( -(x/u_1).^k )).^n;
case 18 % (Reserved for Laplace marginal distribution)
case 19 % (Reserved for Pareto marginal distribution)
case 20 % Generalized extreme value (GEV) distribution
k = param(1); % shape
sigma = param(2); % scale
mu = param(3); % location
n = param(4);
P = (gevcdf(x, k, sigma, mu)).^n;
case 25 % Three-parameter lognormal (LN3) distribution
shape = param(1);
scale = param(2);
thres = param(3);
n = param(4);
P = (lognorm3cdf(x, shape, scale, thres)).^n;
case 30 % sample based custom distibution - typically for non-parametric distributions
% powered option is valid, its effect is directly (numerically) incorporated into the kernel distribution (kernel_sample_*.mat)
ID = param(1);
%!param(2) not relevant
%!param(3) not relevant
%!param(4) not relevant
P = custom_cdf(x, ID, 'sample');
case 31 % vector based custom distibution - typically for non-parametric distributions
% USE 32 INSTEAD OF THIS!
% powered option is not valid
ID = param(1);
%!param(2) not relevant
%!param(3) not relevant
%!param(4) not relevant
P = custom_cdf(x, ID, 'point');
case 32 % generalized non-parametric distribution - vector based
% USE THIS INSTEAD OF 31!
% powered option is not valid
ID = param(1);
shift = param(2);
scale = param(3);
%!param(4) not relevant
P = nonparametric_cdf(x, ID, shift, scale);
case 33 % hardcoded
% USE THIS INSTEAD OF 31!
% powered option is not valid
ID = param(1);
shift = param(2);
scale = param(3);
%!param(4) not relevant
P = hardcoded_cdf(x, ID, shift, scale);
case 51 % Truncated normal marginal distribution
mean = param(1);
stdv = param(2);
xmin = param(3);
xmax = param(4);
P = ( erf(((x-mean)/stdv)/sqrt(2))/2 - erf(((xmin-mean)/stdv)/sqrt(2))/2 ) / ...
( erf(((xmax-mean)/stdv)/sqrt(2))/2 - erf(((xmin-mean)/stdv)/sqrt(2))/2 );
Imin = find(x<xmin); P(Imin) = 0;
Imax = find(x>xmax); P(Imax) = 1;
otherwise
end