-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLikelihood_Ferson_Challenge.m
74 lines (65 loc) · 2.38 KB
/
Likelihood_Ferson_Challenge.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
function logL = Likelihood_Ferson_Challenge(D, theta)
% Calculation of the log_likelihood for the example in problemA.m
%
% USAGE:
% logL = problemA_log_p_D_theta(D, theta)
%
% INPUTS:
% D = experimental observations nobs x dim_x
% theta = epistemic parameters npar x dim_theta
%
% OUTPUTS:
% logL(i) = loglikelihood for the set of parameters theta(i,:) and the
% data D, i = 1, 2, ...npar. logL = npar x 1
%--------------------------------------------------------------------------
% who when observations
%--------------------------------------------------------------------------
% Diego Andres Alvarez Jul-24-2013 First algorithm
% Rocchetta Roberto Gen-12-2016 Modified for crack detection
%--------------------------------------------------------------------------
% Diego Andres Alvarez - [email protected]
%%
npar = size(theta,1); % number of thetas to evaluate
logL = zeros(npar,1);
for i = 1:npar
logL(i) = sum(log(p_x_theta_pdf(D, theta(i,:))));
%logL(i) = sum((p_x_theta_pdf(D, theta(i,:),net)));
if isinf(logL(i))
logL(i) = -1e10;
end
end
return;
%%
function p = p_x_theta_pdf(x, theta_i)
Mu=theta_i(1);
Sig=theta_i(2);
Vu=theta_i(3);
Omega=theta_i(4);
A=theta_i(5);
B=theta_i(6);
% check the normal distribution parameter,if lbound greater than ubound, fix the likelihoood to infinity and evaluate next theta
if A>B
p=Inf;
return
end
Ns=2000; %MC samples for the probabilistic model to be tested
X = normrnd(Mu,Sig,[Ns,1]);
Y = betarnd(Vu,Omega,[Ns,1]);
Z = unifrnd(A,B,[Ns,1]);
W_model=X.*Y./Z;
%% Estimate the PDF p_x_theta_pdf(x | theta)
%Type 1) f = ksdensity(x,xi) specifies the vector xi of values, where the density
% estimate of the data in x is to be evaluated
p = ksdensity(W_model, x); % p(i) = p_x_theta_pdf(x(i,:) | theta)
%% Type 1) compute 2-sided Kolmogorov-Smirnov test values for each of the samples
% binEdges = [-inf ; sort([x;W_model]) ; inf];
% binCounts1 = histc (x , binEdges, 1);
% binCounts2 = histc (W_model , binEdges, 1);
% sampleCDF1 = cumsum(binCounts1)./sum(binCounts1);
% sampleCDF2 = cumsum(binCounts2)./sum(binCounts2);
%
% ks = abs(sampleCDF1(ismember(binEdges,x))-sampleCDF2(ismember(binEdges,x)))';
% assuming that the ks value are zero mean normally distributed, evaluate
% the value of the normal pdf for these ks.
% p = normpdf(ks);
return;