-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathferum_pdf.m
302 lines (224 loc) · 9.67 KB
/
ferum_pdf.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
function p = ferum_pdf(type,x,param)
% Probability Density Function
%
%! p = ferum_pdf(type,x,param)
%
% Evaluates probability density function and return the corresponding density value.
%
% Output: - p = probability 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 distribution
mean = param(1);
stdv = param(2);
%!param(3) not relevant
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = 1/( sqrt(2*pi) * stdv ) * exp( -1/2 * ((x-mean)/stdv).^2 );
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 2 % Lognormal marginal distribution
lambda = param(1); %mu
zeta = param(2); %sigma
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = 1./( sqrt(2*pi) * zeta * x ) .* exp( -1/2 * ((log(x)-lambda)/zeta).^2 );
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 3 % Gamma distribution
lambda = param(1);
k = param(2);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = lambda * (lambda*x).^(k-1) / gamma(k) .* exp(-lambda*x);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 4 % Shifted exponential distribution
lambda = param(1);
x_zero = param(2);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = lambda * exp(-lambda*(x-x_zero));
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 5 % Shifted Rayleigh distribution
a = param(1);
x_zero = param(2);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = (x-x_zero)/a^2 .* exp(-0.5*((x-x_zero)/a).^2);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 6 % Uniform distribution
a = param(1);
b = param(2);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = 1 / (b-a);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 7 % Beta distribution - NO powered option is avaialable!
q = param(1);
r = param(2);
a = param(3);
b = param(4);
p = (x-a).^(q-1) .* (b-x).^(r-1) / ( (gamma(q)*gamma(r)/gamma(q+r)) * (b-a)^(q+r-1) );
case 8 % Chi-square distribution
nu = param(1);
lambda = 0.5;
k = nu/2;
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = lambda * (lambda*x).^(k-1) .* exp(-lambda*x) / gamma(k);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 11 % Type I largest value distribution ( same as Gumbel distribution )
u_n = param(1);
a_n = param(2);
%!param(3) not relevant
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = a_n * exp( -a_n*(x-u_n) - exp(-a_n*(x-u_n)) );
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 12 % Type I smallest value distribution
u_1 = param(1);
a_1 = param(2);
%!param(3) not relevant
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = a_1 * exp( a_1*(x-u_1) - exp(a_1*(x-u_1)) );
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 13 % Type II largest value distribution
u_n = param(1);
k = param(2);
%!param(3) not relevant
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = k/u_n * (u_n./x).^(k+1) .* exp(-(u_n./x).^k);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 14 % Type III smallest value distribution
u_1 = param(1);
k = param(2);
epsilon = param(3);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = k/(u_1-epsilon) * ((x-epsilon)/(u_1-epsilon)).^(k-1) ...
.* exp(-((x-epsilon)/(u_1-epsilon)).^k);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
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);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = a_n * exp( -a_n*(x-u_n) - exp(-a_n*(x-u_n)) );
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
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);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = k/u_1 * (x/u_1).^(k-1) .* exp(-(x/u_1).^k);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 18 % (Reserved for Laplace marginal distribution)
case 19 % (Reserved for Pareto marginal distribution)
case 20 % Generalized extreme value (GEV) distribution
k = param(1);
sigma = param(2);
mu = param(3);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = gevpdf(x, k, sigma, mu);
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
case 25 % Three-parameter lognormal (LN3) distribution
shape = param(1);
scale = param(2);
thres = param(3);
n = param(4);
if n == 1 % not powered distribution, to avoid finite difference calculation
p = lognorm3pdf(x, shape, scale, thres, 'par');
else % powered distribution
Fn = @(x) ferum_cdf(type, x, param);
p = cfd(Fn, x);
end
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_pdf(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_pdf(x, ID, 'point');
case 32 % generalized non-parametric distribution - vector based
% USE THIS INSTEAD OF 31!
% powered option is not valid
ID = param(1);
location = param(2);
scale = param(3);
%!param(4) not relevant
p = nonparametric_pdf(x, ID, location, scale);
case 33 % hardcoded
ID = param(1);
location = param(2);
scale = param(3);
%!param(4) not relevant
p = hardcoded_pdf(x, ID, location, scale);
case 51 % Truncated normal marginal distribution; NO powered option is avaialable!
mean = param(1);
stdv = param(2);
xmin = param(3);
xmax = param(4);
p = 1/(normcdf((xmax-mean)/stdv)-normcdf((xmin-mean)/stdv)) * 1/( sqrt(2*pi) * stdv ) * exp( -1/2 * ((x-mean)/stdv).^2 );
Imin = find(x<xmin); p(Imin) = 0;
Imax = find(x>xmax); p(Imax) = 0;
otherwise
end
end