资源简介
Matlab LDA降维经典程序,新手或参考,不错的资源。
代码片段和文件信息
function [ldagammaldaphilikelihood]=ldainference(dab)
% LDAINFERENCE
%
% function [ldagammaldaphilikelihood]=ldainference(dab)
%
% Variational inference algorithm for the LDA Model
%
% input: (document vector corpus parameters
% d is a Nx1 word occurrence vector
% a is a kx1 dirichlet parameter
% b is a kxV matrix
% output: (variational parameters)
% ldagamma is a kx1 vector
% ldaphi is a kxN matrix
% likelihood is the (variational) log likelihood of
% the document.
%
% where V is the size of the vocabulary
% k is the # of topics
% N is the number of words in d (sum(d))
%
% Authors: Jonathan Huang (jch1 at cs.cmu.edu)
% Tomasz Malisiewicz (tomasz at cmu.edu)
epsilon = .00001; % convergence criterion
V = size(b2);
k = length(a);
N = length(d);
% initialize variational parameters
ldaphi = repmat(1/kkN);
ldagamma = a + repmat(N/kk1);
oldphi=ldaphi;
oldgamma=ldagamma;
maxiter = 200;
numiter = 1;
change=2*epsilon;
% until convergence...
while change>epsilon
oldphi=ldaphi;
oldgamma=ldagamma;
ldaphi = b(:d).*repmat(exp(digamma(ldagamma))1N);
ldaphi = ldaphi ./ repmat(sum(ldaphi)k1);
ldagamma = a + sum(ldaphi‘)‘;
change = max(max(abs(ldagamma-oldgamma)) ...
max(max(abs(ldaphi-oldphi))));
numiter = numiter + 1;
if (numiter > maxiter)
break
end
end
dig = digamma(ldagamma);
digsum = digamma(sum(ldagamma));
likelihood=gammaln(sum(a))-sum(gammaln(a)) + sum((a-1).*(dig-digsum)) ...
- gammaln(sum(ldagamma))+sum(gammaln(ldagamma)) ...
- sum((ldagamma-1).*(dig-digsum)) - sum(sum(ldaphi.*log(ldaphi))) ...
+ (dig-digsum)‘*sum(ldaphi2) + sum(sum(ldaphi.*log(b(:d))));
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2008-04-22 17:08 Jonathan Huang
文件 1812 2008-04-22 16:59 Jonathan Huang\ldainference.m
文件 3991 2008-04-22 16:59 Jonathan Huang\lda_param_est.m
文件 1401 2008-04-22 16:59 Jonathan Huang\trainLDA.m
----------- --------- ---------- ----- ----
7204 4
- 上一篇:FDTD算法的Matlab源程序
- 下一篇:求解水分运动方程
评论
共有 条评论