-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_cdf.m
45 lines (33 loc) · 986 Bytes
/
custom_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
% Cumulative distrtibution function of a random variable
%
% P = CUSTOM_CDF(x, ID, type)
%
%INPUT
% x - value at which we are interested in the cdf value, P(X<x)
% ID - ID value of the distribution (specified in probdata.marg)
% type - definition type of the custom distribution, 'sample' or 'point'
%
%OUTPUT
% P - probability of x not being exceeded
%
%NOTE:
%
function P = custom_cdf(x, ID, type)
persistent S
switch (lower(type))
case 'sample'
% load(['tmp\kernel_sample_', num2str(ID), '.mat'], 'x_grid', 'cdf')
% P = interp1(x_grid, cdf, x);
% %P = interp1(x_grid, cdf, x, 'pchip');
case 'point'
% distribution function is given by discrete points
if isempty(S)
load('tmp\vector_distr_struct.mat', 'S')
end
x_grid = S(ID).x_grid;
cdf = S(ID).cdf;
P = interp1(x_grid, cdf, x);
otherwise
error(['Unknown type: ', type])
end
end