Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
192 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function objv = fmm_em_evalobjv(pb, sol) | ||
%FMM_EM_EVALOBJV Evaluates objective of EM estimation for FMM | ||
% | ||
% objv = FMM_EM_EVALOBJV(pb, sol); | ||
% | ||
|
||
mdl = pb.model; | ||
w = pb.weights; | ||
pric = pb.pricount; | ||
|
||
Q = sol.Q; | ||
n = size(Q, 2); | ||
|
||
if isempty(w) | ||
w = ones(n, 1); | ||
end | ||
|
||
% sum of observation log-likelihoods | ||
|
||
L = sol.logliks; | ||
if isempty(L) | ||
L = evaluate_loglik(mdl, sol.components, pb.obs); | ||
end | ||
|
||
sll_obs = sum(L .* Q, 1) * w; | ||
|
||
% sum of assignment log-likelihoods | ||
|
||
log_pi = log(sol.pi); | ||
sll_q = log_pi' * (Q * w); | ||
|
||
% sum of component log-priors | ||
|
||
lpri_comp = evaluate_logpri(mdl, sol.components); | ||
lpri_comp = sum(lpri_comp); | ||
|
||
% the log-prior of pi | ||
|
||
if pric > 0 | ||
lpri_pi = pric * sum(log_pi); | ||
else | ||
lpri_pi = 0; | ||
end | ||
|
||
% entropy of Q | ||
|
||
ent_q = - (nansum(Q .* log(Q), 1) * w); | ||
|
||
% overall | ||
|
||
objv = sll_obs + sll_q + lpri_comp + lpri_pi + ent_q; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function sol = fmm_em_update(pb, sol) | ||
%PLI_FMM_EM_UPDATE Update an EM solution of Finite mixture estimation | ||
% | ||
% sol = PLI_FMM_EM_UPDATE(pb, sol); | ||
% | ||
|
||
mdl = pb.model; | ||
n = pb.nobs; | ||
obs = pb.obs; | ||
w = pb.weights; | ||
pric = pb.pricount; | ||
|
||
% M-step | ||
|
||
if isempty(w) | ||
pi = sol.Q * ones(n, 1); | ||
W = sol.Q.'; | ||
else | ||
pi = sol.Q * w; | ||
W = bsxfun(@times, sol.Q.', w); | ||
end | ||
|
||
if pric > 0 | ||
pi = pi + pric; | ||
end | ||
pi = pi / sum(pi); | ||
|
||
params = update_params(mdl, obs, W, [], sol.components); | ||
L = evaluate_loglik(mdl, params, obs); | ||
|
||
% E-step | ||
|
||
Q = pli_nrmexp(bsxfun(@plus, L, log(pi)), 1); | ||
|
||
% write update to sol | ||
|
||
sol.pi = pi; | ||
sol.components = params; | ||
sol.logliks = L; | ||
sol.Q = Q; | ||
|